VTK  9.2.5
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 
142 #ifndef vtkPlot_h
143 #define vtkPlot_h
144 
145 #include "vtkChartsCoreModule.h" // For export macro
146 #include "vtkContextItem.h"
147 #include "vtkContextPolygon.h" // For vtkContextPolygon
148 #include "vtkRect.h" // For vtkRectd ivar
149 #include "vtkSmartPointer.h" // Needed to hold SP ivars
150 #include "vtkStdString.h" // Needed to hold TooltipLabelFormat ivar
151 
152 class vtkVariant;
153 class vtkTable;
154 class vtkIdTypeArray;
155 class vtkContextMapper2D;
156 class vtkPen;
157 class vtkBrush;
158 class vtkAxis;
159 class vtkStringArray;
160 class vtkAlgorithmOutput;
161 
162 class VTKCHARTSCORE_EXPORT vtkPlot : public vtkContextItem
163 {
164 public:
165  vtkTypeMacro(vtkPlot, vtkContextItem);
166  void PrintSelf(ostream& os, vtkIndent indent) override;
167 
173  void Update() override;
174 
176 
181  vtkSetMacro(LegendVisibility, bool);
182  vtkGetMacro(LegendVisibility, bool);
183  vtkBooleanMacro(LegendVisibility, bool);
185 
193  virtual bool PaintLegend(vtkContext2D* painter, const vtkRectf& rect, int legendIndex);
194 
196 
208  virtual void SetTooltipLabelFormat(const vtkStdString& label);
211 
213 
216  virtual void SetTooltipNotation(int notation);
217  virtual int GetTooltipNotation();
219 
221 
224  virtual void SetTooltipPrecision(int precision);
225  virtual int GetTooltipPrecision();
227 
233  const vtkVector2d& plotPos, vtkIdType seriesIndex, vtkIdType segmentIndex);
234 
240  virtual vtkIdType GetNearestPoint(const vtkVector2f& point, const vtkVector2f& tolerance,
241  vtkVector2f* location, vtkIdType* segmentId);
242 
246  virtual bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max);
247 
251  virtual bool SelectPointsInPolygon(const vtkContextPolygon& polygon);
252 
254 
257  virtual void SetColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
258  virtual void SetColor(double r, double g, double b);
259  virtual void GetColor(double rgb[3]);
260  void GetColor(unsigned char rgb[3]);
262 
266  virtual void SetWidth(float width);
267 
271  virtual float GetWidth();
272 
274 
277  void SetPen(vtkPen* pen);
280 
282 
285  void SetBrush(vtkBrush* brush);
288 
290 
297 
299 
306 
310  virtual void SetLabel(const vtkStdString& label);
311 
316 
321  virtual void SetLabels(vtkStringArray* labels);
322 
328 
332  virtual int GetNumberOfLabels();
333 
338 
345 
350 
355 
357 
361  vtkGetMacro(UseIndexForXSeries, bool);
363 
365 
369  vtkSetMacro(UseIndexForXSeries, bool);
371 
373 
377  virtual void SetInputData(vtkTable* table);
378  virtual void SetInputData(
379  vtkTable* table, const vtkStdString& xColumn, const vtkStdString& yColumn);
380  void SetInputData(vtkTable* table, vtkIdType xColumn, vtkIdType yColumn);
382 
384 
389 
393  virtual vtkTable* GetInput();
394 
399 
405  virtual void SetInputArray(int index, const vtkStdString& name);
406 
408 
414  vtkSetMacro(Selectable, bool);
415  vtkGetMacro(Selectable, bool);
416  vtkBooleanMacro(Selectable, bool);
418 
420 
425  virtual void SetSelection(vtkIdTypeArray* id);
426  vtkGetObjectMacro(Selection, vtkIdTypeArray);
428 
430 
433  vtkGetObjectMacro(XAxis, vtkAxis);
434  virtual void SetXAxis(vtkAxis* axis);
436 
438 
441  vtkGetObjectMacro(YAxis, vtkAxis);
442  virtual void SetYAxis(vtkAxis* axis);
444 
446 
452  void SetShiftScale(const vtkRectd& shiftScale);
455 
461  virtual void GetBounds(double bounds[4]) { bounds[0] = bounds[1] = bounds[2] = bounds[3] = 0.0; }
462 
487  virtual void GetUnscaledInputBounds(double bounds[4])
488  {
489  // Implemented here by calling GetBounds() to support plot
490  // subclasses that do no log-scaling or plot orientation.
491  return this->GetBounds(bounds);
492  }
493 
495 
499  virtual void SetProperty(const vtkStdString& property, const vtkVariant& var);
500  virtual vtkVariant GetProperty(const vtkStdString& property);
502 
504 
508  static bool ClampPos(double pos[2], double bounds[4]);
509  virtual bool ClampPos(double pos[2]);
511 
515  bool Hit(const vtkContextMouseEvent& mouse) override;
516 
523  virtual bool UpdateCache() { return true; }
524 
525 protected:
527  ~vtkPlot() override;
528 
533 
535 
539  virtual void TransformScreenToData(const vtkVector2f& in, vtkVector2f& out);
540  virtual void TransformDataToScreen(const vtkVector2f& in, vtkVector2f& out);
541  virtual void TransformScreenToData(
542  const double inX, const double inY, double& outX, double& outY);
543  virtual void TransformDataToScreen(
544  const double inX, const double inY, double& outX, double& outY);
546 
550  virtual bool CacheRequiresUpdate();
551 
556 
561 
566 
572 
578 
583 
588 
593 
599 
605 
610 
615 
620 
625 
631 
637 
640 
645 
647 
648 private:
649  vtkPlot(const vtkPlot&) = delete;
650  void operator=(const vtkPlot&) = delete;
651 };
652 
653 #endif // vtkPlot_h
Proxy object to connect input/output ports.
takes care of drawing 2D axes
Definition: vtkAxis.h:181
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:100
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:77
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:119
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:139
Abstract class for 2D plots.
Definition: vtkPlot.h:163
bool UseIndexForXSeries
Use the Y array index for the X value.
Definition: vtkPlot.h:598
vtkBrush * GetSelectionBrush()
Set/get the vtkBrush object that controls how this plot fills selected shapes.
virtual vtkStdString GetLabel()
Get the label of this plot.
virtual int GetTooltipPrecision()
Sets/gets the tooltip precision.
virtual void GetColor(double rgb[3])
Set the plot color.
vtkRectd ShiftScale
The current shift in origin and scaling factor applied to the plot.
Definition: vtkPlot.h:644
virtual int GetTooltipNotation()
Sets/gets the tooltip notation style.
void SetSelectionPen(vtkPen *pen)
Set/get the vtkBrush object that controls how this plot fills selected shapes.
int TooltipPrecision
Definition: vtkPlot.h:639
vtkSmartPointer< vtkStringArray > IndexedLabels
Holds Labels when they're auto-created.
Definition: vtkPlot.h:592
void SetIndexedLabels(vtkStringArray *labels)
Set indexed labels for the plot.
virtual void SetInputData(vtkTable *table, const vtkStdString &xColumn, const vtkStdString &yColumn)
This is a convenience function to set the input table and the x, y column for the plot.
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:619
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()
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.
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:646
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:487
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:614
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:577
vtkPen * GetSelectionPen()
Set/get the vtkBrush object that controls how this plot fills selected shapes.
virtual void GetBounds(double bounds[4])
Get the bounds for this plot as (Xmin, Xmax, Ymin, Ymax).
Definition: vtkPlot.h:461
virtual void SetTooltipLabelFormat(const vtkStdString &label)
Sets/gets a printf-style string to build custom tooltip labels from.
virtual void SetXAxis(vtkAxis *axis)
Get/set the X axis associated with this plot.
virtual bool UpdateCache()
Update the internal cache.
Definition: vtkPlot.h:523
vtkAxis * YAxis
The X axis associated with this plot.
Definition: vtkPlot.h:624
vtkStdString TooltipDefaultLabelFormat
The default printf-style string to build custom tooltip labels from.
Definition: vtkPlot.h:636
virtual void SetColor(double r, double g, double b)
Set the plot color.
vtkSmartPointer< vtkPen > SelectionPen
This object stores the vtkPen that controls how the selected elements of the plot are drawn.
Definition: vtkPlot.h:571
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()
Set/get the vtkBrush object that controls how this plot fills shapes.
void GetColor(unsigned char rgb[3])
Set the plot color.
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:630
bool Selectable
Whether plot points can be selected or not.
Definition: vtkPlot.h:609
int TooltipNotation
Definition: vtkPlot.h:638
vtkRectd GetShiftScale()
Get/set the origin shift and scaling factor used by the plot, this is normally 0.0 offset and 1....
vtkSmartPointer< vtkContextMapper2D > Data
This data member contains the data that will be plotted, it inherits from vtkAlgorithm.
Definition: vtkPlot.h:604
vtkSmartPointer< vtkStringArray > Labels
Plot labels, used by legend.
Definition: vtkPlot.h:582
void SetInputData(vtkTable *table, vtkIdType xColumn, vtkIdType yColumn)
This is a convenience function to set the input table and the x, y column for the plot.
void Update() override
Perform any updates to the item that may be necessary before rendering.
vtkAlgorithmOutput * GetInputConnection()
Get the input connection used by the plot.
virtual void SetTooltipPrecision(int precision)
Sets/gets the tooltip precision.
void SetShiftScale(const vtkRectd &shiftScale)
Get/set the origin shift and scaling factor used by the plot, this is normally 0.0 offset and 1....
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)
Get/set the Y axis associated with this plot.
bool Hit(const vtkContextMouseEvent &mouse) override
Returns true if the supplied x, y coordinate is inside the item.
vtkTimeStamp BuildTime
The point cache is marked dirty until it has been initialized.
Definition: vtkPlot.h:555
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:587
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.
virtual void SetInputConnection(vtkAlgorithmOutput *input)
This is a convenience function to set the input connection for the plot.
vtkSmartPointer< vtkBrush > Brush
This object stores the vtkBrush that controls how the plot is drawn.
Definition: vtkPlot.h:565
virtual bool CacheRequiresUpdate()
Test if the internal cache requires an update.
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:560
virtual float GetWidth()
Get the width of the line.
virtual vtkStringArray * GetLabels()
Get the plot labels.
vtkPen * GetPen()
Set/get the vtkPen object that controls how this plot draws (out)lines.
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)
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:108
a vtkAbstractArray subclass for strings
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:183
record modification and/or execution time
Definition: vtkTimeStamp.h:55
A atomic type representing the union of many types.
Definition: vtkVariant.h:159
void GetBounds(T a, double bds[6])
@ 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:332
#define max(a, b)