VTK  9.1.0
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 "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_0_0
34 #include "vtkRect.h" // For vtkRectd ivar
35 #include "vtkSmartPointer.h" // Needed to hold SP ivars
36 #include "vtkStdString.h" // Needed to hold TooltipLabelFormat ivar
37 
38 class vtkVariant;
39 class vtkTable;
40 class vtkIdTypeArray;
41 class vtkContextMapper2D;
42 class vtkPen;
43 class vtkBrush;
44 class vtkAxis;
45 class vtkStringArray;
46 
47 class VTKCHARTSCORE_EXPORT vtkPlot : public vtkContextItem
48 {
49 public:
50  vtkTypeMacro(vtkPlot, vtkContextItem);
51  void PrintSelf(ostream& os, vtkIndent indent) override;
52 
54 
59  vtkSetMacro(LegendVisibility, bool);
60  vtkGetMacro(LegendVisibility, bool);
61  vtkBooleanMacro(LegendVisibility, bool);
63 
71  virtual bool PaintLegend(vtkContext2D* painter, const vtkRectf& rect, int legendIndex);
72 
74 
86  virtual void SetTooltipLabelFormat(const vtkStdString& label);
89 
91 
94  virtual void SetTooltipNotation(int notation);
95  virtual int GetTooltipNotation();
97 
99 
102  virtual void SetTooltipPrecision(int precision);
103  virtual int GetTooltipPrecision();
105 
111  const vtkVector2d& plotPos, vtkIdType seriesIndex, vtkIdType segmentIndex);
112 
118  virtual vtkIdType GetNearestPoint(const vtkVector2f& point, const vtkVector2f& tolerance,
119  vtkVector2f* location, vtkIdType* segmentId);
120 
128  VTK_DEPRECATED_IN_9_0_0("Use the vtkPlot::GetNearestPoint() overload with a segmentId argument")
129  virtual vtkIdType GetNearestPoint(
130  const vtkVector2f& point, const vtkVector2f& tolerance, vtkVector2f* location);
131 
135  virtual bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max);
136 
140  virtual bool SelectPointsInPolygon(const vtkContextPolygon& polygon);
141 
143 
146  virtual void SetColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
147  virtual void SetColor(double r, double g, double b);
148  virtual void GetColor(double rgb[3]);
149  void GetColor(unsigned char rgb[3]);
151 
155  virtual void SetWidth(float width);
156 
160  virtual float GetWidth();
161 
163 
166  void SetPen(vtkPen* pen);
167  vtkPen* GetPen();
169 
171 
174  void SetBrush(vtkBrush* brush);
175  vtkBrush* GetBrush();
177 
179 
183  void SetSelectionPen(vtkPen* pen);
184  vtkPen* GetSelectionPen();
186 
188 
192  void SetSelectionBrush(vtkBrush* brush);
193  vtkBrush* GetSelectionBrush();
195 
199  virtual void SetLabel(const vtkStdString& label);
200 
204  virtual vtkStdString GetLabel();
205 
210  virtual void SetLabels(vtkStringArray* labels);
211 
216  virtual vtkStringArray* GetLabels();
217 
221  virtual int GetNumberOfLabels();
222 
227 
233  void SetIndexedLabels(vtkStringArray* labels);
234 
238  virtual vtkStringArray* GetIndexedLabels();
239 
244 
246 
250  vtkGetMacro(UseIndexForXSeries, bool);
252 
254 
258  vtkSetMacro(UseIndexForXSeries, bool);
260 
262 
266  virtual void SetInputData(vtkTable* table);
267  virtual void SetInputData(
268  vtkTable* table, const vtkStdString& xColumn, const vtkStdString& yColumn);
269  void SetInputData(vtkTable* table, vtkIdType xColumn, vtkIdType yColumn);
271 
275  virtual vtkTable* GetInput();
276 
282  virtual void SetInputArray(int index, const vtkStdString& name);
283 
285 
291  vtkSetMacro(Selectable, bool);
292  vtkGetMacro(Selectable, bool);
293  vtkBooleanMacro(Selectable, bool);
295 
297 
302  virtual void SetSelection(vtkIdTypeArray* id);
303  vtkGetObjectMacro(Selection, vtkIdTypeArray);
305 
307 
310  vtkGetObjectMacro(XAxis, vtkAxis);
311  virtual void SetXAxis(vtkAxis* axis);
313 
315 
318  vtkGetObjectMacro(YAxis, vtkAxis);
319  virtual void SetYAxis(vtkAxis* axis);
321 
323 
329  void SetShiftScale(const vtkRectd& shiftScale);
330  vtkRectd GetShiftScale();
332 
338  virtual void GetBounds(double bounds[4]) { bounds[0] = bounds[1] = bounds[2] = bounds[3] = 0.0; }
339 
364  virtual void GetUnscaledInputBounds(double bounds[4])
365  {
366  // Implemented here by calling GetBounds() to support plot
367  // subclasses that do no log-scaling or plot orientation.
368  return this->GetBounds(bounds);
369  }
370 
377  virtual void UpdateCache() {}
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 
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 
519  // VTK_DEPRECATED_IN_9_0_0("used to track deprecation integration logic")
520  bool LegacyRecursionFlag = false;
521 
522 private:
523  vtkPlot(const vtkPlot&) = delete;
524  void operator=(const vtkPlot&) = delete;
525 };
526 
527 #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:54
base class for items that are part of a vtkContextScene.
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
Abstract class for 2D plots.
Definition: vtkPlot.h:48
bool UseIndexForXSeries
Use the Y array index for the X value.
Definition: vtkPlot.h:465
virtual void UpdateCache()
Subclasses that build data caches to speed up painting should override this method to update such cac...
Definition: vtkPlot.h:377
virtual int GetTooltipPrecision()
Sets/gets the tooltip precision.
vtkRectd ShiftScale
The current shift in origin and scaling factor applied to the plot.
Definition: vtkPlot.h:511
virtual int GetTooltipNotation()
Sets/gets the tooltip notation style.
int TooltipPrecision
Definition: vtkPlot.h:506
vtkSmartPointer< vtkStringArray > IndexedLabels
Holds Labels when they're auto-created.
Definition: vtkPlot.h:459
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,...
~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.
bool LegendVisibility
Definition: vtkPlot.h:513
virtual void GetUnscaledInputBounds(double bounds[4])
Provide un-log-scaled bounds for the plot inputs.
Definition: vtkPlot.h:364
vtkIdTypeArray * Selection
Selected indices for the table the plot is rendering.
Definition: vtkPlot.h:481
vtkSmartPointer< vtkBrush > SelectionBrush
This object stores the vtkBrush that controls how the selected elements of the plot are drawn.
Definition: vtkPlot.h:444
virtual void SetTooltipLabelFormat(const vtkStdString &label)
Sets/gets a printf-style string to build custom tooltip labels from.
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
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...
virtual void SetProperty(const vtkStdString &property, const vtkVariant &var)
A General setter/getter that should be overridden.
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
vtkSmartPointer< vtkContextMapper2D > Data
This data member contains the data that will be plotted, it inherits from vtkAlgorithm.
Definition: vtkPlot.h:471
vtkSmartPointer< vtkStringArray > Labels
Plot labels, used by legend.
Definition: vtkPlot.h:449
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.
bool Hit(const vtkContextMouseEvent &mouse) override
Returns true if the supplied x, y coordinate is inside the item.
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:454
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.
vtkSmartPointer< vtkBrush > Brush
This object stores the vtkBrush that controls how the plot is drawn.
Definition: vtkPlot.h:432
vtkSmartPointer< vtkPen > Pen
This object stores the vtkPen that controls how the plot is drawn.
Definition: vtkPlot.h:427
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.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:36
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
void GetBounds(T a, double bds[6])
vtkSmartPointer< vtkDataArray > GetData(const Ioss::GroupingEntity *entity, const std::string &fieldname, Ioss::Transform *transform=nullptr, Cache *cache=nullptr, const std::string &cachekey=std::string())
Returns a VTK array for a given field (fieldname) on the chosen block (or set) entity.
@ 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
#define VTK_DEPRECATED_IN_9_0_0(reason)
int vtkIdType
Definition: vtkType.h:332
#define max(a, b)