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 =========================================================================*/
39 #ifndef vtkBoxRepresentation_h
40 #define vtkBoxRepresentation_h
41 
42 #include "vtkInteractionWidgetsModule.h" // For export macro
44 
45 class vtkActor;
46 class vtkPolyDataMapper;
47 class vtkLineSource;
48 class vtkSphereSource;
49 class vtkCellPicker;
50 class vtkProperty;
51 class vtkPolyData;
52 class vtkPoints;
55 class vtkTransform;
56 class vtkPlane;
57 class vtkPlanes;
58 class vtkBox;
59 class vtkDoubleArray;
60 class vtkMatrix4x4;
61 
62 class VTKINTERACTIONWIDGETS_EXPORT vtkBoxRepresentation : public vtkWidgetRepresentation
63 {
64 public:
68  static vtkBoxRepresentation* New();
69 
71 
75  void PrintSelf(ostream& os, vtkIndent indent) override;
77 
86  void GetPlanes(vtkPlanes* planes);
87 
88  // Get the underlying planes used by this rep
89  // this can be used as a cropping planes in vtkMapper
90  vtkPlane* GetUnderlyingPlane(int i) { return this->Planes[i]; }
91 
93 
99  vtkSetMacro(InsideOut, vtkTypeBool);
100  vtkGetMacro(InsideOut, vtkTypeBool);
101  vtkBooleanMacro(InsideOut, vtkTypeBool);
103 
111  virtual void GetTransform(vtkTransform* t);
112 
119  virtual void SetTransform(vtkTransform* t);
120 
131  void GetPolyData(vtkPolyData* pd);
132 
134 
139  vtkGetObjectMacro(HandleProperty, vtkProperty);
140  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
142 
144 
149  vtkGetObjectMacro(FaceProperty, vtkProperty);
150  vtkGetObjectMacro(SelectedFaceProperty, vtkProperty);
152 
154 
159  vtkGetObjectMacro(OutlineProperty, vtkProperty);
160  vtkGetObjectMacro(SelectedOutlineProperty, vtkProperty);
162 
164 
168  void SetOutlineFaceWires(int);
169  vtkGetMacro(OutlineFaceWires, int);
170  void OutlineFaceWiresOn() { this->SetOutlineFaceWires(1); }
171  void OutlineFaceWiresOff() { this->SetOutlineFaceWires(0); }
173 
175 
180  void SetOutlineCursorWires(int);
181  vtkGetMacro(OutlineCursorWires, int);
182  void OutlineCursorWiresOn() { this->SetOutlineCursorWires(1); }
183  void OutlineCursorWiresOff() { this->SetOutlineCursorWires(0); }
185 
187 
191  virtual void HandlesOn();
192  virtual void HandlesOff();
194 
196 
199  void PlaceWidget(double bounds[6]) override;
200  void BuildRepresentation() override;
201  int ComputeInteractionState(int X, int Y, int modify = 0) override;
202  void StartWidgetInteraction(double e[2]) override;
203  void WidgetInteraction(double e[2]) override;
204  double* GetBounds() VTK_SIZEHINT(6) override;
205  void StartComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
206  unsigned long event, void* calldata) override;
207  void ComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
208  unsigned long event, void* calldata) override;
209  int ComputeComplexInteractionState(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
210  unsigned long event, void* calldata, int modify = 0) override;
211  void EndComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
212  unsigned long event, void* calldata) override;
214 
216 
219  void ReleaseGraphicsResources(vtkWindow*) override;
220  int RenderOpaqueGeometry(vtkViewport*) override;
221  int RenderTranslucentPolygonalGeometry(vtkViewport*) override;
222  vtkTypeBool HasTranslucentPolygonalGeometry() override;
224 
225  // Used to manage the state of the widget
226  enum
227  {
228  Outside = 0,
237  Scaling
238  };
239 
249  void SetInteractionState(int state);
250 
252 
256  vtkGetMacro(TwoPlaneMode, bool);
257  void SetTwoPlaneMode(bool);
259 
261 
265  vtkGetMacro(SnapToAxes, bool);
266  vtkSetMacro(SnapToAxes, bool);
268 
270 
274  void StepForward();
275  void StepBackward();
277 
278  /*
279  * Register internal Pickers within PickingManager
280  */
281  void RegisterPickers() override;
282 
284 
288  vtkGetMacro(TranslationAxis, int);
289  vtkSetClampMacro(TranslationAxis, int, -1, 2);
291 
293 
296  void SetXTranslationAxisOn() { this->TranslationAxis = Axis::XAxis; }
297  void SetYTranslationAxisOn() { this->TranslationAxis = Axis::YAxis; }
298  void SetZTranslationAxisOn() { this->TranslationAxis = Axis::ZAxis; }
299  void SetTranslationAxisOff() { this->TranslationAxis = Axis::NONE; }
301 
303 
306  bool IsTranslationConstrained() { return this->TranslationAxis != Axis::NONE; }
308 
314  void GetActors(vtkPropCollection*) override;
315 
316 protected:
318  ~vtkBoxRepresentation() override;
319 
320  // Manage how the representation appears
321  double LastEventPosition[3];
322  double LastEventOrientation[4];
323  double StartEventOrientation[4];
324  double SnappedEventOrientations[3][4];
325  bool SnappedOrientation[3];
327 
329 
330  // Constraint axis translation
332 
333  // the hexahedron (6 faces)
337  vtkPoints* Points; // used by others as well
338  double N[6][3]; // the normals of the faces
339 
340  // A face of the hexahedron
344 
345  // glyphs representing hot spots (e.g., handles)
349  virtual void PositionHandles();
350  int HighlightHandle(vtkProp* prop); // returns cell id
351  void HighlightFace(int cellId);
352  void HighlightOutline(int highlight);
353  virtual void ComputeNormals();
354  virtual void SizeHandles();
355 
356  // wireframe outline
360 
361  // Do the picking
367 
368  // Transform the hexahedral points (used for rotations)
370 
371  // Support GetBounds() method
373 
374  // Properties used to control the appearance of selected objects and
375  // the manipulator in general.
382  virtual void CreateDefaultProperties();
383 
384  // Control the orientation of the normals
388  void GenerateOutline();
389 
390  // Helper methods
391  virtual void Translate(const double* p1, const double* p2);
392  virtual void Scale(const double* p1, const double* p2, int X, int Y);
393  virtual void Rotate(int X, int Y, const double* p1, const double* p2, const double* vpn);
394  void MovePlusXFace(const double* p1, const double* p2);
395  void MoveMinusXFace(const double* p1, const double* p2);
396  void MovePlusYFace(const double* p1, const double* p2);
397  void MoveMinusYFace(const double* p1, const double* p2);
398  void MovePlusZFace(const double* p1, const double* p2);
399  void MoveMinusZFace(const double* p1, const double* p2);
400  void UpdatePose(const double* p1, const double* d1, const double* p2, const double* d2);
401 
402  // Internal ivars for performance
406 
407  // The actual planes which are being manipulated
408  vtkPlane* Planes[6];
409 
410  //"dir" is the direction in which the face can be moved i.e. the axis passing
411  // through the center
412  void MoveFace(const double* p1, const double* p2, const double* dir, double* x1, double* x2,
413  double* x3, double* x4, double* x5);
414  // Helper method to obtain the direction in which the face is to be moved.
415  // Handles special cases where some of the scale factors are 0.
416  void GetDirection(const double Nx[3], const double Ny[3], const double Nz[3], double dir[3]);
417 
418 private:
420  void operator=(const vtkBoxRepresentation&) = delete;
421 };
422 
423 #endif
vtkProperty * SelectedHandleProperty
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:56
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:51
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:41
virtual void PlaceWidget(double vtkNotUsed(bounds)[6])
The following is a suggested API for widget representations.
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:55
represent surface properties of a geometric object
Definition: vtkProperty.h:67
virtual void StartWidgetInteraction(double eventPos[2])
bool IsTranslationConstrained()
Returns true if ContrainedAxis.
implicit function for convex set of planes
Definition: vtkPlanes.h:52
a class defining the representation for the vtkBoxWidget2
vtkProperty * SelectedFaceProperty
vtkPlane * GetUnderlyingPlane(int i)
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:60
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:90
abstract class defines interface between the widget and widget representation classes ...
virtual void BuildRepresentation()=0
Subclasses of vtkWidgetRepresentation must implement these methods.
double * GetBounds() override
Methods to make this class behave as a vtkProp.
dynamic, self-adjusting array of double
an ordered list of Props
int vtkTypeBool
Definition: vtkABI.h:69
window superclass for vtkRenderWindow
Definition: vtkWindow.h:38
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:39
virtual void RegisterPickers()
Register internal Pickers in the Picking Manager.
vtkPolyDataMapper ** HandleMapper
perform various plane computations
Definition: vtkPlane.h:36
virtual void WidgetInteraction(double newEventPos[2])
vtkPolyDataMapper * HexFaceMapper
vtkSphereSource ** HandleGeometry
#define VTK_SIZEHINT(...)
vtkProperty * SelectedOutlineProperty
define the API for widget / widget representation
create a line defined by two end points
Definition: vtkLineSource.h:63
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:72
vtkDoubleArray * PlaneNormals
void OutlineCursorWiresOn()
Control the representation of the outline.
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:41
void OutlineFaceWiresOff()
Control the representation of the outline.
represent and manipulate 3D points
Definition: vtkPoints.h:39
void SetZTranslationAxisOn()
Toggles constraint translation axis on/off.
vtkPolyDataMapper * OutlineMapper
void SetTranslationAxisOff()
Toggles constraint translation axis on/off.