VTK  9.4.20241121
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
130#ifndef vtkPlot_h
131#define vtkPlot_h
132
133#include "vtkChartsCoreModule.h" // For export macro
134#include "vtkContextItem.h"
135#include "vtkContextPolygon.h" // For vtkContextPolygon
136#include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_3_0
137#include "vtkRect.h" // For vtkRectd ivar
138#include "vtkSmartPointer.h" // Needed to hold SP ivars
139#include "vtkStdString.h" // Needed to hold TooltipLabelFormat ivar
140#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
141
142VTK_ABI_NAMESPACE_BEGIN
143class vtkVariant;
144class vtkTable;
145class vtkIdTypeArray;
147class vtkPen;
148class vtkBrush;
149class vtkAxis;
150class vtkStringArray;
152
153class VTKCHARTSCORE_EXPORT VTK_MARSHALAUTO vtkPlot : public vtkContextItem
154{
155public:
156 vtkTypeMacro(vtkPlot, vtkContextItem);
157 void PrintSelf(ostream& os, vtkIndent indent) override;
158
164 void Update() override;
165
167
172 vtkSetMacro(LegendVisibility, bool);
173 vtkGetMacro(LegendVisibility, bool);
174 vtkBooleanMacro(LegendVisibility, bool);
176
184 virtual bool PaintLegend(vtkContext2D* painter, const vtkRectf& rect, int legendIndex);
185
187
199 virtual void SetTooltipLabelFormat(const vtkStdString& label);
202
204
207 virtual void SetTooltipNotation(int notation);
208 virtual int GetTooltipNotation();
210
212
215 virtual void SetTooltipPrecision(int precision);
216 virtual int GetTooltipPrecision();
218
224 const vtkVector2d& plotPos, vtkIdType seriesIndex, vtkIdType segmentIndex);
225
231 virtual vtkIdType GetNearestPoint(const vtkVector2f& point, const vtkVector2f& tolerance,
232 vtkVector2f* location, vtkIdType* segmentId);
233
237 virtual bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max);
238
242 virtual bool SelectPointsInPolygon(const vtkContextPolygon& polygon);
243
247 VTK_MARSHALSETTER(ColorRGBA)
248 virtual void SetColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
249
251
255 virtual void SetColorF(double r, double g, double b, double a);
257 virtual void SetColorF(double r, double g, double b);
258
259 // If removed, please remplace it with the following function:
260 // SetColor(unsigned char r, unsigned char g, unsigned char b)
261 // here and in the inheriting classes overriding it
263 VTK_DEPRECATED_IN_9_3_0("Please use unambiguous SetColorF method instead.")
264 virtual void SetColor(double r, double g, double b) { this->SetColorF(r, g, b); }
266
268
271 void GetColor(unsigned char rgb[3]);
272 VTK_MARSHALGETTER(ColorRGBA)
273 void GetColorRGBA(unsigned char rgba[4]);
275
277
281 virtual void GetColorF(double rgb[3]);
282
283 // If removed, please make GetColor(unsigned char rgb[3]) virtual
285 VTK_DEPRECATED_IN_9_3_0("Please use unambiguous GetColorF method instead.")
286 virtual void GetColor(double rgb[3]) { this->GetColorF(rgb); }
288
292 virtual void SetWidth(float width);
293
297 virtual float GetWidth();
298
300
303 void SetPen(vtkPen* pen);
306
308
311 void SetBrush(vtkBrush* brush);
314
316
323
325
332
336 virtual void SetLabel(const vtkStdString& label);
337
342
347 virtual void SetLabels(vtkStringArray* labels);
348
354
358 virtual int GetNumberOfLabels();
359
364
371
376
381
383
387 vtkGetMacro(UseIndexForXSeries, bool);
389
391
395 vtkSetMacro(UseIndexForXSeries, bool);
397
399
403 VTK_MARSHALSETTER(Input)
404 virtual void SetInputData(vtkTable* table);
405 virtual void SetInputData(
406 vtkTable* table, const vtkStdString& xColumn, const vtkStdString& yColumn);
407 void SetInputData(vtkTable* table, vtkIdType xColumn, vtkIdType yColumn);
409
411
415 virtual void SetInputConnection(vtkAlgorithmOutput* input);
417
421 VTK_MARSHALGETTER(Input)
422 virtual vtkTable* GetInput();
423
428 vtkAlgorithmOutput* GetInputConnection();
429
435 virtual void SetInputArray(int index, const vtkStdString& name);
436
438
442 void SetXAxisInputArrayToProcess(const std::string& name);
443 std::string GetXAxisInputArrayToProcess();
444 void SetYAxisInputArrayToProcess(const std::string& name);
445 std::string GetYAxisInputArrayToProcess();
447
449
455 vtkSetMacro(Selectable, bool);
456 vtkGetMacro(Selectable, bool);
457 vtkBooleanMacro(Selectable, bool);
459
461
466 virtual void SetSelection(vtkIdTypeArray* id);
467 vtkGetObjectMacro(Selection, vtkIdTypeArray);
469
471
474 vtkGetObjectMacro(XAxis, vtkAxis);
475 virtual void SetXAxis(vtkAxis* axis);
477
479
482 vtkGetObjectMacro(YAxis, vtkAxis);
483 virtual void SetYAxis(vtkAxis* axis);
485
487
493 void SetShiftScale(const vtkRectd& shiftScale);
494 vtkRectd GetShiftScale();
496
502 virtual void GetBounds(double bounds[4]) { bounds[0] = bounds[1] = bounds[2] = bounds[3] = 0.0; }
503
528 virtual void GetUnscaledInputBounds(double bounds[4])
529 {
530 // Implemented here by calling GetBounds() to support plot
531 // subclasses that do no log-scaling or plot orientation.
532 return this->GetBounds(bounds);
533 }
534
536
540 virtual void SetProperty(const vtkStdString& property, const vtkVariant& var);
541 virtual vtkVariant GetProperty(const vtkStdString& property);
543
545
549 static bool ClampPos(double pos[2], double bounds[4]);
550 virtual bool ClampPos(double pos[2]);
552
556 bool Hit(const vtkContextMouseEvent& mouse) override;
557
564 virtual bool UpdateCache() { return true; }
565
571 vtkDataArray* points, vtkDataArray* selectedPoints, vtkIdTypeArray* selectedIds);
572
573protected:
575 ~vtkPlot() override;
576
580 vtkStdString GetNumber(double position, vtkAxis* axis);
581
583
587 virtual void TransformScreenToData(const vtkVector2f& in, vtkVector2f& out);
588 virtual void TransformDataToScreen(const vtkVector2f& in, vtkVector2f& out);
589 virtual void TransformScreenToData(double inX, double inY, double& outX, double& outY);
590 virtual void TransformDataToScreen(double inX, double inY, double& outX, double& outY);
592
596 virtual bool CacheRequiresUpdate();
597
602
607
612
618
624
629
634
639
645
651
656
661
666
671
677
683
686
691
693
694private:
695 vtkPlot(const vtkPlot&) = delete;
696 void operator=(const vtkPlot&) = delete;
697};
698
699VTK_ABI_NAMESPACE_END
700#endif // vtkPlot_h
Proxy object to connect input/output ports.
takes care of drawing 2D axes
Definition vtkAxis.h:171
provides a brush that fills shapes drawn by vtkContext2D.
Definition vtkBrush.h:90
Class for drawing 2D primitives to a graphical context.
base class for items that are part of a vtkContextScene.
Abstract class for 2D context mappers.
data structure to represent mouse events.
abstract superclass for arrays of numeric data
dynamic, self-adjusting array of vtkIdType
a simple class to control print indentation
Definition vtkIndent.h:108
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition vtkPen.h:79
Abstract class for 2D plots.
Definition vtkPlot.h:154
bool UseIndexForXSeries
Use the Y array index for the X value.
Definition vtkPlot.h:644
virtual vtkStdString GetLabel()
Get the label of this plot.
virtual int GetTooltipPrecision()
Sets/gets the tooltip precision.
vtkContextMapper2D * GetData()
Get the data object that the plot will draw.
vtkRectd ShiftScale
The current shift in origin and scaling factor applied to the plot.
Definition vtkPlot.h:690
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:685
vtkSmartPointer< vtkStringArray > IndexedLabels
Holds Labels when they're auto-created.
Definition vtkPlot.h:638
void SetIndexedLabels(vtkStringArray *labels)
Set indexed labels for the plot.
virtual bool SelectPoints(const vtkVector2f &min, const vtkVector2f &max)
Select all points in the specified rectangle.
vtkAxis * XAxis
The X axis associated with this plot.
Definition vtkPlot.h:665
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,...
static void FilterSelectedPoints(vtkDataArray *points, vtkDataArray *selectedPoints, vtkIdTypeArray *selectedIds)
Utility function that fills up selectedPoints with tuples from points.
vtkPen * GetPen()
Get the plot color as floating rgb values (comprised between 0.0 and 1.0)
virtual void SetWidth(float width)
@
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.
vtkStdString GetLabel(vtkIdType index)
Get the label at the specified index.
bool LegendVisibility
Definition vtkPlot.h:692
virtual void GetUnscaledInputBounds(double bounds[4])
Provide un-log-scaled bounds for the plot inputs.
Definition vtkPlot.h:528
vtkPen * GetSelectionPen()
Set/get the vtkBrush object that controls how this plot fills selected shapes.
virtual void TransformScreenToData(double inX, double inY, double &outX, double &outY)
Transform the mouse event in the control-points space.
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:660
virtual vtkStringArray * GetLabels()
Get the plot labels.
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:623
virtual void SetTooltipLabelFormat(const vtkStdString &label)
Sets/gets a printf-style string to build custom tooltip labels from.
virtual bool UpdateCache()
Update the internal cache.
Definition vtkPlot.h:564
vtkAxis * YAxis
The X axis associated with this plot.
Definition vtkPlot.h:670
vtkStdString TooltipDefaultLabelFormat
The default printf-style string to build custom tooltip labels from.
Definition vtkPlot.h:682
vtkSmartPointer< vtkPen > SelectionPen
This object stores the vtkPen that controls how the selected elements of the plot are drawn.
Definition vtkPlot.h:617
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.
void GetColor(unsigned char rgb[3])
Get the plot color as integer rgb values (comprised between 0 and 255)
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:676
bool Selectable
Whether plot points can be selected or not.
Definition vtkPlot.h:655
int TooltipNotation
Definition vtkPlot.h:684
virtual vtkStringArray * GetIndexedLabels()
Get the indexed labels array.
virtual void TransformDataToScreen(double inX, double inY, double &outX, double &outY)
Transform the mouse event in the control-points space.
vtkSmartPointer< vtkContextMapper2D > Data
This data member contains the data that will be plotted, it inherits from vtkAlgorithm.
Definition vtkPlot.h:650
vtkSmartPointer< vtkStringArray > Labels
Plot labels, used by legend.
Definition vtkPlot.h:628
void Update() override
Perform any updates to the item that may be necessary before rendering.
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.
vtkTimeStamp BuildTime
The point cache is marked dirty until it has been initialized.
Definition vtkPlot.h:601
vtkBrush * GetSelectionBrush()
Set/get the vtkBrush object that controls how this plot fills selected shapes.
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:633
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:611
virtual bool CacheRequiresUpdate()
Test if the internal cache requires an update.
virtual bool SelectPointsInPolygon(const vtkContextPolygon &polygon)
Select all points in the specified polygon.
vtkBrush * GetBrush()
Set/get the vtkBrush object that controls how this plot fills shapes.
vtkSmartPointer< vtkPen > Pen
This object stores the vtkPen that controls how the plot is drawn.
Definition vtkPlot.h:606
virtual float GetWidth()
Get the width of the line.
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 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.
Hold a reference to a vtkObjectBase instance.
Wrapper around std::string to keep symbols short.
a vtkAbstractArray subclass for strings
A table, which contains similar-typed columns of data.
Definition vtkTable.h:169
record modification and/or execution time
A type representing the union of many types.
Definition vtkVariant.h:162
#define VTK_DEPRECATED_IN_9_3_0(reason)
int vtkIdType
Definition vtkType.h:315
#define VTK_MARSHALSETTER(property)
#define VTK_MARSHAL_EXCLUDE_REASON_IS_REDUNDANT
#define VTK_MARSHALGETTER(property)
#define VTK_MARSHAL_EXCLUDE_REASON_IS_INTERNAL
#define VTK_MARSHALAUTO
#define VTK_MARSHALEXCLUDE(reason)
#define max(a, b)