VTK  9.2.6
vtkBoxRepresentation.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkBoxRepresentation.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 =========================================================================*/
58 #ifndef vtkBoxRepresentation_h
59 #define vtkBoxRepresentation_h
60 
61 #include "vtkInteractionWidgetsModule.h" // For export macro
63 
64 class vtkActor;
65 class vtkPolyDataMapper;
66 class vtkLineSource;
67 class vtkSphereSource;
68 class vtkCellPicker;
69 class vtkProperty;
70 class vtkPolyData;
71 class vtkPoints;
74 class vtkTransform;
75 class vtkPlane;
76 class vtkPlanes;
77 class vtkBox;
78 class vtkDoubleArray;
79 class vtkMatrix4x4;
80 
81 class VTKINTERACTIONWIDGETS_EXPORT vtkBoxRepresentation : public vtkWidgetRepresentation
82 {
83 public:
88 
90 
94  void PrintSelf(ostream& os, vtkIndent indent) override;
96 
105  void GetPlanes(vtkPlanes* planes);
106 
107  // Get the underlying planes used by this rep
108  // this can be used as a cropping planes in vtkMapper
109  vtkPlane* GetUnderlyingPlane(int i) { return this->Planes[i]; }
110 
112 
118  vtkSetMacro(InsideOut, vtkTypeBool);
119  vtkGetMacro(InsideOut, vtkTypeBool);
120  vtkBooleanMacro(InsideOut, vtkTypeBool);
122 
130  virtual void GetTransform(vtkTransform* t);
131 
138  virtual void SetTransform(vtkTransform* t);
139 
151 
153 
158  vtkGetObjectMacro(HandleProperty, vtkProperty);
159  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
161 
163 
168  vtkGetObjectMacro(FaceProperty, vtkProperty);
169  vtkGetObjectMacro(SelectedFaceProperty, vtkProperty);
171 
173 
178  vtkGetObjectMacro(OutlineProperty, vtkProperty);
179  vtkGetObjectMacro(SelectedOutlineProperty, vtkProperty);
181 
183 
188  vtkGetMacro(OutlineFaceWires, int);
189  void OutlineFaceWiresOn() { this->SetOutlineFaceWires(1); }
190  void OutlineFaceWiresOff() { this->SetOutlineFaceWires(0); }
192 
194 
200  vtkGetMacro(OutlineCursorWires, int);
201  void OutlineCursorWiresOn() { this->SetOutlineCursorWires(1); }
202  void OutlineCursorWiresOff() { this->SetOutlineCursorWires(0); }
204 
206 
210  virtual void HandlesOn();
211  virtual void HandlesOff();
213 
215 
218  void PlaceWidget(double bounds[6]) override;
219  void BuildRepresentation() override;
220  int ComputeInteractionState(int X, int Y, int modify = 0) override;
221  void StartWidgetInteraction(double e[2]) override;
222  void WidgetInteraction(double e[2]) override;
223  double* GetBounds() VTK_SIZEHINT(6) override;
224  void StartComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
225  unsigned long event, void* calldata) override;
226  void ComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
227  unsigned long event, void* calldata) override;
228  int ComputeComplexInteractionState(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
229  unsigned long event, void* calldata, int modify = 0) override;
230  void EndComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
231  unsigned long event, void* calldata) override;
233 
235 
238  void ReleaseGraphicsResources(vtkWindow*) override;
239  int RenderOpaqueGeometry(vtkViewport*) override;
240  int RenderTranslucentPolygonalGeometry(vtkViewport*) override;
241  vtkTypeBool HasTranslucentPolygonalGeometry() override;
243 
244  // Used to manage the state of the widget
245  enum
246  {
247  Outside = 0,
256  Scaling
257  };
258 
268  void SetInteractionState(int state);
269 
271 
275  vtkGetMacro(TwoPlaneMode, bool);
276  void SetTwoPlaneMode(bool);
278 
280 
284  vtkGetMacro(SnapToAxes, bool);
285  vtkSetMacro(SnapToAxes, bool);
287 
289 
293  void StepForward();
294  void StepBackward();
296 
297  /*
298  * Register internal Pickers within PickingManager
299  */
300  void RegisterPickers() override;
301 
303 
307  vtkGetMacro(TranslationAxis, int);
308  vtkSetClampMacro(TranslationAxis, int, -1, 2);
310 
312 
315  void SetXTranslationAxisOn() { this->TranslationAxis = Axis::XAxis; }
316  void SetYTranslationAxisOn() { this->TranslationAxis = Axis::YAxis; }
317  void SetZTranslationAxisOn() { this->TranslationAxis = Axis::ZAxis; }
318  void SetTranslationAxisOff() { this->TranslationAxis = Axis::NONE; }
320 
322 
325  bool IsTranslationConstrained() { return this->TranslationAxis != Axis::NONE; }
327 
333  void GetActors(vtkPropCollection*) override;
334 
335 protected:
338 
339  // Manage how the representation appears
340  double LastEventPosition[3];
341  double LastEventOrientation[4];
342  double StartEventOrientation[4];
343  double SnappedEventOrientations[3][4];
344  bool SnappedOrientation[3];
346 
348 
349  // Constraint axis translation
351 
352  // the hexahedron (6 faces)
356  vtkPoints* Points; // used by others as well
357  double N[6][3]; // the normals of the faces
358 
359  // A face of the hexahedron
363 
364  // glyphs representing hot spots (e.g., handles)
368  virtual void PositionHandles();
369  int HighlightHandle(vtkProp* prop); // returns cell id
370  void HighlightFace(int cellId);
371  void HighlightOutline(int highlight);
372  virtual void ComputeNormals();
373  virtual void SizeHandles();
374 
375  // wireframe outline
379 
380  // Do the picking
386 
387  // Transform the hexahedral points (used for rotations)
389 
390  // Support GetBounds() method
392 
393  // Properties used to control the appearance of selected objects and
394  // the manipulator in general.
401  virtual void CreateDefaultProperties();
402 
403  // Control the orientation of the normals
408 
409  // Helper methods
410  virtual void Translate(const double* p1, const double* p2);
411  virtual void Scale(const double* p1, const double* p2, int X, int Y);
412  virtual void Rotate(int X, int Y, const double* p1, const double* p2, const double* vpn);
413  void MovePlusXFace(const double* p1, const double* p2);
414  void MoveMinusXFace(const double* p1, const double* p2);
415  void MovePlusYFace(const double* p1, const double* p2);
416  void MoveMinusYFace(const double* p1, const double* p2);
417  void MovePlusZFace(const double* p1, const double* p2);
418  void MoveMinusZFace(const double* p1, const double* p2);
419  void UpdatePose(const double* p1, const double* d1, const double* p2, const double* d2);
420 
421  // Internal ivars for performance
425 
426  // The actual planes which are being manipulated
427  vtkPlane* Planes[6];
428 
429  //"dir" is the direction in which the face can be moved i.e. the axis passing
430  // through the center
431  void MoveFace(const double* p1, const double* p2, const double* dir, double* x1, double* x2,
432  double* x3, double* x4, double* x5);
433  // Helper method to obtain the direction in which the face is to be moved.
434  // Handles special cases where some of the scale factors are 0.
435  void GetDirection(const double Nx[3], const double Ny[3], const double Nz[3], double dir[3]);
436 
437 private:
439  void operator=(const vtkBoxRepresentation&) = delete;
440 };
441 
442 #endif
define the API for widget / widget representation
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:161
a class defining the representation for the vtkBoxWidget2
int ComputeInteractionState(int X, int Y, int modify=0) override
These are methods that satisfy vtkWidgetRepresentation's API.
void SetZTranslationAxisOn()
Toggles constraint translation axis on/off.
virtual void PositionHandles()
virtual void SetTransform(vtkTransform *t)
Set the position, scale and orientation of the box widget using the transform specified.
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for the class.
void MovePlusZFace(const double *p1, const double *p2)
void OutlineCursorWiresOff()
Control the representation of the outline.
void MoveMinusYFace(const double *p1, const double *p2)
void GetPlanes(vtkPlanes *planes)
Get the planes describing the implicit function defined by the box widget.
void SetOutlineCursorWires(int)
Control the representation of the outline.
vtkPolyDataMapper * HexFaceMapper
void StepBackward()
For complex events should we snap orientations to be aligned with the x y z axes.
void GetActors(vtkPropCollection *) override
These methods are necessary to make this representation behave as a vtkProp (i.e.,...
void MoveMinusXFace(const double *p1, const double *p2)
void MoveFace(const double *p1, const double *p2, const double *dir, double *x1, double *x2, double *x3, double *x4, double *x5)
virtual void HandlesOff()
Switches handles (the spheres) on or off by manipulating the underlying actor visibility.
void HighlightFace(int cellId)
int HighlightHandle(vtkProp *prop)
bool IsTranslationConstrained()
Returns true if ContrainedAxis.
void OutlineFaceWiresOn()
Control the representation of the outline.
vtkPolyDataMapper * OutlineMapper
void GetDirection(const double Nx[3], const double Ny[3], const double Nz[3], double dir[3])
void SetXTranslationAxisOn()
Toggles constraint translation axis on/off.
virtual void Translate(const double *p1, const double *p2)
void MovePlusYFace(const double *p1, const double *p2)
static vtkBoxRepresentation * New()
Instantiate the class.
virtual void SizeHandles()
void BuildRepresentation() override
These are methods that satisfy vtkWidgetRepresentation's API.
virtual void Rotate(int X, int Y, const double *p1, const double *p2, const double *vpn)
vtkSphereSource ** HandleGeometry
virtual void GetTransform(vtkTransform *t)
Retrieve a linear transform characterizing the transformation of the box.
vtkDoubleArray * PlaneNormals
void SetTwoPlaneMode(bool)
In two plane mode only the X planes are shown this is useful for defining thick slabs.
void WidgetInteraction(double e[2]) override
These are methods that satisfy vtkWidgetRepresentation's API.
vtkProperty * SelectedOutlineProperty
void OutlineCursorWiresOn()
Control the representation of the outline.
virtual void ComputeNormals()
vtkProperty * SelectedFaceProperty
void HighlightOutline(int highlight)
void GetPolyData(vtkPolyData *pd)
Grab the polydata (including points) that define the box widget.
void UpdatePose(const double *p1, const double *d1, const double *p2, const double *d2)
vtkProperty * SelectedHandleProperty
void MovePlusXFace(const double *p1, const double *p2)
vtkPolyDataMapper * HexMapper
void SetYTranslationAxisOn()
Toggles constraint translation axis on/off.
void StartWidgetInteraction(double e[2]) override
These are methods that satisfy vtkWidgetRepresentation's API.
void SetTranslationAxisOff()
Toggles constraint translation axis on/off.
void StepForward()
For complex events should we snap orientations to be aligned with the x y z axes.
vtkPolyDataMapper ** HandleMapper
vtkCellPicker * HandlePicker
void SetInteractionState(int state)
The interaction state may be set from a widget (e.g., vtkBoxWidget2) or other object.
virtual void HandlesOn()
Switches handles (the spheres) on or off by manipulating the underlying actor visibility.
void SetOutlineFaceWires(int)
Control the representation of the outline.
~vtkBoxRepresentation() override
void OutlineFaceWiresOff()
Control the representation of the outline.
double * GetBounds() override
These are methods that satisfy vtkWidgetRepresentation's API.
virtual void CreateDefaultProperties()
void RegisterPickers() override
Register internal Pickers in the Picking Manager.
void PlaceWidget(double bounds[6]) override
These are methods that satisfy vtkWidgetRepresentation's API.
virtual void Scale(const double *p1, const double *p2, int X, int Y)
vtkPlane * GetUnderlyingPlane(int i)
void MoveMinusZFace(const double *p1, const double *p2)
implicit function for a bounding box
Definition: vtkBox.h:141
ray-cast cell picker for all kinds of Prop3Ds
dynamic, self-adjusting array of double
a simple class to control print indentation
Definition: vtkIndent.h:119
create a line defined by two end points
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:151
perform various plane computations
Definition: vtkPlane.h:146
implicit function for convex set of planes
Definition: vtkPlanes.h:162
represent the position of a point in 3D space
represent and manipulate 3D points
Definition: vtkPoints.h:149
Superclass for algorithms that produce only polydata as output.
map vtkPolyData to graphics primitives
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:200
an ordered list of Props
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:76
represent surface properties of a geometric object
Definition: vtkProperty.h:177
platform-independent render window interaction including picking and frame rate control.
create a polygonal sphere centered at the origin
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:170
abstract specification for Viewports
Definition: vtkViewport.h:56
abstract class defines interface between the widget and widget representation classes
window superclass for vtkRenderWindow
Definition: vtkWindow.h:39
@ dir
Definition: vtkX3D.h:330
int vtkTypeBool
Definition: vtkABI.h:69
#define VTK_SIZEHINT(...)