VTK
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 "vtkProp.h"
47 #include "vtkWeakPointer.h" // needed for vtkWeakPointer iVar.
48 #include "vtkNew.h" // for ivars
49 
51 class vtkAbstractWidget;
52 class vtkMatrix4x4;
53 class vtkPickingManager;
54 class vtkProp3D;
56 class vtkRenderer;
57 class vtkTransform;
58 
59 
60 class VTKINTERACTIONWIDGETS_EXPORT vtkWidgetRepresentation : public vtkProp
61 {
62 public:
64 
68  void PrintSelf(ostream& os, vtkIndent indent) override;
70 
72 
76  vtkBooleanMacro(PickingManaged, bool);
77  void SetPickingManaged(bool managed);
78  vtkGetMacro(PickingManaged, bool);
80 
82 
98  virtual void SetRenderer(vtkRenderer *ren);
99  virtual vtkRenderer* GetRenderer();
100  virtual void BuildRepresentation() = 0;
102 
135  virtual void PlaceWidget(double* vtkNotUsed(bounds[6])) {}
136  virtual void StartWidgetInteraction(double eventPos[2]) { (void)eventPos; }
137  virtual void WidgetInteraction(double newEventPos[2]) { (void)newEventPos; }
138  virtual void EndWidgetInteraction(double newEventPos[2]) { (void)newEventPos; }
139  virtual int ComputeInteractionState(int X, int Y, int modify=0);
140  virtual int GetInteractionState()
141  {return this->InteractionState;}
142  virtual void Highlight(int vtkNotUsed(highlightOn)) {}
143 
145  // Widgets were originally designed to be driven by 2D mouse events
146  // With Virtual Reality and multitouch we get mnore complex events
147  // that may involve multiple pointers as well as 3D pointers and
148  // orientations. As such we provide pointers to the interactor
149  // widget and an event type so that representations can access the
150  // values they need.
154  unsigned long /* event */,
155  void * /*callData*/) { }
156  virtual void ComplexInteraction(
159  unsigned long /* event */,
160  void * /* callData */) { }
161  virtual void EndComplexInteraction(
164  unsigned long /* event */,
165  void * /* callData */) { }
166  virtual int ComputeComplexInteractionState(
168  vtkAbstractWidget *widget,
169  unsigned long event, void *callData, int modify = 0);
171 
173 
180  vtkSetClampMacro(PlaceFactor,double,0.01,VTK_DOUBLE_MAX);
181  vtkGetMacro(PlaceFactor,double);
183 
185 
194  vtkSetClampMacro(HandleSize,double,0.001,1000);
195  vtkGetMacro(HandleSize,double);
197 
199 
203  vtkGetMacro( NeedToRender, vtkTypeBool );
204  vtkSetClampMacro( NeedToRender, vtkTypeBool, 0, 1 );
205  vtkBooleanMacro( NeedToRender, vtkTypeBool );
207 
215  double *GetBounds() VTK_SIZEHINT(6) override {return nullptr;}
216  void ShallowCopy(vtkProp *prop) override;
217  void GetActors(vtkPropCollection *) override {}
218  void GetActors2D(vtkPropCollection *) override {}
219  void GetVolumes(vtkPropCollection *) override {}
221  int RenderOverlay(vtkViewport *vtkNotUsed(viewport)) override {return 0;}
222  int RenderOpaqueGeometry(vtkViewport *vtkNotUsed(viewport)) override {return 0;}
223  int RenderTranslucentPolygonalGeometry(vtkViewport *vtkNotUsed(viewport)) override {return 0;}
224  int RenderVolumetricGeometry(vtkViewport *vtkNotUsed(viewport)) override {return 0;}
226 
232  virtual void RegisterPickers();
233 
237  virtual void UnRegisterPickers();
238 
239 protected:
241  ~vtkWidgetRepresentation() override;
242 
243  // The renderer in which this widget is placed
245 
246  // The state of this representation based on a recent event
248 
249  // These are used to track the beginning of interaction with the representation
250  // It's dimensioned [3] because some events re processed in 3D.
251  double StartEventPosition[3];
252 
253  // Instance variable and members supporting suclasses
254  double PlaceFactor; // Used to control how widget is placed around bounding box
255  int Placed; // Indicate whether widget has been placed
256  void AdjustBounds(double bounds[6], double newBounds[6], double center[3]);
257  double InitialBounds[6]; //initial bounds on place widget (valid after PlaceWidget)
258  double InitialLength; //initial length on place widget
259 
260  // Sizing handles is tricky because the procedure requires information
261  // relative to the last pick, as well as a live renderer to perform
262  // coordinate conversions. In some cases, a pick is never made so handle
263  // sizing has to follow a different path. The following ivars help with
264  // this process.
265  int ValidPick; //indicate when valid picks are made
266 
267  // This variable controls whether the picking is managed by the Picking
268  // Manager or not. True by default.
270 
275  vtkPickingManager* GetPickingManager();
276 
282  vtkAssemblyPath* GetAssemblyPath(double X, double Y, double Z,
283  vtkAbstractPropPicker* picker);
284  vtkAssemblyPath* GetAssemblyPath3DPoint(double pos[3],
285  vtkAbstractPropPicker* picker);
286 
287  // Members use to control handle size. The two methods return a "radius"
288  // in world coordinates. Note that the HandleSize data member is used
289  // internal to the SizeHandles__() methods.
290  double HandleSize; //controlling relative size of widget handles
291  double SizeHandlesRelativeToViewport(double factor, double pos[3]);
292  double SizeHandlesInPixels(double factor,double pos[3]);
293 
294  // Try and reduce multiple renders
296 
297  // This is the time that the representation was built. This data member
298  // can be used to reduce the time spent building the widget.
300 
301  // update the pose of a prop based on two sets of
302  // position, orientation vectors
303  void UpdatePropPose(vtkProp3D *prop,
304  const double *pos1, const double *orient1,
305  const double *pos2, const double *orient2);
308 
309 private:
311  void operator=(const vtkWidgetRepresentation&) = delete;
312 };
313 
314 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:52
virtual void EndWidgetInteraction(double newEventPos[2])
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:41
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:169
abstract specification for Viewports
Definition: vtkViewport.h:47
void GetActors2D(vtkPropCollection *) override
virtual void StartWidgetInteraction(double eventPos[2])
record modification and/or execution time
Definition: vtkTimeStamp.h:35
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:60
represents an 3D object for placement in a rendered scene
Definition: vtkProp3D.h:46
abstract class defines interface between the widget and widget representation classes ...
double * GetBounds() override
Methods to make this class behave as a vtkProp.
an ordered list of Props
int vtkTypeBool
Definition: vtkABI.h:69
void GetVolumes(vtkPropCollection *) override
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
platform-independent render window interaction including picking and frame rate control.
int RenderTranslucentPolygonalGeometry(vtkViewport *vtkNotUsed(viewport)) override
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:39
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])
int RenderOpaqueGeometry(vtkViewport *vtkNotUsed(viewport)) override
#define VTK_SIZEHINT(...)
int RenderOverlay(vtkViewport *vtkNotUsed(viewport)) override
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...
virtual void PlaceWidget(double *vtkNotUsed(bounds[6]))
The following is a suggested API for widget representations.
virtual void Highlight(int vtkNotUsed(highlightOn))
void GetActors(vtkPropCollection *) override
For some exporters and other other operations we must be able to collect all the actors or volumes...
int RenderVolumetricGeometry(vtkViewport *vtkNotUsed(viewport)) override