VTK  9.7.1
vtkCameraOrientationRepresentation.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
19 #ifndef vtkCameraOrientationRepresentation_h
20 #define vtkCameraOrientationRepresentation_h
21 
22 #include "vtkInteractionWidgetsModule.h" // needed for export macro
24 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
25 
26 #include <algorithm> // std::min, std::max
27 
28 VTK_ABI_NAMESPACE_BEGIN
29 class vtkActor;
30 class vtkDiskSource;
31 class vtkDoubleArray;
33 class vtkImageData;
34 class vtkPoints;
35 class vtkPolyData;
36 class vtkPropCollection;
37 class vtkProperty;
38 class vtkPropPicker;
39 class vtkTextProperty;
40 class vtkTexture;
41 class vtkTubeFilter;
42 
43 class VTKINTERACTIONWIDGETS_EXPORT VTK_MARSHALAUTO vtkCameraOrientationRepresentation
45 {
46 public:
49  void PrintSelf(ostream& os, vtkIndent indent) override;
50 
51  enum class InteractionStateType : int
52  {
53  Outside = 0, // corresponds to vtkCameraOrientationWidget::Inactive
54  Hovering, // corresponds to vtkCameraOrientationWidget::Hot
55  Rotating // corresponds to vtkCameraOrientationWidget::Active
56  };
57 
62  void ApplyInteractionState(const InteractionStateType& state);
63  void ApplyInteractionState(const int& state);
64 
71  {
72  // clamp to 0-2
73  this->InteractionState = std::min(std::max(this->InteractionState, 0), 2);
74  // convert
75  return static_cast<InteractionStateType>(this->InteractionState);
76  }
77 
79 
82  vtkSetVector2Macro(Size, int);
83  vtkGetVector2Macro(Size, int);
85 
87 
90  vtkSetVector2Macro(Padding, int);
91  vtkGetVector2Macro(Padding, int);
93 
94  enum class AnchorType : int
95  {
96  LowerLeft = 0,
97  UpperLeft,
98  LowerRight,
99  UpperRight
100  };
101 
103 
106  vtkSetEnumMacro(AnchorPosition, AnchorType);
107  vtkGetEnumMacro(AnchorPosition, AnchorType);
109  {
110  this->AnchorPosition = AnchorType::LowerLeft;
111  this->Modified();
112  }
114  {
115  this->AnchorPosition = AnchorType::UpperLeft;
116  this->Modified();
117  }
119  {
120  this->AnchorPosition = AnchorType::LowerRight;
121  this->Modified();
122  }
124  {
125  this->AnchorPosition = AnchorType::UpperRight;
126  this->Modified();
127  }
129 
131 
135  vtkSetMacro(TotalLength, double);
136  vtkGetMacro(TotalLength, double);
138 
140 
144  vtkSetMacro(NormalizedHandleDia, double);
145  vtkGetMacro(NormalizedHandleDia, double);
147 
149 
152  vtkGetMacro(Azimuth, double);
153  vtkGetVector3Macro(Back, double);
154  vtkGetMacro(Elevation, double);
155  vtkGetVector3Macro(Up, double);
157 
159 
162  vtkSetClampMacro(ShaftResolution, int, 3, 256);
163  vtkGetMacro(ShaftResolution, int);
165 
167 
170  vtkSetClampMacro(HandleCircumferentialResolution, int, 3, 256);
171  vtkGetMacro(HandleCircumferentialResolution, int);
173 
175 
178  vtkSetClampMacro(ContainerCircumferentialResolution, int, 3, 256);
179  vtkGetMacro(ContainerCircumferentialResolution, int);
181 
183 
186  vtkSetClampMacro(ContainerRadialResolution, int, 3, 256);
187  vtkGetMacro(ContainerRadialResolution, int);
189 
191 
194  vtkGetMacro(PickedAxis, int);
195  vtkGetMacro(PickedDir, int);
197 
199 
202  void SetXPlusLabelText(const std::string& label)
203  {
204  this->AxisLabelsText[0][0] = label;
205  this->Modified();
206  }
207  std::string GetXPlusLabelText() { return this->AxisLabelsText[0][0]; }
208  void SetYPlusLabelText(const std::string& label)
209  {
210  this->AxisLabelsText[1][0] = label;
211  this->Modified();
212  }
213  std::string GetYPlusLabelText() { return this->AxisLabelsText[1][0]; }
214  void SetZPlusLabelText(const std::string& label)
215  {
216  this->AxisLabelsText[2][0] = label;
217  this->Modified();
218  }
219  std::string GetZPlusLabelText() { return this->AxisLabelsText[2][0]; }
221 
223 
226  void SetXMinusLabelText(const std::string& label)
227  {
228  this->AxisLabelsText[0][1] = label;
229  this->Modified();
230  }
231  std::string GetXMinusLabelText() { return this->AxisLabelsText[0][1]; }
232  void SetYMinusLabelText(const std::string& label)
233  {
234  this->AxisLabelsText[1][1] = label;
235  this->Modified();
236  }
237  std::string GetYMinusLabelText() { return this->AxisLabelsText[1][1]; }
238  void SetZMinusLabelText(const std::string& label)
239  {
240  this->AxisLabelsText[2][1] = label;
241  this->Modified();
242  }
243  std::string GetZMinusLabelText() { return this->AxisLabelsText[2][1]; }
245 
247 
250  vtkTextProperty* GetXPlusLabelProperty();
251  vtkTextProperty* GetYPlusLabelProperty();
252  vtkTextProperty* GetZPlusLabelProperty();
254 
256 
259  vtkTextProperty* GetXMinusLabelProperty();
260  vtkTextProperty* GetYMinusLabelProperty();
261  vtkTextProperty* GetZMinusLabelProperty();
263 
265 
268  void SetXAxisColor(double color[3]);
269  void SetXAxisColor(double, double, double);
271 
273 
276  void SetYAxisColor(double color[3]);
277  void SetYAxisColor(double, double, double);
279 
281 
284  void SetZAxisColor(double color[3]);
285  void SetZAxisColor(double, double, double);
287 
289 
292  void SetAxisColor(int ax, double color[3]);
293  void SetAxisColor(int ax, double, double, double);
295 
297 
300  double* GetXAxisColor() VTK_SIZEHINT(3);
301  void GetXAxisColor(double color[3]);
303 
305 
308  double* GetYAxisColor() VTK_SIZEHINT(3);
309  void GetYAxisColor(double color[3]);
311 
313 
316  double* GetZAxisColor() VTK_SIZEHINT(3);
317  void GetZAxisColor(double color[3]);
319 
321 
324  double* GetAxisColor(int ax) VTK_SIZEHINT(3);
325  void GetAxisColor(int ax, double color[3]);
327 
331  vtkProperty* GetContainerProperty();
332 
334 
337  void SetContainerVisibility(bool state);
338  vtkBooleanMacro(ContainerVisibility, bool);
339  bool GetContainerVisibility();
341 
347  void GetActors(vtkPropCollection*) override;
348 
352  vtkTransform* GetTransform();
353 
355 
358  void PlaceWidget(double*) override {} // this representation is an overlay. Doesn't need this.
359  void BuildRepresentation() override;
360  void StartWidgetInteraction(double eventPos[2]) override;
361  void WidgetInteraction(double newEventPos[2]) override;
362  void EndWidgetInteraction(double newEventPos[2]) override;
363  int ComputeInteractionState(int X, int Y, int modify = 0) override;
364  double* GetBounds() VTK_SIZEHINT(6) override;
366 
368 
371  void ReleaseGraphicsResources(vtkWindow*) override;
372  int RenderOpaqueGeometry(vtkViewport*) override;
373  int RenderTranslucentPolygonalGeometry(vtkViewport*) override;
374  vtkTypeBool HasTranslucentPolygonalGeometry() override;
376 
380  void ShallowCopy(vtkProp* prop) override;
381 
385  bool IsAnyHandleSelected() { return (this->PickedAxis != -1) && (this->PickedDir != -1); }
386 
387 protected:
390 
391  virtual void CreateDefaultGeometry();
392  virtual void CreateDefaultProperties();
393  virtual void PositionHandles();
394  virtual void HighlightHandle();
395  virtual void Rotate(double newEventPos[2]);
396  void RegisterPickers() override;
397  void FinalizeHandlePicks();
398 
399  // description of source shapes.
403 
404  // geometries of handles and shafts. (position, color info)
406  vtkNew<vtkPoints> Points; // used to store handle positions, also used by shafts
407 
408  // defaults are slight variations of r, y, g
410 
411  // props
413  vtkNew<vtkActor> Handles[3][2];
415 
416  // font-sz, font-type, frame color of the labels.
417  vtkNew<vtkTextProperty> AxisVectorTextProperties[3][2];
418  vtkNew<vtkImageData> LabelImages[3][2];
419  vtkNew<vtkTexture> LabelTextures[3][2];
420 
422 
423  // Store rotation of gizmo.
425 
426  // Positioning of the representation within a parent renderer.
427  AnchorType AnchorPosition = AnchorType::UpperRight;
428  int Padding[2] = { 10, 10 }; // In display coords.
429  int Size[2] = { 120, 120 }; // In display coords.
430 
431  // Geometrical, textual, interaction description of the representation.
432  std::string AxisLabelsText[3][2] = { { "X", "-X" }, { "Y", "-Y" }, { "Z", "-Z" } };
433  double Azimuth = 0.;
434  double Back[3] = { 0., 0., -1. };
435  double Bounds[6] = {};
436  double Elevation = 0.;
437  double MotionFactor = 1.;
438  double NormalizedHandleDia = 0.4;
439  double TotalLength = 1.;
440  double Up[3] = { 0., 1., 0. };
441  int ContainerCircumferentialResolution = 32;
442  int ContainerRadialResolution = 1;
443  int HandleCircumferentialResolution = 32;
444  int ShaftResolution = 10;
445 
446  // Picking information.
447  int PickedAxis = -1;
448  int LastPickedAx = -1;
449  int PickedDir = -1;
450  int LastPickedDir = -1;
451 
452  // Event tracking
453  double LastEventPosition[3] = {};
454 
455 private:
457  void operator=(const vtkCameraOrientationRepresentation&) = delete;
458 };
459 
460 VTK_ABI_NAMESPACE_END
461 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:49
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for instances of this class.
virtual void EndWidgetInteraction(double newEventPos[2])
std::string GetXMinusLabelText()
Set/Get the '-' axis label text.
void SetXPlusLabelText(const std::string &label)
Set/Get the '+' axis label text.
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:41
std::string GetYMinusLabelText()
Set/Get the '-' axis label text.
virtual int ComputeInteractionState(int X, int Y, int modify=0)
pick an actor/prop using graphics hardware
Definition: vtkPropPicker.h:35
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])
void SetYPlusLabelText(const std::string &label)
Set/Get the '+' axis label text.
std::string GetZPlusLabelText()
Set/Get the '+' axis label text.
void SetYMinusLabelText(const std::string &label)
Set/Get the '-' axis label text.
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:50
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:71
abstract class defines interface between the widget and widget representation classes ...
virtual void BuildRepresentation()=0
Subclasses of vtkWidgetRepresentation must implement these methods.
void AnchorToLowerLeft()
Get/Set the widget anchor type.
double * GetBounds() override
Methods to make this class behave as a vtkProp.
dynamic, self-adjusting array of double
an ordered list of Props
int vtkTypeBool
Definition: vtkABI.h:64
window superclass for vtkRenderWindow
Definition: vtkWindow.h:41
void SetZMinusLabelText(const std::string &label)
Set/Get the '-' axis label text.
std::string GetZMinusLabelText()
Set/Get the '-' axis label text.
filter that generates tubes around lines
Definition: vtkTubeFilter.h:75
a simple class to control print indentation
Definition: vtkIndent.h:28
virtual void RegisterPickers()
Register internal Pickers in the Picking Manager.
topologically and geometrically regular array of data
Definition: vtkImageData.h:45
handles properties associated with a texture map
Definition: vtkTexture.h:58
create a ellipsoidal-shaped button
virtual void WidgetInteraction(double newEventPos[2])
virtual void Modified()
Update the modification time for this object.
#define VTK_SIZEHINT(...)
represent text properties.
std::string GetYPlusLabelText()
Set/Get the '+' axis label text.
void AnchorToUpperRight()
Get/Set the widget anchor type.
InteractionStateType GetInteractionStateAsEnum() noexcept
Convenient method to get InteractionState as enum.
create a disk with hole in center
Definition: vtkDiskSource.h:34
void SetXMinusLabelText(const std::string &label)
Set/Get the '-' axis label text.
void SetZPlusLabelText(const std::string &label)
Set/Get the '+' axis label text.
std::string GetXPlusLabelText()
Set/Get the '+' axis label text.
#define VTK_MARSHALAUTO
A 3D representation for vtkCameraOrientationWidget.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
#define max(a, b)
represent and manipulate 3D points
Definition: vtkPoints.h:30
void AnchorToLowerRight()
Get/Set the widget anchor type.
void AnchorToUpperLeft()
Get/Set the widget anchor type.