VTK  9.4.20241013
vtkWidgetRepresentation.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
46#ifndef vtkWidgetRepresentation_h
47#define vtkWidgetRepresentation_h
48
49#include "vtkInteractionWidgetsModule.h" // For export macro
50#include "vtkNew.h" // for ivars
51#include "vtkProp.h"
52#include "vtkWeakPointer.h" // needed for vtkWeakPointer iVar.
53#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
54
55VTK_ABI_NAMESPACE_BEGIN
58class vtkMatrix4x4;
60class vtkProp3D;
62class vtkRenderer;
63class vtkTransform;
64
65class VTKINTERACTIONWIDGETS_EXPORT VTK_MARSHALAUTO vtkWidgetRepresentation : public vtkProp
66{
67public:
69
73 void PrintSelf(ostream& os, vtkIndent indent) override;
75
77
81 vtkBooleanMacro(PickingManaged, bool);
82 void SetPickingManaged(bool managed);
83 vtkGetMacro(PickingManaged, bool);
85
87
103 virtual void SetRenderer(vtkRenderer* ren);
105 virtual void BuildRepresentation() = 0;
107
140 virtual void PlaceWidget(double vtkNotUsed(bounds)[6]);
141 virtual void StartWidgetInteraction(double eventPos[2]) { (void)eventPos; }
142 virtual void WidgetInteraction(double newEventPos[2]) { (void)newEventPos; }
143 virtual void EndWidgetInteraction(double newEventPos[2]) { (void)newEventPos; }
144 virtual int ComputeInteractionState(int X, int Y, int modify = 0);
145 virtual int GetInteractionState() { return this->InteractionState; }
146 virtual void Highlight(int vtkNotUsed(highlightOn)) {}
147
149 // Widgets were originally designed to be driven by 2D mouse events
150 // With Virtual Reality and multitouch we get mnore complex events
151 // that may involve multiple pointers as well as 3D pointers and
152 // orientations. As such we provide pointers to the interactor
153 // widget and an event type so that representations can access the
154 // values they need.
156 vtkRenderWindowInteractor*, vtkAbstractWidget*, unsigned long /* event */, void* /*callData*/)
157 {
158 }
159 virtual void ComplexInteraction(
160 vtkRenderWindowInteractor*, vtkAbstractWidget*, unsigned long /* event */, void* /* callData */)
161 {
162 }
164 vtkRenderWindowInteractor*, vtkAbstractWidget*, unsigned long /* event */, void* /* callData */)
165 {
166 }
168 vtkAbstractWidget* widget, unsigned long event, void* callData, int modify = 0);
170
172
179 vtkSetClampMacro(PlaceFactor, double, 0.01, VTK_DOUBLE_MAX);
180 vtkGetMacro(PlaceFactor, double);
182
184
193 vtkSetClampMacro(HandleSize, double, 0.001, 1000);
194 vtkGetMacro(HandleSize, double);
196
198
202 vtkGetMacro(NeedToRender, vtkTypeBool);
203 vtkSetClampMacro(NeedToRender, vtkTypeBool, 0, 1);
204 vtkBooleanMacro(NeedToRender, vtkTypeBool);
206
214 double* GetBounds() VTK_SIZEHINT(6) override { return nullptr; }
215 void ShallowCopy(vtkProp* prop) override;
216 void GetActors(vtkPropCollection*) override {}
218 void GetVolumes(vtkPropCollection*) override {}
220 int RenderOverlay(vtkViewport* vtkNotUsed(viewport)) override { return 0; }
221 int RenderOpaqueGeometry(vtkViewport* vtkNotUsed(viewport)) override { return 0; }
222 int RenderTranslucentPolygonalGeometry(vtkViewport* vtkNotUsed(viewport)) override { return 0; }
223 int RenderVolumetricGeometry(vtkViewport* vtkNotUsed(viewport)) override { return 0; }
225
231 virtual void RegisterPickers();
232
236 virtual void UnRegisterPickers();
237
239
242 enum Axis
243 {
244 NONE = -1,
245 XAxis = 0,
246 YAxis = 1,
247 ZAxis = 2,
248 Custom = 3
249 };
251
252protected:
255
256 // The renderer in which this widget is placed
258
259 // The state of this representation based on a recent event
261
262 // These are used to track the beginning of interaction with the representation
263 // It's dimensioned [3] because some events re processed in 3D.
264 double StartEventPosition[3];
265
266 // Instance variable and members supporting suclasses
267 double PlaceFactor; // Used to control how widget is placed around bounding box
268 int Placed; // Indicate whether widget has been placed
269 void AdjustBounds(double bounds[6], double newBounds[6], double center[3]);
270 double InitialBounds[6]; // initial bounds on place widget (valid after PlaceWidget)
271 double InitialLength; // initial length on place widget
272
273 // Sizing handles is tricky because the procedure requires information
274 // relative to the last pick, as well as a live renderer to perform
275 // coordinate conversions. In some cases, a pick is never made so handle
276 // sizing has to follow a different path. The following ivars help with
277 // this process.
278 int ValidPick; // indicate when valid picks are made
279
280 // This variable controls whether the picking is managed by the Picking
281 // Manager or not. True by default.
283
289
295 vtkAssemblyPath* GetAssemblyPath(double X, double Y, double Z, vtkAbstractPropPicker* picker);
297
298 // Helper function to cull events if they are not near to the actual widget
299 // representation. This is needed typically in situations of extreme zoom
300 // for 3D widgets. The current event position, and 3D bounds of the widget
301 // are provided.
302 bool NearbyEvent(int X, int Y, double bounds[6]);
303
304 // Members use to control handle size. The two methods return a "radius"
305 // in world coordinates. Note that the HandleSize data member is used
306 // internal to the SizeHandles__() methods.
307 double HandleSize; // controlling relative size of widget handles
308 double SizeHandlesRelativeToViewport(double factor, double pos[3]);
309 double SizeHandlesInPixels(double factor, double pos[3]);
310
311 // Try and reduce multiple renders
313
314 // This is the time that the representation was built. This data member
315 // can be used to reduce the time spent building the widget.
317
318 // update the pose of a prop based on two sets of
319 // position, orientation vectors
320 void UpdatePropPose(vtkProp3D* prop, const double* pos1, const double* orient1,
321 const double* pos2, const double* orient2);
324
325private:
327 void operator=(const vtkWidgetRepresentation&) = delete;
328};
329
330VTK_ABI_NAMESPACE_END
331#endif
abstract API for pickers that can pick an instance of vtkProp
define the API for widget / widget representation
a list of nodes that form an assembly path
a simple class to control print indentation
Definition vtkIndent.h:108
represent and manipulate 4x4 transformation matrices
Allocate and hold a VTK object.
Definition vtkNew.h:167
Class defines API to manage the picking process.
represents an 3D object for placement in a rendered scene
Definition vtkProp3D.h:89
an ordered list of Props
abstract superclass for all actors, volumes and annotations
Definition vtkProp.h:66
platform-independent render window interaction including picking and frame rate control.
abstract specification for renderers
record modification and/or execution time
describes linear transformations via a 4x4 matrix
abstract specification for Viewports
Definition vtkViewport.h:65
a weak reference to a vtkObject.
abstract class defines interface between the widget and widget representation classes
bool NearbyEvent(int X, int Y, double bounds[6])
void AdjustBounds(double bounds[6], double newBounds[6], double center[3])
virtual void StartComplexInteraction(vtkRenderWindowInteractor *, vtkAbstractWidget *, unsigned long, void *)
virtual int ComputeComplexInteractionState(vtkRenderWindowInteractor *iren, vtkAbstractWidget *widget, unsigned long event, void *callData, int modify=0)
int RenderOpaqueGeometry(vtkViewport *vtkNotUsed(viewport)) override
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for instances of this class.
virtual void EndComplexInteraction(vtkRenderWindowInteractor *, vtkAbstractWidget *, unsigned long, void *)
vtkTypeBool HasTranslucentPolygonalGeometry() override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THESE METHODS OUTSIDE OF THE RENDE...
void GetVolumes(vtkPropCollection *) override
vtkNew< vtkTransform > TempTransform
virtual void UnRegisterPickers()
Unregister internal pickers from the Picking Manager.
virtual void Highlight(int vtkNotUsed(highlightOn))
vtkPickingManager * GetPickingManager()
Return the picking manager associated on the context on which the widget representation currently bel...
virtual void SetRenderer(vtkRenderer *ren)
Subclasses of vtkWidgetRepresentation must implement these methods.
void ShallowCopy(vtkProp *prop) override
Shallow copy of this vtkProp.
vtkWeakPointer< vtkRenderer > Renderer
~vtkWidgetRepresentation() override
virtual void WidgetInteraction(double newEventPos[2])
void ReleaseGraphicsResources(vtkWindow *) override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE Release any graphics resources that are being...
vtkAssemblyPath * GetAssemblyPath3DPoint(double pos[3], vtkAbstractPropPicker *picker)
virtual void ComplexInteraction(vtkRenderWindowInteractor *, vtkAbstractWidget *, unsigned long, void *)
virtual void EndWidgetInteraction(double newEventPos[2])
virtual void RegisterPickers()
Register internal Pickers in the Picking Manager.
double SizeHandlesRelativeToViewport(double factor, double pos[3])
virtual void StartWidgetInteraction(double eventPos[2])
void UpdatePropPose(vtkProp3D *prop, const double *pos1, const double *orient1, const double *pos2, const double *orient2)
vtkNew< vtkMatrix4x4 > TempMatrix
virtual void BuildRepresentation()=0
Subclasses of vtkWidgetRepresentation must implement these methods.
void SetPickingManaged(bool managed)
Enable/Disable the use of a manager to process the picking.
virtual int ComputeInteractionState(int X, int Y, int modify=0)
virtual vtkRenderer * GetRenderer()
Subclasses of vtkWidgetRepresentation must implement these methods.
double * GetBounds() override
Methods to make this class behave as a vtkProp.
int RenderTranslucentPolygonalGeometry(vtkViewport *vtkNotUsed(viewport)) override
void GetActors(vtkPropCollection *) override
For some exporters and other other operations we must be able to collect all the actors or volumes.
virtual void PlaceWidget(double vtkNotUsed(bounds)[6])
The following is a suggested API for widget representations.
void GetActors2D(vtkPropCollection *) override
int RenderVolumetricGeometry(vtkViewport *vtkNotUsed(viewport)) override
double SizeHandlesInPixels(double factor, double pos[3])
vtkAssemblyPath * GetAssemblyPath(double X, double Y, double Z, vtkAbstractPropPicker *picker)
Proceed to a pick, whether through the PickingManager if the picking is managed or directly using the...
int RenderOverlay(vtkViewport *vtkNotUsed(viewport)) override
window superclass for vtkRenderWindow
Definition vtkWindow.h:48
int vtkTypeBool
Definition vtkABI.h:64
#define VTK_DOUBLE_MAX
Definition vtkType.h:154
#define VTK_SIZEHINT(...)
#define VTK_MARSHALAUTO