VTK  9.0.20201030
vtkWidgetRepresentation.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkWidgetRepresentation.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
42 #ifndef vtkWidgetRepresentation_h
43 #define vtkWidgetRepresentation_h
44 
45 #include "vtkInteractionWidgetsModule.h" // For export macro
46 #include "vtkNew.h" // for ivars
47 #include "vtkProp.h"
48 #include "vtkWeakPointer.h" // needed for vtkWeakPointer iVar.
49 
51 class vtkAbstractWidget;
52 class vtkMatrix4x4;
53 class vtkPickingManager;
54 class vtkProp3D;
56 class vtkRenderer;
57 class vtkTransform;
58 
59 class VTKINTERACTIONWIDGETS_EXPORT vtkWidgetRepresentation : public vtkProp
60 {
61 public:
63 
67  void PrintSelf(ostream& os, vtkIndent indent) override;
69 
71 
75  vtkBooleanMacro(PickingManaged, bool);
76  void SetPickingManaged(bool managed);
77  vtkGetMacro(PickingManaged, bool);
79 
81 
97  virtual void SetRenderer(vtkRenderer* ren);
98  virtual vtkRenderer* GetRenderer();
99  virtual void BuildRepresentation() = 0;
101 
134  virtual void PlaceWidget(double* vtkNotUsed(bounds[6]));
135  virtual void StartWidgetInteraction(double eventPos[2]) { (void)eventPos; }
136  virtual void WidgetInteraction(double newEventPos[2]) { (void)newEventPos; }
137  virtual void EndWidgetInteraction(double newEventPos[2]) { (void)newEventPos; }
138  virtual int ComputeInteractionState(int X, int Y, int modify = 0);
139  virtual int GetInteractionState() { return this->InteractionState; }
140  virtual void Highlight(int vtkNotUsed(highlightOn)) {}
141 
143  // Widgets were originally designed to be driven by 2D mouse events
144  // With Virtual Reality and multitouch we get mnore complex events
145  // that may involve multiple pointers as well as 3D pointers and
146  // orientations. As such we provide pointers to the interactor
147  // widget and an event type so that representations can access the
148  // values they need.
150  vtkRenderWindowInteractor*, vtkAbstractWidget*, unsigned long /* event */, void* /*callData*/)
151  {
152  }
153  virtual void ComplexInteraction(
154  vtkRenderWindowInteractor*, vtkAbstractWidget*, unsigned long /* event */, void* /* callData */)
155  {
156  }
157  virtual void EndComplexInteraction(
158  vtkRenderWindowInteractor*, vtkAbstractWidget*, unsigned long /* event */, void* /* callData */)
159  {
160  }
161  virtual int ComputeComplexInteractionState(vtkRenderWindowInteractor* iren,
162  vtkAbstractWidget* widget, unsigned long event, void* callData, int modify = 0);
164 
166 
173  vtkSetClampMacro(PlaceFactor, double, 0.01, VTK_DOUBLE_MAX);
174  vtkGetMacro(PlaceFactor, double);
176 
178 
187  vtkSetClampMacro(HandleSize, double, 0.001, 1000);
188  vtkGetMacro(HandleSize, double);
190 
192 
196  vtkGetMacro(NeedToRender, vtkTypeBool);
197  vtkSetClampMacro(NeedToRender, vtkTypeBool, 0, 1);
198  vtkBooleanMacro(NeedToRender, vtkTypeBool);
200 
208  double* GetBounds() VTK_SIZEHINT(6) override { return nullptr; }
209  void ShallowCopy(vtkProp* prop) override;
210  void GetActors(vtkPropCollection*) override {}
211  void GetActors2D(vtkPropCollection*) override {}
212  void GetVolumes(vtkPropCollection*) override {}
214  int RenderOverlay(vtkViewport* vtkNotUsed(viewport)) override { return 0; }
215  int RenderOpaqueGeometry(vtkViewport* vtkNotUsed(viewport)) override { return 0; }
216  int RenderTranslucentPolygonalGeometry(vtkViewport* vtkNotUsed(viewport)) override { return 0; }
217  int RenderVolumetricGeometry(vtkViewport* vtkNotUsed(viewport)) override { return 0; }
219 
225  virtual void RegisterPickers();
226 
230  virtual void UnRegisterPickers();
231 
233 
236  enum Axis
237  {
238  NONE = -1,
239  XAxis = 0,
240  YAxis = 1,
241  ZAxis = 2
242  };
244 
245 protected:
247  ~vtkWidgetRepresentation() override;
248 
249  // The renderer in which this widget is placed
251 
252  // The state of this representation based on a recent event
254 
255  // These are used to track the beginning of interaction with the representation
256  // It's dimensioned [3] because some events re processed in 3D.
257  double StartEventPosition[3];
258 
259  // Instance variable and members supporting suclasses
260  double PlaceFactor; // Used to control how widget is placed around bounding box
261  int Placed; // Indicate whether widget has been placed
262  void AdjustBounds(double bounds[6], double newBounds[6], double center[3]);
263  double InitialBounds[6]; // initial bounds on place widget (valid after PlaceWidget)
264  double InitialLength; // initial length on place widget
265 
266  // Sizing handles is tricky because the procedure requires information
267  // relative to the last pick, as well as a live renderer to perform
268  // coordinate conversions. In some cases, a pick is never made so handle
269  // sizing has to follow a different path. The following ivars help with
270  // this process.
271  int ValidPick; // indicate when valid picks are made
272 
273  // This variable controls whether the picking is managed by the Picking
274  // Manager or not. True by default.
276 
281  vtkPickingManager* GetPickingManager();
282 
288  vtkAssemblyPath* GetAssemblyPath(double X, double Y, double Z, vtkAbstractPropPicker* picker);
289  vtkAssemblyPath* GetAssemblyPath3DPoint(double pos[3], vtkAbstractPropPicker* picker);
290 
291  // Helper function to cull events if they are not near to the actual widget
292  // representation. This is needed typically in situations of extreme zoom
293  // for 3D widgets. The current event position, and 3D bounds of the widget
294  // are provided.
295  bool NearbyEvent(int X, int Y, double bounds[6]);
296 
297  // Members use to control handle size. The two methods return a "radius"
298  // in world coordinates. Note that the HandleSize data member is used
299  // internal to the SizeHandles__() methods.
300  double HandleSize; // controlling relative size of widget handles
301  double SizeHandlesRelativeToViewport(double factor, double pos[3]);
302  double SizeHandlesInPixels(double factor, double pos[3]);
303 
304  // Try and reduce multiple renders
306 
307  // This is the time that the representation was built. This data member
308  // can be used to reduce the time spent building the widget.
310 
311  // update the pose of a prop based on two sets of
312  // position, orientation vectors
313  void UpdatePropPose(vtkProp3D* prop, const double* pos1, const double* orient1,
314  const double* pos2, const double* orient2);
317 
318 private:
320  void operator=(const vtkWidgetRepresentation&) = delete;
321 };
322 
323 #endif
vtkWidgetRepresentation::StartWidgetInteraction
virtual void StartWidgetInteraction(double eventPos[2])
Definition: vtkWidgetRepresentation.h:135
vtkWidgetRepresentation::GetActors
void GetActors(vtkPropCollection *) override
For some exporters and other other operations we must be able to collect all the actors or volumes.
Definition: vtkWidgetRepresentation.h:210
vtkWidgetRepresentation::NeedToRender
vtkTypeBool NeedToRender
Definition: vtkWidgetRepresentation.h:305
vtkWidgetRepresentation::Renderer
vtkWeakPointer< vtkRenderer > Renderer
Definition: vtkWidgetRepresentation.h:250
vtkWidgetRepresentation::EndWidgetInteraction
virtual void EndWidgetInteraction(double newEventPos[2])
Definition: vtkWidgetRepresentation.h:137
vtkProp3D
represents an 3D object for placement in a rendered scene
Definition: vtkProp3D.h:43
vtkWidgetRepresentation::Placed
int Placed
Definition: vtkWidgetRepresentation.h:261
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:32
vtkWidgetRepresentation
abstract class defines interface between the widget and widget representation classes
Definition: vtkWidgetRepresentation.h:59
vtkX3D::center
Definition: vtkX3D.h:236
vtkWidgetRepresentation::ValidPick
int ValidPick
Definition: vtkWidgetRepresentation.h:271
vtkWidgetRepresentation::GetActors2D
void GetActors2D(vtkPropCollection *) override
Definition: vtkWidgetRepresentation.h:211
vtkTransform
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:54
vtkAssemblyPath
a list of nodes that form an assembly path
Definition: vtkAssemblyPath.h:41
vtkProp.h
vtkWidgetRepresentation::StartComplexInteraction
virtual void StartComplexInteraction(vtkRenderWindowInteractor *, vtkAbstractWidget *, unsigned long, void *)
Definition: vtkWidgetRepresentation.h:149
vtkWidgetRepresentation::GetVolumes
void GetVolumes(vtkPropCollection *) override
Definition: vtkWidgetRepresentation.h:212
vtkWidgetRepresentation::InteractionState
int InteractionState
Definition: vtkWidgetRepresentation.h:253
vtkWindow
window superclass for vtkRenderWindow
Definition: vtkWindow.h:38
vtkWidgetRepresentation::RenderTranslucentPolygonalGeometry
int RenderTranslucentPolygonalGeometry(vtkViewport *vtkNotUsed(viewport)) override
Definition: vtkWidgetRepresentation.h:216
vtkWidgetRepresentation::ReleaseGraphicsResources
void ReleaseGraphicsResources(vtkWindow *) override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE Release any graphics resources that are being...
Definition: vtkWidgetRepresentation.h:213
vtkAbstractWidget
define the API for widget / widget representation
Definition: vtkAbstractWidget.h:65
vtkWidgetRepresentation::ComplexInteraction
virtual void ComplexInteraction(vtkRenderWindowInteractor *, vtkAbstractWidget *, unsigned long, void *)
Definition: vtkWidgetRepresentation.h:153
vtkWidgetRepresentation::EndComplexInteraction
virtual void EndComplexInteraction(vtkRenderWindowInteractor *, vtkAbstractWidget *, unsigned long, void *)
Definition: vtkWidgetRepresentation.h:157
vtkWidgetRepresentation::TempTransform
vtkNew< vtkTransform > TempTransform
Definition: vtkWidgetRepresentation.h:315
vtkWidgetRepresentation::WidgetInteraction
virtual void WidgetInteraction(double newEventPos[2])
Definition: vtkWidgetRepresentation.h:136
vtkWidgetRepresentation::GetBounds
double * GetBounds() override
Methods to make this class behave as a vtkProp.
Definition: vtkWidgetRepresentation.h:208
vtkProp::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
VTK_SIZEHINT
#define VTK_SIZEHINT(...)
Definition: vtkWrappingHints.h:45
vtkWidgetRepresentation::TempMatrix
vtkNew< vtkMatrix4x4 > TempMatrix
Definition: vtkWidgetRepresentation.h:316
vtkWidgetRepresentation::GetInteractionState
virtual int GetInteractionState()
Definition: vtkWidgetRepresentation.h:139
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkMatrix4x4
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:35
vtkWidgetRepresentation::BuildTime
vtkTimeStamp BuildTime
Definition: vtkWidgetRepresentation.h:309
vtkNew< vtkTransform >
vtkWeakPointer.h
vtkProp::ShallowCopy
virtual void ShallowCopy(vtkProp *prop)
Shallow copy of this vtkProp.
vtkRenderWindowInteractor
platform-independent render window interaction including picking and frame rate control.
Definition: vtkRenderWindowInteractor.h:82
vtkViewport
abstract specification for Viewports
Definition: vtkViewport.h:44
vtkAbstractPropPicker
abstract API for pickers that can pick an instance of vtkProp
Definition: vtkAbstractPropPicker.h:79
vtkProp
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:56
vtkWidgetRepresentation::PickingManaged
bool PickingManaged
Definition: vtkWidgetRepresentation.h:275
vtkWidgetRepresentation::RenderOverlay
int RenderOverlay(vtkViewport *vtkNotUsed(viewport)) override
Definition: vtkWidgetRepresentation.h:214
vtkNew.h
vtkWidgetRepresentation::RenderOpaqueGeometry
int RenderOpaqueGeometry(vtkViewport *vtkNotUsed(viewport)) override
Definition: vtkWidgetRepresentation.h:215
vtkWidgetRepresentation::PlaceFactor
double PlaceFactor
Definition: vtkWidgetRepresentation.h:260
vtkRenderer
abstract specification for renderers
Definition: vtkRenderer.h:67
vtkWidgetRepresentation::Axis
Axis
Axis labels.
Definition: vtkWidgetRepresentation.h:236
vtkWidgetRepresentation::HandleSize
double HandleSize
Definition: vtkWidgetRepresentation.h:300
vtkWidgetRepresentation::RenderVolumetricGeometry
int RenderVolumetricGeometry(vtkViewport *vtkNotUsed(viewport)) override
Definition: vtkWidgetRepresentation.h:217
vtkWidgetRepresentation::HasTranslucentPolygonalGeometry
vtkTypeBool HasTranslucentPolygonalGeometry() override
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THESE METHODS OUTSIDE OF THE RENDE...
Definition: vtkWidgetRepresentation.h:218
vtkPropCollection
an ordered list of Props
Definition: vtkPropCollection.h:35
VTK_DOUBLE_MAX
#define VTK_DOUBLE_MAX
Definition: vtkType.h:157
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkWeakPointer< vtkRenderer >
vtkWidgetRepresentation::InitialLength
double InitialLength
Definition: vtkWidgetRepresentation.h:264
vtkWidgetRepresentation::Highlight
virtual void Highlight(int vtkNotUsed(highlightOn))
Definition: vtkWidgetRepresentation.h:140
vtkPickingManager
Definition: vtkPickingManager.h:82