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
26
27#ifndef vtkPlot_h
28#define vtkPlot_h
29
30#include "vtkChartsCoreModule.h" // For export macro
31#include "vtkContextItem.h"
32#include "vtkContextPolygon.h" // For vtkContextPolygon
33#include "vtkRect.h" // For vtkRectd ivar
34#include "vtkSmartPointer.h" // Needed to hold SP ivars
35#include "vtkStdString.h" // Needed to hold TooltipLabelFormat ivar
36
37class vtkVariant;
38class vtkTable;
39class vtkIdTypeArray;
41class vtkPen;
42class vtkBrush;
43class vtkAxis;
44class vtkStringArray;
46
47class VTKCHARTSCORE_EXPORT vtkPlot : public vtkContextItem
48{
49public:
50 vtkTypeMacro(vtkPlot, vtkContextItem);
51 void PrintSelf(ostream& os, vtkIndent indent) override;
52
58 void Update() override;
59
61
66 vtkSetMacro(LegendVisibility, bool);
67 vtkGetMacro(LegendVisibility, bool);
68 vtkBooleanMacro(LegendVisibility, bool);
70
78 virtual bool PaintLegend(vtkContext2D* painter, const vtkRectf& rect, int legendIndex);
79
81
93 virtual void SetTooltipLabelFormat(const vtkStdString& label);
96
98
101 virtual void SetTooltipNotation(int notation);
102 virtual int GetTooltipNotation();
104
106
109 virtual void SetTooltipPrecision(int precision);
110 virtual int GetTooltipPrecision();
112
118 const vtkVector2d& plotPos, vtkIdType seriesIndex, vtkIdType segmentIndex);
119
125 virtual vtkIdType GetNearestPoint(const vtkVector2f& point, const vtkVector2f& tolerance,
126 vtkVector2f* location, vtkIdType* segmentId);
127
131 virtual bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max);
132
136 virtual bool SelectPointsInPolygon(const vtkContextPolygon& polygon);
137
139
142 virtual void SetColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
143 virtual void SetColor(double r, double g, double b);
144 virtual void GetColor(double rgb[3]);
145 void GetColor(unsigned char rgb[3]);
147
151 virtual void SetWidth(float width);
152
156 virtual float GetWidth();
157
159
162 void SetPen(vtkPen* pen);
165
167
170 void SetBrush(vtkBrush* brush);
173
175
182
184
191
195 virtual void SetLabel(const vtkStdString& label);
196
201
206 virtual void SetLabels(vtkStringArray* labels);
207
213
217 virtual int GetNumberOfLabels();
218
223
230
235
240
242
246 vtkGetMacro(UseIndexForXSeries, bool);
248
250
254 vtkSetMacro(UseIndexForXSeries, bool);
256
258
262 virtual void SetInputData(vtkTable* table);
263 virtual void SetInputData(
264 vtkTable* table, const vtkStdString& xColumn, const vtkStdString& yColumn);
265 void SetInputData(vtkTable* table, vtkIdType xColumn, vtkIdType yColumn);
267
269
274
278 virtual vtkTable* GetInput();
279
284
290 virtual void SetInputArray(int index, const vtkStdString& name);
291
293
299 vtkSetMacro(Selectable, bool);
300 vtkGetMacro(Selectable, bool);
301 vtkBooleanMacro(Selectable, bool);
303
305
310 virtual void SetSelection(vtkIdTypeArray* id);
311 vtkGetObjectMacro(Selection, vtkIdTypeArray);
313
315
318 vtkGetObjectMacro(XAxis, vtkAxis);
319 virtual void SetXAxis(vtkAxis* axis);
321
323
326 vtkGetObjectMacro(YAxis, vtkAxis);
327 virtual void SetYAxis(vtkAxis* axis);
329
331
337 void SetShiftScale(const vtkRectd& shiftScale);
340
346 virtual void GetBounds(double bounds[4]) { bounds[0] = bounds[1] = bounds[2] = bounds[3] = 0.0; }
347
372 virtual void GetUnscaledInputBounds(double bounds[4])
373 {
374 // Implemented here by calling GetBounds() to support plot
375 // subclasses that do no log-scaling or plot orientation.
376 return this->GetBounds(bounds);
377 }
378
380
384 virtual void SetProperty(const vtkStdString& property, const vtkVariant& var);
385 virtual vtkVariant GetProperty(const vtkStdString& property);
387
389
393 static bool ClampPos(double pos[2], double bounds[4]);
394 virtual bool ClampPos(double pos[2]);
396
400 bool Hit(const vtkContextMouseEvent& mouse) override;
401
408 virtual bool UpdateCache() { return true; }
409
410protected:
412 ~vtkPlot() override;
413
417 vtkStdString GetNumber(double position, vtkAxis* axis);
418
420
424 virtual void TransformScreenToData(const vtkVector2f& in, vtkVector2f& out);
425 virtual void TransformDataToScreen(const vtkVector2f& in, vtkVector2f& out);
427 const double inX, const double inY, double& outX, double& outY);
429 const double inX, const double inY, double& outX, double& outY);
431
435 virtual bool CacheRequiresUpdate();
436
441
446
451
457
463
468
473
478
484
490
495
500
505
510
516
522
525
530
532
533private:
534 vtkPlot(const vtkPlot&) = delete;
535 void operator=(const vtkPlot&) = delete;
536};
537
538#endif // vtkPlot_h
Proxy object to connect input/output ports.
takes care of drawing 2D axes
Definition vtkAxis.h:69
provides a brush that fills shapes drawn by vtkContext2D.
Definition vtkBrush.h:38
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:34
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition vtkPen.h:37
bool UseIndexForXSeries
Use the Y array index for the X value.
Definition vtkPlot.h:483
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:529
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:524
vtkSmartPointer< vtkStringArray > IndexedLabels
Holds Labels when they're auto-created.
Definition vtkPlot.h:477
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:504
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:531
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:372
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:499
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:462
virtual void GetBounds(double bounds[4])
Get the bounds for this plot as (Xmin, Xmax, Ymin, Ymax).
Definition vtkPlot.h:346
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:408
vtkAxis * YAxis
The X axis associated with this plot.
Definition vtkPlot.h:509
vtkStdString TooltipDefaultLabelFormat
The default printf-style string to build custom tooltip labels from.
Definition vtkPlot.h:521
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:456
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:515
bool Selectable
Whether plot points can be selected or not.
Definition vtkPlot.h:494
int TooltipNotation
Definition vtkPlot.h:523
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:489
vtkSmartPointer< vtkStringArray > Labels
Plot labels, used by legend.
Definition vtkPlot.h:467
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:440
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:472
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:450
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:445
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:68
record modification and/or execution time
A atomic type representing the union of many types.
Definition vtkVariant.h:64
int vtkIdType
Definition vtkType.h:332
#define max(a, b)