VTK  9.7.1
vtkOrientationRepresentation.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
26 #ifndef vtkOrientationRepresentation_h
27 #define vtkOrientationRepresentation_h
28 
29 #include "vtkInteractionWidgetsModule.h" // For export macro
30 #include "vtkNew.h" // For vtkNew
31 #include "vtkSmartPointer.h" // For vtkSmartPointer
33 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
34 
35 #include <map>
36 
37 VTK_ABI_NAMESPACE_BEGIN
38 class vtkActor;
39 class vtkArrowSource;
40 class vtkBox;
41 class vtkCellPicker;
43 class vtkPolyDataNormals;
44 class vtkProperty;
46 class vtkTransform;
47 
48 class VTKINTERACTIONWIDGETS_EXPORT VTK_MARSHALAUTO vtkOrientationRepresentation
50 {
51 public:
56 
58 
62  void PrintSelf(ostream& os, vtkIndent indent) override;
64 
66 
69  vtkTransform* GetTransform();
71 
73 
77  virtual void SetOrientation(double values[3]);
78  virtual void SetOrientationX(double value);
79  virtual void SetOrientationY(double value);
80  virtual void SetOrientationZ(double value);
81  double* GetOrientation();
82  double GetOrientationX();
83  double GetOrientationY();
84  double GetOrientationZ();
86 
88 
93  void SetProperty(int axis, bool selected, vtkProperty* property);
94  void SetPropertyX(bool selected, vtkProperty* property)
95  {
96  this->SetProperty(Axis::X_AXIS, selected, property);
97  }
98  void SetPropertyY(bool selected, vtkProperty* property)
99  {
100  this->SetProperty(Axis::Y_AXIS, selected, property);
101  }
102  void SetPropertyZ(bool selected, vtkProperty* property)
103  {
104  this->SetProperty(Axis::Z_AXIS, selected, property);
105  }
106  vtkProperty* GetProperty(int axis, bool selected);
107  vtkProperty* GetPropertyX(bool selected) { return this->GetProperty(Axis::X_AXIS, selected); }
108  vtkProperty* GetPropertyY(bool selected) { return this->GetProperty(Axis::Y_AXIS, selected); }
109  vtkProperty* GetPropertyZ(bool selected) { return this->GetProperty(Axis::Z_AXIS, selected); }
111 
113 
119  vtkSetClampMacro(TorusLength, double, MINIMUM_TORUS_LENGTH, MAXIMUM_TORUS_LENGTH);
120  vtkGetMacro(TorusLength, double);
122 
124 
131  vtkSetClampMacro(TorusThickness, double, MINIMUM_TORUS_THICKNESS, MAXIMUM_TORUS_THICKNESS);
132  vtkGetMacro(TorusThickness, double);
134 
136 
140  vtkSetMacro(ShowArrows, bool);
141  vtkGetMacro(ShowArrows, bool);
142  vtkBooleanMacro(ShowArrows, bool);
144 
146 
151  vtkSetClampMacro(ArrowDistance, double, MINIMUM_ARROW_DISTANCE, MAXIMUM_ARROW_DISTANCE);
152  vtkGetMacro(ArrowDistance, double);
154 
156 
164  vtkSetClampMacro(ArrowLength, double, MINIMUM_ARROW_LENGTH, MAXIMUM_ARROW_LENGTH);
165  vtkGetMacro(ArrowLength, double);
167 
169 
177  vtkSetMacro(ArrowTipLength, double);
178  vtkGetMacro(ArrowTipLength, double);
180 
182 
187  vtkSetClampMacro(ArrowTipRadius, double, MINIMUM_ARROW_TIP_RADIUS, MAXIMUM_ARROW_TIP_RADIUS);
188  vtkGetMacro(ArrowTipRadius, double);
190 
192 
197  vtkSetClampMacro(
198  ArrowShaftRadius, double, MINIMUM_ARROW_SHAFT_RADIUS, MAXIMUM_ARROW_SHAFT_RADIUS);
199  vtkGetMacro(ArrowShaftRadius, double);
201 
203 
206  void PlaceWidget(double bounds[6]) override;
207  void BuildRepresentation() override;
208  int ComputeInteractionState(int X, int Y, int modify = 0) override;
209  void StartWidgetInteraction(double e[2]) override;
210  void WidgetInteraction(double e[2]) override;
211  double* GetBounds() VTK_SIZEHINT(6) override;
213 
215 
218  void ReleaseGraphicsResources(vtkWindow*) override;
219  int RenderOpaqueGeometry(vtkViewport*) override;
220  int RenderTranslucentPolygonalGeometry(vtkViewport*) override;
221  vtkTypeBool HasTranslucentPolygonalGeometry() override;
223 
233  void SetInteractionState(int state);
234 
235  /*
236  * Register internal Pickers within PickingManager
237  */
238  void RegisterPickers() override;
239 
245  void GetActors(vtkPropCollection*) override;
246 
247  // Used to manage the state of the widget
248  enum
249  {
250  Outside = 0,
253  RotatingZ
254  };
255 
256  // Used to select properties axis dependent
257  enum Axis : int
258  {
259  X_AXIS = 0,
261  Z_AXIS
262  };
263 
264 protected:
266  ~vtkOrientationRepresentation() override;
267 
268  virtual void CreateDefaultProperties();
269  void UpdateGeometry();
270  void HighlightHandle();
271 
272 private:
274  void operator=(const vtkOrientationRepresentation&) = delete;
275 
279  void InitSources();
284  void InitTransforms();
285 
290  void Rotate(const double p1[4], const double p2[4], const double baseVector[3]);
291 
295  vtkSmartPointer<vtkPolyDataNormals> GetArrowsOutput(int axisIndex);
296 
297  // Manage how the representation appears
298  double LastEventPosition[3] = { 0.0 };
299 
300  // Support GetBounds() method
301  vtkNew<vtkBox> BoundingBox;
302 
303  // Do the picking
304  vtkNew<vtkCellPicker> HandlePicker;
305  vtkSmartPointer<vtkProp> CurrentHandle;
306  vtkSmartPointer<vtkProp> LastHandle;
307 
308  // Transform information
309  vtkNew<vtkTransform> BaseTransform;
310  vtkNew<vtkTransform> OrientationTransform;
311 
312  // Actors and geometry
313  vtkNew<vtkTransform> ArrowPosTransform;
314  vtkNew<vtkTransform> ArrowPosInvTransform;
315  vtkNew<vtkTransform> ArrowScaleTransform;
316  std::vector<vtkSmartPointer<vtkArrowSource>> ArrowSources;
317  std::vector<vtkSmartPointer<vtkSuperquadricSource>> TorusSources;
318  std::map<Axis, vtkNew<vtkActor>> TorusActors;
319  std::map<Axis, vtkNew<vtkActor>> ArrowsActors;
320  // Parameters used to control the appearance of selected objects and
321  // the manipulator in general.
322  std::map<Axis, vtkSmartPointer<vtkProperty>> Properties;
323  std::map<Axis, vtkSmartPointer<vtkProperty>> SelectedProperties;
324  // ... torus specific
325  double TorusLength = 7.5;
326  double TorusThickness = 0.005;
327  // ... arrow specific
328  bool ShowArrows = false;
329  double ArrowDistance = 0.0;
330  double ArrowLength = 0.05;
331  double ArrowTipLength = 1.0;
332  double ArrowTipRadius = 0.03;
333  double ArrowShaftRadius = 0.001;
334 
335  // Minima/maxima to clamp values
336  static constexpr double MINIMUM_TORUS_THICKNESS = 0.001;
337  static constexpr double MAXIMUM_TORUS_THICKNESS = 0.1;
338  static constexpr double MINIMUM_TORUS_LENGTH = 0.01;
339  static constexpr double MAXIMUM_TORUS_LENGTH = 100.0;
340 
341  static constexpr double MINIMUM_ARROW_DISTANCE = 0.0;
342  static constexpr double MAXIMUM_ARROW_DISTANCE = 0.5;
343  static constexpr double MINIMUM_ARROW_LENGTH = 0.01;
344  static constexpr double MAXIMUM_ARROW_LENGTH = 0.5;
345  static constexpr double MINIMUM_ARROW_TIP_RADIUS = 0.001;
346  static constexpr double MAXIMUM_ARROW_TIP_RADIUS = 0.5;
347  static constexpr double MINIMUM_ARROW_SHAFT_RADIUS = 0.001;
348  static constexpr double MAXIMUM_ARROW_SHAFT_RADIUS = 0.5;
349 };
350 
351 VTK_ABI_NAMESPACE_END
352 #endif
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for instances of this class.
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:41
virtual void PlaceWidget(double bounds[6])
The following is a suggested API for widget representations.
virtual int ComputeInteractionState(int X, int Y, int modify=0)
abstract specification for Viewports
Definition: vtkViewport.h:46
represent surface properties of a geometric object
Definition: vtkProperty.h:59
virtual void StartWidgetInteraction(double eventPos[2])
create a polygonal superquadric centered at the origin
vtkProperty * GetPropertyZ(bool selected)
Set/Get the properties values.
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:50
abstract class defines interface between the widget and widget representation classes ...
virtual void BuildRepresentation()=0
Subclasses of vtkWidgetRepresentation must implement these methods.
double * GetBounds() override
Methods to make this class behave as a vtkProp.
an ordered list of Props
int vtkTypeBool
Definition: vtkABI.h:64
window superclass for vtkRenderWindow
Definition: vtkWindow.h:41
vtkProperty * GetPropertyX(bool selected)
Set/Get the properties values.
vtkProperty * GetPropertyY(bool selected)
Set/Get the properties values.
a simple class to control print indentation
Definition: vtkIndent.h:28
Appends a cylinder to a cone to form an arrow.
compute normals for polygonal mesh
virtual void WidgetInteraction(double newEventPos[2])
#define VTK_SIZEHINT(...)
void SetPropertyX(bool selected, vtkProperty *property)
Set/Get the properties values.
3D Widget for manipulating a vtkCamera
a class defining the representation for the vtkOrientationWidget
ray-cast cell picker for all kinds of Prop3Ds
Definition: vtkCellPicker.h:62
#define VTK_MARSHALAUTO
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
implicit function for a bounding box
Definition: vtkBox.h:30
void SetPropertyY(bool selected, vtkProperty *property)
Set/Get the properties values.
void SetPropertyZ(bool selected, vtkProperty *property)
Set/Get the properties values.