VTK  9.5.20251216
vtkControlPointsItem.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
18
19#ifndef vtkControlPointsItem_h
20#define vtkControlPointsItem_h
21
22#include "vtkPlot.h"
23
24#include "vtkChartsCoreModule.h" // For export macro
25#include "vtkCommand.h" // For vtkCommand enum
26#include "vtkSmartPointer.h" // For SmartPointer
27#include "vtkVector.h" // For vtkVector2f
28#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
29#include <string> // Used by GetControlPointLabel
30
31VTK_ABI_NAMESPACE_BEGIN
33class vtkContext2D;
34class vtkControlPointsAddPointItem;
36class vtkPoints2D;
37class vtkTransform2D;
38
39class VTKCHARTSCORE_EXPORT VTK_MARSHALAUTO vtkControlPointsItem : public vtkPlot
40{
41public:
43 void PrintSelf(ostream& os, vtkIndent indent) override;
44
45 // Events fires by this class (and subclasses).
46 // \li CurrentPointChangedEvent is fired when the current point index is changed.
47 // \li CurrentPointEditEvent is fired to request the application to show UI to
48 // edit the current point.
49 // \li vtkCommand::StartEvent and vtkCommand::EndEvent is fired
50 // to mark groups of changes to control points.
51 enum
52 {
55 };
56
61 void GetBounds(double bounds[4]) override;
62
64
69 vtkSetVector4Macro(UserBounds, double);
70 vtkGetVector4Macro(UserBounds, double);
72
74
79 vtkSetVector4Macro(ValidBounds, double);
80 vtkGetVector4Macro(ValidBounds, double);
82
84
88 vtkGetMacro(ScreenPointRadius, float);
89 vtkSetMacro(ScreenPointRadius, float);
91
93
97 vtkGetMacro(DrawPoints, bool);
98 vtkSetMacro(DrawPoints, bool);
99 vtkBooleanMacro(DrawPoints, bool);
101
107 bool Paint(vtkContext2D* painter) override;
108
112 void SelectPoint(vtkIdType pointId);
113
119 void SelectPoint(double* currentPoint);
120
125
130
136 void DeselectPoint(double* currentPoint);
137
142
148
154 void ToggleSelectPoint(double* currentPoint);
155
159 bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max) override;
160
165
170 vtkIdType FindPoint(double* pos);
171
177 bool IsOverPoint(double* pos, vtkIdType pointId);
178
183
189 void GetControlPointsIds(vtkIdTypeArray* ids, bool excludeFirstAndLast = false) const;
190
192
197 vtkSetMacro(StrokeMode, bool);
198 vtkGetMacro(StrokeMode, bool);
200
202
208 vtkSetMacro(SwitchPointsMode, bool);
209 vtkGetMacro(SwitchPointsMode, bool);
211
213
217 vtkSetMacro(EndPointsXMovable, bool);
218 vtkGetMacro(EndPointsXMovable, bool);
219 vtkSetMacro(EndPointsYMovable, bool);
220 vtkGetMacro(EndPointsYMovable, bool);
221 virtual bool GetEndPointsMovable();
223
225
229 vtkSetMacro(EndPointsRemovable, bool);
230 vtkGetMacro(EndPointsRemovable, bool);
232
234
238 vtkSetMacro(ShowLabels, bool);
239 vtkGetMacro(ShowLabels, bool);
241
243
247 vtkSetStringMacro(LabelFormat);
248 vtkGetStringMacro(LabelFormat);
250
256 virtual vtkIdType AddPoint(double* newPos) = 0;
257
263 virtual vtkIdType RemovePoint(double* pos) = 0;
264
270
275
279 virtual vtkIdType GetNumberOfPoints() const = 0;
280
286 virtual void GetControlPoint(vtkIdType index, double* point) const = 0;
287
292 virtual void SetControlPoint(vtkIdType index, double* point) = 0;
293
302 void MovePoints(const vtkVector2f& translation, vtkIdTypeArray* pointIds);
303
309 void MovePoints(const vtkVector2f& translation, bool dontMoveFirstAndLast = false);
310
319 void SpreadPoints(float factor, vtkIdTypeArray* pointIds);
320
326 void SpreadPoints(float factor, bool dontSpreadFirstAndLast = false);
327
333
338
340
343 vtkGetObjectMacro(SelectedPointPen, vtkPen);
345
347
351 vtkGetObjectMacro(SelectedPointBrush, vtkBrush);
353
355
361 vtkGetMacro(UseAddPointItem, bool);
362 vtkSetMacro(UseAddPointItem, bool);
363 vtkBooleanMacro(UseAddPointItem, bool);
365
371
377
379
382 bool MouseButtonPressEvent(const vtkContextMouseEvent& mouse) override;
383 bool MouseDoubleClickEvent(const vtkContextMouseEvent& mouse) override;
385 bool MouseMoveEvent(const vtkContextMouseEvent& mouse) override;
386 bool KeyPressEvent(const vtkContextKeyEvent& key) override;
387 bool KeyReleaseEvent(const vtkContextKeyEvent& key) override;
389
390protected:
393
395
403 virtual void emitEvent(unsigned long event, void* params = nullptr) = 0;
404
405 static void CallComputePoints(
406 vtkObject* sender, unsigned long event, void* receiver, void* params);
407
409
413 virtual void ComputePoints();
416
422 bool Hit(const vtkContextMouseEvent& mouse) override;
423
425
429 bool ClampValidDataPos(double pos[2]);
430 bool ClampValidScreenPos(double pos[2]);
432
434
440 virtual void DrawPoint(vtkContext2D* painter, vtkIdType index);
442
443 void SetCurrentPointPos(const vtkVector2f& newPos);
445 void MoveCurrentPoint(const vtkVector2f& translation);
446 vtkIdType MovePoint(vtkIdType point, const vtkVector2f& translation);
447
450
451 void Stroke(const vtkVector2f& newPos);
452 virtual void EditPoint(float vtkNotUsed(tX), float vtkNotUsed(tY));
453
457 virtual std::string GetControlPointLabel(vtkIdType index);
458
459 void AddPointId(vtkIdType addedPointId);
460
466
471
478 virtual void ComputeBounds(double* bounds);
479
487
488 double Bounds[4] = { 0., -1., 0., -1. };
489 double UserBounds[4] = { 0., -1., 0., -1. };
490 double ValidBounds[4] = { 0., -1., 0., -1. };
491
493 float ScreenPointRadius = 6.f;
494
495 bool DrawPoints = true;
496 bool StrokeMode = false;
497 bool SwitchPointsMode = false;
498 bool MouseMoved = false;
504 bool InvertShadow = false;
505 bool EndPointsXMovable = true;
506 bool EndPointsYMovable = true;
508 bool ShowLabels = false;
509 char* LabelFormat = nullptr;
510
511private:
513 void operator=(const vtkControlPointsItem&) = delete;
514
515 void ComputeBounds();
516
517 vtkIdType RemovePointId(vtkIdType removedPointId);
518
519 bool UseAddPointItem = false;
521};
522VTK_ABI_NAMESPACE_END
523#endif
provides a brush that fills shapes drawn by vtkContext2D.
Definition vtkBrush.h:90
supports function callbacks
Class for drawing 2D primitives to a graphical context.
data structure to represent key events.
data structure to represent mouse events.
void SetCurrentPoint(vtkIdType index)
Sets the current point selected.
vtkNew< vtkCallbackCommand > Callback
virtual vtkIdType RemovePoint(double *pos)=0
Remove a point of the function.
virtual void DrawPoint(vtkContext2D *painter, vtkIdType index)
Internal function that paints a collection of points and optionally excludes some.
bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse) override
Mouse and key events.
static void CallComputePoints(vtkObject *sender, unsigned long event, void *receiver, void *params)
vtkNew< vtkBrush > SelectedPointBrush
void SpreadPoints(float factor, bool dontSpreadFirstAndLast=false)
Utility function to spread all the control points of a given factor If dontSpreadFirstAndLast is true...
bool IsEndPointPicked()
Return true if any of the end points is current point or part of the selection.
~vtkControlPointsItem() override
bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse) override
Mouse and key events.
virtual void ComputeBounds(double *bounds)
Compute the bounds for this item.
void DeselectPoint(double *currentPoint)
Utility function that unselects a point providing its coordinates.
virtual void GetControlPoint(vtkIdType index, double *point) const =0
Returns the x and y coordinates as well as the midpoint and sharpness of the control point correspond...
vtkIdType GetCurrentPoint() const
Returns the current point ID selected or -1 if there is no point current.
friend class vtkPiecewisePointHandleItem
bool Paint(vtkContext2D *painter) override
Paint the points with a fixed size (cosmetic) which doesn't depend on the scene zoom factor.
void AddPointId(vtkIdType addedPointId)
bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse) override
Mouse and key events.
void ToggleSelectPoint(double *currentPoint)
Utility function that toggles the selection a point providing its coordinates.
vtkPlot * GetAddPointItem()
Item dedicated to add point, to be added below all other items.
void ToggleSelectPoint(vtkIdType pointId)
Toggle the selection of a point by its ID.
virtual void SetControlPoint(vtkIdType index, double *point)=0
Sets the x and y coordinates as well as the midpoint and sharpness of the control point corresponding...
void MovePoints(const vtkVector2f &translation, bool dontMoveFirstAndLast=false)
Utility function to move all the control points of the given translation If dontMoveFirstAndLast is t...
void StartInteractionIfNotStarted()
void ResetBounds()
Recompute the bounds next time they are requested.
bool IsPointRemovable(vtkIdType pointId)
Return true if the point is removable.
bool SelectPoints(const vtkVector2f &min, const vtkVector2f &max) override
Select all points in the specified rectangle.
virtual void EditPoint(float tX, float tY)
virtual void ComputePoints()
Must be reimplemented by subclasses to calculate the points to draw.
virtual bool GetEndPointsMovable()
If EndPointsMovable is false, the two end points will not be moved.
vtkIdType RemovePoint(vtkIdType pointId)
Remove a point give its id.
bool KeyPressEvent(const vtkContextKeyEvent &key) override
Mouse and key events.
void GetBounds(double bounds[4]) override
Bounds of the item, typically the bound of all the control points except if custom bounds have been s...
vtkVector2f GetSelectionCenterOfMass() const
void MoveCurrentPoint(const vtkVector2f &translation)
void SpreadPoints(float factor, vtkIdTypeArray *pointIds)
Spread the points referred by pointIds If factor > 0, points are moved away from each other.
virtual vtkIdType AddPoint(double *newPos)=0
Add a point to the function.
virtual void emitEvent(unsigned long event, void *params=nullptr)=0
vtkIdType FindPoint(double *pos)
Returns the vtkIdType of the point given its coordinates and a tolerance based on the screen point si...
void RemoveCurrentPoint()
Remove the current point.
void SelectPoint(double *currentPoint)
Utility function that selects a point providing its coordinates.
bool Hit(const vtkContextMouseEvent &mouse) override
Returns true if the supplied x, y are within the bounds or on a control point.
void Stroke(const vtkVector2f &newPos)
virtual std::string GetControlPointLabel(vtkIdType index)
Generate label for a control point.
virtual vtkMTimeType GetControlPointsMTime()=0
Must be reimplemented by subclasses to calculate the points to draw.
void SelectAllPoints()
Select all the points.
vtkIdType SetPointPos(vtkIdType point, const vtkVector2f &newPos)
void DrawUnselectedPoints(vtkContext2D *painter)
Internal function that paints a collection of points and optionally excludes some.
bool IsOverPoint(double *pos, vtkIdType pointId)
Returns true if pos is above the pointId point, false otherwise.
vtkIdType MovePoint(vtkIdType point, const vtkVector2f &translation)
void DeselectAllPoints()
Unselect all the previously selected points.
void DrawSelectedPoints(vtkContext2D *painter)
Internal function that paints a collection of points and optionally excludes some.
virtual vtkIdType GetNumberOfPoints() const =0
Returns the total number of points.
vtkVector2f GetCenterOfMass(vtkIdTypeArray *pointIDs) const
bool ClampValidDataPos(double pos[2])
Clamp the given 2D pos into the bounds of the function.
void SetCurrentPointPos(const vtkVector2f &newPos)
void SelectPoint(vtkIdType pointId)
Select a point by its ID.
bool KeyReleaseEvent(const vtkContextKeyEvent &key) override
Mouse and key events.
vtkIdType GetControlPointId(double *pos)
Returns the id of the control point exactly matching pos, -1 if not found.
void MovePoints(const vtkVector2f &translation, vtkIdTypeArray *pointIds)
Move the points referred by pointIds by a given translation.
int GetInteractionsCount() const
vtkIdType GetNumberOfSelectedPoints() const
Return the number of selected points.
void GetControlPointsIds(vtkIdTypeArray *ids, bool excludeFirstAndLast=false) const
Utility function that returns an array of all the control points IDs Typically: [0,...
vtkNew< vtkTransform2D > ControlPointsTransform
void DeselectPoint(vtkIdType pointId)
Unselect a point by its ID.
bool ClampValidScreenPos(double pos[2])
Clamp the given 2D pos into the bounds of the function.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkNew< vtkPen > SelectedPointPen
bool MouseMoveEvent(const vtkContextMouseEvent &mouse) override
Mouse and key events.
dynamic, self-adjusting array of vtkIdType
a simple class to control print indentation
Definition vtkIndent.h:108
Allocate and hold a VTK object.
Definition vtkNew.h:167
abstract base class for most VTK objects
Definition vtkObject.h:162
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition vtkPen.h:79
a vtkContextItem that draws handles around a point of a piecewise function
represent and manipulate 2D points
Definition vtkPoints2D.h:27
describes linear transformations via a 3x3 matrix
int vtkIdType
Definition vtkType.h:368
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:323
#define VTK_MARSHALAUTO
#define max(a, b)