VTK  9.3.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 "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_3_0
28 #include "vtkRect.h" // For vtkRectd ivar
29 #include "vtkSmartPointer.h" // Needed to hold SP ivars
30 #include "vtkStdString.h" // Needed to hold TooltipLabelFormat ivar
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 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 
89  virtual void SetTooltipLabelFormat(const vtkStdString& label);
90  virtual vtkStdString GetTooltipLabelFormat();
92 
94 
97  virtual void SetTooltipNotation(int notation);
98  virtual int GetTooltipNotation();
100 
102 
105  virtual void SetTooltipPrecision(int precision);
106  virtual int GetTooltipPrecision();
108 
113  virtual vtkStdString GetTooltipLabel(
114  const vtkVector2d& plotPos, vtkIdType seriesIndex, vtkIdType segmentIndex);
115 
121  virtual vtkIdType GetNearestPoint(const vtkVector2f& point, const vtkVector2f& tolerance,
122  vtkVector2f* location, vtkIdType* segmentId);
123 
127  virtual bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max);
128 
132  virtual bool SelectPointsInPolygon(const vtkContextPolygon& polygon);
133 
137  virtual void SetColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
138 
140 
143  virtual void SetColorF(double r, double g, double b, double a);
144  virtual void SetColorF(double r, double g, double b);
145 
146  // If removed, please remplace it with the following function:
147  // SetColor(unsigned char r, unsigned char g, unsigned char b)
148  // here and in the inheriting classes overriding it
149  VTK_DEPRECATED_IN_9_3_0("Please use unambiguous SetColorF method instead.")
150  virtual void SetColor(double r, double g, double b) { this->SetColorF(r, g, b); };
152 
156  void GetColor(unsigned char rgb[3]);
157 
159 
162  virtual void GetColorF(double rgb[3]);
163 
164  // If removed, please make GetColor(unsigned char rgb[3]) virtual
165  VTK_DEPRECATED_IN_9_3_0("Please use unambiguous GetColorF method instead.")
166  virtual void GetColor(double rgb[3]) { this->GetColorF(rgb); };
168 
172  virtual void SetWidth(float width);
173 
177  virtual float GetWidth();
178 
180 
183  void SetPen(vtkPen* pen);
184  vtkPen* GetPen();
186 
188 
191  void SetBrush(vtkBrush* brush);
192  vtkBrush* GetBrush();
194 
196 
200  void SetSelectionPen(vtkPen* pen);
201  vtkPen* GetSelectionPen();
203 
205 
209  void SetSelectionBrush(vtkBrush* brush);
210  vtkBrush* GetSelectionBrush();
212 
216  virtual void SetLabel(const vtkStdString& label);
217 
221  virtual vtkStdString GetLabel();
222 
227  virtual void SetLabels(vtkStringArray* labels);
228 
233  virtual vtkStringArray* GetLabels();
234 
238  virtual int GetNumberOfLabels();
239 
243  vtkStdString GetLabel(vtkIdType index);
244 
250  void SetIndexedLabels(vtkStringArray* labels);
251 
255  virtual vtkStringArray* GetIndexedLabels();
256 
261 
263 
267  vtkGetMacro(UseIndexForXSeries, bool);
269 
271 
275  vtkSetMacro(UseIndexForXSeries, bool);
277 
279 
283  virtual void SetInputData(vtkTable* table);
284  virtual void SetInputData(
285  vtkTable* table, const vtkStdString& xColumn, const vtkStdString& yColumn);
286  void SetInputData(vtkTable* table, vtkIdType xColumn, vtkIdType yColumn);
288 
290 
293  virtual void SetInputConnection(vtkAlgorithmOutput* input);
295 
299  virtual vtkTable* GetInput();
300 
304  vtkAlgorithmOutput* GetInputConnection();
305 
311  virtual void SetInputArray(int index, const vtkStdString& name);
312 
314 
320  vtkSetMacro(Selectable, bool);
321  vtkGetMacro(Selectable, bool);
322  vtkBooleanMacro(Selectable, bool);
324 
326 
331  virtual void SetSelection(vtkIdTypeArray* id);
332  vtkGetObjectMacro(Selection, vtkIdTypeArray);
334 
336 
339  vtkGetObjectMacro(XAxis, vtkAxis);
340  virtual void SetXAxis(vtkAxis* axis);
342 
344 
347  vtkGetObjectMacro(YAxis, vtkAxis);
348  virtual void SetYAxis(vtkAxis* axis);
350 
352 
358  void SetShiftScale(const vtkRectd& shiftScale);
359  vtkRectd GetShiftScale();
361 
367  virtual void GetBounds(double bounds[4]) { bounds[0] = bounds[1] = bounds[2] = bounds[3] = 0.0; }
368 
393  virtual void GetUnscaledInputBounds(double bounds[4])
394  {
395  // Implemented here by calling GetBounds() to support plot
396  // subclasses that do no log-scaling or plot orientation.
397  return this->GetBounds(bounds);
398  }
399 
401 
405  virtual void SetProperty(const vtkStdString& property, const vtkVariant& var);
406  virtual vtkVariant GetProperty(const vtkStdString& property);
408 
410 
414  static bool ClampPos(double pos[2], double bounds[4]);
415  virtual bool ClampPos(double pos[2]);
417 
421  bool Hit(const vtkContextMouseEvent& mouse) override;
422 
429  virtual bool UpdateCache() { return true; }
430 
435  static void FilterSelectedPoints(
436  vtkDataArray* points, vtkDataArray* selectedPoints, vtkIdTypeArray* selectedIds);
437 
438 protected:
439  vtkPlot();
440  ~vtkPlot() override;
441 
445  vtkStdString GetNumber(double position, vtkAxis* axis);
446 
448 
452  virtual void TransformScreenToData(const vtkVector2f& in, vtkVector2f& out);
453  virtual void TransformDataToScreen(const vtkVector2f& in, vtkVector2f& out);
454  virtual void TransformScreenToData(double inX, double inY, double& outX, double& outY);
455  virtual void TransformDataToScreen(double inX, double inY, double& outX, double& outY);
457 
461  virtual bool CacheRequiresUpdate();
462 
467 
472 
477 
483 
489 
494 
499 
504 
510 
516 
521 
526 
531 
536 
542 
548 
551 
556 
558 
559 private:
560  vtkPlot(const vtkPlot&) = delete;
561  void operator=(const vtkPlot&) = delete;
562 };
563 
564 VTK_ABI_NAMESPACE_END
565 #endif // vtkPlot_h
vtkAxis * XAxis
The X axis associated with this plot.
Definition: vtkPlot.h:530
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:28
void GetBounds(T a, double bds[6])
vtkRectd ShiftScale
The current shift in origin and scaling factor applied to the plot.
Definition: vtkPlot.h:555
base class for items that are part of a vtkContextScene.
vtkSmartPointer< vtkStringArray > IndexedLabels
Holds Labels when they're auto-created.
Definition: vtkPlot.h:503
vtkSmartPointer< vtkBrush > Brush
This object stores the vtkBrush that controls how the plot is drawn.
Definition: vtkPlot.h:476
int TooltipNotation
Definition: vtkPlot.h:549
record modification and/or execution time
Definition: vtkTimeStamp.h:24
virtual void GetBounds(double bounds[4])
Get the bounds for this plot as (Xmin, Xmax, Ymin, Ymax).
Definition: vtkPlot.h:367
a vtkAbstractArray subclass for strings
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:315
bool Selectable
Whether plot points can be selected or not.
Definition: vtkPlot.h:520
int TooltipPrecision
Definition: vtkPlot.h:550
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:482
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:547
vtkIdTypeArray * Selection
Selected indices for the table the plot is rendering.
Definition: vtkPlot.h:525
#define VTK_DEPRECATED_IN_9_3_0(reason)
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:29
takes care of drawing 2D axes
Definition: vtkAxis.h:60
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:488
vtkTimeStamp BuildTime
The point cache is marked dirty until it has been initialized.
Definition: vtkPlot.h:466
vtkSmartPointer< vtkContextMapper2D > Data
This data member contains the data that will be plotted, it inherits from vtkAlgorithm.
Definition: vtkPlot.h:515
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:429
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:28
Abstract class for 2D plots.
Definition: vtkPlot.h:43
vtkSmartPointer< vtkStringArray > Labels
Plot labels, used by legend.
Definition: vtkPlot.h:493
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:498
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:58
virtual void GetUnscaledInputBounds(double bounds[4])
Provide un-log-scaled bounds for the plot inputs.
Definition: vtkPlot.h:393
vtkAxis * YAxis
The X axis associated with this plot.
Definition: vtkPlot.h:535
virtual bool Hit(const vtkContextMouseEvent &mouse)
Return true if the supplied x, y coordinate is inside the item.
bool LegendVisibility
Definition: vtkPlot.h:557
vtkStdString TooltipLabelFormat
A printf-style string to build custom tooltip labels from.
Definition: vtkPlot.h:541
vtkSmartPointer< vtkPen > Pen
This object stores the vtkPen that controls how the plot is drawn.
Definition: vtkPlot.h:471
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:509