VTK  9.2.20230328
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 VTK_ABI_NAMESPACE_BEGIN
65 class vtkActor;
66 class vtkPolyDataMapper;
67 class vtkLineSource;
68 class vtkSphereSource;
69 class vtkCellPicker;
70 class vtkProperty;
71 class vtkPolyData;
72 class vtkPoints;
75 class vtkTransform;
76 class vtkPlane;
77 class vtkPlanes;
78 class vtkBox;
79 class vtkDoubleArray;
80 class vtkMatrix4x4;
81 
82 class VTKINTERACTIONWIDGETS_EXPORT vtkBoxRepresentation : public vtkWidgetRepresentation
83 {
84 public:
89 
91 
95  void PrintSelf(ostream& os, vtkIndent indent) override;
97 
106  void GetPlanes(vtkPlanes* planes);
107 
108  // Get the underlying planes used by this rep
109  // this can be used as a cropping planes in vtkMapper
110  vtkPlane* GetUnderlyingPlane(int i) { return this->Planes[i]; }
111 
113 
119  vtkSetMacro(InsideOut, vtkTypeBool);
120  vtkGetMacro(InsideOut, vtkTypeBool);
121  vtkBooleanMacro(InsideOut, vtkTypeBool);
123 
131  virtual void GetTransform(vtkTransform* t);
132 
139  virtual void SetTransform(vtkTransform* t);
140 
152 
154 
159  vtkGetObjectMacro(HandleProperty, vtkProperty);
160  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
162 
164 
169  vtkGetObjectMacro(FaceProperty, vtkProperty);
170  vtkGetObjectMacro(SelectedFaceProperty, vtkProperty);
172 
174 
179  vtkGetObjectMacro(OutlineProperty, vtkProperty);
180  vtkGetObjectMacro(SelectedOutlineProperty, vtkProperty);
182 
184 
187  void SetForegroundColor(double _arg1, double _arg2, double _arg3);
188  void SetForegroundColor(const double _arg[3])
189  {
190  this->SetForegroundColor(_arg[0], _arg[1], _arg[2]);
191  }
193 
195 
199  void SetInteractionColor(double _arg1, double _arg2, double _arg3);
200  void SetInteractionColor(const double _arg[3])
201  {
202  this->SetInteractionColor(_arg[0], _arg[1], _arg[2]);
203  }
205 
207 
212  vtkGetMacro(OutlineFaceWires, int);
213  void OutlineFaceWiresOn() { this->SetOutlineFaceWires(1); }
214  void OutlineFaceWiresOff() { this->SetOutlineFaceWires(0); }
216 
218 
224  vtkGetMacro(OutlineCursorWires, int);
225  void OutlineCursorWiresOn() { this->SetOutlineCursorWires(1); }
226  void OutlineCursorWiresOff() { this->SetOutlineCursorWires(0); }
228 
230 
234  virtual void HandlesOn();
235  virtual void HandlesOff();
237 
239 
242  void PlaceWidget(double bounds[6]) override;
243  void BuildRepresentation() override;
244  int ComputeInteractionState(int X, int Y, int modify = 0) override;
245  void StartWidgetInteraction(double e[2]) override;
246  void WidgetInteraction(double e[2]) override;
247  double* GetBounds() VTK_SIZEHINT(6) override;
248  void StartComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
249  unsigned long event, void* calldata) override;
250  void ComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
251  unsigned long event, void* calldata) override;
252  int ComputeComplexInteractionState(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
253  unsigned long event, void* calldata, int modify = 0) override;
254  void EndComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
255  unsigned long event, void* calldata) override;
257 
259 
262  void ReleaseGraphicsResources(vtkWindow*) override;
263  int RenderOpaqueGeometry(vtkViewport*) override;
264  int RenderTranslucentPolygonalGeometry(vtkViewport*) override;
265  vtkTypeBool HasTranslucentPolygonalGeometry() override;
267 
268  // Used to manage the state of the widget
269  enum
270  {
271  Outside = 0,
280  Scaling
281  };
282 
292  void SetInteractionState(int state);
293 
295 
299  vtkGetMacro(TwoPlaneMode, bool);
300  void SetTwoPlaneMode(bool);
302 
304 
308  vtkGetMacro(SnapToAxes, bool);
309  vtkSetMacro(SnapToAxes, bool);
311 
313 
317  void StepForward();
318  void StepBackward();
320 
321  /*
322  * Register internal Pickers within PickingManager
323  */
324  void RegisterPickers() override;
325 
327 
331  vtkGetMacro(TranslationAxis, int);
332  vtkSetClampMacro(TranslationAxis, int, -1, 2);
334 
336 
339  void SetXTranslationAxisOn() { this->TranslationAxis = Axis::XAxis; }
340  void SetYTranslationAxisOn() { this->TranslationAxis = Axis::YAxis; }
341  void SetZTranslationAxisOn() { this->TranslationAxis = Axis::ZAxis; }
342  void SetTranslationAxisOff() { this->TranslationAxis = Axis::NONE; }
344 
346 
349  bool IsTranslationConstrained() { return this->TranslationAxis != Axis::NONE; }
351 
357  void GetActors(vtkPropCollection*) override;
358 
359 protected:
362 
363  // Manage how the representation appears
364  double LastEventPosition[3];
365  double LastEventOrientation[4];
366  double StartEventOrientation[4];
367  double SnappedEventOrientations[3][4];
368  bool SnappedOrientation[3];
370 
372 
373  // Constraint axis translation
375 
376  // the hexahedron (6 faces)
380  vtkPoints* Points; // used by others as well
381  double N[6][3]; // the normals of the faces
382 
383  // A face of the hexahedron
387 
388  // glyphs representing hot spots (e.g., handles)
392  virtual void PositionHandles();
393  int HighlightHandle(vtkProp* prop); // returns cell id
394  void HighlightFace(int cellId);
395  void HighlightOutline(int highlight);
396  virtual void ComputeNormals();
397  virtual void SizeHandles();
398 
399  // wireframe outline
403 
404  // Do the picking
410 
411  // Transform the hexahedral points (used for rotations)
413 
414  // Support GetBounds() method
416 
417  // Properties used to control the appearance of selected objects and
418  // the manipulator in general.
425  virtual void CreateDefaultProperties();
426 
427  // Control the orientation of the normals
432 
433  // Helper methods
434  virtual void Translate(const double* p1, const double* p2);
435  virtual void Scale(const double* p1, const double* p2, int X, int Y);
436  virtual void Rotate(int X, int Y, const double* p1, const double* p2, const double* vpn);
437  void MovePlusXFace(const double* p1, const double* p2);
438  void MoveMinusXFace(const double* p1, const double* p2);
439  void MovePlusYFace(const double* p1, const double* p2);
440  void MoveMinusYFace(const double* p1, const double* p2);
441  void MovePlusZFace(const double* p1, const double* p2);
442  void MoveMinusZFace(const double* p1, const double* p2);
443  void UpdatePose(const double* p1, const double* d1, const double* p2, const double* d2);
444 
445  // Internal ivars for performance
449 
450  // The actual planes which are being manipulated
451  vtkPlane* Planes[6];
452 
453  //"dir" is the direction in which the face can be moved i.e. the axis passing
454  // through the center
455  void MoveFace(const double* p1, const double* p2, const double* dir, double* x1, double* x2,
456  double* x3, double* x4, double* x5);
457  // Helper method to obtain the direction in which the face is to be moved.
458  // Handles special cases where some of the scale factors are 0.
459  void GetDirection(const double Nx[3], const double Ny[3], const double Nz[3], double dir[3]);
460 
461 private:
463  void operator=(const vtkBoxRepresentation&) = delete;
464 };
465 
466 VTK_ABI_NAMESPACE_END
467 #endif
define the API for widget / widget representation
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:162
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:142
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:120
create a line defined by two end points
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:152
perform various plane computations
Definition: vtkPlane.h:147
implicit function for convex set of planes
Definition: vtkPlanes.h:163
represent the position of a point in 3D space
represent and manipulate 3D points
Definition: vtkPoints.h:150
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:201
an ordered list of Props
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:77
represent surface properties of a geometric object
Definition: vtkProperty.h:178
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:171
abstract specification for Viewports
Definition: vtkViewport.h:57
abstract class defines interface between the widget and widget representation classes
window superclass for vtkRenderWindow
Definition: vtkWindow.h:40
@ dir
Definition: vtkX3D.h:336
int vtkTypeBool
Definition: vtkABI.h:71
#define VTK_SIZEHINT(...)