VTK  9.0.1
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 
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 
37 class vtkVariant;
38 class vtkTable;
39 class vtkIdTypeArray;
40 class vtkContextMapper2D;
41 class vtkPen;
42 class vtkBrush;
43 class vtkAxis;
44 class vtkStringArray;
45 
46 class VTKCHARTSCORE_EXPORT vtkPlot : public vtkContextItem
47 {
48 public:
49  vtkTypeMacro(vtkPlot, vtkContextItem);
50  void PrintSelf(ostream& os, vtkIndent indent) override;
51 
53 
58  vtkSetMacro(LegendVisibility, bool);
59  vtkGetMacro(LegendVisibility, bool);
60  vtkBooleanMacro(LegendVisibility, bool);
62 
70  virtual bool PaintLegend(vtkContext2D* painter, const vtkRectf& rect, int legendIndex);
71 
73 
85  virtual void SetTooltipLabelFormat(const vtkStdString& label);
88 
90 
93  virtual void SetTooltipNotation(int notation);
94  virtual int GetTooltipNotation();
96 
98 
101  virtual void SetTooltipPrecision(int precision);
102  virtual int GetTooltipPrecision();
104 
110  const vtkVector2d& plotPos, vtkIdType seriesIndex, vtkIdType segmentIndex);
111 
117  virtual vtkIdType GetNearestPoint(const vtkVector2f& point, const vtkVector2f& tolerance,
119 #ifndef VTK_LEGACY_REMOVE
120  vtkIdType* segmentId);
121 #else
122  vtkIdType* segmentId = nullptr);
123 #endif // VTK_LEGACY_REMOVE
124 
125 #ifndef VTK_LEGACY_REMOVE
133  VTK_LEGACY(virtual vtkIdType GetNearestPoint(
134  const vtkVector2f& point, const vtkVector2f& tolerance, vtkVector2f* location));
135 #endif // VTK_LEGACY_REMOVE
136 
140  virtual bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max);
141 
145  virtual bool SelectPointsInPolygon(const vtkContextPolygon& polygon);
146 
148 
151  virtual void SetColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
152  virtual void SetColor(double r, double g, double b);
153  virtual void GetColor(double rgb[3]);
154  void GetColor(unsigned char rgb[3]);
156 
160  virtual void SetWidth(float width);
161 
165  virtual float GetWidth();
166 
168 
171  void SetPen(vtkPen* pen);
174 
176 
179  void SetBrush(vtkBrush* brush);
182 
184 
191 
193 
200 
204  virtual void SetLabel(const vtkStdString& label);
205 
210 
215  virtual void SetLabels(vtkStringArray* labels);
216 
222 
226  virtual int GetNumberOfLabels();
227 
232 
239 
244 
249 
251 
255  vtkGetMacro(UseIndexForXSeries, bool);
257 
259 
263  vtkSetMacro(UseIndexForXSeries, bool);
265 
267 
271  virtual void SetInputData(vtkTable* table);
272  virtual void SetInputData(
273  vtkTable* table, const vtkStdString& xColumn, const vtkStdString& yColumn);
274  void SetInputData(vtkTable* table, vtkIdType xColumn, vtkIdType yColumn);
276 
280  virtual vtkTable* GetInput();
281 
287  virtual void SetInputArray(int index, const vtkStdString& name);
288 
290 
296  vtkSetMacro(Selectable, bool);
297  vtkGetMacro(Selectable, bool);
298  vtkBooleanMacro(Selectable, bool);
300 
302 
307  virtual void SetSelection(vtkIdTypeArray* id);
308  vtkGetObjectMacro(Selection, vtkIdTypeArray);
310 
312 
315  vtkGetObjectMacro(XAxis, vtkAxis);
316  virtual void SetXAxis(vtkAxis* axis);
318 
320 
323  vtkGetObjectMacro(YAxis, vtkAxis);
324  virtual void SetYAxis(vtkAxis* axis);
326 
328 
334  void SetShiftScale(const vtkRectd& scaling);
337 
343  virtual void GetBounds(double bounds[4]) { bounds[0] = bounds[1] = bounds[2] = bounds[3] = 0.0; }
344 
369  virtual void GetUnscaledInputBounds(double bounds[4])
370  {
371  // Implemented here by calling GetBounds() to support plot
372  // subclasses that do no log-scaling or plot orientation.
373  return this->GetBounds(bounds);
374  }
375 
382  virtual void UpdateCache() {}
383 
385 
389  virtual void SetProperty(const vtkStdString& property, const vtkVariant& var);
390  virtual vtkVariant GetProperty(const vtkStdString& property);
392 
394 
398  static bool ClampPos(double pos[2], double bounds[4]);
399  virtual bool ClampPos(double pos[2]);
401 
402 protected:
404  ~vtkPlot() override;
405 
410 
412 
416  virtual void TransformScreenToData(const vtkVector2f& in, vtkVector2f& out);
417  virtual void TransformDataToScreen(const vtkVector2f& in, vtkVector2f& out);
418  virtual void TransformScreenToData(
419  const double inX, const double inY, double& outX, double& outY);
420  virtual void TransformDataToScreen(
421  const double inX, const double inY, double& outX, double& outY);
423 
428 
433 
439 
445 
450 
455 
460 
466 
472 
477 
482 
487 
492 
498 
504 
507 
512 
514 
515 #ifndef VTK_LEGACY_REMOVE
520  bool LegacyRecursionFlag = false;
521 #endif // VTK_LEGACY_REMOVE
522 
523 private:
524  vtkPlot(const vtkPlot&) = delete;
525  void operator=(const vtkPlot&) = delete;
526 };
527 
528 #endif // vtkPlot_h
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.
Definition: vtkContext2D.h:53
base class for items that are part of a vtkContextScene.
Abstract class for 2D context mappers.
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
Abstract class for 2D plots.
Definition: vtkPlot.h:47
bool UseIndexForXSeries
Use the Y array index for the X value.
Definition: vtkPlot.h:465
vtkBrush * GetSelectionBrush()
virtual vtkStdString GetLabel()
Get the label of this plot.
virtual void UpdateCache()
Subclasses that build data caches to speed up painting should override this method to update such cac...
Definition: vtkPlot.h:382
virtual int GetTooltipPrecision()
virtual void GetColor(double rgb[3])
vtkRectd ShiftScale
The current shift in origin and scaling factor applied to the plot.
Definition: vtkPlot.h:511
virtual int GetTooltipNotation()
void SetSelectionPen(vtkPen *pen)
Set/get the vtkBrush object that controls how this plot fills selected shapes.
int TooltipPrecision
Definition: vtkPlot.h:506
vtkSmartPointer< vtkStringArray > IndexedLabels
Holds Labels when they're auto-created.
Definition: vtkPlot.h:459
void SetIndexedLabels(vtkStringArray *labels)
Set indexed labels for the plot.
virtual void SetInputData(vtkTable *table, const vtkStdString &xColumn, const vtkStdString &yColumn)
virtual bool SelectPoints(const vtkVector2f &min, const vtkVector2f &max)
Select all points in the specified rectangle.
virtual vtkTable * GetInput()
Get the input table used by the plot.
vtkAxis * XAxis
The X axis associated with this plot.
Definition: vtkPlot.h:486
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,...
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()
virtual vtkVariant GetProperty(const vtkStdString &property)
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:513
vtkContextMapper2D * GetData()
Get the data object that the plot will draw.
virtual vtkStringArray * GetIndexedLabels()
Get the indexed labels array.
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:369
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:481
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:444
vtkPen * GetSelectionPen()
virtual void GetBounds(double bounds[4])
Get the bounds for this plot as (Xmin, Xmax, Ymin, Ymax).
Definition: vtkPlot.h:343
virtual void SetTooltipLabelFormat(const vtkStdString &label)
Sets/gets a printf-style string to build custom tooltip labels from.
virtual void SetXAxis(vtkAxis *axis)
vtkAxis * YAxis
The X axis associated with this plot.
Definition: vtkPlot.h:491
vtkStdString TooltipDefaultLabelFormat
The default printf-style string to build custom tooltip labels from.
Definition: vtkPlot.h:503
virtual void SetColor(double r, double g, double b)
vtkSmartPointer< vtkPen > SelectionPen
This object stores the vtkPen that controls how the selected elements of the plot are drawn.
Definition: vtkPlot.h:438
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.
vtkBrush * GetBrush()
void GetColor(unsigned char rgb[3])
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:497
bool Selectable
Whether plot points can be selected or not.
Definition: vtkPlot.h:476
int TooltipNotation
Definition: vtkPlot.h:505
vtkRectd GetShiftScale()
vtkSmartPointer< vtkContextMapper2D > Data
This data member contains the data that will be plotted, it inherits from vtkAlgorithm.
Definition: vtkPlot.h:471
void SetShiftScale(const vtkRectd &scaling)
Get/set the origin shift and scaling factor used by the plot, this is normally 0.0 offset and 1....
vtkSmartPointer< vtkStringArray > Labels
Plot labels, used by legend.
Definition: vtkPlot.h:449
void SetInputData(vtkTable *table, vtkIdType xColumn, vtkIdType yColumn)
virtual void SetTooltipPrecision(int precision)
Sets/gets the tooltip precision.
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)
virtual void TransformDataToScreen(const double inX, const double inY, double &outX, double &outY)
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:454
virtual void TransformDataToScreen(const vtkVector2f &in, vtkVector2f &out)
virtual bool ClampPos(double pos[2])
vtkStdString GetNumber(double position, vtkAxis *axis)
Get the properly formatted number for the supplied position and axis.
vtkSmartPointer< vtkBrush > Brush
This object stores the vtkBrush that controls how the plot is drawn.
Definition: vtkPlot.h:432
virtual bool SelectPointsInPolygon(const vtkContextPolygon &polygon)
Select all points in the specified polygon.
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:427
virtual float GetWidth()
Get the width of the line.
virtual vtkStringArray * GetLabels()
Get the plot labels.
vtkPen * GetPen()
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)
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.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:35
a vtkAbstractArray subclass for strings
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:63
A atomic type representing the union of many types.
Definition: vtkVariant.h:66
@ point
Definition: vtkX3D.h:242
@ location
Definition: vtkX3D.h:412
@ name
Definition: vtkX3D.h:225
@ position
Definition: vtkX3D.h:267
@ index
Definition: vtkX3D.h:252
int vtkIdType
Definition: vtkType.h:338
#define max(a, b)