VTK  9.3.0
vtkPlot.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
30#ifndef vtkPlot_h
31#define vtkPlot_h
32
33#include "vtkChartsCoreModule.h" // For export macro
34#include "vtkContextItem.h"
35#include "vtkContextPolygon.h" // For vtkContextPolygon
36#include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_3_0
37#include "vtkRect.h" // For vtkRectd ivar
38#include "vtkSmartPointer.h" // Needed to hold SP ivars
39#include "vtkStdString.h" // Needed to hold TooltipLabelFormat ivar
40
41VTK_ABI_NAMESPACE_BEGIN
42class vtkVariant;
43class vtkTable;
44class vtkIdTypeArray;
46class vtkPen;
47class vtkBrush;
48class vtkAxis;
49class vtkStringArray;
51
52class VTKCHARTSCORE_EXPORT vtkPlot : public vtkContextItem
53{
54public:
55 vtkTypeMacro(vtkPlot, vtkContextItem);
56 void PrintSelf(ostream& os, vtkIndent indent) override;
57
63 void Update() override;
64
66
71 vtkSetMacro(LegendVisibility, bool);
72 vtkGetMacro(LegendVisibility, bool);
73 vtkBooleanMacro(LegendVisibility, bool);
75
83 virtual bool PaintLegend(vtkContext2D* painter, const vtkRectf& rect, int legendIndex);
84
86
98 virtual void SetTooltipLabelFormat(const vtkStdString& label);
101
103
106 virtual void SetTooltipNotation(int notation);
107 virtual int GetTooltipNotation();
109
111
114 virtual void SetTooltipPrecision(int precision);
115 virtual int GetTooltipPrecision();
117
123 const vtkVector2d& plotPos, vtkIdType seriesIndex, vtkIdType segmentIndex);
124
130 virtual vtkIdType GetNearestPoint(const vtkVector2f& point, const vtkVector2f& tolerance,
131 vtkVector2f* location, vtkIdType* segmentId);
132
136 virtual bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max);
137
141 virtual bool SelectPointsInPolygon(const vtkContextPolygon& polygon);
142
146 virtual void SetColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
147
149
152 virtual void SetColorF(double r, double g, double b, double a);
153 virtual void SetColorF(double r, double g, double b);
154
155 // If removed, please remplace it with the following function:
156 // SetColor(unsigned char r, unsigned char g, unsigned char b)
157 // here and in the inheriting classes overriding it
158 VTK_DEPRECATED_IN_9_3_0("Please use unambiguous SetColorF method instead.")
159 virtual void SetColor(double r, double g, double b) { this->SetColorF(r, g, b); };
161
165 void GetColor(unsigned char rgb[3]);
166
168
171 virtual void GetColorF(double rgb[3]);
172
173 // If removed, please make GetColor(unsigned char rgb[3]) virtual
174 VTK_DEPRECATED_IN_9_3_0("Please use unambiguous GetColorF method instead.")
175 virtual void GetColor(double rgb[3]) { this->GetColorF(rgb); };
177
181 virtual void SetWidth(float width);
182
186 virtual float GetWidth();
187
189
192 void SetPen(vtkPen* pen);
195
197
200 void SetBrush(vtkBrush* brush);
203
205
212
214
221
225 virtual void SetLabel(const vtkStdString& label);
226
231
236 virtual void SetLabels(vtkStringArray* labels);
237
243
247 virtual int GetNumberOfLabels();
248
253
260
265
270
272
276 vtkGetMacro(UseIndexForXSeries, bool);
278
280
284 vtkSetMacro(UseIndexForXSeries, bool);
286
288
292 virtual void SetInputData(vtkTable* table);
293 virtual void SetInputData(
294 vtkTable* table, const vtkStdString& xColumn, const vtkStdString& yColumn);
295 void SetInputData(vtkTable* table, vtkIdType xColumn, vtkIdType yColumn);
297
299
304
308 virtual vtkTable* GetInput();
309
314
320 virtual void SetInputArray(int index, const vtkStdString& name);
321
323
329 vtkSetMacro(Selectable, bool);
330 vtkGetMacro(Selectable, bool);
331 vtkBooleanMacro(Selectable, bool);
333
335
340 virtual void SetSelection(vtkIdTypeArray* id);
341 vtkGetObjectMacro(Selection, vtkIdTypeArray);
343
345
348 vtkGetObjectMacro(XAxis, vtkAxis);
349 virtual void SetXAxis(vtkAxis* axis);
351
353
356 vtkGetObjectMacro(YAxis, vtkAxis);
357 virtual void SetYAxis(vtkAxis* axis);
359
361
367 void SetShiftScale(const vtkRectd& shiftScale);
370
376 virtual void GetBounds(double bounds[4]) { bounds[0] = bounds[1] = bounds[2] = bounds[3] = 0.0; }
377
402 virtual void GetUnscaledInputBounds(double bounds[4])
403 {
404 // Implemented here by calling GetBounds() to support plot
405 // subclasses that do no log-scaling or plot orientation.
406 return this->GetBounds(bounds);
407 }
408
410
414 virtual void SetProperty(const vtkStdString& property, const vtkVariant& var);
415 virtual vtkVariant GetProperty(const vtkStdString& property);
417
419
423 static bool ClampPos(double pos[2], double bounds[4]);
424 virtual bool ClampPos(double pos[2]);
426
430 bool Hit(const vtkContextMouseEvent& mouse) override;
431
438 virtual bool UpdateCache() { return true; }
439
445 vtkDataArray* points, vtkDataArray* selectedPoints, vtkIdTypeArray* selectedIds);
446
447protected:
449 ~vtkPlot() override;
450
454 vtkStdString GetNumber(double position, vtkAxis* axis);
455
457
461 virtual void TransformScreenToData(const vtkVector2f& in, vtkVector2f& out);
462 virtual void TransformDataToScreen(const vtkVector2f& in, vtkVector2f& out);
463 virtual void TransformScreenToData(double inX, double inY, double& outX, double& outY);
464 virtual void TransformDataToScreen(double inX, double inY, double& outX, double& outY);
466
470 virtual bool CacheRequiresUpdate();
471
476
481
486
492
498
503
508
513
519
525
530
535
540
545
551
557
560
565
567
568private:
569 vtkPlot(const vtkPlot&) = delete;
570 void operator=(const vtkPlot&) = delete;
571};
572
573VTK_ABI_NAMESPACE_END
574#endif // vtkPlot_h
Proxy object to connect input/output ports.
takes care of drawing 2D axes
Definition vtkAxis.h:70
provides a brush that fills shapes drawn by vtkContext2D.
Definition vtkBrush.h:39
Class for drawing 2D primitives to a graphical context.
base class for items that are part of a vtkContextScene.
Abstract class for 2D context mappers.
data structure to represent mouse events.
abstract superclass for arrays of numeric data
dynamic, self-adjusting array of vtkIdType
a simple class to control print indentation
Definition vtkIndent.h:38
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition vtkPen.h:38
Abstract class for 2D plots.
Definition vtkPlot.h:53
bool UseIndexForXSeries
Use the Y array index for the X value.
Definition vtkPlot.h:518
virtual vtkStdString GetLabel()
Get the label of this plot.
virtual int GetTooltipPrecision()
Sets/gets the tooltip precision.
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:564
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:559
vtkSmartPointer< vtkStringArray > IndexedLabels
Holds Labels when they're auto-created.
Definition vtkPlot.h:512
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:539
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,...
static void FilterSelectedPoints(vtkDataArray *points, vtkDataArray *selectedPoints, vtkIdTypeArray *selectedIds)
Utility function that fills up selectedPoints with tuples from points.
vtkPen * GetPen()
Get the plot color as floating rgb values (comprised between 0.0 and 1.0)
virtual void SetWidth(float width)
@
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 with integer values (comprised between 0 and 255)
vtkStdString GetLabel(vtkIdType index)
Get the label at the specified index.
bool LegendVisibility
Definition vtkPlot.h:566
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:402
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.
virtual void TransformScreenToData(double inX, double inY, double &outX, double &outY)
Transform the mouse event in the control-points space.
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:534
virtual vtkStringArray * GetLabels()
Get the plot labels.
virtual void SetLabel(const vtkStdString &label)
Set the label of this plot.
virtual void SetColorF(double r, double g, double b, double a)
Set the plot color with floating values (comprised between 0.0 and 1.0)
vtkSmartPointer< vtkBrush > SelectionBrush
This object stores the vtkBrush that controls how the selected elements of the plot are drawn.
Definition vtkPlot.h:497
virtual void GetBounds(double bounds[4])
Get the bounds for this plot as (Xmin, Xmax, Ymin, Ymax).
Definition vtkPlot.h:376
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:438
vtkAxis * YAxis
The X axis associated with this plot.
Definition vtkPlot.h:544
vtkStdString TooltipDefaultLabelFormat
The default printf-style string to build custom tooltip labels from.
Definition vtkPlot.h:556
vtkSmartPointer< vtkPen > SelectionPen
This object stores the vtkPen that controls how the selected elements of the plot are drawn.
Definition vtkPlot.h:491
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])
Get the plot color as integer rgb values (comprised between 0 and 255)
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:550
bool Selectable
Whether plot points can be selected or not.
Definition vtkPlot.h:529
int TooltipNotation
Definition vtkPlot.h:558
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.
virtual void TransformDataToScreen(double inX, double inY, double &outX, double &outY)
Transform the mouse event in the control-points space.
vtkSmartPointer< vtkContextMapper2D > Data
This data member contains the data that will be plotted, it inherits from vtkAlgorithm.
Definition vtkPlot.h:524
vtkSmartPointer< vtkStringArray > Labels
Plot labels, used by legend.
Definition vtkPlot.h:502
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:475
vtkBrush * GetSelectionBrush()
Set/get the vtkBrush object that controls how this plot fills selected shapes.
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:507
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:485
virtual void SetColorF(double r, double g, double b)
Set the plot color with floating values (comprised between 0.0 and 1.0)
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:480
virtual float GetWidth()
Get the width of the line.
virtual void GetColorF(double rgb[3])
Get the plot color as floating rgb values (comprised between 0.0 and 1.0)
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 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:68
record modification and/or execution time
A type representing the union of many types.
Definition vtkVariant.h:62
#define VTK_DEPRECATED_IN_9_3_0(reason)
int vtkIdType
Definition vtkType.h:315
#define max(a, b)