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 
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 
43 class vtkVariant;
44 class vtkTable;
45 class vtkIdTypeArray;
46 class vtkContextMapper2D;
47 class vtkPen;
48 class vtkBrush;
49 class vtkAxis;
50 class vtkStringArray;
51 class vtkAlgorithmOutput;
52 
53 class VTKCHARTSCORE_EXPORT vtkPlot : public vtkContextItem
54 {
55 public:
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);
100  virtual vtkStdString GetTooltipLabelFormat();
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 
123  virtual vtkStdString GetTooltipLabel(
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);
169  vtkPen* GetPen();
171 
173 
176  void SetBrush(vtkBrush* brush);
177  vtkBrush* GetBrush();
179 
181 
185  void SetSelectionPen(vtkPen* pen);
186  vtkPen* GetSelectionPen();
188 
190 
194  void SetSelectionBrush(vtkBrush* brush);
195  vtkBrush* GetSelectionBrush();
197 
201  virtual void SetLabel(const vtkStdString& label);
202 
206  virtual vtkStdString GetLabel();
207 
212  virtual void SetLabels(vtkStringArray* labels);
213 
218  virtual vtkStringArray* GetLabels();
219 
223  virtual int GetNumberOfLabels();
224 
228  vtkStdString GetLabel(vtkIdType index);
229 
235  void SetIndexedLabels(vtkStringArray* labels);
236 
240  virtual vtkStringArray* GetIndexedLabels();
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 
278  virtual void SetInputConnection(vtkAlgorithmOutput* input);
280 
284  virtual vtkTable* GetInput();
285 
289  vtkAlgorithmOutput* GetInputConnection();
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);
344  vtkRectd GetShiftScale();
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 
416 protected:
417  vtkPlot();
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);
432  virtual void TransformScreenToData(
433  const double inX, const double inY, double& outX, double& outY);
434  virtual void TransformDataToScreen(
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 
539 private:
540  vtkPlot(const vtkPlot&) = delete;
541  void operator=(const vtkPlot&) = delete;
542 };
543 
544 #endif // vtkPlot_h
vtkAxis * XAxis
The X axis associated with this plot.
Definition: vtkPlot.h:510
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:38
void GetBounds(T a, double bds[6])
vtkRectd ShiftScale
The current shift in origin and scaling factor applied to the plot.
Definition: vtkPlot.h:535
base class for items that are part of a vtkContextScene.
vtkSmartPointer< vtkStringArray > IndexedLabels
Holds Labels when they're auto-created.
Definition: vtkPlot.h:483
vtkSmartPointer< vtkBrush > Brush
This object stores the vtkBrush that controls how the plot is drawn.
Definition: vtkPlot.h:456
int TooltipNotation
Definition: vtkPlot.h:529
record modification and/or execution time
Definition: vtkTimeStamp.h:35
virtual void GetBounds(double bounds[4])
Get the bounds for this plot as (Xmin, Xmax, Ymin, Ymax).
Definition: vtkPlot.h:352
a vtkAbstractArray subclass for strings
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:332
bool Selectable
Whether plot points can be selected or not.
Definition: vtkPlot.h:500
int TooltipPrecision
Definition: vtkPlot.h:530
Abstract class for 2D context mappers.
vtkSmartPointer< vtkPen > SelectionPen
This object stores the vtkPen that controls how the selected elements of the plot are drawn...
Definition: vtkPlot.h:462
A atomic type representing the union of many types.
Definition: vtkVariant.h:69
Proxy object to connect input/output ports.
vtkStdString TooltipDefaultLabelFormat
The default printf-style string to build custom tooltip labels from.
Definition: vtkPlot.h:527
vtkIdTypeArray * Selection
Selected indices for the table the plot is rendering.
Definition: vtkPlot.h:505
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:57
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:40
takes care of drawing 2D axes
Definition: vtkAxis.h:71
data structure to represent mouse events.
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkSmartPointer< vtkBrush > SelectionBrush
This object stores the vtkBrush that controls how the selected elements of the plot are drawn...
Definition: vtkPlot.h:468
vtkTimeStamp BuildTime
The point cache is marked dirty until it has been initialized.
Definition: vtkPlot.h:446
vtkSmartPointer< vtkContextMapper2D > Data
This data member contains the data that will be plotted, it inherits from vtkAlgorithm.
Definition: vtkPlot.h:495
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual bool UpdateCache()
Update the internal cache.
Definition: vtkPlot.h:414
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:39
Abstract class for 2D plots.
Definition: vtkPlot.h:53
vtkSmartPointer< vtkStringArray > Labels
Plot labels, used by legend.
Definition: vtkPlot.h:473
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.
vtkSmartPointer< vtkStringArray > AutoLabels
Holds Labels when they're auto-created.
Definition: vtkPlot.h:478
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:73
virtual void GetUnscaledInputBounds(double bounds[4])
Provide un-log-scaled bounds for the plot inputs.
Definition: vtkPlot.h:378
vtkAxis * YAxis
The X axis associated with this plot.
Definition: vtkPlot.h:515
virtual bool Hit(const vtkContextMouseEvent &mouse)
Return true if the supplied x, y coordinate is inside the item.
bool LegendVisibility
Definition: vtkPlot.h:537
vtkStdString TooltipLabelFormat
A printf-style string to build custom tooltip labels from.
Definition: vtkPlot.h:521
vtkSmartPointer< vtkPen > Pen
This object stores the vtkPen that controls how the plot is drawn.
Definition: vtkPlot.h:451
virtual void Update()
Perform any updates to the item that may be necessary before rendering.
#define max(a, b)
bool UseIndexForXSeries
Use the Y array index for the X value.
Definition: vtkPlot.h:489