VTK  9.3.20240419
vtkCurveRepresentation.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
18 #ifndef vtkCurveRepresentation_h
19 #define vtkCurveRepresentation_h
20 
21 #include "vtkInteractionWidgetsModule.h" // For export macro
22 #include "vtkPolyDataAlgorithm.h" // needed for vtkPolyDataAlgorithm
24 
25 VTK_ABI_NAMESPACE_BEGIN
26 class vtkActor;
27 class vtkCellPicker;
28 class vtkDoubleArray;
29 class vtkHandleSource;
30 class vtkPlaneSource;
31 class vtkPoints;
32 class vtkPolyData;
33 class vtkProp;
34 class vtkProperty;
35 class vtkTransform;
36 
37 #define VTK_PROJECTION_YZ 0
38 #define VTK_PROJECTION_XZ 1
39 #define VTK_PROJECTION_XY 2
40 #define VTK_PROJECTION_OBLIQUE 3
41 class VTKINTERACTIONWIDGETS_EXPORT vtkCurveRepresentation : public vtkWidgetRepresentation
42 {
43 public:
45  void PrintSelf(ostream& os, vtkIndent indent) override;
46 
47  // Used to manage the InteractionState of the widget
49  {
50  Outside = 0,
58  Pushing
59  };
60 
62 
65  vtkSetMacro(InteractionState, int);
67 
69 
78  vtkSetMacro(ProjectToPlane, vtkTypeBool);
79  vtkGetMacro(ProjectToPlane, vtkTypeBool);
80  vtkBooleanMacro(ProjectToPlane, vtkTypeBool);
82 
88 
89  vtkSetClampMacro(ProjectionNormal, int, VTK_PROJECTION_YZ, VTK_PROJECTION_OBLIQUE);
90  vtkGetMacro(ProjectionNormal, int);
91  void SetProjectionNormalToXAxes() { this->SetProjectionNormal(0); }
92  void SetProjectionNormalToYAxes() { this->SetProjectionNormal(1); }
93  void SetProjectionNormalToZAxes() { this->SetProjectionNormal(2); }
94  void SetProjectionNormalToOblique() { this->SetProjectionNormal(3); }
95 
97 
105  vtkGetMacro(ProjectionPosition, double);
107 
115  virtual void GetPolyData(vtkPolyData* pd) = 0;
116 
118 
122  vtkGetObjectMacro(HandleProperty, vtkProperty);
123  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
125 
127 
131  vtkGetObjectMacro(LineProperty, vtkProperty);
132  vtkGetObjectMacro(SelectedLineProperty, vtkProperty);
134 
136 
139  virtual void SetNumberOfHandles(int npts) = 0;
140  vtkGetMacro(NumberOfHandles, int);
142 
144 
149  virtual void SetDirectional(bool val);
150  vtkGetMacro(Directional, bool);
151  vtkBooleanMacro(Directional, bool);
153 
155 
159  virtual void SetHandlePosition(int handle, double x, double y, double z);
160  virtual void SetHandlePosition(int handle, double xyz[3]);
161  virtual void GetHandlePosition(int handle, double xyz[3]);
162  virtual double* GetHandlePosition(int handle);
165 
167 
172  void SetClosed(vtkTypeBool closed);
173  vtkGetMacro(Closed, vtkTypeBool);
174  vtkBooleanMacro(Closed, vtkTypeBool);
176 
183 
189  virtual double GetSummedLength() = 0;
190 
197  virtual void InitializeHandles(vtkPoints* points) = 0;
198 
200 
205  void BuildRepresentation() override = 0;
206  int ComputeInteractionState(int X, int Y, int modify = 0) override;
207  void StartWidgetInteraction(double e[2]) override;
208  void WidgetInteraction(double e[2]) override;
209  void EndWidgetInteraction(double e[2]) override;
210  double* GetBounds() override;
212 
214 
220  int RenderOverlay(vtkViewport*) override;
223 
228  void SetLineColor(double r, double g, double b);
229 
231 
234  void SetInteractionColor(double, double, double);
235  void SetInteractionColor(double c[3]) { this->SetInteractionColor(c[0], c[1], c[2]); }
236  void SetForegroundColor(double, double, double);
237  void SetForegroundColor(double c[3]) { this->SetForegroundColor(c[0], c[1], c[2]); }
239 
240  /*
241  * Register internal Pickers within PickingManager
242  */
243  void RegisterPickers() override;
244 
246 
252  vtkGetMacro(CurrentHandleIndex, int);
254 
256 
260  vtkGetMacro(TranslationAxis, int);
261  vtkSetClampMacro(TranslationAxis, int, -1, 2);
263 
265 
268  void SetXTranslationAxisOn() { this->TranslationAxis = Axis::XAxis; }
269  void SetYTranslationAxisOn() { this->TranslationAxis = Axis::YAxis; }
270  void SetZTranslationAxisOn() { this->TranslationAxis = Axis::ZAxis; }
271  void SetTranslationAxisOff() { this->TranslationAxis = Axis::NONE; }
273 
275 
278  bool IsTranslationConstrained() { return this->TranslationAxis != Axis::NONE; }
280 
288  void GetActors(vtkPropCollection*) override;
289 
290 protected:
293 
294  double LastEventPosition[3];
295  double Bounds[6];
296 
297  // Controlling vars
302 
303  // Projection capabilities
307 
308  int NumberOfHandles = 0;
310 
311  // The line segments
313  void HighlightLine(int highlight);
314  int HighlightHandle(vtkProp* prop); // returns handle index or -1 on fail
315 
316  // accessors to glyphs representing hot spots (e.g., handles)
317  virtual vtkActor* GetHandleActor(int index) = 0;
319 
323  virtual int GetHandleIndex(vtkProp* prop) = 0;
324  virtual void SizeHandles();
325 
329  virtual int InsertHandleOnLine(double* pos) = 0;
330 
331  virtual void PushHandle(double* pos);
332  virtual void EraseHandle(const int&);
333 
334  // Do the picking
337  double LastPickPosition[3];
341 
342  // Methods to manipulate the curve.
343  void MovePoint(double* p1, double* p2);
344  void Scale(double* p1, double* p2, int X, int Y);
345  void Translate(double* p1, double* p2);
346  void Spin(double* p1, double* p2, double* vpn);
347 
348  // Transform the control points (used for spinning)
350 
351  // Manage how the representation appears
352  bool Directional = false;
353 
354  // Properties used to control the appearance of selected objects and
355  // the manipulator in general.
361 
362  // For efficient spinning
363  double Centroid[3];
365 
367 
368 private:
370  void operator=(const vtkCurveRepresentation&) = delete;
371 };
372 VTK_ABI_NAMESPACE_END
373 #endif
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:151
ray-cast cell picker for all kinds of Prop3Ds
Definition: vtkCellPicker.h:91
base class for a widget that represents a curve that connects control points.
void SetForegroundColor(double, double, double)
Set the color when unselected and selected.
virtual void PushHandle(double *pos)
void Translate(double *p1, double *p2)
int RenderTranslucentPolygonalGeometry(vtkViewport *) override
Methods supporting, and required by, the rendering process.
void SetProjectionPosition(double position)
Set the position of poly line handles and points in terms of a plane's position.
virtual int InsertHandleOnLine(double *pos)=0
Returns the position of insertion or -1 on fail.
void RegisterPickers() override
Register internal Pickers in the Picking Manager.
virtual double GetSummedLength()=0
Get the approximate vs.
virtual vtkDoubleArray * GetHandlePositions()=0
Set/Get the position of the handles.
void SetInteractionColor(double c[3])
Set the color when unselected and selected.
void SetTranslationAxisOff()
Toggles constraint translation axis on/off.
virtual vtkActor * GetHandleActor(int index)=0
void Scale(double *p1, double *p2, int X, int Y)
~vtkCurveRepresentation() override
vtkTypeBool HasTranslucentPolygonalGeometry() override
Methods supporting, and required by, the rendering process.
virtual double * GetHandlePosition(int handle)
Set/Get the position of the handles.
void WidgetInteraction(double e[2]) override
These are methods that satisfy vtkWidgetRepresentation API.
void EndWidgetInteraction(double e[2]) override
These are methods that satisfy vtkWidgetRepresentation API.
void SetZTranslationAxisOn()
Toggles constraint translation axis on/off.
void SetForegroundColor(double c[3])
Set the color when unselected and selected.
vtkTypeBool IsClosed()
Convenience method to determine whether the curve is closed in a geometric sense.
void Spin(double *p1, double *p2, double *vpn)
double * GetBounds() override
These are methods that satisfy vtkWidgetRepresentation API.
void SetClosed(vtkTypeBool closed)
Control whether the curve is open or closed.
virtual void SetNumberOfHandles(int npts)=0
Set/Get the number of handles for this widget.
void SetInteractionColor(double, double, double)
Set the color when unselected and selected.
void SetLineColor(double r, double g, double b)
Convenience method to set the line color.
void ProjectPointsToObliquePlane()
void ReleaseGraphicsResources(vtkWindow *) override
Methods supporting, and required by, the rendering process.
int RenderOverlay(vtkViewport *) override
Methods supporting, and required by, the rendering process.
int HighlightHandle(vtkProp *prop)
void BuildRepresentation() override=0
These are methods that satisfy vtkWidgetRepresentation API.
int ComputeInteractionState(int X, int Y, int modify=0) override
These are methods that satisfy vtkWidgetRepresentation API.
int RenderOpaqueGeometry(vtkViewport *) override
Methods supporting, and required by, the rendering process.
void SetPlaneSource(vtkPlaneSource *plane)
Set up a reference to a vtkPlaneSource that could be from another widget object, e....
virtual void InitializeHandles(vtkPoints *points)=0
Convenience method to allocate and set the handles from a vtkPoints instance.
void SetYTranslationAxisOn()
Toggles constraint translation axis on/off.
virtual vtkHandleSource * GetHandleSource(int index)=0
void HighlightLine(int highlight)
virtual void SetDirectional(bool val)
Set the representation to be directional or not.
void SetXTranslationAxisOn()
Toggles constraint translation axis on/off.
virtual void SetHandlePosition(int handle, double x, double y, double z)
Set/Get the position of the handles.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void StartWidgetInteraction(double e[2]) override
These are methods that satisfy vtkWidgetRepresentation API.
bool IsTranslationConstrained()
Returns true if ConstrainedAxis.
void GetActors(vtkPropCollection *) override
Methods to make this class behave as a vtkProp.
virtual void GetHandlePosition(int handle, double xyz[3])
Set/Get the position of the handles.
virtual void GetPolyData(vtkPolyData *pd)=0
Grab the polydata (including points) that defines the interpolating curve.
virtual void EraseHandle(const int &)
void MovePoint(double *p1, double *p2)
virtual void SizeHandles()
virtual void SetHandlePosition(int handle, double xyz[3])
Set/Get the position of the handles.
virtual int GetHandleIndex(vtkProp *prop)=0
returns handle index or -1 on fail
void SetCurrentHandleIndex(int index)
Get/Set the current handle index.
dynamic, self-adjusting array of double
interface that can be inherited to define handler sources for any kind of interaction.
a simple class to control print indentation
Definition: vtkIndent.h:108
create an array of quadrilaterals located in a plane
represent and manipulate 3D points
Definition: vtkPoints.h:139
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:181
an ordered list of Props
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:66
represent surface properties of a geometric object
Definition: vtkProperty.h:167
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:160
abstract specification for Viewports
Definition: vtkViewport.h:65
abstract class defines interface between the widget and widget representation classes
window superclass for vtkRenderWindow
Definition: vtkWindow.h:48
@ points
Definition: vtkX3D.h:446
@ position
Definition: vtkX3D.h:261
@ index
Definition: vtkX3D.h:246
int vtkTypeBool
Definition: vtkABI.h:64
#define VTK_PROJECTION_YZ
#define VTK_PROJECTION_OBLIQUE