VTK  9.3.0
vtkBoxRepresentation.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
36 #ifndef vtkBoxRepresentation_h
37 #define vtkBoxRepresentation_h
38 
39 #include "vtkInteractionWidgetsModule.h" // For export macro
41 
42 VTK_ABI_NAMESPACE_BEGIN
43 class vtkActor;
44 class vtkPolyDataMapper;
45 class vtkLineSource;
46 class vtkSphereSource;
47 class vtkCellPicker;
48 class vtkProperty;
49 class vtkPolyData;
50 class vtkPoints;
53 class vtkTransform;
54 class vtkPlane;
55 class vtkPlanes;
56 class vtkBox;
57 class vtkDoubleArray;
58 class vtkMatrix4x4;
59 
60 class VTKINTERACTIONWIDGETS_EXPORT vtkBoxRepresentation : public vtkWidgetRepresentation
61 {
62 public:
67 
69 
73  void PrintSelf(ostream& os, vtkIndent indent) override;
75 
84  void GetPlanes(vtkPlanes* planes);
85 
86  // Get the underlying planes used by this rep
87  // this can be used as a cropping planes in vtkMapper
88  vtkPlane* GetUnderlyingPlane(int i) { return this->Planes[i]; }
89 
91 
97  vtkSetMacro(InsideOut, vtkTypeBool);
98  vtkGetMacro(InsideOut, vtkTypeBool);
99  vtkBooleanMacro(InsideOut, vtkTypeBool);
101 
109  virtual void GetTransform(vtkTransform* t);
110 
117  virtual void SetTransform(vtkTransform* t);
118 
130 
132 
137  vtkGetObjectMacro(HandleProperty, vtkProperty);
138  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
140 
142 
147  vtkGetObjectMacro(FaceProperty, vtkProperty);
148  vtkGetObjectMacro(SelectedFaceProperty, vtkProperty);
150 
152 
157  vtkGetObjectMacro(OutlineProperty, vtkProperty);
158  vtkGetObjectMacro(SelectedOutlineProperty, vtkProperty);
160 
162 
165  void SetForegroundColor(double _arg1, double _arg2, double _arg3);
166  void SetForegroundColor(const double _arg[3])
167  {
168  this->SetForegroundColor(_arg[0], _arg[1], _arg[2]);
169  }
171 
173 
177  void SetInteractionColor(double _arg1, double _arg2, double _arg3);
178  void SetInteractionColor(const double _arg[3])
179  {
180  this->SetInteractionColor(_arg[0], _arg[1], _arg[2]);
181  }
183 
185 
190  vtkGetMacro(OutlineFaceWires, int);
191  void OutlineFaceWiresOn() { this->SetOutlineFaceWires(1); }
192  void OutlineFaceWiresOff() { this->SetOutlineFaceWires(0); }
194 
196 
202  vtkGetMacro(OutlineCursorWires, int);
203  void OutlineCursorWiresOn() { this->SetOutlineCursorWires(1); }
204  void OutlineCursorWiresOff() { this->SetOutlineCursorWires(0); }
206 
208 
212  virtual void HandlesOn();
213  virtual void HandlesOff();
215 
217 
220  void PlaceWidget(double bounds[6]) override;
221  void BuildRepresentation() override;
222  int ComputeInteractionState(int X, int Y, int modify = 0) override;
223  void StartWidgetInteraction(double e[2]) override;
224  void WidgetInteraction(double e[2]) override;
225  double* GetBounds() VTK_SIZEHINT(6) override;
226  void StartComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
227  unsigned long event, void* calldata) override;
228  void ComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
229  unsigned long event, void* calldata) override;
230  int ComputeComplexInteractionState(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
231  unsigned long event, void* calldata, int modify = 0) override;
232  void EndComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
233  unsigned long event, void* calldata) override;
235 
237 
240  void ReleaseGraphicsResources(vtkWindow*) override;
241  int RenderOpaqueGeometry(vtkViewport*) override;
242  int RenderTranslucentPolygonalGeometry(vtkViewport*) override;
243  vtkTypeBool HasTranslucentPolygonalGeometry() override;
245 
246  // Used to manage the state of the widget
247  enum
248  {
249  Outside = 0,
258  Scaling
259  };
260 
270  void SetInteractionState(int state);
271 
273 
277  vtkGetMacro(TwoPlaneMode, bool);
278  void SetTwoPlaneMode(bool);
280 
282 
286  vtkGetMacro(SnapToAxes, bool);
287  vtkSetMacro(SnapToAxes, bool);
289 
291 
295  void StepForward();
296  void StepBackward();
298 
299  /*
300  * Register internal Pickers within PickingManager
301  */
302  void RegisterPickers() override;
303 
305 
309  vtkGetMacro(TranslationAxis, int);
310  vtkSetClampMacro(TranslationAxis, int, -1, 2);
312 
314 
317  void SetXTranslationAxisOn() { this->TranslationAxis = Axis::XAxis; }
318  void SetYTranslationAxisOn() { this->TranslationAxis = Axis::YAxis; }
319  void SetZTranslationAxisOn() { this->TranslationAxis = Axis::ZAxis; }
320  void SetTranslationAxisOff() { this->TranslationAxis = Axis::NONE; }
322 
324 
327  bool IsTranslationConstrained() { return this->TranslationAxis != Axis::NONE; }
329 
335  void GetActors(vtkPropCollection*) override;
336 
337 protected:
340 
341  // Manage how the representation appears
342  double LastEventPosition[3];
343  double LastEventOrientation[4];
344  double StartEventOrientation[4];
345  double SnappedEventOrientations[3][4];
346  bool SnappedOrientation[3];
348 
350 
351  // Constraint axis translation
353 
354  // the hexahedron (6 faces)
358  vtkPoints* Points; // used by others as well
359  double N[6][3]; // the normals of the faces
360 
361  // A face of the hexahedron
365 
366  // glyphs representing hot spots (e.g., handles)
370  virtual void PositionHandles();
371  int HighlightHandle(vtkProp* prop); // returns cell id
372  void HighlightFace(int cellId);
373  void HighlightOutline(int highlight);
374  virtual void ComputeNormals();
375  virtual void SizeHandles();
376 
377  // wireframe outline
381 
382  // Do the picking
388 
389  // Transform the hexahedral points (used for rotations)
391 
392  // Support GetBounds() method
394 
395  // Properties used to control the appearance of selected objects and
396  // the manipulator in general.
403  virtual void CreateDefaultProperties();
404 
405  // Control the orientation of the normals
410 
411  // Helper methods
412  virtual void Translate(const double* p1, const double* p2);
413  virtual void Scale(const double* p1, const double* p2, int X, int Y);
414  virtual void Rotate(int X, int Y, const double* p1, const double* p2, const double* vpn);
415  void MovePlusXFace(const double* p1, const double* p2);
416  void MoveMinusXFace(const double* p1, const double* p2);
417  void MovePlusYFace(const double* p1, const double* p2);
418  void MoveMinusYFace(const double* p1, const double* p2);
419  void MovePlusZFace(const double* p1, const double* p2);
420  void MoveMinusZFace(const double* p1, const double* p2);
421  void UpdatePose(const double* p1, const double* d1, const double* p2, const double* d2);
422 
423  // Internal ivars for performance
427 
428  // The actual planes which are being manipulated
429  vtkPlane* Planes[6];
430 
431  //"dir" is the direction in which the face can be moved i.e. the axis passing
432  // through the center
433  void MoveFace(const double* p1, const double* p2, const double* dir, double* x1, double* x2,
434  double* x3, double* x4, double* x5);
435  // Helper method to obtain the direction in which the face is to be moved.
436  // Handles special cases where some of the scale factors are 0.
437  void GetDirection(const double Nx[3], const double Ny[3], const double Nz[3], double dir[3]);
438 
439 private:
441  void operator=(const vtkBoxRepresentation&) = delete;
442 };
443 
444 VTK_ABI_NAMESPACE_END
445 #endif
define the API for widget / widget representation
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:50
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.
void SetForegroundColor(const double _arg[3])
Set the foreground color (the outline of the box).
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 ConstrainedAxis.
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 SetInteractionColor(const double _arg[3])
Set the interaction color.
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 SetForegroundColor(double _arg1, double _arg2, double _arg3)
Set the foreground color (the outline of the box).
void MoveMinusZFace(const double *p1, const double *p2)
void SetInteractionColor(double _arg1, double _arg2, double _arg3)
Set the interaction color.
implicit function for a bounding box
Definition: vtkBox.h:40
ray-cast cell picker for all kinds of Prop3Ds
Definition: vtkCellPicker.h:71
dynamic, self-adjusting array of double
a simple class to control print indentation
Definition: vtkIndent.h:38
create a line defined by two end points
Definition: vtkLineSource.h:62
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:40
perform various plane computations
Definition: vtkPlane.h:35
implicit function for convex set of planes
Definition: vtkPlanes.h:51
represent the position of a point in 3D space
represent and manipulate 3D points
Definition: vtkPoints.h:38
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:89
an ordered list of Props
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:55
represent surface properties of a geometric object
Definition: vtkProperty.h:66
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:59
abstract specification for Viewports
Definition: vtkViewport.h:54
abstract class defines interface between the widget and widget representation classes
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
@ dir
Definition: vtkX3D.h:324
int vtkTypeBool
Definition: vtkABI.h:64
#define VTK_SIZEHINT(...)