VTK  9.4.20241121
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 "vtkInteractionWidgetsModule.h" // For export macro
9#include "vtkSetGet.h"
10#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
148
153 vtkSetVector6Macro(WidgetBounds, double);
154 double* GetWidgetBounds();
156
161 void GetPolyData(vtkPolyData* pd);
162
167 void UpdatePlacement();
168
172 vtkGetObjectMacro(FrustumProperty, vtkProperty);
173
175
179 vtkGetObjectMacro(EdgeHandleProperty, vtkProperty);
180 vtkGetObjectMacro(SelectedEdgeHandleProperty, vtkProperty);
182
184
188 void SetInteractionColor(double, double, double);
189 void SetInteractionColor(double c[3]) { this->SetInteractionColor(c[0], c[1], c[2]); }
190 void SetHandleColor(double, double, double);
191 void SetHandleColor(double c[3]) { this->SetHandleColor(c[0], c[1], c[2]); }
192 void SetForegroundColor(double, double, double);
193 void SetForegroundColor(double c[3]) { this->SetForegroundColor(c[0], c[1], c[2]); }
195
197
200 int ComputeInteractionState(int X, int Y, int modify = 0) override;
201 void PlaceWidget(double bounds[6]) override;
202 void BuildRepresentation() override;
203 void StartWidgetInteraction(double eventPos[2]) override;
204 void WidgetInteraction(double newEventPos[2]) override;
205 void EndWidgetInteraction(double newEventPos[2]) override;
207
209
212 double* GetBounds() override;
213 void GetActors(vtkPropCollection* pc) override;
219
227 vtkSetClampMacro(InteractionState, InteractionStateType, InteractionStateType::Outside,
228 InteractionStateType::TranslatingOriginOnAxis);
229
231
236 vtkGetMacro(RepresentationState, InteractionStateType);
238
239 /*
240 * Register internal Pickers within PickingManager
241 */
242 void RegisterPickers() override;
243
245
249 vtkGetMacro(TranslationAxis, int);
250 vtkSetClampMacro(TranslationAxis, int, Axis::NONE, Axis::ZAxis);
252
254
257 void SetXTranslationAxisOn() { this->TranslationAxis = Axis::XAxis; }
258 void SetYTranslationAxisOn() { this->TranslationAxis = Axis::YAxis; }
259 void SetZTranslationAxisOn() { this->TranslationAxis = Axis::ZAxis; }
260 void SetTranslationAxisOff() { this->TranslationAxis = Axis::NONE; }
262
266 bool IsTranslationConstrained() { return this->TranslationAxis != Axis::NONE; }
267
271 void GetFrustum(vtkFrustum* frustum) const;
272
273protected:
276
277private:
278 enum class FrustumFace
279 {
280 None = -1,
281 Right = 0,
282 Left,
283 Top,
284 Bottom,
285 Near,
286 };
287
288 struct SphereHandle
289 {
292 vtkNew<vtkActor> Actor;
293
294 SphereHandle();
295 };
296
297 struct EdgeHandle
298 {
299 vtkNew<vtkPolyData> PolyData;
302 vtkNew<vtkActor> Actor;
303
304 EdgeHandle();
305 };
306
307 struct EllipseHandle
308 {
312 vtkNew<vtkActor> Actor;
313
314 EllipseHandle();
315 };
316
318 void operator=(const vtkImplicitFrustumRepresentation&) = delete;
319
320 // Helpers to get the frustum basis
321 vtkVector3d GetForwardAxis();
322 vtkVector3d GetUpAxis();
323 vtkVector3d GetRightAxis();
324
325 void HighlightOriginHandle(bool highlight);
326 void HighlightFarPlaneVerticalHandle(bool highlight);
327 void HighlightFarPlaneHorizontalHandle(bool highlight);
328 void HighlightNearPlaneHandle(bool highlight);
329 void HighlightRollHandle(bool highlight);
330 void HighlightYawHandle(bool highlight);
331 void HighlightPitchHandle(bool highlight);
332
333 // Methods to manipulate the frustum
334 void TranslateOrigin(const vtkVector3d& p1, const vtkVector3d& p2);
335 void TranslateOriginOnAxis(const vtkVector3d& p1, const vtkVector3d& p2);
336 void AdjustHorizontalAngle(const vtkVector3d& p1, const vtkVector3d& p2);
337 void AdjustVerticalAngle(const vtkVector3d& p1, const vtkVector3d& p2);
338 void AdjustNearPlaneDistance(
339 const vtkVector2d& eventPosition, const vtkVector3d& p1, const vtkVector3d& p2);
340 void Rotate(
341 const vtkVector3d& prevPickPoint, const vtkVector3d& pickPoint, const vtkVector3d& axis);
342
343 // Set the frustum transform according to the representation's orientation and position
344 void UpdateFrustumTransform();
345
346 // Re-compute the widget handles' sizes
347 void SizeHandles();
348
349 // Generate the frustum polydata, cropped by the bounding box
350 void BuildFrustum();
351
352 // The actual frustum we're manipulating
353 vtkNew<vtkFrustum> Frustum;
354
355 InteractionStateType RepresentationState = InteractionStateType::Outside;
356 int TranslationAxis = Axis::NONE;
357
358 // Keep track of event positions
359 vtkVector3d LastEventPosition = { 0., 0., 0. };
360
361 bool AlongXAxis = false;
362 bool AlongYAxis = false;
363 bool AlongZAxis = false;
364
365 vtkVector<double, 6> WidgetBounds;
366 double Length = 1;
367
368 vtkVector3d Origin = { 0, 0, 0 };
369 vtkNew<vtkTransform> OrientationTransform;
370
371 vtkNew<vtkPolyData> FrustumPD;
372 vtkNew<vtkPolyDataMapper> FrustumMapper;
373 vtkNew<vtkActor> FrustumActor;
374 bool DrawFrustum = true;
375
376 std::array<EdgeHandle, 4> FarPlaneHandles;
377 EdgeHandle NearPlaneEdgesHandle;
378 SphereHandle NearPlaneCenterHandle;
379 EllipseHandle RollHandle;
380 EllipseHandle YawHandle;
381 EllipseHandle PitchHandle;
382 SphereHandle OriginHandle;
383
384 FrustumFace ActiveEdgeHandle = FrustumFace::None;
385
387 vtkNew<vtkCellPicker> FrustumPicker;
388
389 // Properties used to control the appearance of selected objects and the manipulator in general.
390 vtkNew<vtkProperty> FrustumProperty;
391 vtkNew<vtkProperty> EdgeHandleProperty;
392 vtkNew<vtkProperty> SelectedEdgeHandleProperty;
393 vtkNew<vtkProperty> OriginHandleProperty;
394 vtkNew<vtkProperty> SelectedOriginHandleProperty;
395
396 vtkNew<vtkBox> BoundingBox;
397};
398
399VTK_ABI_NAMESPACE_END
400#endif
represents an object (geometry & properties) in a rendered scene
Definition vtkActor.h:151
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 SetYTranslationAxisOn()
Toggles constraint translation axis on/off.
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.
bool IsTranslationConstrained()
Returns true if translation is constrained to an axis.
void SetOrigin(double x[3])
Get the origin of the frustum representation.
double * GetOrigin()
Get the origin of the frustum representation.
void SetTranslationAxisOff()
Toggles constraint translation axis on/off.
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
Methods invoked by print to print information about the object including superclasses.
void SetOrigin(const vtkVector3d &xyz)
Get the origin of the frustum representation.
void ReleaseGraphicsResources(vtkWindow *) override
Methods supporting the rendering process.
void SetZTranslationAxisOn()
Toggles constraint translation axis on/off.
void SetHandleColor(double c[3])
Set the color of all the widgets handles (origin, orientations, near plane and angles) and their colo...
void SetXTranslationAxisOn()
Toggles constraint translation axis on/off.
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
templated base type for storage of vectors.
Definition vtkVector.h:59
abstract specification for Viewports
Definition vtkViewport.h:65
abstract class defines interface between the widget and widget representation classes
window superclass for vtkRenderWindow
Definition vtkWindow.h:48
int vtkTypeBool
Definition vtkABI.h:64
@ None
!< For HCURL
#define VTK_SIZEHINT(...)
#define VTK_MARSHALAUTO