VTK  9.3.0
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
27VTK_ABI_NAMESPACE_BEGIN
29class vtkAxis;
30class vtkContext3D;
32class vtkPen;
34class vtkPlot3D;
35class vtkTable;
36class vtkTransform;
38
39class VTKCHARTSCORE_EXPORT vtkChartXYZ : public vtkContextItem
40{
41public:
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
81
85 vtkAxis* GetAxis(int axis);
86
90 virtual void SetAxis(int axisIndex, vtkAxis* axis);
91
93
96 void SetAxisColor(const vtkColor4ub& color);
99
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
175
179 virtual bool RemovePlot(vtkPlot3D* plot);
180
185
191
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
230
234 vtkGetMacro(ClippingPlanesEnabled, bool);
235
239 vtkSetMacro(ScaleBoxWithPlot, bool);
240
244 vtkGetMacro(ScaleBoxWithPlot, bool);
245
246protected:
248 ~vtkChartXYZ() override;
249
254 {
258 DOWN
259 };
260
265 {
271 STANDARD
272 };
273
278 {
286 NORTH_WEST
287 };
288
294 virtual void CalculateTransforms();
295
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
363
368
373
378
382 void ZoomAxes(int delta);
383
389
400
405
409 void DrawAxes(vtkContext3D* context);
410
416
422
432
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
618 std::string XAxisLabel;
619
623 std::string YAxisLabel;
624
628 std::string ZAxisLabel;
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
692private:
693 vtkChartXYZ(const vtkChartXYZ&) = delete;
694 void operator=(const vtkChartXYZ&) = delete;
695};
696
697VTK_ABI_NAMESPACE_END
698#endif
takes care of drawing 2D axes
Definition vtkAxis.h:61
Factory class for drawing 3D XYZ charts.
Definition vtkChartXYZ.h:40
~vtkChartXYZ() override
void SetClippingPlanesEnabled(bool)
Hide data outside the box.
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.
@ USE_MARGINS_AND_SCENE_SIZE
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.
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()
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Class for drawing 2D primitives to a graphical context.
Class for drawing 3D primitives to a graphical context.
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:29
Allocate and hold a VTK object.
Definition vtkNew.h:51
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition vtkPen.h:29
maintain a list of planes
Abstract class for 3D plots.
Definition vtkPlot3D.h:35
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:59
represent text properties.
describes linear transformations via a 4x4 matrix
dynamic, self-adjusting array of unsigned char
int vtkIdType
Definition vtkType.h:315
#define max(a, b)