VTK  9.7.1
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 
21 #ifndef vtkPlot_h
22 #define vtkPlot_h
23 
24 #include "vtkChartsCoreModule.h" // For export macro
25 #include "vtkContextItem.h"
26 #include "vtkContextPolygon.h" // For vtkContextPolygon
27 #include "vtkRect.h" // For vtkRectd ivar
28 #include "vtkSmartPointer.h" // Needed to hold SP ivars
29 #include "vtkStdString.h" // Needed to hold TooltipLabelFormat ivar
30 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
31 
32 VTK_ABI_NAMESPACE_BEGIN
33 class vtkVariant;
34 class vtkTable;
35 class vtkIdTypeArray;
36 class vtkContextMapper2D;
37 class vtkPen;
38 class vtkBrush;
39 class vtkAxis;
40 class vtkStringArray;
41 class vtkAlgorithmOutput;
42 
43 class VTKCHARTSCORE_EXPORT VTK_MARSHALAUTO vtkPlot : public vtkContextItem
44 {
45 public:
46  vtkTypeMacro(vtkPlot, vtkContextItem);
47  void PrintSelf(ostream& os, vtkIndent indent) override;
48 
54  void Update() override;
55 
57 
62  vtkSetMacro(LegendVisibility, bool);
63  vtkGetMacro(LegendVisibility, bool);
64  vtkBooleanMacro(LegendVisibility, bool);
66 
74  virtual bool PaintLegend(vtkContext2D* painter, const vtkRectf& rect, int legendIndex);
75 
77 
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 
149  virtual void SetColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
150  virtual void SetColor(unsigned char r, unsigned char g, unsigned char b);
152 
154 
158  virtual void SetColorF(double r, double g, double b, double a);
160  virtual void SetColorF(double r, double g, double b);
162 
164 
167  virtual void GetColor(unsigned char rgb[3]);
169  void GetColorRGBA(unsigned char rgba[4]);
171 
173 
177  virtual void GetColorF(double rgb[3]);
179 
183  virtual void SetWidth(float width);
184 
188  virtual float GetWidth();
189 
191 
194  void SetPen(vtkPen* pen);
195  vtkPen* GetPen();
197 
199 
202  void SetBrush(vtkBrush* brush);
203  vtkBrush* GetBrush();
205 
207 
211  void SetSelectionPen(vtkPen* pen);
212  vtkPen* GetSelectionPen();
214 
216 
220  void SetSelectionBrush(vtkBrush* brush);
221  vtkBrush* GetSelectionBrush();
223 
227  virtual void SetLabel(const vtkStdString& label);
228 
232  virtual vtkStdString GetLabel();
233 
238  virtual void SetLabels(vtkStringArray* labels);
239 
244  virtual vtkStringArray* GetLabels();
245 
249  virtual int GetNumberOfLabels();
250 
254  vtkStdString GetLabel(vtkIdType index);
255 
261  void SetIndexedLabels(vtkStringArray* labels);
262 
266  virtual vtkStringArray* GetIndexedLabels();
267 
272 
274 
278  vtkGetMacro(UseIndexForXSeries, bool);
280 
282 
286  vtkSetMacro(UseIndexForXSeries, bool);
288 
290 
294  VTK_MARSHALSETTER(Input)
295  virtual void SetInputData(vtkTable* table);
296  virtual void SetInputData(
297  vtkTable* table, const vtkStdString& xColumn, const vtkStdString& yColumn);
298  void SetInputData(vtkTable* table, vtkIdType xColumn, vtkIdType yColumn);
300 
302 
306  virtual void SetInputConnection(vtkAlgorithmOutput* input);
308 
312  VTK_MARSHALGETTER(Input)
313  virtual vtkTable* GetInput();
314 
319  vtkAlgorithmOutput* GetInputConnection();
320 
326  virtual void SetInputArray(int index, const vtkStdString& name);
327 
329 
333  void SetXAxisInputArrayToProcess(const std::string& name);
334  std::string GetXAxisInputArrayToProcess();
335  void SetYAxisInputArrayToProcess(const std::string& name);
336  std::string GetYAxisInputArrayToProcess();
338 
340 
346  vtkSetMacro(Selectable, bool);
347  vtkGetMacro(Selectable, bool);
348  vtkBooleanMacro(Selectable, bool);
350 
352 
357  virtual void SetSelection(vtkIdTypeArray* id);
358  vtkGetObjectMacro(Selection, vtkIdTypeArray);
360 
362 
365  vtkGetObjectMacro(XAxis, vtkAxis);
366  virtual void SetXAxis(vtkAxis* axis);
368 
370 
373  vtkGetObjectMacro(YAxis, vtkAxis);
374  virtual void SetYAxis(vtkAxis* axis);
376 
378 
384  void SetShiftScale(const vtkRectd& shiftScale);
385  vtkRectd GetShiftScale();
387 
393  virtual void GetBounds(double bounds[4]) { bounds[0] = bounds[1] = bounds[2] = bounds[3] = 0.0; }
394 
419  virtual void GetUnscaledInputBounds(double bounds[4])
420  {
421  // Implemented here by calling GetBounds() to support plot
422  // subclasses that do no log-scaling or plot orientation.
423  this->GetBounds(bounds);
424  }
425 
427 
431  virtual void SetProperty(const vtkStdString& property, const vtkVariant& var);
432  virtual vtkVariant GetProperty(const vtkStdString& property);
434 
436 
440  static bool ClampPos(double pos[2], double bounds[4]);
441  virtual bool ClampPos(double pos[2]);
443 
447  bool Hit(const vtkContextMouseEvent& mouse) override;
448 
455  virtual bool UpdateCache() { return true; }
456 
461  static void FilterSelectedPoints(
462  vtkDataArray* points, vtkDataArray* selectedPoints, vtkIdTypeArray* selectedIds);
463 
464 protected:
465  vtkPlot();
466  ~vtkPlot() override;
467 
471  vtkStdString GetNumber(double position, vtkAxis* axis);
472 
474 
478  virtual void TransformScreenToData(const vtkVector2f& in, vtkVector2f& out);
479  virtual void TransformDataToScreen(const vtkVector2f& in, vtkVector2f& out);
480  virtual void TransformScreenToData(double inX, double inY, double& outX, double& outY);
481  virtual void TransformDataToScreen(double inX, double inY, double& outX, double& outY);
483 
487  virtual bool CacheRequiresUpdate();
488 
493 
498 
503 
509 
515 
520 
525 
530 
536 
542 
547 
552 
557 
562 
568 
574 
577 
582 
584 
585 private:
586  vtkPlot(const vtkPlot&) = delete;
587  void operator=(const vtkPlot&) = delete;
588 };
589 
590 VTK_ABI_NAMESPACE_END
591 #endif // vtkPlot_h
vtkAxis * XAxis
The X axis associated with this plot.
Definition: vtkPlot.h:556
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:27
void GetBounds(T a, double bds[6])
vtkRectd ShiftScale
The current shift in origin and scaling factor applied to the plot.
Definition: vtkPlot.h:581
base class for items that are part of a vtkContextScene.
vtkSmartPointer< vtkStringArray > IndexedLabels
Holds Labels when they're auto-created.
Definition: vtkPlot.h:529
vtkSmartPointer< vtkBrush > Brush
This object stores the vtkBrush that controls how the plot is drawn.
Definition: vtkPlot.h:502
int TooltipNotation
Definition: vtkPlot.h:575
record modification and/or execution time
Definition: vtkTimeStamp.h:24
#define VTK_MARSHAL_EXCLUDE_REASON_IS_REDUNDANT
a vtkAbstractArray subclass for strings
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:363
bool Selectable
Whether plot points can be selected or not.
Definition: vtkPlot.h:546
int TooltipPrecision
Definition: vtkPlot.h:576
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:508
A type representing the union of many types.
Definition: vtkVariant.h:52
Proxy object to connect input/output ports.
vtkStdString TooltipDefaultLabelFormat
The default printf-style string to build custom tooltip labels from.
Definition: vtkPlot.h:573
vtkIdTypeArray * Selection
Selected indices for the table the plot is rendering.
Definition: vtkPlot.h:551
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:49
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:30
takes care of drawing 2D axes
Definition: vtkAxis.h:61
data structure to represent mouse events.
a simple class to control print indentation
Definition: vtkIndent.h:28
vtkSmartPointer< vtkBrush > SelectionBrush
This object stores the vtkBrush that controls how the selected elements of the plot are drawn...
Definition: vtkPlot.h:514
vtkTimeStamp BuildTime
The point cache is marked dirty until it has been initialized.
Definition: vtkPlot.h:492
vtkSmartPointer< vtkContextMapper2D > Data
This data member contains the data that will be plotted, it inherits from vtkAlgorithm.
Definition: vtkPlot.h:541
#define VTK_MARSHALGETTER(property)
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
virtual bool UpdateCache()
Update the internal cache.
Definition: vtkPlot.h:455
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:29
Abstract class for 2D plots.
Definition: vtkPlot.h:43
vtkSmartPointer< vtkStringArray > Labels
Plot labels, used by legend.
Definition: vtkPlot.h:519
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.
#define VTK_MARSHALEXCLUDE(reason)
vtkSmartPointer< vtkStringArray > AutoLabels
Holds Labels when they're auto-created.
Definition: vtkPlot.h:524
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:59
virtual void GetUnscaledInputBounds(double bounds[4])
Provide un-log-scaled bounds for the plot inputs.
Definition: vtkPlot.h:419
vtkAxis * YAxis
The X axis associated with this plot.
Definition: vtkPlot.h:561
virtual bool Hit(const vtkContextMouseEvent &mouse)
Return true if the supplied x, y coordinate is inside the item.
#define VTK_MARSHALAUTO
bool LegendVisibility
Definition: vtkPlot.h:583
vtkStdString TooltipLabelFormat
A printf-style string to build custom tooltip labels from.
Definition: vtkPlot.h:567
vtkSmartPointer< vtkPen > Pen
This object stores the vtkPen that controls how the plot is drawn.
Definition: vtkPlot.h:497
virtual void Update()
Perform any updates to the item that may be necessary before rendering.
#define max(a, b)
#define VTK_MARSHAL_EXCLUDE_REASON_IS_INTERNAL
#define VTK_MARSHALSETTER(property)
bool UseIndexForXSeries
Use the Y array index for the X value.
Definition: vtkPlot.h:535