VTK  9.7.1
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 "vtkVector.h" // for vtkVector3d
53 #include "vtkWeakPointer.h" // needed for vtkWeakPointer iVar.
54 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
55 
56 VTK_ABI_NAMESPACE_BEGIN
57 class vtkAbstractPicker;
59 class vtkAbstractWidget;
60 class vtkMatrix4x4;
61 class vtkPickingManager;
62 class vtkProp3D;
64 class vtkRenderer;
65 class vtkTransform;
66 
67 class VTKINTERACTIONWIDGETS_EXPORT VTK_MARSHALAUTO vtkWidgetRepresentation : public vtkProp
68 {
69 public:
71 
75  void PrintSelf(ostream& os, vtkIndent indent) override;
77 
79 
83  vtkBooleanMacro(PickingManaged, bool);
84  void SetPickingManaged(bool managed);
85  vtkGetMacro(PickingManaged, bool);
87 
89 
105  virtual void SetRenderer(vtkRenderer* ren);
106  virtual vtkRenderer* GetRenderer();
107  virtual void BuildRepresentation() = 0;
109 
142  virtual void PlaceWidget(double vtkNotUsed(bounds)[6]);
143  virtual void StartWidgetInteraction(double eventPos[2]) { (void)eventPos; }
144  virtual void WidgetInteraction(double newEventPos[2]) { (void)newEventPos; }
145  virtual void EndWidgetInteraction(double newEventPos[2]) { (void)newEventPos; }
146  virtual int ComputeInteractionState(int X, int Y, int modify = 0);
147  virtual int GetInteractionState() { return this->InteractionState; }
148  virtual void Highlight(int vtkNotUsed(highlightOn)) {}
149 
151  // Widgets were originally designed to be driven by 2D mouse events
152  // With Virtual Reality and multitouch we get mnore complex events
153  // that may involve multiple pointers as well as 3D pointers and
154  // orientations. As such we provide pointers to the interactor
155  // widget and an event type so that representations can access the
156  // values they need.
158  vtkRenderWindowInteractor*, vtkAbstractWidget*, unsigned long /* event */, void* /*callData*/)
159  {
160  }
161  virtual void ComplexInteraction(
162  vtkRenderWindowInteractor*, vtkAbstractWidget*, unsigned long /* event */, void* /* callData */)
163  {
164  }
165  virtual void EndComplexInteraction(
166  vtkRenderWindowInteractor*, vtkAbstractWidget*, unsigned long /* event */, void* /* callData */)
167  {
168  }
169  virtual int ComputeComplexInteractionState(vtkRenderWindowInteractor* iren,
170  vtkAbstractWidget* widget, unsigned long event, void* callData, int modify = 0);
172 
174 
181  vtkSetClampMacro(PlaceFactor, double, 0.01, VTK_DOUBLE_MAX);
182  vtkGetMacro(PlaceFactor, double);
184 
186 
195  vtkSetClampMacro(HandleSize, double, 0.001, 1000);
196  vtkGetMacro(HandleSize, double);
198 
200 
204  vtkGetMacro(NeedToRender, vtkTypeBool);
205  vtkSetClampMacro(NeedToRender, vtkTypeBool, 0, 1);
206  vtkBooleanMacro(NeedToRender, vtkTypeBool);
208 
216  double* GetBounds() VTK_SIZEHINT(6) override { return nullptr; }
217  void ShallowCopy(vtkProp* prop) override;
218  void GetActors(vtkPropCollection*) override {}
219  void GetActors2D(vtkPropCollection*) override {}
220  void GetVolumes(vtkPropCollection*) override {}
222  int RenderOverlay(vtkViewport* vtkNotUsed(viewport)) override { return 0; }
223  int RenderOpaqueGeometry(vtkViewport* vtkNotUsed(viewport)) override { return 0; }
224  int RenderTranslucentPolygonalGeometry(vtkViewport* vtkNotUsed(viewport)) override { return 0; }
225  int RenderVolumetricGeometry(vtkViewport* vtkNotUsed(viewport)) override { return 0; }
227 
233  virtual void RegisterPickers();
234 
238  virtual void UnRegisterPickers();
239 
241 
244  enum Axis
245  {
246  NONE = -1,
247  XAxis = 0,
248  YAxis = 1,
249  ZAxis = 2,
250  Custom = 3
251  };
253 
254 protected:
256  ~vtkWidgetRepresentation() override;
257 
261  vtkVector3d GetWorldPoint(vtkAbstractPicker* picker, double screenPos[2]);
262 
263  // The renderer in which this widget is placed
265 
266  // The state of this representation based on a recent event
268 
269  // These are used to track the beginning of interaction with the representation
270  // It's dimensioned [3] because some events re processed in 3D.
271  double StartEventPosition[3];
272 
273  // Instance variable and members supporting suclasses
274  double PlaceFactor; // Used to control how widget is placed around bounding box
275  int Placed; // Indicate whether widget has been placed
276  void AdjustBounds(double bounds[6], double newBounds[6], double center[3]);
277  double InitialBounds[6]; // initial bounds on place widget (valid after PlaceWidget)
278  double InitialLength; // initial length on place widget
279 
280  // Sizing handles is tricky because the procedure requires information
281  // relative to the last pick, as well as a live renderer to perform
282  // coordinate conversions. In some cases, a pick is never made so handle
283  // sizing has to follow a different path. The following ivars help with
284  // this process.
285  int ValidPick; // indicate when valid picks are made
286 
287  // This variable controls whether the picking is managed by the Picking
288  // Manager or not. True by default.
290 
295  vtkPickingManager* GetPickingManager();
296 
302  vtkAssemblyPath* GetAssemblyPath(double X, double Y, double Z, vtkAbstractPropPicker* picker);
303  vtkAssemblyPath* GetAssemblyPath3DPoint(double pos[3], vtkAbstractPropPicker* picker);
304 
305  // Helper function to cull events if they are not near to the actual widget
306  // representation. This is needed typically in situations of extreme zoom
307  // for 3D widgets. The current event position, and 3D bounds of the widget
308  // are provided.
309  bool NearbyEvent(int X, int Y, double bounds[6]);
310 
311  // Members use to control handle size. The two methods return a "radius"
312  // in world coordinates. Note that the HandleSize data member is used
313  // internal to the SizeHandles__() methods.
314  double HandleSize; // controlling relative size of widget handles
315  double SizeHandlesRelativeToViewport(double factor, double pos[3]);
316  double SizeHandlesInPixels(double factor, double pos[3]);
317 
318  // Try and reduce multiple renders
320 
321  // This is the time that the representation was built. This data member
322  // can be used to reduce the time spent building the widget.
324 
325  // update the pose of a prop based on two sets of
326  // position, orientation vectors
327  void UpdatePropPose(vtkProp3D* prop, const double* pos1, const double* orient1,
328  const double* pos2, const double* orient2);
331 
332 private:
334  void operator=(const vtkWidgetRepresentation&) = delete;
335 };
336 
337 VTK_ABI_NAMESPACE_END
338 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:49
virtual void EndWidgetInteraction(double newEventPos[2])
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:31
Class defines API to manage the picking process.
virtual void ShallowCopy(vtkProp *prop)
Shallow copy of this vtkProp.
#define VTK_DOUBLE_MAX
Definition: vtkType.h:202
abstract specification for Viewports
Definition: vtkViewport.h:46
void GetActors2D(vtkPropCollection *) override
virtual void StartWidgetInteraction(double eventPos[2])
record modification and/or execution time
Definition: vtkTimeStamp.h:24
vtkWeakPointer< vtkRenderer > Renderer
virtual void ComplexInteraction(vtkRenderWindowInteractor *, vtkAbstractWidget *, unsigned long, void *)
abstract specification for renderers
Definition: vtkRenderer.h:63
virtual void EndComplexInteraction(vtkRenderWindowInteractor *, vtkAbstractWidget *, unsigned long, void *)
vtkNew< vtkTransform > TempTransform
virtual void StartComplexInteraction(vtkRenderWindowInteractor *, vtkAbstractWidget *, unsigned long, void *)
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:50
represents an 3D object for placement in a rendered scene
Definition: vtkProp3D.h:39
int RenderOpaqueGeometry(vtkViewport *viewport) override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THESE METHODS OUTSIDE OF THE RENDE...
abstract class defines interface between the widget and widget representation classes ...
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
void GetVolumes(vtkPropCollection *) override
window superclass for vtkRenderWindow
Definition: vtkWindow.h:41
platform-independent render window interaction including picking and frame rate control.
a list of nodes that form an assembly path
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
a simple class to control print indentation
Definition: vtkIndent.h:28
int RenderOverlay(vtkViewport *viewport) override
vtkNew< vtkMatrix4x4 > TempMatrix
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])
virtual void Highlight(int highlightOn)
#define VTK_SIZEHINT(...)
define the API for widget / widget representation
abstract API for pickers that can pick an instance of vtkProp
vtkTypeBool HasTranslucentPolygonalGeometry() override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THESE METHODS OUTSIDE OF THE RENDE...
define API for picking subclasses
#define VTK_MARSHALAUTO
int RenderVolumetricGeometry(vtkViewport *viewport) override
void GetActors(vtkPropCollection *) override
For some exporters and other other operations we must be able to collect all the actors or volumes...