VTK  9.2.20230606
vtkTensorRepresentation.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkTensorRepresentation.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 =========================================================================*/
46 #ifndef vtkTensorRepresentation_h
47 #define vtkTensorRepresentation_h
48 
49 #include "vtkInteractionWidgetsModule.h" // For export macro
51 
52 VTK_ABI_NAMESPACE_BEGIN
53 class vtkActor;
54 class vtkPolyDataMapper;
55 class vtkLineSource;
56 class vtkSphereSource;
57 class vtkCellPicker;
58 class vtkProperty;
59 class vtkPolyData;
60 class vtkPoints;
63 class vtkTransform;
64 class vtkMatrix4x4;
65 class vtkPlane;
66 class vtkPlanes;
67 class vtkBox;
68 class vtkDoubleArray;
69 
70 class VTKINTERACTIONWIDGETS_EXPORT vtkTensorRepresentation : public vtkWidgetRepresentation
71 {
72 public:
74 
79  void PrintSelf(ostream& os, vtkIndent indent) override;
81 
83 
97  void SetTensor(double tensor[9]);
98  void SetSymmetricTensor(double symTensor[6]);
99  void GetTensor(double tensor[9]) { std::copy(this->Tensor, this->Tensor + 9, tensor); }
100  void GetSymmetricTensor(double symTensor[6])
101  {
102  symTensor[0] = this->Tensor[0];
103  symTensor[1] = this->Tensor[4];
104  symTensor[2] = this->Tensor[8];
105  symTensor[3] = this->Tensor[1];
106  symTensor[4] = this->Tensor[2];
107  symTensor[5] = this->Tensor[5];
108  }
110 
112 
117  void GetEigenvalues(double evals[3])
118  {
119  std::copy(this->Eigenvalues, this->Eigenvalues + 3, evals);
120  }
121  void GetEigenvector(int n, double ev[3])
122  {
123  n = (n < 0 ? 0 : (n > 2 ? 2 : n));
124  std::copy(this->Eigenvectors[n], this->Eigenvectors[n] + 3, ev);
125  }
127 
129 
134  void SetPosition(double pos[3]);
135  void GetPosition(double pos[3])
136  {
137  std::copy(this->TensorPosition, this->TensorPosition + 3, pos);
138  }
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 
188  vtkGetObjectMacro(EllipsoidProperty, vtkProperty);
190 
192 
197  vtkGetMacro(OutlineFaceWires, bool);
198  void OutlineFaceWiresOn() { this->SetOutlineFaceWires(true); }
199  void OutlineFaceWiresOff() { this->SetOutlineFaceWires(false); }
201 
203 
209  vtkGetMacro(OutlineCursorWires, bool);
210  void OutlineCursorWiresOn() { this->SetOutlineCursorWires(true); }
211  void OutlineCursorWiresOff() { this->SetOutlineCursorWires(false); }
213 
215 
219  virtual void HandlesOn();
220  virtual void HandlesOff();
222 
224 
227  void SetTensorEllipsoid(bool);
228  vtkGetMacro(TensorEllipsoid, bool);
229  void TensorEllipsoidOn() { this->SetTensorEllipsoid(true); }
230  void TensorEllipsoidOff() { this->SetTensorEllipsoid(false); }
232 
239  void PlaceTensor(double tensor[9], double position[3]);
240 
242 
245  void PlaceWidget(double bounds[6]) override;
246  void BuildRepresentation() override;
247  int ComputeInteractionState(int X, int Y, int modify = 0) override;
248  void StartWidgetInteraction(double e[2]) override;
249  void WidgetInteraction(double e[2]) override;
250  double* GetBounds() VTK_SIZEHINT(6) override;
251  void StartComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
252  unsigned long event, void* calldata) override;
253  void ComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
254  unsigned long event, void* calldata) override;
255  int ComputeComplexInteractionState(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
256  unsigned long event, void* calldata, int modify = 0) override;
257  void EndComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
258  unsigned long event, void* calldata) override;
260 
262 
265  void ReleaseGraphicsResources(vtkWindow*) override;
266  int RenderOpaqueGeometry(vtkViewport*) override;
267  int RenderTranslucentPolygonalGeometry(vtkViewport*) override;
268  vtkTypeBool HasTranslucentPolygonalGeometry() override;
270 
271  // Used to manage the state of the widget
272  enum
273  {
274  Outside = 0,
283  Scaling
284  };
285 
295  void SetInteractionState(int state);
296 
298 
302  vtkGetMacro(SnapToAxes, bool);
303  vtkSetMacro(SnapToAxes, bool);
305 
307 
311  void StepForward();
312  void StepBackward();
314 
315  /*
316  * Register internal Pickers within PickingManager
317  */
318  void RegisterPickers() override;
319 
321 
325  vtkGetMacro(TranslationAxis, int);
326  vtkSetClampMacro(TranslationAxis, int, -1, 2);
328 
330 
333  void SetXTranslationAxisOn() { this->TranslationAxis = Axis::XAxis; }
334  void SetYTranslationAxisOn() { this->TranslationAxis = Axis::YAxis; }
335  void SetZTranslationAxisOn() { this->TranslationAxis = Axis::ZAxis; }
336  void SetTranslationAxisOff() { this->TranslationAxis = Axis::NONE; }
338 
340 
343  bool IsTranslationConstrained() { return this->TranslationAxis != Axis::NONE; }
345 
346 protected:
349 
350  // Core data
351  double Tensor[9]; // stored as 3x3 symmetric matrix
352  double Eigenvalues[3];
353  double Eigenvectors[3][3];
354  double TensorPosition[3];
355 
356  // Manage how the representation appears
357  double LastEventPosition[3];
358  double LastEventOrientation[4];
359  double StartEventOrientation[4];
360  double SnappedEventOrientations[3][4];
361  bool SnappedOrientation[3];
363 
364  // Constraint axis translation
366 
367  // the hexahedron (6 faces)
371  vtkPoints* Points; // used by others as well
372  double N[6][3]; // the normals of the faces
373 
374  // A face of the hexahedron
378 
379  // glyphs representing hot spots (e.g., handles)
383  virtual void PositionHandles();
384  int HighlightHandle(vtkProp* prop); // returns cell id
385  void HighlightFace(int cellId);
386  void HighlightOutline(int highlight);
387  virtual void ComputeNormals();
388  virtual void SizeHandles();
389 
390  // wireframe outline
394 
395  // the tensor ellipsoid and transforms
401 
402  // Do the picking
408 
409  // 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.
426  virtual void CreateDefaultProperties();
427 
428  // Control the orientation of the normals
429  bool InsideOut;
434  void UpdateTensorFromWidget(); // tensor information updated from widget state
435  void UpdateWidgetFromTensor(); // widget state updated from tensor specification
436  void UpdateTensorEigenfunctions(double tensor[3][3]);
437 
438  // Helper methods
439  virtual void Translate(const double* p1, const double* p2);
440  virtual void Scale(const double* p1, const double* p2, int X, int Y);
441  virtual void Rotate(int X, int Y, const double* p1, const double* p2, const double* vpn);
442  void MovePlusXFace(const double* p1, const double* p2, bool entry);
443  void MoveMinusXFace(const double* p1, const double* p2, bool entry);
444  void MovePlusYFace(const double* p1, const double* p2, bool entry);
445  void MoveMinusYFace(const double* p1, const double* p2, bool entry);
446  void MovePlusZFace(const double* p1, const double* p2, bool entry);
447  void MoveMinusZFace(const double* p1, const double* p2, bool entry);
448  void UpdatePose(const double* p1, const double* d1, const double* p2, const double* d2);
449 
450  // Internal ivars for performance
453 
454  // The actual planes which are being manipulated
455  vtkPlane* Planes[6];
456 
457  //"dir" is the direction in which the face can be moved i.e. the axis passing
458  // through the center
459  void MoveFace(const double* p1, const double* p2, const double* dir, double* x1, double* x2,
460  double* x3, double* x4, double* x5);
461 
462  // Helper method to obtain the direction in which the face is to be moved.
463  // Handles special cases where some of the scale factors are 0.
464  void GetDirection(const double Nx[3], const double Ny[3], const double Nz[3], double dir[3]);
465 
466 private:
468  void operator=(const vtkTensorRepresentation&) = delete;
469 };
470 
471 VTK_ABI_NAMESPACE_END
472 #endif
define the API for widget / widget representation
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:162
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
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
class defining a representation for the vtkTensorWidget
void SetZTranslationAxisOn()
Toggles constraint translation axis on/off.
void OutlineCursorWiresOn()
Control the representation of the outline.
virtual void SizeHandles()
void GetEigenvalues(double evals[3])
These are methods used to retrieve derived information about the tensor.
void MovePlusXFace(const double *p1, const double *p2, bool entry)
int HighlightHandle(vtkProp *prop)
void SetOutlineFaceWires(bool)
Control the representation of the outline.
void MoveFace(const double *p1, const double *p2, const double *dir, double *x1, double *x2, double *x3, double *x4, double *x5)
void SetPosition(double pos[3])
Set/Get a position for the location of the tensor.
void HighlightFace(int cellId)
void StartWidgetInteraction(double e[2]) override
These are methods that satisfy vtkWidgetRepresentation's API.
void MovePlusZFace(const double *p1, const double *p2, bool entry)
void SetTensor(double tensor[9])
These are the basic methods used to define the tensor (these methods coordinate with the overloaded P...
void SetOutlineCursorWires(bool)
Control the representation of the outline.
virtual void HandlesOn()
Switches handles (the spheres) on or off by manipulating the underlying actor visibility.
virtual void HandlesOff()
Switches handles (the spheres) on or off by manipulating the underlying actor visibility.
~vtkTensorRepresentation() override
double * GetBounds() override
These are methods that satisfy vtkWidgetRepresentation's API.
void TensorEllipsoidOn()
Indicate whether to show the tensor ellipsoid.
virtual void PositionHandles()
vtkPolyDataMapper * OutlineMapper
void UpdateTensorEigenfunctions(double tensor[3][3])
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for instantiation, obtaining type information, and printing.
void SetYTranslationAxisOn()
Toggles constraint translation axis on/off.
vtkPolyDataMapper * HexFaceMapper
void MoveMinusXFace(const double *p1, const double *p2, bool entry)
void SetXTranslationAxisOn()
Toggles constraint translation axis on/off.
void MovePlusYFace(const double *p1, const double *p2, bool entry)
vtkPolyDataMapper ** HandleMapper
void GetPolyData(vtkPolyData *pd)
Grab the polydata (including points) that define the representation.
int ComputeInteractionState(int X, int Y, int modify=0) override
These are methods that satisfy vtkWidgetRepresentation's API.
void GetEigenvector(int n, double ev[3])
These are methods used to retrieve derived information about the tensor.
void UpdatePose(const double *p1, const double *d1, const double *p2, const double *d2)
virtual void ComputeNormals()
void GetDirection(const double Nx[3], const double Ny[3], const double Nz[3], double dir[3])
void PlaceTensor(double tensor[9], double position[3])
This is a specialized place widget method for a tensor.
void GetSymmetricTensor(double symTensor[6])
These are the basic methods used to define the tensor (these methods coordinate with the overloaded P...
bool IsTranslationConstrained()
Returns true if ConstrainedAxis.
virtual void Rotate(int X, int Y, const double *p1, const double *p2, const double *vpn)
virtual void CreateDefaultProperties()
void MoveMinusZFace(const double *p1, const double *p2, bool entry)
vtkPolyDataMapper * EllipsoidMapper
void OutlineCursorWiresOff()
Control the representation of the outline.
void RegisterPickers() override
Register internal Pickers in the Picking Manager.
static vtkTensorRepresentation * New()
Standard methods for instantiation, obtaining type information, and printing.
void StepForward()
For complex events should we snap orientations to be aligned with the x y z axes.
void GetPosition(double pos[3])
Set/Get a position for the location of the tensor.
void TensorEllipsoidOff()
Indicate whether to show the tensor ellipsoid.
void PlaceWidget(double bounds[6]) override
These are methods that satisfy vtkWidgetRepresentation's API.
void OutlineFaceWiresOff()
Control the representation of the outline.
void SetSymmetricTensor(double symTensor[6])
These are the basic methods used to define the tensor (these methods coordinate with the overloaded P...
virtual void Translate(const double *p1, const double *p2)
void SetTranslationAxisOff()
Toggles constraint translation axis on/off.
void StepBackward()
For complex events should we snap orientations to be aligned with the x y z axes.
void OutlineFaceWiresOn()
Control the representation of the outline.
void GetTensor(double tensor[9])
These are the basic methods used to define the tensor (these methods coordinate with the overloaded P...
void SetInteractionState(int state)
The interaction state may be set from a widget (e.g., vtkTensorWidget) or other object.
void SetTensorEllipsoid(bool)
Indicate whether to show the tensor ellipsoid.
void MoveMinusYFace(const double *p1, const double *p2, bool entry)
void WidgetInteraction(double e[2]) override
These are methods that satisfy vtkWidgetRepresentation's API.
virtual void Scale(const double *p1, const double *p2, int X, int Y)
void HighlightOutline(int highlight)
void BuildRepresentation() override
These are methods that satisfy vtkWidgetRepresentation's API.
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
@ position
Definition: vtkX3D.h:273
int vtkTypeBool
Definition: vtkABI.h:71
#define VTK_SIZEHINT(...)