VTK  9.3.1
vtkChartXYZ.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
3 
14 #ifndef vtkChartXYZ_h
15 #define vtkChartXYZ_h
16 
17 #include "vtkChartsCoreModule.h" // For export macro
18 #include "vtkColor.h" // For vtkColor4ub
19 #include "vtkContextItem.h"
20 #include "vtkNew.h" // For ivars
21 #include "vtkRect.h" // For vtkRectf ivars
22 #include "vtkSmartPointer.h" // For ivars
23 #include "vtkStdString.h" // For vtkStdString
24 #include "vtkTextProperty.h" // For axes text properties
25 #include <vector> // For ivars
26 
27 VTK_ABI_NAMESPACE_BEGIN
28 class vtkAnnotationLink;
29 class vtkAxis;
30 class vtkContext3D;
32 class vtkPen;
33 class vtkPlaneCollection;
34 class vtkPlot3D;
35 class vtkTable;
36 class vtkTransform;
38 
39 class VTKCHARTSCORE_EXPORT vtkChartXYZ : public vtkContextItem
40 {
41 public:
42  vtkTypeMacro(vtkChartXYZ, vtkContextItem);
43  void PrintSelf(ostream& os, vtkIndent indent) override;
44 
45  static vtkChartXYZ* New();
46 
56  void SetGeometry(const vtkRectf& bounds);
57 
65  void SetMargins(const vtkVector4i& margins);
66 
70  vtkSetMacro(Angle, double);
71 
75  void SetAroundX(bool isX);
76 
80  virtual void SetAnnotationLink(vtkAnnotationLink* link);
81 
85  vtkAxis* GetAxis(int axis);
86 
90  virtual void SetAxis(int axisIndex, vtkAxis* axis);
91 
93 
96  void SetAxisColor(const vtkColor4ub& color);
97  vtkColor4ub GetAxisColor();
99 
119  vtkTextProperty* GetAxesTextProperty();
120 
124  vtkSetMacro(XAxisLabel, vtkStdString);
125 
129  vtkSetMacro(YAxisLabel, vtkStdString);
130 
134  vtkSetMacro(ZAxisLabel, vtkStdString);
135 
141  vtkSetMacro(EnsureOuterEdgeAxisLabelling, bool);
142 
147  vtkSetMacro(AutoRotate, bool);
148 
153  void SetDecorateAxes(bool b);
154 
159  void SetFitToScene(bool b);
160 
164  void Update() override;
165 
169  bool Paint(vtkContext2D* painter) override;
170 
174  virtual vtkIdType AddPlot(vtkPlot3D* plot);
175 
179  virtual bool RemovePlot(vtkPlot3D* plot);
180 
184  void ClearPlots();
185 
190  void RecalculateBounds();
191 
197  void RecalculateTransform();
198 
202  bool Hit(const vtkContextMouseEvent& mouse) override;
203 
207  bool MouseButtonPressEvent(const vtkContextMouseEvent& mouse) override;
208 
212  bool MouseMoveEvent(const vtkContextMouseEvent& mouse) override;
213 
217  bool MouseWheelEvent(const vtkContextMouseEvent& mouse, int delta) override;
218 
224  bool KeyPressEvent(const vtkContextKeyEvent& key) override;
225 
229  void SetClippingPlanesEnabled(bool);
230 
234  vtkGetMacro(ClippingPlanesEnabled, bool);
235 
239  vtkSetMacro(ScaleBoxWithPlot, bool);
240 
244  vtkGetMacro(ScaleBoxWithPlot, bool);
245 
246 protected:
247  vtkChartXYZ();
248  ~vtkChartXYZ() override;
249 
254  {
257  UP,
258  DOWN
259  };
260 
265  {
271  STANDARD
272  };
273 
278  {
286  NORTH_WEST
287  };
288 
294  virtual void CalculateTransforms();
295 
302  bool CalculatePlotTransform(vtkAxis* x, vtkAxis* y, vtkAxis* z, vtkTransform* transform);
303 
307  bool Rotate(const vtkContextMouseEvent& mouse);
308 
312  bool Rotate(RotateDirection rotateDirection);
313 
317  bool Pan(const vtkContextMouseEvent& mouse);
318 
322  bool Zoom(const vtkContextMouseEvent& mouse);
323 
327  bool Spin(const vtkContextMouseEvent& mouse);
328 
332  void LookDownX();
333 
337  void LookDownY();
338 
342  void LookDownZ();
343 
347  void LookUpX();
348 
352  void LookUpY();
353 
357  void LookUpZ();
358 
362  bool CheckForSceneResize();
363 
367  void RescaleAxes();
368 
372  void ScaleUpAxes();
373 
377  void ScaleDownAxes();
378 
382  void ZoomAxes(int delta);
383 
388  void InitializeAxesBoundaryPoints();
389 
399  void InitializeFutureBox();
400 
404  void ComputeDataBounds();
405 
409  void DrawAxes(vtkContext3D* context);
410 
415  void DetermineWhichAxesToLabel();
416 
421  void NewDetermineWhichAxesToLabel();
422 
427  void LegacyDetermineWhichAxesToLabel();
431  void DrawTickMarks(vtkContext2D* painter);
432 
436  void DrawAxesLabels(vtkContext2D* painter);
437 
443  void GetOffsetForAxisLabel(int axis, float* bounds, float* offset);
444 
450  double CalculateNiceMinMax(double& min, double& max, int axis);
451 
455  void GetClippingPlaneEquation(int i, double* planeEquation);
456 
460  std::size_t GetMarginLeft() const;
461 
465  std::size_t GetMarginBottom() const;
466 
470  std::size_t GetPlotWidth() const;
471 
475  std::size_t GetPlotHeight() const;
476 
480  enum
481  {
483  USE_GEOMETRY
484  } SizeStrategy = USE_GEOMETRY;
485 
490  vtkVector4i Margins = vtkVector4i(40, 40, 40, 40);
491 
496  vtkRectf Geometry = vtkRectf(40, 40, 120, 120);
497 
501  std::vector<vtkSmartPointer<vtkAxis>> Axes;
502 
507  bool AutoRotate = false;
508 
513  bool IsX = false;
514 
519  double Angle = 0;
520 
525  bool DrawAxesDecoration = true;
526 
531  bool FitToScene = true;
532 
537 
544 
549 
554 
560 
566 
572 
579 
584 
589 
594 
599 
603  std::vector<vtkPlot3D*> Plots;
604 
608  std::vector<vtkIdType> FreePlaces;
609 
614 
619 
624 
629 
635  bool EnsureOuterEdgeAxisLabelling = false;
640 
645  float AxesBoundaryPoints[8][3];
646 
651  float TickLabelOffset[3][2];
652 
657 
662 
664 
667  int XAxisToLabel[3];
668  int YAxisToLabel[3];
669  int ZAxisToLabel[3];
671 
675  int DirectionToData[3];
676 
680  double DataBounds[4];
681 
685  bool ClippingPlanesEnabled = true;
686 
690  bool ScaleBoxWithPlot = true;
691 
692 private:
693  vtkChartXYZ(const vtkChartXYZ&) = delete;
694  void operator=(const vtkChartXYZ&) = delete;
695 };
696 
697 VTK_ABI_NAMESPACE_END
698 #endif
int SceneHeight
The height of the scene, as of the most recent call to Paint().
Definition: vtkChartXYZ.h:656
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:28
data structure to represent key events.
int SceneWidth
The weight of the scene, as of the most recent call to Paint().
Definition: vtkChartXYZ.h:661
AxisState
The state of an axis.
Definition: vtkChartXYZ.h:264
vtkNew< vtkTransform > PlotTransform
This transform translates and scales the plots' data points so that they appear within the axes of th...
Definition: vtkChartXYZ.h:543
base class for items that are part of a vtkContextScene.
virtual bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse)
Mouse button down event Return true if the item holds the event, false if the event can be propagated...
vtkNew< vtkTransform > Scale
This transform keeps track of how the data points have been scaled (zoomed in or zoomed out) within t...
Definition: vtkChartXYZ.h:565
virtual bool Paint(vtkContext2D *painter)
Paint event for the item, called whenever the item needs to be drawn.
maintain a list of planes
vtkNew< vtkTransform > Rotation
This transform keeps track of how the chart has been rotated.
Definition: vtkChartXYZ.h:553
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:49
int vtkIdType
Definition: vtkType.h:315
std::vector< vtkIdType > FreePlaces
These plots got removed (from Plots), try to reuse the free spot.
Definition: vtkChartXYZ.h:608
vtkNew< vtkTextProperty > AxesTextProperty
The text properties of the axes.
Definition: vtkChartXYZ.h:613
std::vector< vtkSmartPointer< vtkAxis > > Axes
The 3 axes of this chart.
Definition: vtkChartXYZ.h:501
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:49
virtual bool MouseWheelEvent(const vtkContextMouseEvent &mouse, int delta)
Mouse wheel event, positive delta indicates forward movement of the wheel.
takes care of drawing 2D axes
Definition: vtkAxis.h:60
data structure to represent mouse events.
a simple class to control print indentation
Definition: vtkIndent.h:28
std::string YAxisLabel
The label for the Y Axis.
Definition: vtkChartXYZ.h:623
std::string ZAxisLabel
The label for the Z Axis.
Definition: vtkChartXYZ.h:628
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:28
vtkNew< vtkTransform > Translation
This transform keeps track of how the data points have been panned within the chart.
Definition: vtkChartXYZ.h:559
vtkSmartPointer< vtkAnnotationLink > Link
This link is used to share selected points with other classes.
Definition: vtkChartXYZ.h:598
represent text properties.
virtual bool KeyPressEvent(const vtkContextKeyEvent &key)
Key press event.
dynamic, self-adjusting array of unsigned char
std::vector< vtkPlot3D * > Plots
The plots that are drawn within this chart.
Definition: vtkChartXYZ.h:603
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:58
vtkNew< vtkPen > AxisPen
This is the pen that is used to draw the axes.
Definition: vtkChartXYZ.h:593
Direction
The direction to data from an axis.
Definition: vtkChartXYZ.h:277
virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse)
Mouse move event.
vtkNew< vtkTransform > ContextTransform
This is the transform that is applied when rendering data from the plots.
Definition: vtkChartXYZ.h:536
virtual bool Hit(const vtkContextMouseEvent &mouse)
Return true if the supplied x, y coordinate is inside the item.
std::string XAxisLabel
The label for the X Axis.
Definition: vtkChartXYZ.h:618
Abstract class for 3D plots.
Definition: vtkPlot3D.h:34
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
vtkNew< vtkPlaneCollection > BoundingCube
The six planes that define the bounding cube of our 3D axes.
Definition: vtkChartXYZ.h:639
RotateDirection
Rotation directions.
Definition: vtkChartXYZ.h:253
vtkNew< vtkTransform > BoxScale
This transform keeps track of how the axes have been scaled (zoomed in or zoomed out).
Definition: vtkChartXYZ.h:571
Factory class for drawing 3D XYZ charts.
Definition: vtkChartXYZ.h:39
vtkNew< vtkTransform > FutureBox
This transform is initialized as a copy of Box.
Definition: vtkChartXYZ.h:578
virtual void Update()
Perform any updates to the item that may be necessary before rendering.
#define max(a, b)
vtkNew< vtkTransform > FutureBoxScale
This transform keeps track of the Scale of the FutureBox transform.
Definition: vtkChartXYZ.h:583
vtkNew< vtkTransform > Box
This is the transform that is applied when rendering data from the plots.
Definition: vtkChartXYZ.h:548
vtkNew< vtkPen > Pen
This is the pen that is used to draw data from the plots.
Definition: vtkChartXYZ.h:588
Class for drawing 3D primitives to a graphical context.
Definition: vtkContext3D.h:33