VTK  9.4.20250205
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 "vtkVector.h" // For vtkVector3d
11#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
12
13VTK_ABI_NAMESPACE_BEGIN
14class vtkActor;
15class vtkBox;
16class vtkConeSource;
17class vtkCellPicker;
19class vtkFrustum;
20class vtkLineSource;
21class vtkProperty;
22class vtkPolyData;
24class vtkSphereSource;
25class vtkTransform;
26class vtkTubeFilter;
27
42class VTKINTERACTIONWIDGETS_EXPORT VTK_MARSHALAUTO vtkImplicitFrustumRepresentation
44{
45public:
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;
208
216 vtkSetClampMacro(InteractionState, InteractionStateType, InteractionStateType::Outside,
217 InteractionStateType::TranslatingOriginOnAxis);
218
220
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
238protected:
241
242private:
243 enum class FrustumFace
244 {
245 None = -1,
246 Right = 0,
247 Left,
248 Top,
249 Bottom,
250 Near,
251 };
252
253 struct SphereHandle
254 {
257 vtkNew<vtkActor> Actor;
258
259 SphereHandle();
260 };
261
262 struct EdgeHandle
263 {
264 vtkNew<vtkPolyData> PolyData;
267 vtkNew<vtkActor> Actor;
268
269 EdgeHandle();
270 };
271
272 struct EllipseHandle
273 {
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
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
362VTK_ABI_NAMESPACE_END
363#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