VTK  9.7.1
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
27 #ifndef vtkBoxRepresentation_h
28 #define vtkBoxRepresentation_h
29 
30 #include "vtkInteractionWidgetsModule.h" // For export macro
32 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
33 
34 VTK_ABI_NAMESPACE_BEGIN
35 class vtkActor;
36 class vtkPolyDataMapper;
37 class vtkLineSource;
38 class vtkSphereSource;
39 class vtkCellPicker;
40 class vtkProperty;
41 class vtkPolyData;
42 class vtkPoints;
45 class vtkTransform;
46 class vtkPlane;
47 class vtkPlanes;
48 class vtkBox;
49 class vtkDoubleArray;
50 class vtkMatrix4x4;
51 
52 class VTKINTERACTIONWIDGETS_EXPORT VTK_MARSHALAUTO vtkBoxRepresentation
54 {
55 public:
59  static vtkBoxRepresentation* New();
60 
62 
66  void PrintSelf(ostream& os, vtkIndent indent) override;
68 
77  void GetPlanes(vtkPlanes* planes);
78 
79  // Get the underlying planes used by this rep
80  // this can be used as a cropping planes in vtkMapper
81  vtkPlane* GetUnderlyingPlane(int i) { return this->Planes[i]; }
82 
84 
90  vtkSetMacro(InsideOut, vtkTypeBool);
91  vtkGetMacro(InsideOut, vtkTypeBool);
92  vtkBooleanMacro(InsideOut, vtkTypeBool);
94 
103  virtual void GetTransform(vtkTransform* t);
104 
112  virtual void SetTransform(vtkTransform* t);
113 
124  void GetPolyData(vtkPolyData* pd);
125 
127 
132  vtkGetObjectMacro(HandleProperty, vtkProperty);
133  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
135 
137 
142  vtkGetObjectMacro(FaceProperty, vtkProperty);
143  vtkGetObjectMacro(SelectedFaceProperty, vtkProperty);
145 
147 
152  vtkGetObjectMacro(OutlineProperty, vtkProperty);
153  vtkGetObjectMacro(SelectedOutlineProperty, vtkProperty);
155 
157 
160  void SetForegroundColor(double _arg1, double _arg2, double _arg3);
161  void SetForegroundColor(const double _arg[3])
162  {
163  this->SetForegroundColor(_arg[0], _arg[1], _arg[2]);
164  }
166 
168 
172  void SetInteractionColor(double _arg1, double _arg2, double _arg3);
173  void SetInteractionColor(const double _arg[3])
174  {
175  this->SetInteractionColor(_arg[0], _arg[1], _arg[2]);
176  }
178 
180 
184  void SetOutlineFaceWires(int);
185  vtkGetMacro(OutlineFaceWires, int);
186  void OutlineFaceWiresOn() { this->SetOutlineFaceWires(1); }
187  void OutlineFaceWiresOff() { this->SetOutlineFaceWires(0); }
189 
191 
196  void SetOutlineCursorWires(int);
197  vtkGetMacro(OutlineCursorWires, int);
198  void OutlineCursorWiresOn() { this->SetOutlineCursorWires(1); }
199  void OutlineCursorWiresOff() { this->SetOutlineCursorWires(0); }
201 
203 
207  virtual void HandlesOn();
208  virtual void HandlesOff();
210 
212 
215  void PlaceWidget(double bounds[6]) override;
216  void BuildRepresentation() override;
217  int ComputeInteractionState(int X, int Y, int modify = 0) override;
218  void StartWidgetInteraction(double e[2]) override;
219  void WidgetInteraction(double e[2]) override;
220  double* GetBounds() VTK_SIZEHINT(6) override;
221  void StartComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
222  unsigned long event, void* calldata) override;
223  void ComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
224  unsigned long event, void* calldata) override;
225  int ComputeComplexInteractionState(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
226  unsigned long event, void* calldata, int modify = 0) override;
227  void EndComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
228  unsigned long event, void* calldata) override;
230 
232 
235  void ReleaseGraphicsResources(vtkWindow*) override;
236  int RenderOpaqueGeometry(vtkViewport*) override;
237  int RenderTranslucentPolygonalGeometry(vtkViewport*) override;
238  vtkTypeBool HasTranslucentPolygonalGeometry() override;
240 
241  // Used to manage the state of the widget
242  enum
243  {
244  Outside = 0,
253  Scaling
254  };
255 
265  void SetInteractionState(int state);
266 
268 
272  vtkGetMacro(TwoPlaneMode, bool);
273  void SetTwoPlaneMode(bool);
275 
277 
281  vtkGetMacro(SnapToAxes, bool);
282  vtkSetMacro(SnapToAxes, bool);
284 
286 
290  void StepForward();
291  void StepBackward();
293 
294  /*
295  * Register internal Pickers within PickingManager
296  */
297  void RegisterPickers() override;
298 
300 
304  vtkGetMacro(TranslationAxis, int);
305  vtkSetClampMacro(TranslationAxis, int, -1, 2);
307 
309 
312  void SetXTranslationAxisOn() { this->TranslationAxis = Axis::XAxis; }
313  void SetYTranslationAxisOn() { this->TranslationAxis = Axis::YAxis; }
314  void SetZTranslationAxisOn() { this->TranslationAxis = Axis::ZAxis; }
315  void SetTranslationAxisOff() { this->TranslationAxis = Axis::NONE; }
317 
319 
322  bool IsTranslationConstrained() { return this->TranslationAxis != Axis::NONE; }
324 
330  void GetActors(vtkPropCollection*) override;
331 
333 
338  std::vector<double> GetCorners();
339  void SetCorners(std::vector<double> points);
341 
343  {
344  ROTATE_FREE = 0,
345  ROTATE_X = 1,
346  ROTATE_Y = 2,
347  ROTATE_Z = 3
348  };
349 
351 
356  vtkSetMacro(RotationAxisMode, int);
357  vtkGetMacro(RotationAxisMode, int);
358  void SetRotationAxisModeToFree() { this->SetRotationAxisMode(ROTATE_FREE); }
359  void SetRotationAxisModeToX() { this->SetRotationAxisMode(ROTATE_X); }
360  void SetRotationAxisModeToY() { this->SetRotationAxisMode(ROTATE_Y); }
361  void SetRotationAxisModeToZ() { this->SetRotationAxisMode(ROTATE_Z); }
362 
363  bool IsRotationAxisLocked() const { return this->RotationAxisMode != ROTATE_FREE; }
365 
366 protected:
368  ~vtkBoxRepresentation() override;
369 
370  // Manage how the representation appears
371  double LastEventPosition[3];
372  double LastEventOrientation[4];
373  double StartEventOrientation[4];
374  double SnappedEventOrientations[3][4];
375  bool SnappedOrientation[3];
377 
379 
380  // Constraint axis translation
382 
383  // the hexahedron (6 faces)
387  vtkPoints* Points; // used by others as well
388  double N[6][3]; // the normals of the faces
389 
390  // A face of the hexahedron
394 
395  // glyphs representing hot spots (e.g., handles)
399  virtual void PositionHandles();
400  int HighlightHandle(vtkProp* prop); // returns cell id
401  void HighlightFace(int cellId);
402  void HighlightOutline(int highlight);
403  virtual void ComputeNormals();
404  virtual void SizeHandles();
405 
406  // wireframe outline
410 
411  // Do the picking
417 
418  // Transform the hexahedral points (used for rotations)
420 
421  // Support GetBounds() method
423 
424  // Properties used to control the appearance of selected objects and
425  // the manipulator in general.
432  virtual void CreateDefaultProperties();
433 
434  // Control the orientation of the normals
438  void GenerateOutline();
439 
440  // Helper methods
441  virtual void Translate(const double* p1, const double* p2);
442  virtual void Scale(const double* p1, const double* p2, int X, int Y);
443  virtual void Rotate(int X, int Y, const double* p1, const double* p2, const double* vpn);
444  void MovePlusXFace(const double* p1, const double* p2);
445  void MoveMinusXFace(const double* p1, const double* p2);
446  void MovePlusYFace(const double* p1, const double* p2);
447  void MoveMinusYFace(const double* p1, const double* p2);
448  void MovePlusZFace(const double* p1, const double* p2);
449  void MoveMinusZFace(const double* p1, const double* p2);
450  void UpdatePose(const double* p1, const double* d1, const double* p2, const double* d2);
451 
452  // Internal ivars for performance
456 
457  // The actual planes which are being manipulated
458  vtkPlane* Planes[6];
459 
460  //"dir" is the direction in which the face can be moved i.e. the axis passing
461  // through the center
462  void MoveFace(const double* p1, const double* p2, const double* dir, double* x1, double* x2,
463  double* x3, double* x4, double* x5);
464  // Helper method to obtain the direction in which the face is to be moved.
465  // Handles special cases where some of the scale factors are 0.
466  void GetDirection(const double Nx[3], const double Ny[3], const double Nz[3], double dir[3]);
467 
468 private:
470  void operator=(const vtkBoxRepresentation&) = delete;
471 
472  int RotationAxisMode = ROTATE_FREE;
473 };
474 
475 VTK_ABI_NAMESPACE_END
476 #endif
vtkProperty * SelectedHandleProperty
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:49
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for instances of this class.
vtkPolyDataMapper * HexMapper
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:41
virtual void PlaceWidget(double bounds[6])
The following is a suggested API for widget representations.
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:31
virtual int ComputeInteractionState(int X, int Y, int modify=0)
void SetXTranslationAxisOn()
Toggles constraint translation axis on/off.
represent the position of a point in 3D space
abstract specification for Viewports
Definition: vtkViewport.h:46
represent surface properties of a geometric object
Definition: vtkProperty.h:59
virtual void StartWidgetInteraction(double eventPos[2])
bool IsTranslationConstrained()
Returns true if ConstrainedAxis.
void SetInteractionColor(const double _arg[3])
Set the interaction color.
implicit function for convex set of planes
Definition: vtkPlanes.h:41
a class defining the representation for the vtkBoxWidget2
vtkProperty * SelectedFaceProperty
vtkPlane * GetUnderlyingPlane(int i)
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:50
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:71
abstract class defines interface between the widget and widget representation classes ...
virtual void BuildRepresentation()=0
Subclasses of vtkWidgetRepresentation must implement these methods.
void SetRotationAxisModeToX()
Get/Set the rotation mode of the box.
double * GetBounds() override
Methods to make this class behave as a vtkProp.
dynamic, self-adjusting array of double
an ordered list of Props
void SetRotationAxisModeToZ()
Get/Set the rotation mode of the box.
int vtkTypeBool
Definition: vtkABI.h:64
window superclass for vtkRenderWindow
Definition: vtkWindow.h:41
platform-independent render window interaction including picking and frame rate control.
create a polygonal sphere centered at the origin
Superclass for algorithms that produce only polydata as output.
a simple class to control print indentation
Definition: vtkIndent.h:28
virtual void RegisterPickers()
Register internal Pickers in the Picking Manager.
vtkPolyDataMapper ** HandleMapper
void SetRotationAxisModeToFree()
Get/Set the rotation mode of the box.
perform various plane computations
Definition: vtkPlane.h:31
virtual void WidgetInteraction(double newEventPos[2])
vtkPolyDataMapper * HexFaceMapper
vtkSphereSource ** HandleGeometry
#define VTK_SIZEHINT(...)
#define VTK_MARSHALEXCLUDE(reason)
vtkProperty * SelectedOutlineProperty
define the API for widget / widget representation
create a line defined by two end points
Definition: vtkLineSource.h:53
map vtkPolyData to graphics primitives
void OutlineFaceWiresOn()
Control the representation of the outline.
void OutlineCursorWiresOff()
Control the representation of the outline.
void SetYTranslationAxisOn()
Toggles constraint translation axis on/off.
ray-cast cell picker for all kinds of Prop3Ds
Definition: vtkCellPicker.h:62
vtkDoubleArray * PlaneNormals
void SetRotationAxisModeToY()
Get/Set the rotation mode of the box.
void OutlineCursorWiresOn()
Control the representation of the outline.
bool IsRotationAxisLocked() const
Get/Set the rotation mode of the box.
#define VTK_MARSHALAUTO
vtkCellPicker * HandlePicker
void GetActors(vtkPropCollection *) override
For some exporters and other other operations we must be able to collect all the actors or volumes...
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
implicit function for a bounding box
Definition: vtkBox.h:30
void OutlineFaceWiresOff()
Control the representation of the outline.
represent and manipulate 3D points
Definition: vtkPoints.h:30
void SetZTranslationAxisOn()
Toggles constraint translation axis on/off.
vtkPolyDataMapper * OutlineMapper
void SetTranslationAxisOff()
Toggles constraint translation axis on/off.
#define VTK_MARSHAL_EXCLUDE_REASON_IS_INTERNAL