VTK  9.5.20251207
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
42
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 "vtkWrappingHints.h" // For VTK_MARSHALAUTO
55#include <vector> // For ivars
56
57VTK_ABI_NAMESPACE_BEGIN
59class vtkAxis;
60class vtkContext3D;
62class vtkPen;
64class vtkPlot3D;
65class vtkTable;
66class vtkTransform;
68
69class VTKCHARTSCORE_EXPORT VTK_MARSHALAUTO vtkChartXYZ : public vtkContextItem
70{
71public:
73 void PrintSelf(ostream& os, vtkIndent indent) override;
74
75 static vtkChartXYZ* New();
76
86 void SetGeometry(const vtkRectf& bounds);
87
95 void SetMargins(const vtkVector4i& margins);
96
100 vtkSetMacro(Angle, double);
101
105 void SetAroundX(bool isX);
106
111
115 vtkAxis* GetAxis(int axis);
116
120 virtual void SetAxis(int axisIndex, vtkAxis* axis);
121
123
126 void SetAxisColor(const vtkColor4ub& color);
129
150
155
160
165
172
177 vtkSetMacro(AutoRotate, bool);
178
183 void SetDecorateAxes(bool b);
184
189 void SetFitToScene(bool b);
190
194 void Update() override;
195
199 bool Paint(vtkContext2D* painter) override;
200
205
209 virtual bool RemovePlot(vtkPlot3D* plot);
210
215
221
228
232 bool Hit(const vtkContextMouseEvent& mouse) override;
233
237 bool MouseButtonPressEvent(const vtkContextMouseEvent& mouse) override;
238
242 bool MouseMoveEvent(const vtkContextMouseEvent& mouse) override;
243
247 bool MouseWheelEvent(const vtkContextMouseEvent& mouse, int delta) override;
248
254 bool KeyPressEvent(const vtkContextKeyEvent& key) override;
255
260
264 vtkGetMacro(ClippingPlanesEnabled, bool);
265
269 vtkSetMacro(ScaleBoxWithPlot, bool);
270
274 vtkGetMacro(ScaleBoxWithPlot, bool);
275
276protected:
278 ~vtkChartXYZ() override;
279
290
303
318
324 virtual void CalculateTransforms();
325
333
337 bool Rotate(const vtkContextMouseEvent& mouse);
338
342 bool Rotate(RotateDirection rotateDirection);
343
347 bool Pan(const vtkContextMouseEvent& mouse);
348
352 bool Zoom(const vtkContextMouseEvent& mouse);
353
357 bool Spin(const vtkContextMouseEvent& mouse);
358
362 void LookDownX();
363
367 void LookDownY();
368
372 void LookDownZ();
373
377 void LookUpX();
378
382 void LookUpY();
383
387 void LookUpZ();
388
393
398
403
408
412 void ZoomAxes(int delta);
413
419
430
435
439 void DrawAxes(vtkContext3D* context);
440
446
452
462
467
473 void GetOffsetForAxisLabel(int axis, float* bounds, float* offset);
474
480 double CalculateNiceMinMax(double& min, double& max, int axis);
481
485 void GetClippingPlaneEquation(int i, double* planeEquation);
486
490 std::size_t GetMarginLeft() const;
491
495 std::size_t GetMarginBottom() const;
496
500 std::size_t GetPlotWidth() const;
501
505 std::size_t GetPlotHeight() const;
506
510 enum
511 {
514 } SizeStrategy = USE_GEOMETRY;
515
520 vtkVector4i Margins = vtkVector4i(40, 40, 40, 40);
521
526 vtkRectf Geometry = vtkRectf(40, 40, 120, 120);
527
531 std::vector<vtkSmartPointer<vtkAxis>> Axes;
532
537 bool AutoRotate = false;
538
543 bool IsX = false;
544
549 double Angle = 0;
550
556
561 bool FitToScene = true;
562
567
574
579
584
590
596
602
609
614
619
624
629
633 std::vector<vtkPlot3D*> Plots;
634
638 std::vector<vtkIdType> FreePlaces;
639
644
648 std::string XAxisLabel;
649
653 std::string YAxisLabel;
654
658 std::string ZAxisLabel;
659
670
676
681 float TickLabelOffset[3][2];
682
687
692
694
701
706
710 double DataBounds[4];
711
716
720 bool ScaleBoxWithPlot = true;
721
722private:
723 vtkChartXYZ(const vtkChartXYZ&) = delete;
724 void operator=(const vtkChartXYZ&) = delete;
725};
726
727VTK_ABI_NAMESPACE_END
728#endif
takes care of drawing 2D axes
Definition vtkAxis.h:172
~vtkChartXYZ() override
void SetClippingPlanesEnabled(bool)
Hide data outside the box.
bool AutoRotate
This boolean indicates whether or not we're using this chart to rotate on a timer.
@ USE_MARGINS_AND_SCENE_SIZE
vtkNew< vtkTransform > FutureBoxScale
This transform keeps track of the Scale of the FutureBox transform.
vtkNew< vtkTransform > FutureBox
This transform is initialized as a copy of Box.
std::string XAxisLabel
The label for the X Axis.
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.
bool FitToScene
This boolean indicates whether or not we should automatically resize the chart so that it snugly fill...
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.
int ZAxisToLabel[3]
Which line to label.
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.
int SceneHeight
The height of the scene, as of the most recent call to Paint().
virtual bool RemovePlot(vtkPlot3D *plot)
Removes a plot from the chart.
vtkAxis * GetAxis(int axis)
Get the x (0), y (1) or z (2) axis.
void DrawAxesLabels(vtkContext2D *painter)
Label the axes.
void DrawTickMarks(vtkContext2D *painter)
Draw tick marks and tick mark labels along the axes.
static vtkChartXYZ * New()
int YAxisToLabel[3]
Which line to label.
vtkRectf Geometry
The size and position of this chart.
RotateDirection
Rotation directions.
bool Zoom(const vtkContextMouseEvent &mouse)
Zoom in or out on the data in response to a mouse movement.
std::string YAxisLabel
The label for the Y Axis.
int DirectionToData[3]
What direction the data is from each labeled axis line.
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.
vtkNew< vtkTransform > Scale
This transform keeps track of how the data points have been scaled (zoomed in or zoomed out) within t...
std::vector< vtkSmartPointer< vtkAxis > > Axes
The 3 axes of this chart.
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.
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.
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.
int XAxisToLabel[3]
Which line to label.
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).
std::string ZAxisLabel
The label for the Z Axis.
bool ClippingPlanesEnabled
Hide data outside the box.
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.
vtkNew< vtkTransform > ContextTransform
This is the transform that is applied when rendering data from the plots.
void LookDownX()
Adjust the rotation of the chart so that we are looking down the X axis.
bool DrawAxesDecoration
This boolean indicates whether or not we should draw tick marks and axes labels.
vtkSmartPointer< vtkAnnotationLink > Link
This link is used to share selected points with other classes.
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.
float TickLabelOffset[3][2]
This member variable stores the size of the tick labels for each axis.
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.
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...
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.
double Angle
When we're in AutoRotate mode, this value tells the chart how much it should be rotated.
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.
double DataBounds[4]
A bounding box surrounding the currently rendered data points.
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.
bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse) override
Mouse press event.
bool ScaleBoxWithPlot
When rotating the mousewheel, scale not only the plot but also the box.
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.
vtkVector4i Margins
The margins in pixels for the box ordered top right bottom left Applicable only when SizeStrategy == ...
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.
std::size_t GetPlotWidth() const
Gets the current width of the plot in pixels irrespective of the size-strategy used.
vtkTextProperty * GetAxesTextProperty()
Get the text property for axes.
bool EnsureOuterEdgeAxisLabelling
If set to true, use the new behaviour of ensuring that axis labels are on the outer edges of the char...
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().
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.
float AxesBoundaryPoints[8][3]
Points used to determine whether the axes will fit within the scene as currently sized,...
bool IsX
When we're in AutoRotate mode, this boolean tells us if we should rotate about the X axis or the Y ax...
Class for drawing 2D primitives to a graphical context.
Class for drawing 3D primitives to a graphical context.
vtkContextItem()=default
data structure to represent key events.
data structure to represent mouse events.
a simple class to control print indentation
Definition vtkIndent.h:108
Allocate and hold a VTK object.
Definition vtkNew.h:167
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition vtkPen.h:79
maintain a list of planes
Abstract class for 3D plots.
Definition vtkPlot3D.h:36
Hold a reference to a vtkObjectBase instance.
Wrapper around std::string to keep symbols short.
A table, which contains similar-typed columns of data.
Definition vtkTable.h:169
represent text properties.
describes linear transformations via a 4x4 matrix
dynamic, self-adjusting array of unsigned char
int vtkIdType
Definition vtkType.h:367
#define VTK_MARSHALAUTO
#define max(a, b)