VTK  9.2.6
vtkPlot.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkPlot.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
32
33#ifndef vtkPlot_h
34#define vtkPlot_h
35
36#include "vtkChartsCoreModule.h" // For export macro
37#include "vtkContextItem.h"
38#include "vtkContextPolygon.h" // For vtkContextPolygon
39#include "vtkRect.h" // For vtkRectd ivar
40#include "vtkSmartPointer.h" // Needed to hold SP ivars
41#include "vtkStdString.h" // Needed to hold TooltipLabelFormat ivar
42
43class vtkVariant;
44class vtkTable;
45class vtkIdTypeArray;
47class vtkPen;
48class vtkBrush;
49class vtkAxis;
50class vtkStringArray;
52
53class VTKCHARTSCORE_EXPORT vtkPlot : public vtkContextItem
54{
55public:
56 vtkTypeMacro(vtkPlot, vtkContextItem);
57 void PrintSelf(ostream& os, vtkIndent indent) override;
58
64 void Update() override;
65
67
72 vtkSetMacro(LegendVisibility, bool);
73 vtkGetMacro(LegendVisibility, bool);
74 vtkBooleanMacro(LegendVisibility, bool);
76
84 virtual bool PaintLegend(vtkContext2D* painter, const vtkRectf& rect, int legendIndex);
85
87
99 virtual void SetTooltipLabelFormat(const vtkStdString& label);
102
104
107 virtual void SetTooltipNotation(int notation);
108 virtual int GetTooltipNotation();
110
112
115 virtual void SetTooltipPrecision(int precision);
116 virtual int GetTooltipPrecision();
118
124 const vtkVector2d& plotPos, vtkIdType seriesIndex, vtkIdType segmentIndex);
125
131 virtual vtkIdType GetNearestPoint(const vtkVector2f& point, const vtkVector2f& tolerance,
132 vtkVector2f* location, vtkIdType* segmentId);
133
137 virtual bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max);
138
142 virtual bool SelectPointsInPolygon(const vtkContextPolygon& polygon);
143
145
148 virtual void SetColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
149 virtual void SetColor(double r, double g, double b);
150 virtual void GetColor(double rgb[3]);
151 void GetColor(unsigned char rgb[3]);
153
157 virtual void SetWidth(float width);
158
162 virtual float GetWidth();
163
165
168 void SetPen(vtkPen* pen);
171
173
176 void SetBrush(vtkBrush* brush);
179
181
188
190
197
201 virtual void SetLabel(const vtkStdString& label);
202
207
212 virtual void SetLabels(vtkStringArray* labels);
213
219
223 virtual int GetNumberOfLabels();
224
229
236
241
246
248
252 vtkGetMacro(UseIndexForXSeries, bool);
254
256
260 vtkSetMacro(UseIndexForXSeries, bool);
262
264
268 virtual void SetInputData(vtkTable* table);
269 virtual void SetInputData(
270 vtkTable* table, const vtkStdString& xColumn, const vtkStdString& yColumn);
271 void SetInputData(vtkTable* table, vtkIdType xColumn, vtkIdType yColumn);
273
275
280
284 virtual vtkTable* GetInput();
285
290
296 virtual void SetInputArray(int index, const vtkStdString& name);
297
299
305 vtkSetMacro(Selectable, bool);
306 vtkGetMacro(Selectable, bool);
307 vtkBooleanMacro(Selectable, bool);
309
311
316 virtual void SetSelection(vtkIdTypeArray* id);
317 vtkGetObjectMacro(Selection, vtkIdTypeArray);
319
321
324 vtkGetObjectMacro(XAxis, vtkAxis);
325 virtual void SetXAxis(vtkAxis* axis);
327
329
332 vtkGetObjectMacro(YAxis, vtkAxis);
333 virtual void SetYAxis(vtkAxis* axis);
335
337
343 void SetShiftScale(const vtkRectd& shiftScale);
346
352 virtual void GetBounds(double bounds[4]) { bounds[0] = bounds[1] = bounds[2] = bounds[3] = 0.0; }
353
378 virtual void GetUnscaledInputBounds(double bounds[4])
379 {
380 // Implemented here by calling GetBounds() to support plot
381 // subclasses that do no log-scaling or plot orientation.
382 return this->GetBounds(bounds);
383 }
384
386
390 virtual void SetProperty(const vtkStdString& property, const vtkVariant& var);
391 virtual vtkVariant GetProperty(const vtkStdString& property);
393
395
399 static bool ClampPos(double pos[2], double bounds[4]);
400 virtual bool ClampPos(double pos[2]);
402
406 bool Hit(const vtkContextMouseEvent& mouse) override;
407
414 virtual bool UpdateCache() { return true; }
415
416protected:
418 ~vtkPlot() override;
419
423 vtkStdString GetNumber(double position, vtkAxis* axis);
424
426
430 virtual void TransformScreenToData(const vtkVector2f& in, vtkVector2f& out);
431 virtual void TransformDataToScreen(const vtkVector2f& in, vtkVector2f& out);
433 const double inX, const double inY, double& outX, double& outY);
435 const double inX, const double inY, double& outX, double& outY);
437
441 virtual bool CacheRequiresUpdate();
442
447
452
457
463
469
474
479
484
490
496
501
506
511
516
522
528
531
536
538
539private:
540 vtkPlot(const vtkPlot&) = delete;
541 void operator=(const vtkPlot&) = delete;
542};
543
544#endif // vtkPlot_h
Proxy object to connect input/output ports.
takes care of drawing 2D axes
Definition vtkAxis.h:72
provides a brush that fills shapes drawn by vtkContext2D.
Definition vtkBrush.h:41
Class for drawing 2D primitives to a graphical context.
vtkContextItem()=default
Abstract class for 2D context mappers.
data structure to represent mouse events.
dynamic, self-adjusting array of vtkIdType
a simple class to control print indentation
Definition vtkIndent.h:40
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition vtkPen.h:40
bool UseIndexForXSeries
Use the Y array index for the X value.
Definition vtkPlot.h:489
virtual vtkStdString GetLabel()
Get the label of this plot.
virtual int GetTooltipPrecision()
Sets/gets the tooltip precision.
virtual void GetColor(double rgb[3])
Set the plot color.
vtkContextMapper2D * GetData()
Get the data object that the plot will draw.
vtkRectd ShiftScale
The current shift in origin and scaling factor applied to the plot.
Definition vtkPlot.h:535
virtual int GetTooltipNotation()
Sets/gets the tooltip notation style.
virtual vtkTable * GetInput()
Get the input table used by the plot.
void SetSelectionPen(vtkPen *pen)
Set/get the vtkBrush object that controls how this plot fills selected shapes.
int TooltipPrecision
Definition vtkPlot.h:530
vtkSmartPointer< vtkStringArray > IndexedLabels
Holds Labels when they're auto-created.
Definition vtkPlot.h:483
void SetIndexedLabels(vtkStringArray *labels)
Set indexed labels for the plot.
virtual void SetInputData(vtkTable *table, const vtkStdString &xColumn, const vtkStdString &yColumn)
This is a convenience function to set the input table and the x, y column for the plot.
virtual bool SelectPoints(const vtkVector2f &min, const vtkVector2f &max)
Select all points in the specified rectangle.
vtkAxis * XAxis
The X axis associated with this plot.
Definition vtkPlot.h:510
virtual vtkStdString GetTooltipLabel(const vtkVector2d &plotPos, vtkIdType seriesIndex, vtkIdType segmentIndex)
Generate and return the tooltip label string for this plot The segmentIndex parameter is ignored,...
vtkPen * GetPen()
Set/get the vtkPen object that controls how this plot draws (out)lines.
virtual void SetWidth(float width)
Set the width of the line.
virtual int GetNumberOfLabels()
Get the number of labels associated with this plot.
~vtkPlot() override
virtual vtkStdString GetTooltipLabelFormat()
Sets/gets a printf-style string to build custom tooltip labels from.
virtual vtkVariant GetProperty(const vtkStdString &property)
A General setter/getter that should be overridden.
virtual void SetInputData(vtkTable *table)
This is a convenience function to set the input table and the x, y column for the plot.
virtual void SetColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
Set the plot color.
vtkStdString GetLabel(vtkIdType index)
Get the label at the specified index.
bool LegendVisibility
Definition vtkPlot.h:537
virtual void SetInputArray(int index, const vtkStdString &name)
Convenience function to set the input arrays.
virtual void GetUnscaledInputBounds(double bounds[4])
Provide un-log-scaled bounds for the plot inputs.
Definition vtkPlot.h:378
vtkAlgorithmOutput * GetInputConnection()
Get the input connection used by the plot.
vtkPen * GetSelectionPen()
Set/get the vtkBrush object that controls how this plot fills selected shapes.
void SetBrush(vtkBrush *brush)
Set/get the vtkBrush object that controls how this plot fills shapes.
vtkIdTypeArray * Selection
Selected indices for the table the plot is rendering.
Definition vtkPlot.h:505
virtual vtkStringArray * GetLabels()
Get the plot labels.
virtual void SetLabel(const vtkStdString &label)
Set the label of this plot.
vtkSmartPointer< vtkBrush > SelectionBrush
This object stores the vtkBrush that controls how the selected elements of the plot are drawn.
Definition vtkPlot.h:468
virtual void GetBounds(double bounds[4])
Get the bounds for this plot as (Xmin, Xmax, Ymin, Ymax).
Definition vtkPlot.h:352
virtual void SetTooltipLabelFormat(const vtkStdString &label)
Sets/gets a printf-style string to build custom tooltip labels from.
virtual void SetXAxis(vtkAxis *axis)
Get/set the X axis associated with this plot.
virtual bool UpdateCache()
Update the internal cache.
Definition vtkPlot.h:414
vtkAxis * YAxis
The X axis associated with this plot.
Definition vtkPlot.h:515
vtkStdString TooltipDefaultLabelFormat
The default printf-style string to build custom tooltip labels from.
Definition vtkPlot.h:527
virtual void SetColor(double r, double g, double b)
Set the plot color.
vtkSmartPointer< vtkPen > SelectionPen
This object stores the vtkPen that controls how the selected elements of the plot are drawn.
Definition vtkPlot.h:462
virtual bool PaintLegend(vtkContext2D *painter, const vtkRectf &rect, int legendIndex)
Paint legend event for the plot, called whenever the legend needs the plot items symbol/mark/line dra...
void SetSelectionBrush(vtkBrush *brush)
Set/get the vtkBrush object that controls how this plot fills selected shapes.
virtual void SetProperty(const vtkStdString &property, const vtkVariant &var)
A General setter/getter that should be overridden.
void GetColor(unsigned char rgb[3])
Set the plot color.
void SetPen(vtkPen *pen)
Set/get the vtkPen object that controls how this plot draws (out)lines.
vtkStdString TooltipLabelFormat
A printf-style string to build custom tooltip labels from.
Definition vtkPlot.h:521
bool Selectable
Whether plot points can be selected or not.
Definition vtkPlot.h:500
int TooltipNotation
Definition vtkPlot.h:529
vtkRectd GetShiftScale()
Get/set the origin shift and scaling factor used by the plot, this is normally 0.0 offset and 1....
virtual vtkStringArray * GetIndexedLabels()
Get the indexed labels array.
vtkSmartPointer< vtkContextMapper2D > Data
This data member contains the data that will be plotted, it inherits from vtkAlgorithm.
Definition vtkPlot.h:495
vtkSmartPointer< vtkStringArray > Labels
Plot labels, used by legend.
Definition vtkPlot.h:473
void SetInputData(vtkTable *table, vtkIdType xColumn, vtkIdType yColumn)
This is a convenience function to set the input table and the x, y column for the plot.
void Update() override
Perform any updates to the item that may be necessary before rendering.
virtual void SetTooltipPrecision(int precision)
Sets/gets the tooltip precision.
void SetShiftScale(const vtkRectd &shiftScale)
Get/set the origin shift and scaling factor used by the plot, this is normally 0.0 offset and 1....
static bool ClampPos(double pos[2], double bounds[4])
Clamp the given 2D pos into the provided bounds Return true if the pos has been clamped,...
virtual void TransformScreenToData(const vtkVector2f &in, vtkVector2f &out)
Transform the mouse event in the control-points space.
virtual void SetYAxis(vtkAxis *axis)
Get/set the Y axis associated with this plot.
bool Hit(const vtkContextMouseEvent &mouse) override
Returns true if the supplied x, y coordinate is inside the item.
vtkTimeStamp BuildTime
The point cache is marked dirty until it has been initialized.
Definition vtkPlot.h:446
vtkBrush * GetSelectionBrush()
Set/get the vtkBrush object that controls how this plot fills selected shapes.
virtual void TransformDataToScreen(const double inX, const double inY, double &outX, double &outY)
Transform the mouse event in the control-points space.
virtual vtkIdType GetNearestPoint(const vtkVector2f &point, const vtkVector2f &tolerance, vtkVector2f *location, vtkIdType *segmentId)
Function to query a plot for the nearest point to the specified coordinate.
vtkSmartPointer< vtkStringArray > AutoLabels
Holds Labels when they're auto-created.
Definition vtkPlot.h:478
virtual void TransformDataToScreen(const vtkVector2f &in, vtkVector2f &out)
Transform the mouse event in the control-points space.
virtual bool ClampPos(double pos[2])
Clamp the given 2D pos into the provided bounds Return true if the pos has been clamped,...
vtkStdString GetNumber(double position, vtkAxis *axis)
Get the properly formatted number for the supplied position and axis.
virtual void SetInputConnection(vtkAlgorithmOutput *input)
This is a convenience function to set the input connection for the plot.
vtkSmartPointer< vtkBrush > Brush
This object stores the vtkBrush that controls how the plot is drawn.
Definition vtkPlot.h:456
virtual bool CacheRequiresUpdate()
Test if the internal cache requires an update.
virtual bool SelectPointsInPolygon(const vtkContextPolygon &polygon)
Select all points in the specified polygon.
vtkBrush * GetBrush()
Set/get the vtkBrush object that controls how this plot fills shapes.
virtual void SetSelection(vtkIdTypeArray *id)
Sets the list of points that must be selected.
vtkSmartPointer< vtkPen > Pen
This object stores the vtkPen that controls how the plot is drawn.
Definition vtkPlot.h:451
virtual float GetWidth()
Get the width of the line.
virtual void SetLabels(vtkStringArray *labels)
Set the plot labels, these are used for stacked chart variants, with the index referring to the stack...
virtual void TransformScreenToData(const double inX, const double inY, double &outX, double &outY)
Transform the mouse event in the control-points space.
virtual void SetTooltipNotation(int notation)
Sets/gets the tooltip notation style.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
Hold a reference to a vtkObjectBase instance.
Wrapper around std::string to keep symbols short.
a vtkAbstractArray subclass for strings
A table, which contains similar-typed columns of data.
Definition vtkTable.h:74
record modification and/or execution time
A atomic type representing the union of many types.
Definition vtkVariant.h:70
int vtkIdType
Definition vtkType.h:332
#define max(a, b)