VTK  9.4.20241221
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 "vtkRect.h" // For vtkRectd ivar
137#include "vtkSmartPointer.h" // Needed to hold SP ivars
138#include "vtkStdString.h" // Needed to hold TooltipLabelFormat ivar
139#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
140
141VTK_ABI_NAMESPACE_BEGIN
142class vtkVariant;
143class vtkTable;
144class vtkIdTypeArray;
146class vtkPen;
147class vtkBrush;
148class vtkAxis;
149class vtkStringArray;
151
152class VTKCHARTSCORE_EXPORT VTK_MARSHALAUTO vtkPlot : public vtkContextItem
153{
154public:
155 vtkTypeMacro(vtkPlot, vtkContextItem);
156 void PrintSelf(ostream& os, vtkIndent indent) override;
157
163 void Update() override;
164
166
171 vtkSetMacro(LegendVisibility, bool);
172 vtkGetMacro(LegendVisibility, bool);
173 vtkBooleanMacro(LegendVisibility, bool);
175
183 virtual bool PaintLegend(vtkContext2D* painter, const vtkRectf& rect, int legendIndex);
184
186
198 virtual void SetTooltipLabelFormat(const vtkStdString& label);
201
203
206 virtual void SetTooltipNotation(int notation);
207 virtual int GetTooltipNotation();
209
211
214 virtual void SetTooltipPrecision(int precision);
215 virtual int GetTooltipPrecision();
217
223 const vtkVector2d& plotPos, vtkIdType seriesIndex, vtkIdType segmentIndex);
224
230 virtual vtkIdType GetNearestPoint(const vtkVector2f& point, const vtkVector2f& tolerance,
231 vtkVector2f* location, vtkIdType* segmentId);
232
236 virtual bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max);
237
241 virtual bool SelectPointsInPolygon(const vtkContextPolygon& polygon);
242
244
247 VTK_MARSHALSETTER(ColorRGBA)
248 virtual void SetColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
249 virtual void SetColor(unsigned char r, unsigned char g, unsigned char b);
251
253
257 virtual void SetColorF(double r, double g, double b, double a);
259 virtual void SetColorF(double r, double g, double b);
261
263
266 virtual void GetColor(unsigned char rgb[3]);
267 VTK_MARSHALGETTER(ColorRGBA)
268 void GetColorRGBA(unsigned char rgba[4]);
270
272
276 virtual void GetColorF(double rgb[3]);
278
282 virtual void SetWidth(float width);
283
287 virtual float GetWidth();
288
290
293 void SetPen(vtkPen* pen);
294 vtkPen* GetPen();
296
298
301 void SetBrush(vtkBrush* brush);
302 vtkBrush* GetBrush();
304
306
310 void SetSelectionPen(vtkPen* pen);
311 vtkPen* GetSelectionPen();
313
315
319 void SetSelectionBrush(vtkBrush* brush);
320 vtkBrush* GetSelectionBrush();
322
326 virtual void SetLabel(const vtkStdString& label);
327
331 virtual vtkStdString GetLabel();
332
337 virtual void SetLabels(vtkStringArray* labels);
338
343 virtual vtkStringArray* GetLabels();
344
348 virtual int GetNumberOfLabels();
349
353 vtkStdString GetLabel(vtkIdType index);
354
360 void SetIndexedLabels(vtkStringArray* labels);
361
365 virtual vtkStringArray* GetIndexedLabels();
366
371
373
377 vtkGetMacro(UseIndexForXSeries, bool);
379
381
385 vtkSetMacro(UseIndexForXSeries, bool);
387
389
393 VTK_MARSHALSETTER(Input)
394 virtual void SetInputData(vtkTable* table);
395 virtual void SetInputData(
396 vtkTable* table, const vtkStdString& xColumn, const vtkStdString& yColumn);
397 void SetInputData(vtkTable* table, vtkIdType xColumn, vtkIdType yColumn);
399
401
405 virtual void SetInputConnection(vtkAlgorithmOutput* input);
407
411 VTK_MARSHALGETTER(Input)
412 virtual vtkTable* GetInput();
413
418 vtkAlgorithmOutput* GetInputConnection();
419
425 virtual void SetInputArray(int index, const vtkStdString& name);
426
428
432 void SetXAxisInputArrayToProcess(const std::string& name);
433 std::string GetXAxisInputArrayToProcess();
434 void SetYAxisInputArrayToProcess(const std::string& name);
435 std::string GetYAxisInputArrayToProcess();
437
439
445 vtkSetMacro(Selectable, bool);
446 vtkGetMacro(Selectable, bool);
447 vtkBooleanMacro(Selectable, bool);
449
451
456 virtual void SetSelection(vtkIdTypeArray* id);
457 vtkGetObjectMacro(Selection, vtkIdTypeArray);
459
461
464 vtkGetObjectMacro(XAxis, vtkAxis);
465 virtual void SetXAxis(vtkAxis* axis);
467
469
472 vtkGetObjectMacro(YAxis, vtkAxis);
473 virtual void SetYAxis(vtkAxis* axis);
475
477
483 void SetShiftScale(const vtkRectd& shiftScale);
484 vtkRectd GetShiftScale();
486
492 virtual void GetBounds(double bounds[4]) { bounds[0] = bounds[1] = bounds[2] = bounds[3] = 0.0; }
493
518 virtual void GetUnscaledInputBounds(double bounds[4])
519 {
520 // Implemented here by calling GetBounds() to support plot
521 // subclasses that do no log-scaling or plot orientation.
522 return this->GetBounds(bounds);
523 }
524
526
530 virtual void SetProperty(const vtkStdString& property, const vtkVariant& var);
531 virtual vtkVariant GetProperty(const vtkStdString& property);
533
535
539 static bool ClampPos(double pos[2], double bounds[4]);
540 virtual bool ClampPos(double pos[2]);
542
546 bool Hit(const vtkContextMouseEvent& mouse) override;
547
554 virtual bool UpdateCache() { return true; }
555
561 vtkDataArray* points, vtkDataArray* selectedPoints, vtkIdTypeArray* selectedIds);
562
563protected:
565 ~vtkPlot() override;
566
570 vtkStdString GetNumber(double position, vtkAxis* axis);
571
573
577 virtual void TransformScreenToData(const vtkVector2f& in, vtkVector2f& out);
578 virtual void TransformDataToScreen(const vtkVector2f& in, vtkVector2f& out);
579 virtual void TransformScreenToData(double inX, double inY, double& outX, double& outY);
580 virtual void TransformDataToScreen(double inX, double inY, double& outX, double& outY);
582
586 virtual bool CacheRequiresUpdate();
587
592
597
602
608
614
619
624
629
635
641
646
651
656
661
667
673
676
681
683
684private:
685 vtkPlot(const vtkPlot&) = delete;
686 void operator=(const vtkPlot&) = delete;
687};
688
689VTK_ABI_NAMESPACE_END
690#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:153
bool UseIndexForXSeries
Use the Y array index for the X value.
Definition vtkPlot.h:634
virtual int GetTooltipPrecision()
Sets/gets the tooltip precision.
vtkRectd ShiftScale
The current shift in origin and scaling factor applied to the plot.
Definition vtkPlot.h:680
virtual int GetTooltipNotation()
Sets/gets the tooltip notation style.
int TooltipPrecision
Definition vtkPlot.h:675
vtkSmartPointer< vtkStringArray > IndexedLabels
Holds Labels when they're auto-created.
Definition vtkPlot.h:628
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:655
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.
~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.
bool LegendVisibility
Definition vtkPlot.h:682
virtual void GetUnscaledInputBounds(double bounds[4])
Provide un-log-scaled bounds for the plot inputs.
Definition vtkPlot.h:518
virtual void TransformScreenToData(double inX, double inY, double &outX, double &outY)
Transform the mouse event in the control-points space.
vtkIdTypeArray * Selection
Selected indices for the table the plot is rendering.
Definition vtkPlot.h:650
vtkSmartPointer< vtkBrush > SelectionBrush
This object stores the vtkBrush that controls how the selected elements of the plot are drawn.
Definition vtkPlot.h:613
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:554
vtkAxis * YAxis
The X axis associated with this plot.
Definition vtkPlot.h:660
vtkStdString TooltipDefaultLabelFormat
The default printf-style string to build custom tooltip labels from.
Definition vtkPlot.h:672
vtkSmartPointer< vtkPen > SelectionPen
This object stores the vtkPen that controls how the selected elements of the plot are drawn.
Definition vtkPlot.h:607
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...
virtual void SetProperty(const vtkStdString &property, const vtkVariant &var)
A General setter/getter that should be overridden.
vtkStdString TooltipLabelFormat
A printf-style string to build custom tooltip labels from.
Definition vtkPlot.h:666
bool Selectable
Whether plot points can be selected or not.
Definition vtkPlot.h:645
int TooltipNotation
Definition vtkPlot.h:674
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:640
vtkSmartPointer< vtkStringArray > Labels
Plot labels, used by legend.
Definition vtkPlot.h:618
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:591
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:623
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:601
virtual bool CacheRequiresUpdate()
Test if the internal cache requires an update.
virtual bool SelectPointsInPolygon(const vtkContextPolygon &polygon)
Select all points in the specified polygon.
vtkSmartPointer< vtkPen > Pen
This object stores the vtkPen that controls how the plot is drawn.
Definition vtkPlot.h:596
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
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)