VTK  9.2.5
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 class vtkActor;
53 class vtkPolyDataMapper;
54 class vtkLineSource;
55 class vtkSphereSource;
56 class vtkCellPicker;
57 class vtkProperty;
58 class vtkPolyData;
59 class vtkPoints;
62 class vtkTransform;
63 class vtkMatrix4x4;
64 class vtkPlane;
65 class vtkPlanes;
66 class vtkBox;
67 class vtkDoubleArray;
68 
69 class VTKINTERACTIONWIDGETS_EXPORT vtkTensorRepresentation : public vtkWidgetRepresentation
70 {
71 public:
73 
78  void PrintSelf(ostream& os, vtkIndent indent) override;
80 
82 
96  void SetTensor(double tensor[9]);
97  void SetSymmetricTensor(double symTensor[6]);
98  void GetTensor(double tensor[9]) { std::copy(this->Tensor, this->Tensor + 9, tensor); }
99  void GetSymmetricTensor(double symTensor[6])
100  {
101  symTensor[0] = this->Tensor[0];
102  symTensor[1] = this->Tensor[4];
103  symTensor[2] = this->Tensor[8];
104  symTensor[3] = this->Tensor[1];
105  symTensor[4] = this->Tensor[2];
106  symTensor[5] = this->Tensor[5];
107  }
109 
111 
116  void GetEigenvalues(double evals[3])
117  {
118  std::copy(this->Eigenvalues, this->Eigenvalues + 3, evals);
119  }
120  void GetEigenvector(int n, double ev[3])
121  {
122  n = (n < 0 ? 0 : (n > 2 ? 2 : n));
123  std::copy(this->Eigenvectors[n], this->Eigenvectors[n] + 3, ev);
124  }
126 
128 
133  void SetPosition(double pos[3]);
134  void GetPosition(double pos[3])
135  {
136  std::copy(this->TensorPosition, this->TensorPosition + 3, pos);
137  }
139 
151 
153 
158  vtkGetObjectMacro(HandleProperty, vtkProperty);
159  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
161 
163 
168  vtkGetObjectMacro(FaceProperty, vtkProperty);
169  vtkGetObjectMacro(SelectedFaceProperty, vtkProperty);
171 
173 
178  vtkGetObjectMacro(OutlineProperty, vtkProperty);
179  vtkGetObjectMacro(SelectedOutlineProperty, vtkProperty);
181 
183 
187  vtkGetObjectMacro(EllipsoidProperty, vtkProperty);
189 
191 
196  vtkGetMacro(OutlineFaceWires, bool);
197  void OutlineFaceWiresOn() { this->SetOutlineFaceWires(true); }
198  void OutlineFaceWiresOff() { this->SetOutlineFaceWires(false); }
200 
202 
208  vtkGetMacro(OutlineCursorWires, bool);
209  void OutlineCursorWiresOn() { this->SetOutlineCursorWires(true); }
210  void OutlineCursorWiresOff() { this->SetOutlineCursorWires(false); }
212 
214 
218  virtual void HandlesOn();
219  virtual void HandlesOff();
221 
223 
226  void SetTensorEllipsoid(bool);
227  vtkGetMacro(TensorEllipsoid, bool);
228  void TensorEllipsoidOn() { this->SetTensorEllipsoid(true); }
229  void TensorEllipsoidOff() { this->SetTensorEllipsoid(false); }
231 
238  void PlaceTensor(double tensor[9], double position[3]);
239 
241 
244  void PlaceWidget(double bounds[6]) override;
245  void BuildRepresentation() override;
246  int ComputeInteractionState(int X, int Y, int modify = 0) override;
247  void StartWidgetInteraction(double e[2]) override;
248  void WidgetInteraction(double e[2]) override;
249  double* GetBounds() VTK_SIZEHINT(6) override;
250  void StartComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
251  unsigned long event, void* calldata) override;
252  void ComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
253  unsigned long event, void* calldata) override;
254  int ComputeComplexInteractionState(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
255  unsigned long event, void* calldata, int modify = 0) override;
256  void EndComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
257  unsigned long event, void* calldata) override;
259 
261 
264  void ReleaseGraphicsResources(vtkWindow*) override;
265  int RenderOpaqueGeometry(vtkViewport*) override;
266  int RenderTranslucentPolygonalGeometry(vtkViewport*) override;
267  vtkTypeBool HasTranslucentPolygonalGeometry() override;
269 
270  // Used to manage the state of the widget
271  enum
272  {
273  Outside = 0,
282  Scaling
283  };
284 
294  void SetInteractionState(int state);
295 
297 
301  vtkGetMacro(SnapToAxes, bool);
302  vtkSetMacro(SnapToAxes, bool);
304 
306 
310  void StepForward();
311  void StepBackward();
313 
314  /*
315  * Register internal Pickers within PickingManager
316  */
317  void RegisterPickers() override;
318 
320 
324  vtkGetMacro(TranslationAxis, int);
325  vtkSetClampMacro(TranslationAxis, int, -1, 2);
327 
329 
332  void SetXTranslationAxisOn() { this->TranslationAxis = Axis::XAxis; }
333  void SetYTranslationAxisOn() { this->TranslationAxis = Axis::YAxis; }
334  void SetZTranslationAxisOn() { this->TranslationAxis = Axis::ZAxis; }
335  void SetTranslationAxisOff() { this->TranslationAxis = Axis::NONE; }
337 
339 
342  bool IsTranslationConstrained() { return this->TranslationAxis != Axis::NONE; }
344 
345 protected:
348 
349  // Core data
350  double Tensor[9]; // stored as 3x3 symmetric matrix
351  double Eigenvalues[3];
352  double Eigenvectors[3][3];
353  double TensorPosition[3];
354 
355  // Manage how the representation appears
356  double LastEventPosition[3];
357  double LastEventOrientation[4];
358  double StartEventOrientation[4];
359  double SnappedEventOrientations[3][4];
360  bool SnappedOrientation[3];
362 
363  // Constraint axis translation
365 
366  // the hexahedron (6 faces)
370  vtkPoints* Points; // used by others as well
371  double N[6][3]; // the normals of the faces
372 
373  // A face of the hexahedron
377 
378  // glyphs representing hot spots (e.g., handles)
382  virtual void PositionHandles();
383  int HighlightHandle(vtkProp* prop); // returns cell id
384  void HighlightFace(int cellId);
385  void HighlightOutline(int highlight);
386  virtual void ComputeNormals();
387  virtual void SizeHandles();
388 
389  // wireframe outline
393 
394  // the tensor ellipsoid and transforms
400 
401  // Do the picking
407 
408  // Transform the hexahedral points (used for rotations)
412 
413  // Support GetBounds() method
415 
416  // Properties used to control the appearance of selected objects and
417  // the manipulator in general.
425  virtual void CreateDefaultProperties();
426 
427  // Control the orientation of the normals
428  bool InsideOut;
433  void UpdateTensorFromWidget(); // tensor information updated from widget state
434  void UpdateWidgetFromTensor(); // widget state updated from tensor specification
435  void UpdateTensorEigenfunctions(double tensor[3][3]);
436 
437  // Helper methods
438  virtual void Translate(const double* p1, const double* p2);
439  virtual void Scale(const double* p1, const double* p2, int X, int Y);
440  virtual void Rotate(int X, int Y, const double* p1, const double* p2, const double* vpn);
441  void MovePlusXFace(const double* p1, const double* p2, bool entry);
442  void MoveMinusXFace(const double* p1, const double* p2, bool entry);
443  void MovePlusYFace(const double* p1, const double* p2, bool entry);
444  void MoveMinusYFace(const double* p1, const double* p2, bool entry);
445  void MovePlusZFace(const double* p1, const double* p2, bool entry);
446  void MoveMinusZFace(const double* p1, const double* p2, bool entry);
447  void UpdatePose(const double* p1, const double* d1, const double* p2, const double* d2);
448 
449  // Internal ivars for performance
452 
453  // The actual planes which are being manipulated
454  vtkPlane* Planes[6];
455 
456  //"dir" is the direction in which the face can be moved i.e. the axis passing
457  // through the center
458  void MoveFace(const double* p1, const double* p2, const double* dir, double* x1, double* x2,
459  double* x3, double* x4, double* x5);
460 
461  // Helper method to obtain the direction in which the face is to be moved.
462  // Handles special cases where some of the scale factors are 0.
463  void GetDirection(const double Nx[3], const double Ny[3], const double Nz[3], double dir[3]);
464 
465 private:
467  void operator=(const vtkTensorRepresentation&) = delete;
468 };
469 
470 #endif
define the API for widget / widget representation
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:161
implicit function for a bounding box
Definition: vtkBox.h:141
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:119
create a line defined by two end points
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:151
perform various plane computations
Definition: vtkPlane.h:146
implicit function for convex set of planes
Definition: vtkPlanes.h:162
represent the position of a point in 3D space
represent and manipulate 3D points
Definition: vtkPoints.h:149
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:200
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:76
represent surface properties of a geometric object
Definition: vtkProperty.h:177
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 ContrainedAxis.
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:170
abstract specification for Viewports
Definition: vtkViewport.h:56
abstract class defines interface between the widget and widget representation classes
window superclass for vtkRenderWindow
Definition: vtkWindow.h:39
@ dir
Definition: vtkX3D.h:330
@ position
Definition: vtkX3D.h:267
int vtkTypeBool
Definition: vtkABI.h:69
#define VTK_SIZEHINT(...)