VTK  9.7.1
vtkImplicitFrustumRepresentation.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 
4 #ifndef vtkImplicitFrustumRepresentation_h
5 #define vtkImplicitFrustumRepresentation_h
6 
8 #include "vtkEllipseArcSource.h"
9 #include "vtkInteractionWidgetsModule.h" // For export macro
10 #include "vtkVector.h" // For vtkVector3d
11 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
12 
13 VTK_ABI_NAMESPACE_BEGIN
14 class vtkActor;
15 class vtkBox;
16 class vtkConeSource;
17 class vtkCellPicker;
19 class vtkFrustum;
20 class vtkLineSource;
21 class vtkProperty;
22 class vtkPolyData;
23 class vtkPolyDataMapper;
24 class vtkSphereSource;
25 class vtkTransform;
26 class vtkTubeFilter;
27 
42 class VTKINTERACTIONWIDGETS_EXPORT VTK_MARSHALAUTO vtkImplicitFrustumRepresentation
44 {
45 public:
46  // Manage the state of the widget
48  {
49  Outside = 0,
50  Moving, // Generic state set by the widget
58  TranslatingOriginOnAxis
59  };
60 
63  void PrintSelf(ostream& os, vtkIndent indent) override;
64 
66 
70  void SetOrigin(double x, double y, double z);
71  void SetOrigin(double x[3]);
72  void SetOrigin(const vtkVector3d& xyz);
73  double* GetOrigin() VTK_SIZEHINT(3);
74  void GetOrigin(double xyz[3]) const;
76 
78 
81  void SetOrientation(double x, double y, double z);
82  void SetOrientation(const double xyz[3]);
83  void SetOrientation(const vtkVector3d& xyz);
84  double* GetOrientation() VTK_SIZEHINT(3);
85  void GetOrientation(double& x, double& y, double& z);
86  void GetOrientation(double xyz[3]);
88 
90 
94  double GetHorizontalAngle() const;
95  void SetHorizontalAngle(double angle);
97 
99 
103  double GetVerticalAngle() const;
104  void SetVerticalAngle(double angle);
106 
108 
112  double GetNearPlaneDistance() const;
113  void SetNearPlaneDistance(double angle);
115 
117 
124  void SetAlongXAxis(bool);
125  vtkGetMacro(AlongXAxis, bool);
126  vtkBooleanMacro(AlongXAxis, bool);
127  void SetAlongYAxis(bool);
128  vtkGetMacro(AlongYAxis, bool);
129  vtkBooleanMacro(AlongYAxis, bool);
130  void SetAlongZAxis(bool);
131  vtkGetMacro(AlongZAxis, bool);
132  vtkBooleanMacro(AlongZAxis, bool);
134 
136 
141  void SetDrawFrustum(bool draw);
142  vtkGetMacro(DrawFrustum, bool);
143  vtkBooleanMacro(DrawFrustum, bool);
145 
150  void GetPolyData(vtkPolyData* pd);
151 
156  void UpdatePlacement();
157 
161  vtkGetObjectMacro(FrustumProperty, vtkProperty);
162 
164 
168  vtkGetObjectMacro(EdgeHandleProperty, vtkProperty);
169  vtkGetObjectMacro(SelectedEdgeHandleProperty, vtkProperty);
171 
173 
177  void SetInteractionColor(double, double, double);
178  void SetInteractionColor(double c[3]) { this->SetInteractionColor(c[0], c[1], c[2]); }
179  void SetHandleColor(double, double, double);
180  void SetHandleColor(double c[3]) { this->SetHandleColor(c[0], c[1], c[2]); }
181  void SetForegroundColor(double, double, double);
182  void SetForegroundColor(double c[3]) { this->SetForegroundColor(c[0], c[1], c[2]); }
184 
186 
189  int ComputeInteractionState(int X, int Y, int modify = 0) override;
190  void PlaceWidget(double bounds[6]) override;
191  void BuildRepresentation() override;
192  void StartWidgetInteraction(double eventPos[2]) override;
193  void WidgetInteraction(double newEventPos[2]) override;
194  void EndWidgetInteraction(double newEventPos[2]) override;
196 
198 
201  double* GetBounds() override;
202  void GetActors(vtkPropCollection* pc) override;
203  void ReleaseGraphicsResources(vtkWindow*) override;
204  int RenderOpaqueGeometry(vtkViewport*) override;
208 
216  vtkSetClampMacro(InteractionState, InteractionStateType, InteractionStateType::Outside,
217  InteractionStateType::TranslatingOriginOnAxis);
218 
220 
224  virtual void SetRepresentationState(InteractionStateType);
225  vtkGetMacro(RepresentationState, InteractionStateType);
227 
228  /*
229  * Register internal Pickers within PickingManager
230  */
231  void RegisterPickers() override;
232 
236  void GetFrustum(vtkFrustum* frustum) const;
237 
238 protected:
241 
242 private:
243  enum class FrustumFace
244  {
245  None = -1,
246  Right = 0,
247  Left = 1,
248  Top = 2,
249  Bottom = 3,
250  Near = 4
251  };
252 
253  struct SphereHandle
254  {
257  vtkNew<vtkActor> Actor;
258 
259  SphereHandle();
260  };
261 
262  struct EdgeHandle
263  {
264  vtkNew<vtkPolyData> PolyData;
265  vtkNew<vtkTubeFilter> Tuber;
267  vtkNew<vtkActor> Actor;
268 
269  EdgeHandle();
270  };
271 
272  struct EllipseHandle
273  {
275  vtkNew<vtkTubeFilter> Tuber;
277  vtkNew<vtkActor> Actor;
278 
279  EllipseHandle();
280  };
281 
283  void operator=(const vtkImplicitFrustumRepresentation&) = delete;
284 
285  // Helpers to get the frustum basis
286  vtkVector3d GetForwardAxis();
287  vtkVector3d GetUpAxis();
288  vtkVector3d GetRightAxis();
289 
290  void HighlightOriginHandle(bool highlight);
291  void HighlightFarPlaneVerticalHandle(bool highlight);
292  void HighlightFarPlaneHorizontalHandle(bool highlight);
293  void HighlightNearPlaneHandle(bool highlight);
294  void HighlightRollHandle(bool highlight);
295  void HighlightYawHandle(bool highlight);
296  void HighlightPitchHandle(bool highlight);
297 
298  // Methods to manipulate the frustum
299  void TranslateOrigin(const vtkVector3d& p1, const vtkVector3d& p2);
300  void TranslateOriginOnAxis(const vtkVector3d& p1, const vtkVector3d& p2);
301  void AdjustHorizontalAngle(const vtkVector3d& p1, const vtkVector3d& p2);
302  void AdjustVerticalAngle(const vtkVector3d& p1, const vtkVector3d& p2);
303  void AdjustNearPlaneDistance(
304  const vtkVector2d& eventPosition, const vtkVector3d& p1, const vtkVector3d& p2);
305  void Rotate(
306  const vtkVector3d& prevPickPoint, const vtkVector3d& pickPoint, const vtkVector3d& axis);
307 
308  // Set the frustum transform according to the representation's orientation and position
309  void UpdateFrustumTransform();
310 
311  // Re-compute the widget handles' sizes
312  void SizeHandles();
313 
314  // Generate the frustum polydata, cropped by the bounding box
315  void BuildFrustum();
316 
317  // The actual frustum we're manipulating
318  vtkNew<vtkFrustum> Frustum;
319 
320  InteractionStateType RepresentationState = InteractionStateType::Outside;
321 
322  // Keep track of event positions
323  vtkVector3d LastEventPosition = { 0., 0., 0. };
324 
325  bool AlongXAxis = false;
326  bool AlongYAxis = false;
327  bool AlongZAxis = false;
328 
329  double Length = 1;
330 
331  vtkVector3d Origin = { 0, 0, 0 };
332  vtkNew<vtkTransform> OrientationTransform;
333 
334  vtkNew<vtkPolyData> FrustumPD;
335  vtkNew<vtkPolyDataMapper> FrustumMapper;
336  vtkNew<vtkActor> FrustumActor;
337  bool DrawFrustum = true;
338 
339  std::array<EdgeHandle, 4> FarPlaneHandles;
340  EdgeHandle NearPlaneEdgesHandle;
341  SphereHandle NearPlaneCenterHandle;
342  EllipseHandle RollHandle;
343  EllipseHandle YawHandle;
344  EllipseHandle PitchHandle;
345  SphereHandle OriginHandle;
346 
347  FrustumFace ActiveEdgeHandle = FrustumFace::None;
348 
349  vtkNew<vtkCellPicker> Picker;
350  vtkNew<vtkCellPicker> FrustumPicker;
351 
352  // Properties used to control the appearance of selected objects and the manipulator in general.
353  vtkNew<vtkProperty> FrustumProperty;
354  vtkNew<vtkProperty> EdgeHandleProperty;
355  vtkNew<vtkProperty> SelectedEdgeHandleProperty;
356  vtkNew<vtkProperty> OriginHandleProperty;
357  vtkNew<vtkProperty> SelectedOriginHandleProperty;
358 
359  vtkNew<vtkBox> BoundingBox;
360 };
361 
362 VTK_ABI_NAMESPACE_END
363 #endif
virtual void EndWidgetInteraction(double newEventPos[2])
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)
void SetInteractionColor(double c[3])
Set the color of all the widgets handles (origin, orientations, near plane and angles) and their colo...
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])
generate polygonal cone
Definition: vtkConeSource.h:34
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:50
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:71
int RenderOpaqueGeometry(vtkViewport *viewport) override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THESE METHODS OUTSIDE OF THE RENDE...
virtual void BuildRepresentation()=0
Subclasses of vtkWidgetRepresentation must implement these methods.
create an elliptical arc
int RenderTranslucentPolygonalGeometry(vtkViewport *viewport) override
double * GetBounds() override
Methods to make this class behave as a vtkProp.
an ordered list of Props
int vtkTypeBool
Definition: vtkABI.h:64
implicit function for a frustum
Definition: vtkFrustum.h:34
window superclass for vtkRenderWindow
Definition: vtkWindow.h:41
create a polygonal sphere centered at the origin
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.
!< For HCURL
void ReleaseGraphicsResources(vtkWindow *) override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE Release any graphics resources that are being...
virtual void WidgetInteraction(double newEventPos[2])
#define VTK_SIZEHINT(...)
create a line defined by two end points
Definition: vtkLineSource.h:53
map vtkPolyData to graphics primitives
Extends the vtkWidgetRepresentation to help positioning widget in space and how it should be displaye...
vtkTypeBool HasTranslucentPolygonalGeometry() override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THESE METHODS OUTSIDE OF THE RENDE...
void SetForegroundColor(double c[3])
Set the color of all the widgets handles (origin, orientations, near plane and angles) and their colo...
The representation for a vtkImplicitFrustumWidget.
ray-cast cell picker for all kinds of Prop3Ds
Definition: vtkCellPicker.h:62
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for instances of this class.
#define VTK_MARSHALAUTO
void GetActors(vtkPropCollection *) override
For some exporters and other other operations we must be able to collect all the actors or volumes...
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 SetHandleColor(double c[3])
Set the color of all the widgets handles (origin, orientations, near plane and angles) and their colo...