VTK  9.0.3
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 =========================================================================*/
36 #ifndef vtkBoxRepresentation_h
37 #define vtkBoxRepresentation_h
38 
39 #include "vtkInteractionWidgetsModule.h" // For export macro
41 
42 class vtkActor;
43 class vtkPolyDataMapper;
44 class vtkLineSource;
45 class vtkSphereSource;
46 class vtkCellPicker;
47 class vtkProperty;
48 class vtkPolyData;
49 class vtkPoints;
52 class vtkTransform;
53 class vtkPlane;
54 class vtkPlanes;
55 class vtkBox;
56 class vtkDoubleArray;
57 class vtkMatrix4x4;
58 
59 class VTKINTERACTIONWIDGETS_EXPORT vtkBoxRepresentation : public vtkWidgetRepresentation
60 {
61 public:
66 
68 
72  void PrintSelf(ostream& os, vtkIndent indent) override;
74 
83  void GetPlanes(vtkPlanes* planes);
84 
85  // Get the underlying planes used by this rep
86  // this can be used as a cropping planes in vtkMapper
87  vtkPlane* GetUnderlyingPlane(int i) { return this->Planes[i]; }
88 
90 
96  vtkSetMacro(InsideOut, vtkTypeBool);
97  vtkGetMacro(InsideOut, vtkTypeBool);
98  vtkBooleanMacro(InsideOut, vtkTypeBool);
100 
108  virtual void GetTransform(vtkTransform* t);
109 
116  virtual void SetTransform(vtkTransform* t);
117 
129 
131 
136  vtkGetObjectMacro(HandleProperty, vtkProperty);
137  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
139 
141 
146  vtkGetObjectMacro(FaceProperty, vtkProperty);
147  vtkGetObjectMacro(SelectedFaceProperty, vtkProperty);
149 
151 
156  vtkGetObjectMacro(OutlineProperty, vtkProperty);
157  vtkGetObjectMacro(SelectedOutlineProperty, vtkProperty);
159 
161 
166  vtkGetMacro(OutlineFaceWires, int);
167  void OutlineFaceWiresOn() { this->SetOutlineFaceWires(1); }
168  void OutlineFaceWiresOff() { this->SetOutlineFaceWires(0); }
170 
172 
178  vtkGetMacro(OutlineCursorWires, int);
179  void OutlineCursorWiresOn() { this->SetOutlineCursorWires(1); }
180  void OutlineCursorWiresOff() { this->SetOutlineCursorWires(0); }
182 
184 
188  virtual void HandlesOn();
189  virtual void HandlesOff();
191 
193 
196  void PlaceWidget(double bounds[6]) override;
197  void BuildRepresentation() override;
198  int ComputeInteractionState(int X, int Y, int modify = 0) override;
199  void StartWidgetInteraction(double e[2]) override;
200  void WidgetInteraction(double e[2]) override;
201  double* GetBounds() VTK_SIZEHINT(6) override;
202  void StartComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
203  unsigned long event, void* calldata) override;
204  void ComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
205  unsigned long event, void* calldata) override;
206  int ComputeComplexInteractionState(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
207  unsigned long event, void* calldata, int modify = 0) override;
208  void EndComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
209  unsigned long event, void* calldata) override;
211 
213 
216  void ReleaseGraphicsResources(vtkWindow*) override;
217  int RenderOpaqueGeometry(vtkViewport*) override;
218  int RenderTranslucentPolygonalGeometry(vtkViewport*) override;
219  vtkTypeBool HasTranslucentPolygonalGeometry() override;
221 
222  // Used to manage the state of the widget
223  enum
224  {
225  Outside = 0,
234  Scaling
235  };
236 
246  void SetInteractionState(int state);
247 
249 
253  vtkGetMacro(TwoPlaneMode, bool);
254  void SetTwoPlaneMode(bool);
256 
258 
262  vtkGetMacro(SnapToAxes, bool);
263  vtkSetMacro(SnapToAxes, bool);
265 
267 
271  void StepForward();
272  void StepBackward();
274 
275  /*
276  * Register internal Pickers within PickingManager
277  */
278  void RegisterPickers() override;
279 
281 
285  vtkGetMacro(TranslationAxis, int);
286  vtkSetClampMacro(TranslationAxis, int, -1, 2);
288 
290 
293  void SetXTranslationAxisOn() { this->TranslationAxis = Axis::XAxis; }
294  void SetYTranslationAxisOn() { this->TranslationAxis = Axis::YAxis; }
295  void SetZTranslationAxisOn() { this->TranslationAxis = Axis::ZAxis; }
296  void SetTranslationAxisOff() { this->TranslationAxis = Axis::NONE; }
298 
300 
303  bool IsTranslationConstrained() { return this->TranslationAxis != Axis::NONE; }
305 
306 protected:
309 
310  // Manage how the representation appears
311  double LastEventPosition[3];
312  double LastEventOrientation[4];
313  double StartEventOrientation[4];
314  double SnappedEventOrientations[3][4];
315  bool SnappedOrientation[3];
317 
319 
320  // Constraint axis translation
322 
323  // the hexahedron (6 faces)
327  vtkPoints* Points; // used by others as well
328  double N[6][3]; // the normals of the faces
329 
330  // A face of the hexahedron
334 
335  // glyphs representing hot spots (e.g., handles)
339  virtual void PositionHandles();
340  int HighlightHandle(vtkProp* prop); // returns cell id
341  void HighlightFace(int cellId);
342  void HighlightOutline(int highlight);
343  virtual void ComputeNormals();
344  virtual void SizeHandles();
345 
346  // wireframe outline
350 
351  // Do the picking
357 
358  // Transform the hexahedral points (used for rotations)
360 
361  // Support GetBounds() method
363 
364  // Properties used to control the appearance of selected objects and
365  // the manipulator in general.
372  virtual void CreateDefaultProperties();
373 
374  // Control the orientation of the normals
379 
380  // Helper methods
381  virtual void Translate(const double* p1, const double* p2);
382  virtual void Scale(const double* p1, const double* p2, int X, int Y);
383  virtual void Rotate(int X, int Y, const double* p1, const double* p2, const double* vpn);
384  void MovePlusXFace(const double* p1, const double* p2);
385  void MoveMinusXFace(const double* p1, const double* p2);
386  void MovePlusYFace(const double* p1, const double* p2);
387  void MoveMinusYFace(const double* p1, const double* p2);
388  void MovePlusZFace(const double* p1, const double* p2);
389  void MoveMinusZFace(const double* p1, const double* p2);
390  void UpdatePose(const double* p1, const double* d1, const double* p2, const double* d2);
391 
392  // Internal ivars for performance
396 
397  // The actual planes which are being manipulated
398  vtkPlane* Planes[6];
399 
400  //"dir" is the direction in which the face can be moved i.e. the axis passing
401  // through the center
402  void MoveFace(const double* p1, const double* p2, const double* dir, double* x1, double* x2,
403  double* x3, double* x4, double* x5);
404  // Helper method to obtain the direction in which the face is to be moved.
405  // Handles special cases where some of the scale factors are 0.
406  void GetDirection(const double Nx[3], const double Ny[3], const double Nz[3], double dir[3]);
407 
408 private:
410  void operator=(const vtkBoxRepresentation&) = delete;
411 };
412 
413 #endif
define the API for widget / widget representation
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:46
a class defining the representation for the vtkBoxWidget2
int ComputeInteractionState(int X, int Y, int modify=0) override
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
Methods invoked by print to print information about the object including superclasses.
void MovePlusZFace(const double *p1, const double *p2)
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 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()
void HighlightFace(int cellId)
int HighlightHandle(vtkProp *prop)
bool IsTranslationConstrained()
Returns true if ContrainedAxis.
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
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)
void WidgetInteraction(double e[2]) override
vtkProperty * SelectedOutlineProperty
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 StartWidgetInteraction(double e[2]) override
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
double * GetBounds() override
Get the bounds for this Prop as (Xmin,Xmax,Ymin,Ymax,Zmin,Zmax).
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:39
ray-cast cell picker for all kinds of Prop3Ds
Definition: vtkCellPicker.h:67
dynamic, self-adjusting array of double
a simple class to control print indentation
Definition: vtkIndent.h:34
create a line defined by two end points
Definition: vtkLineSource.h:61
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:36
perform various plane computations
Definition: vtkPlane.h:32
implicit function for convex set of planes
Definition: vtkPlanes.h:50
represent the position of a point in 3D space
represent and manipulate 3D points
Definition: vtkPoints.h:34
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:85
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:48
represent surface properties of a geometric object
Definition: vtkProperty.h:62
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:55
abstract specification for Viewports
Definition: vtkViewport.h:45
abstract class defines interface between the widget and widget representation classes
window superclass for vtkRenderWindow
Definition: vtkWindow.h:35
@ dir
Definition: vtkX3D.h:330
int vtkTypeBool
Definition: vtkABI.h:69
#define VTK_SIZEHINT(...)