VTK  9.1.0
vtkChartXYZ.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkChartXYZ.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
23 #ifndef vtkChartXYZ_h
24 #define vtkChartXYZ_h
25 
26 #include "vtkChartsCoreModule.h" // For export macro
27 #include "vtkColor.h" // For vtkColor4ub
28 #include "vtkContextItem.h"
29 #include "vtkNew.h" // For ivars
30 #include "vtkRect.h" // For vtkRectf ivars
31 #include "vtkSmartPointer.h" // For ivars
32 #include "vtkStdString.h" // For vtkStdString
33 #include "vtkTextProperty.h" // For axes text properties
34 #include <vector> // For ivars
35 
36 class vtkAnnotationLink;
37 class vtkAxis;
38 class vtkContext3D;
40 class vtkPen;
41 class vtkPlaneCollection;
42 class vtkPlot3D;
43 class vtkTable;
44 class vtkTransform;
46 
47 class VTKCHARTSCORE_EXPORT vtkChartXYZ : public vtkContextItem
48 {
49 public:
50  vtkTypeMacro(vtkChartXYZ, vtkContextItem);
51  void PrintSelf(ostream& os, vtkIndent indent) override;
52 
53  static vtkChartXYZ* New();
54 
64  void SetGeometry(const vtkRectf& bounds);
65 
73  void SetMargins(const vtkVector4i& margins);
74 
78  vtkSetMacro(Angle, double);
79 
83  void SetAroundX(bool isX);
84 
88  virtual void SetAnnotationLink(vtkAnnotationLink* link);
89 
93  vtkAxis* GetAxis(int axis);
94 
98  virtual void SetAxis(int axisIndex, vtkAxis* axis);
99 
101 
107 
128 
132  vtkSetMacro(XAxisLabel, vtkStdString);
133 
137  vtkSetMacro(YAxisLabel, vtkStdString);
138 
142  vtkSetMacro(ZAxisLabel, vtkStdString);
143 
149  vtkSetMacro(EnsureOuterEdgeAxisLabelling, bool);
150 
155  vtkSetMacro(AutoRotate, bool);
156 
161  void SetDecorateAxes(bool b);
162 
167  void SetFitToScene(bool b);
168 
172  void Update() override;
173 
177  bool Paint(vtkContext2D* painter) override;
178 
182  virtual vtkIdType AddPlot(vtkPlot3D* plot);
183 
187  virtual bool RemovePlot(vtkPlot3D* plot);
188 
192  void ClearPlots();
193 
199 
206 
210  bool Hit(const vtkContextMouseEvent& mouse) override;
211 
215  bool MouseButtonPressEvent(const vtkContextMouseEvent& mouse) override;
216 
220  bool MouseMoveEvent(const vtkContextMouseEvent& mouse) override;
221 
225  bool MouseWheelEvent(const vtkContextMouseEvent& mouse, int delta) override;
226 
232  bool KeyPressEvent(const vtkContextKeyEvent& key) override;
233 
238 
242  vtkGetMacro(ClippingPlanesEnabled, bool);
243 
247  vtkSetMacro(ScaleBoxWithPlot, bool);
248 
252  vtkGetMacro(ScaleBoxWithPlot, bool);
253 
254 protected:
256  ~vtkChartXYZ() override;
257 
262  {
265  UP,
266  DOWN
267  };
268 
273  {
279  STANDARD
280  };
281 
286  {
294  NORTH_WEST
295  };
296 
302  virtual void CalculateTransforms();
303 
311 
315  bool Rotate(const vtkContextMouseEvent& mouse);
316 
320  bool Rotate(const RotateDirection rotateDirection);
321 
325  bool Pan(const vtkContextMouseEvent& mouse);
326 
330  bool Zoom(const vtkContextMouseEvent& mouse);
331 
335  bool Spin(const vtkContextMouseEvent& mouse);
336 
340  void LookDownX();
341 
345  void LookDownY();
346 
350  void LookDownZ();
351 
355  void LookUpX();
356 
360  void LookUpY();
361 
365  void LookUpZ();
366 
371 
375  void RescaleAxes();
376 
380  void ScaleUpAxes();
381 
386 
390  void ZoomAxes(int delta);
391 
397 
408 
413 
417  void DrawAxes(vtkContext3D* context);
418 
424 
430 
439  void DrawTickMarks(vtkContext2D* painter);
440 
444  void DrawAxesLabels(vtkContext2D* painter);
445 
451  void GetOffsetForAxisLabel(int axis, float* bounds, float* offset);
452 
458  double CalculateNiceMinMax(double& min, double& max, int axis);
459 
463  void GetClippingPlaneEquation(int i, double* planeEquation);
464 
468  std::size_t GetMarginLeft() const;
469 
473  std::size_t GetMarginBottom() const;
474 
478  std::size_t GetPlotWidth() const;
479 
483  std::size_t GetPlotHeight() const;
484 
488  enum
489  {
491  USE_GEOMETRY
492  } SizeStrategy = USE_GEOMETRY;
493 
498  vtkVector4i Margins = vtkVector4i(40, 40, 40, 40);
499 
504  vtkRectf Geometry = vtkRectf(40, 40, 120, 120);
505 
509  std::vector<vtkSmartPointer<vtkAxis>> Axes;
510 
515  bool AutoRotate = false;
516 
521  bool IsX = false;
522 
527  double Angle = 0;
528 
533  bool DrawAxesDecoration = true;
534 
539  bool FitToScene = true;
540 
545 
552 
557 
562 
568 
574 
580 
587 
592 
597 
602 
607 
611  std::vector<vtkPlot3D*> Plots;
612 
616  std::vector<vtkIdType> FreePlaces;
617 
622 
627 
632 
637 
643  bool EnsureOuterEdgeAxisLabelling = false;
648 
653  float AxesBoundaryPoints[8][3];
654 
659  float TickLabelOffset[3][2];
660 
665 
670 
672 
675  int XAxisToLabel[3];
676  int YAxisToLabel[3];
677  int ZAxisToLabel[3];
679 
683  int DirectionToData[3];
684 
688  double DataBounds[4];
689 
693  bool ClippingPlanesEnabled = true;
694 
698  bool ScaleBoxWithPlot = true;
699 
700 private:
701  vtkChartXYZ(const vtkChartXYZ&) = delete;
702  void operator=(const vtkChartXYZ&) = delete;
703 };
704 
705 #endif
takes care of drawing 2D axes
Definition: vtkAxis.h:69
Factory class for drawing 3D XYZ charts.
Definition: vtkChartXYZ.h:48
~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:591
vtkNew< vtkTransform > FutureBox
This transform is initialized as a copy of Box.
Definition: vtkChartXYZ.h:586
std::string XAxisLabel
The label for the X Axis.
Definition: vtkChartXYZ.h:626
@ USE_MARGINS_AND_SCENE_SIZE
Definition: vtkChartXYZ.h:490
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:556
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:596
int SceneHeight
The height of the scene, as of the most recent call to Paint().
Definition: vtkChartXYZ.h:664
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:262
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:631
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:573
std::vector< vtkSmartPointer< vtkAxis > > Axes
The 3 axes of this chart.
Definition: vtkChartXYZ.h:509
bool Spin(const vtkContextMouseEvent &mouse)
Spin the chart in response to a mouse movement.
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:647
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:561
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:601
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:579
std::string ZAxisLabel
The label for the Z Axis.
Definition: vtkChartXYZ.h:636
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:611
vtkNew< vtkTransform > ContextTransform
This is the transform that is applied when rendering data from the plots.
Definition: vtkChartXYZ.h:544
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:606
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:286
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:567
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:551
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 Rotate(const RotateDirection rotateDirection)
Rotate the chart in a specific direction.
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:621
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:273
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:616
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:669
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:54
Class for drawing 3D primitives to a graphical context.
Definition: vtkContext3D.h:41
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:34
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:37
maintain a list of planes
Abstract class for 3D plots.
Definition: vtkPlot3D.h:45
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:36
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:63
represent text properties.
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:55
dynamic, self-adjusting array of unsigned char
@ key
Definition: vtkX3D.h:263
@ color
Definition: vtkX3D.h:227
@ offset
Definition: vtkX3D.h:444
@ string
Definition: vtkX3D.h:496
int vtkIdType
Definition: vtkType.h:332
#define max(a, b)