VTK  9.3.20240419
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 
43 #ifndef vtkChartXYZ_h
44 #define vtkChartXYZ_h
45 
46 #include "vtkChartsCoreModule.h" // For export macro
47 #include "vtkColor.h" // For vtkColor4ub
48 #include "vtkContextItem.h"
49 #include "vtkNew.h" // For ivars
50 #include "vtkRect.h" // For vtkRectf ivars
51 #include "vtkSmartPointer.h" // For ivars
52 #include "vtkStdString.h" // For vtkStdString
53 #include "vtkTextProperty.h" // For axes text properties
54 #include <vector> // For ivars
55 
56 VTK_ABI_NAMESPACE_BEGIN
57 class vtkAnnotationLink;
58 class vtkAxis;
59 class vtkContext3D;
61 class vtkPen;
62 class vtkPlaneCollection;
63 class vtkPlot3D;
64 class vtkTable;
65 class vtkTransform;
67 
68 class VTKCHARTSCORE_EXPORT vtkChartXYZ : public vtkContextItem
69 {
70 public:
71  vtkTypeMacro(vtkChartXYZ, vtkContextItem);
72  void PrintSelf(ostream& os, vtkIndent indent) override;
73 
74  static vtkChartXYZ* New();
75 
85  void SetGeometry(const vtkRectf& bounds);
86 
94  void SetMargins(const vtkVector4i& margins);
95 
99  vtkSetMacro(Angle, double);
100 
104  void SetAroundX(bool isX);
105 
110 
114  vtkAxis* GetAxis(int axis);
115 
119  virtual void SetAxis(int axisIndex, vtkAxis* axis);
120 
122 
128 
149 
153  vtkSetMacro(XAxisLabel, vtkStdString);
154 
158  vtkSetMacro(YAxisLabel, vtkStdString);
159 
163  vtkSetMacro(ZAxisLabel, vtkStdString);
164 
170  vtkSetMacro(EnsureOuterEdgeAxisLabelling, bool);
171 
176  vtkSetMacro(AutoRotate, bool);
177 
182  void SetDecorateAxes(bool b);
183 
188  void SetFitToScene(bool b);
189 
193  void Update() override;
194 
198  bool Paint(vtkContext2D* painter) override;
199 
203  virtual vtkIdType AddPlot(vtkPlot3D* plot);
204 
208  virtual bool RemovePlot(vtkPlot3D* plot);
209 
213  void ClearPlots();
214 
220 
227 
231  bool Hit(const vtkContextMouseEvent& mouse) override;
232 
236  bool MouseButtonPressEvent(const vtkContextMouseEvent& mouse) override;
237 
241  bool MouseMoveEvent(const vtkContextMouseEvent& mouse) override;
242 
246  bool MouseWheelEvent(const vtkContextMouseEvent& mouse, int delta) override;
247 
253  bool KeyPressEvent(const vtkContextKeyEvent& key) override;
254 
259 
263  vtkGetMacro(ClippingPlanesEnabled, bool);
264 
268  vtkSetMacro(ScaleBoxWithPlot, bool);
269 
273  vtkGetMacro(ScaleBoxWithPlot, bool);
274 
275 protected:
277  ~vtkChartXYZ() override;
278 
283  {
286  UP,
287  DOWN
288  };
289 
294  {
300  STANDARD
301  };
302 
307  {
315  NORTH_WEST
316  };
317 
323  virtual void CalculateTransforms();
324 
332 
336  bool Rotate(const vtkContextMouseEvent& mouse);
337 
341  bool Rotate(RotateDirection rotateDirection);
342 
346  bool Pan(const vtkContextMouseEvent& mouse);
347 
351  bool Zoom(const vtkContextMouseEvent& mouse);
352 
356  bool Spin(const vtkContextMouseEvent& mouse);
357 
361  void LookDownX();
362 
366  void LookDownY();
367 
371  void LookDownZ();
372 
376  void LookUpX();
377 
381  void LookUpY();
382 
386  void LookUpZ();
387 
392 
396  void RescaleAxes();
397 
401  void ScaleUpAxes();
402 
407 
411  void ZoomAxes(int delta);
412 
418 
429 
434 
438  void DrawAxes(vtkContext3D* context);
439 
445 
451 
460  void DrawTickMarks(vtkContext2D* painter);
461 
465  void DrawAxesLabels(vtkContext2D* painter);
466 
472  void GetOffsetForAxisLabel(int axis, float* bounds, float* offset);
473 
479  double CalculateNiceMinMax(double& min, double& max, int axis);
480 
484  void GetClippingPlaneEquation(int i, double* planeEquation);
485 
489  std::size_t GetMarginLeft() const;
490 
494  std::size_t GetMarginBottom() const;
495 
499  std::size_t GetPlotWidth() const;
500 
504  std::size_t GetPlotHeight() const;
505 
509  enum
510  {
512  USE_GEOMETRY
513  } SizeStrategy = USE_GEOMETRY;
514 
519  vtkVector4i Margins = vtkVector4i(40, 40, 40, 40);
520 
525  vtkRectf Geometry = vtkRectf(40, 40, 120, 120);
526 
530  std::vector<vtkSmartPointer<vtkAxis>> Axes;
531 
536  bool AutoRotate = false;
537 
542  bool IsX = false;
543 
548  double Angle = 0;
549 
554  bool DrawAxesDecoration = true;
555 
560  bool FitToScene = true;
561 
566 
573 
578 
583 
589 
595 
601 
608 
613 
618 
623 
628 
632  std::vector<vtkPlot3D*> Plots;
633 
637  std::vector<vtkIdType> FreePlaces;
638 
643 
648 
653 
658 
664  bool EnsureOuterEdgeAxisLabelling = false;
669 
674  float AxesBoundaryPoints[8][3];
675 
680  float TickLabelOffset[3][2];
681 
686 
691 
693 
696  int XAxisToLabel[3];
697  int YAxisToLabel[3];
698  int ZAxisToLabel[3];
700 
704  int DirectionToData[3];
705 
709  double DataBounds[4];
710 
714  bool ClippingPlanesEnabled = true;
715 
719  bool ScaleBoxWithPlot = true;
720 
721 private:
722  vtkChartXYZ(const vtkChartXYZ&) = delete;
723  void operator=(const vtkChartXYZ&) = delete;
724 };
725 
726 VTK_ABI_NAMESPACE_END
727 #endif
takes care of drawing 2D axes
Definition: vtkAxis.h:170
Factory class for drawing 3D XYZ charts.
Definition: vtkChartXYZ.h:69
~vtkChartXYZ() override
void SetClippingPlanesEnabled(bool)
Hide data outside the box.
vtkNew< vtkTransform > FutureBoxScale
This transform keeps track of the Scale of the FutureBox transform.
Definition: vtkChartXYZ.h:612
vtkNew< vtkTransform > FutureBox
This transform is initialized as a copy of Box.
Definition: vtkChartXYZ.h:607
std::string XAxisLabel
The label for the X Axis.
Definition: vtkChartXYZ.h:647
@ USE_MARGINS_AND_SCENE_SIZE
Definition: vtkChartXYZ.h:511
void ScaleDownAxes()
Scale down the axes when the scene gets smaller.
bool Paint(vtkContext2D *painter) override
Paint event for the chart, called whenever the chart needs to be drawn.
void RescaleAxes()
Scale the axes up or down in response to a scene resize.
vtkNew< vtkTransform > Box
This is the transform that is applied when rendering data from the plots.
Definition: vtkChartXYZ.h:577
void SetAxisColor(const vtkColor4ub &color)
Set the color for the axes.
void LookUpX()
Adjust the rotation of the chart so that we are looking up the X axis.
vtkNew< vtkPen > Pen
This is the pen that is used to draw data from the plots.
Definition: vtkChartXYZ.h:617
int SceneHeight
The height of the scene, as of the most recent call to Paint().
Definition: vtkChartXYZ.h:685
virtual bool RemovePlot(vtkPlot3D *plot)
Removes a plot from the chart.
void DrawAxesLabels(vtkContext2D *painter)
Label the axes.
void DrawTickMarks(vtkContext2D *painter)
Draw tick marks and tick mark labels along the axes.
static vtkChartXYZ * New()
RotateDirection
Rotation directions.
Definition: vtkChartXYZ.h:283
bool Zoom(const vtkContextMouseEvent &mouse)
Zoom in or out on the data in response to a mouse movement.
vtkTextProperty * GetAxesTextProperty()
Get the text property for axes.
std::string YAxisLabel
The label for the Y Axis.
Definition: vtkChartXYZ.h:652
void Update() override
Perform any updates to the item that may be necessary before rendering.
bool Rotate(const vtkContextMouseEvent &mouse)
Rotate the chart in response to a mouse movement.
double CalculateNiceMinMax(double &min, double &max, int axis)
Calculate the next "nicest" numbers above and below the current minimum.
vtkAxis * GetAxis(int axis)
Get the x (0), y (1) or z (2) axis.
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:594
std::vector< vtkSmartPointer< vtkAxis > > Axes
The 3 axes of this chart.
Definition: vtkChartXYZ.h:530
bool Spin(const vtkContextMouseEvent &mouse)
Spin the chart in response to a mouse movement.
bool Rotate(RotateDirection rotateDirection)
Rotate the chart in a specific direction.
void GetClippingPlaneEquation(int i, double *planeEquation)
Get the equation for the ith face of our bounding cube.
vtkNew< vtkPlaneCollection > BoundingCube
The six planes that define the bounding cube of our 3D axes.
Definition: vtkChartXYZ.h:668
virtual void CalculateTransforms()
Calculate the transformation matrices used to draw data points and axes in the scene.
vtkNew< vtkTransform > Rotation
This transform keeps track of how the chart has been rotated.
Definition: vtkChartXYZ.h:582
void LegacyDetermineWhichAxesToLabel()
Old-style axis labelling, for compatibility; labelling may occur in less optimal places e....
void DrawAxes(vtkContext3D *context)
Draw the cube axes of this chart.
vtkNew< vtkPen > AxisPen
This is the pen that is used to draw the axes.
Definition: vtkChartXYZ.h:622
bool CalculatePlotTransform(vtkAxis *x, vtkAxis *y, vtkAxis *z, vtkTransform *transform)
Given the x, y and z vtkAxis, and a transform, calculate the transform that the points in a chart wou...
vtkNew< vtkTransform > BoxScale
This transform keeps track of how the axes have been scaled (zoomed in or zoomed out).
Definition: vtkChartXYZ.h:600
std::string ZAxisLabel
The label for the Z Axis.
Definition: vtkChartXYZ.h:657
void LookUpZ()
Adjust the rotation of the chart so that we are looking up the Z axis.
void GetOffsetForAxisLabel(int axis, float *bounds, float *offset)
Compute how some text should be offset from an axis.
void ClearPlots()
Remove all the plots from this chart.
std::size_t GetPlotHeight() const
Gets the current height of the plot in pixels irrespective of the size-strategy used.
void DetermineWhichAxesToLabel()
For each of the XYZ dimensions, find the axis line that is furthest from the rendered data.
std::vector< vtkPlot3D * > Plots
The plots that are drawn within this chart.
Definition: vtkChartXYZ.h:632
vtkNew< vtkTransform > ContextTransform
This is the transform that is applied when rendering data from the plots.
Definition: vtkChartXYZ.h:565
void LookDownX()
Adjust the rotation of the chart so that we are looking down the X axis.
vtkSmartPointer< vtkAnnotationLink > Link
This link is used to share selected points with other classes.
Definition: vtkChartXYZ.h:627
std::size_t GetMarginBottom() const
Gets the current margin top in pixels irrespective of the size-strategy used.
Direction
The direction to data from an axis.
Definition: vtkChartXYZ.h:307
void SetAroundX(bool isX)
Set whether or not we're rotating about the X axis.
void SetMargins(const vtkVector4i &margins)
Set the margins in pixels ordered top right bottom left The box will be drawn inside those margins,...
void ZoomAxes(int delta)
Change the scaling of the axes by a specified amount.
void LookUpY()
Adjust the rotation of the chart so that we are looking up the Y axis.
void SetDecorateAxes(bool b)
Set whether or not axes labels & tick marks should be drawn.
vtkNew< vtkTransform > Translation
This transform keeps track of how the data points have been panned within the chart.
Definition: vtkChartXYZ.h:588
void InitializeFutureBox()
Initialize the "future box" transform.
vtkNew< vtkTransform > PlotTransform
This transform translates and scales the plots' data points so that they appear within the axes of th...
Definition: vtkChartXYZ.h:572
bool CheckForSceneResize()
Check to see if the scene changed size since the last render.
void InitializeAxesBoundaryPoints()
Initialize a list of "test points".
vtkColor4ub GetAxisColor()
Set the color for the axes.
bool KeyPressEvent(const vtkContextKeyEvent &key) override
Key press event.
void ScaleUpAxes()
Scale up the axes when the scene gets larger.
void SetGeometry(const vtkRectf &bounds)
Set the geometry in pixel coordinates (origin and width/height).
virtual void SetAxis(int axisIndex, vtkAxis *axis)
Set the x (0), y (1) or z (2) axis.
void ComputeDataBounds()
Compute a bounding box for the data that is rendered within the axes.
void LookDownZ()
Adjust the rotation of the chart so that we are looking down the Z axis.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkNew< vtkTextProperty > AxesTextProperty
The text properties of the axes.
Definition: vtkChartXYZ.h:642
bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse) override
Mouse press event.
void RecalculateBounds()
Determine the XYZ bounds of the plots within this chart.
void SetFitToScene(bool b)
Set whether or not the chart should automatically resize itself to fill the scene.
void NewDetermineWhichAxesToLabel()
New style axis labelling, ensuring labelling is always at the edges of the chart in the most sensible...
bool MouseWheelEvent(const vtkContextMouseEvent &mouse, int delta) override
Mouse wheel event.
bool MouseMoveEvent(const vtkContextMouseEvent &mouse) override
Mouse move event.
AxisState
The state of an axis.
Definition: vtkChartXYZ.h:294
void LookDownY()
Adjust the rotation of the chart so that we are looking down the Y axis.
std::vector< vtkIdType > FreePlaces
These plots got removed (from Plots), try to reuse the free spot.
Definition: vtkChartXYZ.h:637
std::size_t GetPlotWidth() const
Gets the current width of the plot in pixels irrespective of the size-strategy used.
virtual void SetAnnotationLink(vtkAnnotationLink *link)
Set the vtkAnnotationLink for the chart.
void RecalculateTransform()
Use this chart's Geometry to set the endpoints of its axes.
int SceneWidth
The weight of the scene, as of the most recent call to Paint().
Definition: vtkChartXYZ.h:690
virtual vtkIdType AddPlot(vtkPlot3D *plot)
Adds a plot to the chart.
bool Hit(const vtkContextMouseEvent &mouse) override
Returns true if the transform is interactive, false otherwise.
std::size_t GetMarginLeft() const
Gets the current margin left in pixels irrespective of the size-strategy used.
bool Pan(const vtkContextMouseEvent &mouse)
Pan the data within the chart in response to a mouse movement.
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:69
Class for drawing 3D primitives to a graphical context.
Definition: vtkContext3D.h:53
base class for items that are part of a vtkContextScene.
data structure to represent key events.
data structure to represent mouse events.
a simple class to control print indentation
Definition: vtkIndent.h:108
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:78
maintain a list of planes
Abstract class for 3D plots.
Definition: vtkPlot3D.h:35
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:78
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:168
represent text properties.
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:160
dynamic, self-adjusting array of unsigned char
@ key
Definition: vtkX3D.h:257
@ color
Definition: vtkX3D.h:221
@ offset
Definition: vtkX3D.h:438
@ string
Definition: vtkX3D.h:490
int vtkIdType
Definition: vtkType.h:315
#define max(a, b)