VTK  9.4.20250114
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
9#include "vtkInteractionWidgetsModule.h" // For export macro
10#include "vtkSetGet.h"
11#include "vtkVector.h" // For vtkVector3d
12#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
13
14VTK_ABI_NAMESPACE_BEGIN
15class vtkActor;
16class vtkBox;
17class vtkConeSource;
18class vtkCellPicker;
20class vtkFrustum;
21class vtkLineSource;
22class vtkProperty;
23class vtkPolyData;
25class vtkSphereSource;
26class vtkTransform;
27class vtkTubeFilter;
28
43class VTKINTERACTIONWIDGETS_EXPORT VTK_MARSHALAUTO vtkImplicitFrustumRepresentation
45{
46public:
47 // Manage the state of the widget
49 {
50 Outside = 0,
51 Moving, // Generic state set by the widget
59 TranslatingOriginOnAxis
60 };
61
64 void PrintSelf(ostream& os, vtkIndent indent) override;
65
67
71 void SetOrigin(double x, double y, double z);
72 void SetOrigin(double x[3]);
73 void SetOrigin(const vtkVector3d& xyz);
74 double* GetOrigin() VTK_SIZEHINT(3);
75 void GetOrigin(double xyz[3]) const;
77
79
82 void SetOrientation(double x, double y, double z);
83 void SetOrientation(const double xyz[3]);
84 void SetOrientation(const vtkVector3d& xyz);
85 double* GetOrientation() VTK_SIZEHINT(3);
86 void GetOrientation(double& x, double& y, double& z);
87 void GetOrientation(double xyz[3]);
89
91
95 double GetHorizontalAngle() const;
96 void SetHorizontalAngle(double angle);
98
100
104 double GetVerticalAngle() const;
105 void SetVerticalAngle(double angle);
107
109
113 double GetNearPlaneDistance() const;
114 void SetNearPlaneDistance(double angle);
116
118
125 void SetAlongXAxis(bool);
126 vtkGetMacro(AlongXAxis, bool);
127 vtkBooleanMacro(AlongXAxis, bool);
128 void SetAlongYAxis(bool);
129 vtkGetMacro(AlongYAxis, bool);
130 vtkBooleanMacro(AlongYAxis, bool);
131 void SetAlongZAxis(bool);
132 vtkGetMacro(AlongZAxis, bool);
133 vtkBooleanMacro(AlongZAxis, bool);
135
137
142 void SetDrawFrustum(bool draw);
143 vtkGetMacro(DrawFrustum, bool);
144 vtkBooleanMacro(DrawFrustum, bool);
146
151 void GetPolyData(vtkPolyData* pd);
152
157 void UpdatePlacement();
158
162 vtkGetObjectMacro(FrustumProperty, vtkProperty);
163
165
169 vtkGetObjectMacro(EdgeHandleProperty, vtkProperty);
170 vtkGetObjectMacro(SelectedEdgeHandleProperty, vtkProperty);
172
174
178 void SetInteractionColor(double, double, double);
179 void SetInteractionColor(double c[3]) { this->SetInteractionColor(c[0], c[1], c[2]); }
180 void SetHandleColor(double, double, double);
181 void SetHandleColor(double c[3]) { this->SetHandleColor(c[0], c[1], c[2]); }
182 void SetForegroundColor(double, double, double);
183 void SetForegroundColor(double c[3]) { this->SetForegroundColor(c[0], c[1], c[2]); }
185
187
190 int ComputeInteractionState(int X, int Y, int modify = 0) override;
191 void PlaceWidget(double bounds[6]) override;
192 void BuildRepresentation() override;
193 void StartWidgetInteraction(double eventPos[2]) override;
194 void WidgetInteraction(double newEventPos[2]) override;
195 void EndWidgetInteraction(double newEventPos[2]) override;
197
199
202 double* GetBounds() override;
203 void GetActors(vtkPropCollection* pc) override;
209
217 vtkSetClampMacro(InteractionState, InteractionStateType, InteractionStateType::Outside,
218 InteractionStateType::TranslatingOriginOnAxis);
219
221
226 vtkGetMacro(RepresentationState, InteractionStateType);
228
229 /*
230 * Register internal Pickers within PickingManager
231 */
232 void RegisterPickers() override;
233
237 void GetFrustum(vtkFrustum* frustum) const;
238
239protected:
242
243private:
244 enum class FrustumFace
245 {
246 None = -1,
247 Right = 0,
248 Left,
249 Top,
250 Bottom,
251 Near,
252 };
253
254 struct SphereHandle
255 {
258 vtkNew<vtkActor> Actor;
259
260 SphereHandle();
261 };
262
263 struct EdgeHandle
264 {
265 vtkNew<vtkPolyData> PolyData;
268 vtkNew<vtkActor> Actor;
269
270 EdgeHandle();
271 };
272
273 struct EllipseHandle
274 {
278 vtkNew<vtkActor> Actor;
279
280 EllipseHandle();
281 };
282
284 void operator=(const vtkImplicitFrustumRepresentation&) = delete;
285
286 // Helpers to get the frustum basis
287 vtkVector3d GetForwardAxis();
288 vtkVector3d GetUpAxis();
289 vtkVector3d GetRightAxis();
290
291 void HighlightOriginHandle(bool highlight);
292 void HighlightFarPlaneVerticalHandle(bool highlight);
293 void HighlightFarPlaneHorizontalHandle(bool highlight);
294 void HighlightNearPlaneHandle(bool highlight);
295 void HighlightRollHandle(bool highlight);
296 void HighlightYawHandle(bool highlight);
297 void HighlightPitchHandle(bool highlight);
298
299 // Methods to manipulate the frustum
300 void TranslateOrigin(const vtkVector3d& p1, const vtkVector3d& p2);
301 void TranslateOriginOnAxis(const vtkVector3d& p1, const vtkVector3d& p2);
302 void AdjustHorizontalAngle(const vtkVector3d& p1, const vtkVector3d& p2);
303 void AdjustVerticalAngle(const vtkVector3d& p1, const vtkVector3d& p2);
304 void AdjustNearPlaneDistance(
305 const vtkVector2d& eventPosition, const vtkVector3d& p1, const vtkVector3d& p2);
306 void Rotate(
307 const vtkVector3d& prevPickPoint, const vtkVector3d& pickPoint, const vtkVector3d& axis);
308
309 // Set the frustum transform according to the representation's orientation and position
310 void UpdateFrustumTransform();
311
312 // Re-compute the widget handles' sizes
313 void SizeHandles();
314
315 // Generate the frustum polydata, cropped by the bounding box
316 void BuildFrustum();
317
318 // The actual frustum we're manipulating
319 vtkNew<vtkFrustum> Frustum;
320
321 InteractionStateType RepresentationState = InteractionStateType::Outside;
322
323 // Keep track of event positions
324 vtkVector3d LastEventPosition = { 0., 0., 0. };
325
326 bool AlongXAxis = false;
327 bool AlongYAxis = false;
328 bool AlongZAxis = false;
329
330 double Length = 1;
331
332 vtkVector3d Origin = { 0, 0, 0 };
333 vtkNew<vtkTransform> OrientationTransform;
334
335 vtkNew<vtkPolyData> FrustumPD;
336 vtkNew<vtkPolyDataMapper> FrustumMapper;
337 vtkNew<vtkActor> FrustumActor;
338 bool DrawFrustum = true;
339
340 std::array<EdgeHandle, 4> FarPlaneHandles;
341 EdgeHandle NearPlaneEdgesHandle;
342 SphereHandle NearPlaneCenterHandle;
343 EllipseHandle RollHandle;
344 EllipseHandle YawHandle;
345 EllipseHandle PitchHandle;
346 SphereHandle OriginHandle;
347
348 FrustumFace ActiveEdgeHandle = FrustumFace::None;
349
351 vtkNew<vtkCellPicker> FrustumPicker;
352
353 // Properties used to control the appearance of selected objects and the manipulator in general.
354 vtkNew<vtkProperty> FrustumProperty;
355 vtkNew<vtkProperty> EdgeHandleProperty;
356 vtkNew<vtkProperty> SelectedEdgeHandleProperty;
357 vtkNew<vtkProperty> OriginHandleProperty;
358 vtkNew<vtkProperty> SelectedOriginHandleProperty;
359
360 vtkNew<vtkBox> BoundingBox;
361};
362
363VTK_ABI_NAMESPACE_END
364#endif
represents an object (geometry & properties) in a rendered scene
Definition vtkActor.h:151
Extends the vtkWidgetRepresentation to help positioning widget in space and how it should be displaye...
implicit function for a bounding box
Definition vtkBox.h:110
ray-cast cell picker for all kinds of Prop3Ds
generate polygonal cone
create an elliptical arc
implicit function for a frustum
Definition vtkFrustum.h:35
The representation for a vtkImplicitFrustumWidget.
virtual void SetRepresentationState(InteractionStateType)
Sets the visual appearance of the representation based on the state it is in.
void SetHandleColor(double, double, double)
Set the color of all the widgets handles (origin, orientations, near plane and angles) and their colo...
void GetActors(vtkPropCollection *pc) override
Methods supporting the rendering process.
int RenderOpaqueGeometry(vtkViewport *) override
Methods supporting the rendering process.
int ComputeInteractionState(int X, int Y, int modify=0) override
Methods to interface with the vtkImplicitFrustumWidget.
void SetForegroundColor(double, double, double)
Set the color of all the widgets handles (origin, orientations, near plane and angles) and their colo...
int RenderTranslucentPolygonalGeometry(vtkViewport *) override
Methods supporting the rendering process.
void SetOrigin(double x, double y, double z)
Get the origin of the frustum representation.
void GetFrustum(vtkFrustum *frustum) const
Get the concrete represented frustum.
void EndWidgetInteraction(double newEventPos[2]) override
Methods to interface with the vtkImplicitFrustumWidget.
static vtkImplicitFrustumRepresentation * New()
void PlaceWidget(double bounds[6]) override
Methods to interface with the vtkImplicitFrustumWidget.
void SetOrigin(double x[3])
Get the origin of the frustum representation.
double * GetOrigin()
Get the origin of the frustum representation.
void WidgetInteraction(double newEventPos[2]) override
Methods to interface with the vtkImplicitFrustumWidget.
vtkTypeBool HasTranslucentPolygonalGeometry() override
Methods supporting the rendering process.
void StartWidgetInteraction(double eventPos[2]) override
Methods to interface with the vtkImplicitFrustumWidget.
void SetInteractionColor(double c[3])
Set the color of all the widgets handles (origin, orientations, near plane and angles) and their colo...
void BuildRepresentation() override
Methods to interface with the vtkImplicitFrustumWidget.
double * GetBounds() override
Methods supporting the rendering process.
void RegisterPickers() override
Register internal Pickers in the Picking Manager.
void SetForegroundColor(double c[3])
Set the color of all the widgets handles (origin, orientations, near plane and angles) and their colo...
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for instances of this class.
void SetOrigin(const vtkVector3d &xyz)
Get the origin of the frustum representation.
void ReleaseGraphicsResources(vtkWindow *) override
Methods supporting the rendering process.
void SetHandleColor(double c[3])
Set the color of all the widgets handles (origin, orientations, near plane and angles) and their colo...
a simple class to control print indentation
Definition vtkIndent.h:108
create a line defined by two end points
Allocate and hold a VTK object.
Definition vtkNew.h:167
map vtkPolyData to graphics primitives
concrete dataset represents vertices, lines, polygons, and triangle strips
an ordered list of Props
represent surface properties of a geometric object
create a polygonal sphere centered at the origin
describes linear transformations via a 4x4 matrix
filter that generates tubes around lines
abstract specification for Viewports
Definition vtkViewport.h:65
window superclass for vtkRenderWindow
Definition vtkWindow.h:48
int vtkTypeBool
Definition vtkABI.h:64
@ None
!< For HCURL
#define VTK_SIZEHINT(...)
#define VTK_MARSHALAUTO