VTK  9.7.1
vtkTensorRepresentation.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
34 #ifndef vtkTensorRepresentation_h
35 #define vtkTensorRepresentation_h
36 
37 #include "vtkInteractionWidgetsModule.h" // For export macro
39 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
40 
41 #include <algorithm> // std::min, std::max
42 
43 VTK_ABI_NAMESPACE_BEGIN
44 class vtkActor;
45 class vtkPolyDataMapper;
46 class vtkLineSource;
47 class vtkSphereSource;
48 class vtkCellPicker;
49 class vtkProperty;
50 class vtkPolyData;
51 class vtkPoints;
54 class vtkTransform;
55 class vtkMatrix4x4;
56 class vtkPlane;
57 class vtkPlanes;
58 class vtkBox;
59 class vtkDoubleArray;
60 
61 class VTKINTERACTIONWIDGETS_EXPORT VTK_MARSHALAUTO vtkTensorRepresentation
63 {
64 public:
66 
69  static vtkTensorRepresentation* New();
71  void PrintSelf(ostream& os, vtkIndent indent) override;
73 
75 
89  void SetTensor(double tensor[9]);
90  void SetSymmetricTensor(double symTensor[6]);
91  void GetTensor(double tensor[9]) { std::copy(this->Tensor, this->Tensor + 9, tensor); }
92  void GetSymmetricTensor(double symTensor[6])
93  {
94  symTensor[0] = this->Tensor[0];
95  symTensor[1] = this->Tensor[4];
96  symTensor[2] = this->Tensor[8];
97  symTensor[3] = this->Tensor[1];
98  symTensor[4] = this->Tensor[2];
99  symTensor[5] = this->Tensor[5];
100  }
102 
104 
109  void GetEigenvalues(double evals[3])
110  {
111  std::copy(this->Eigenvalues, this->Eigenvalues + 3, evals);
112  }
113  void GetEigenvector(int n, double ev[3])
114  {
115  n = std::min(std::max(n, 0), 2);
116  std::copy(this->Eigenvectors[n], this->Eigenvectors[n] + 3, ev);
117  }
119 
121 
126  void SetPosition(double pos[3]);
127  void GetPosition(double pos[3])
128  {
129  std::copy(this->TensorPosition, this->TensorPosition + 3, pos);
130  }
132 
143  void GetPolyData(vtkPolyData* pd);
144 
146 
151  vtkGetObjectMacro(HandleProperty, vtkProperty);
152  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
154 
156 
161  vtkGetObjectMacro(FaceProperty, vtkProperty);
162  vtkGetObjectMacro(SelectedFaceProperty, vtkProperty);
164 
166 
171  vtkGetObjectMacro(OutlineProperty, vtkProperty);
172  vtkGetObjectMacro(SelectedOutlineProperty, vtkProperty);
174 
176 
180  vtkGetObjectMacro(EllipsoidProperty, vtkProperty);
182 
184 
188  void SetOutlineFaceWires(bool);
189  vtkGetMacro(OutlineFaceWires, bool);
190  void OutlineFaceWiresOn() { this->SetOutlineFaceWires(true); }
191  void OutlineFaceWiresOff() { this->SetOutlineFaceWires(false); }
193 
195 
200  void SetOutlineCursorWires(bool);
201  vtkGetMacro(OutlineCursorWires, bool);
202  void OutlineCursorWiresOn() { this->SetOutlineCursorWires(true); }
203  void OutlineCursorWiresOff() { this->SetOutlineCursorWires(false); }
205 
207 
211  virtual void HandlesOn();
212  virtual void HandlesOff();
214 
216 
219  void SetTensorEllipsoid(bool);
220  vtkGetMacro(TensorEllipsoid, bool);
221  void TensorEllipsoidOn() { this->SetTensorEllipsoid(true); }
222  void TensorEllipsoidOff() { this->SetTensorEllipsoid(false); }
224 
231  void PlaceTensor(double tensor[9], double position[3]);
232 
234 
237  void PlaceWidget(double bounds[6]) override;
238  void BuildRepresentation() override;
239  int ComputeInteractionState(int X, int Y, int modify = 0) override;
240  void StartWidgetInteraction(double e[2]) override;
241  void WidgetInteraction(double e[2]) override;
242  double* GetBounds() VTK_SIZEHINT(6) override;
243  void StartComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
244  unsigned long event, void* calldata) override;
245  void ComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
246  unsigned long event, void* calldata) override;
247  int ComputeComplexInteractionState(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
248  unsigned long event, void* calldata, int modify = 0) override;
249  void EndComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
250  unsigned long event, void* calldata) override;
252 
254 
257  void ReleaseGraphicsResources(vtkWindow*) override;
258  int RenderOpaqueGeometry(vtkViewport*) override;
259  int RenderTranslucentPolygonalGeometry(vtkViewport*) override;
260  vtkTypeBool HasTranslucentPolygonalGeometry() override;
262 
263  // Used to manage the state of the widget
264  enum
265  {
266  Outside = 0,
275  Scaling
276  };
277 
287  void SetInteractionState(int state);
288 
290 
294  vtkGetMacro(SnapToAxes, bool);
295  vtkSetMacro(SnapToAxes, bool);
297 
299 
303  void StepForward();
304  void StepBackward();
306 
307  /*
308  * Register internal Pickers within PickingManager
309  */
310  void RegisterPickers() override;
311 
313 
317  vtkGetMacro(TranslationAxis, int);
318  vtkSetClampMacro(TranslationAxis, int, -1, 2);
320 
322 
325  void SetXTranslationAxisOn() { this->TranslationAxis = Axis::XAxis; }
326  void SetYTranslationAxisOn() { this->TranslationAxis = Axis::YAxis; }
327  void SetZTranslationAxisOn() { this->TranslationAxis = Axis::ZAxis; }
328  void SetTranslationAxisOff() { this->TranslationAxis = Axis::NONE; }
330 
332 
335  bool IsTranslationConstrained() { return this->TranslationAxis != Axis::NONE; }
337 
338 protected:
340  ~vtkTensorRepresentation() override;
341 
342  // Core data
343  double Tensor[9]; // stored as 3x3 symmetric matrix
344  double Eigenvalues[3];
345  double Eigenvectors[3][3];
346  double TensorPosition[3];
347 
348  // Manage how the representation appears
349  double LastEventPosition[3];
350  double LastEventOrientation[4];
351  double StartEventOrientation[4];
352  double SnappedEventOrientations[3][4];
353  bool SnappedOrientation[3];
355 
356  // Constraint axis translation
358 
359  // the hexahedron (6 faces)
363  vtkPoints* Points; // used by others as well
364  double N[6][3]; // the normals of the faces
365 
366  // A face of the hexahedron
370 
371  // glyphs representing hot spots (e.g., handles)
375  virtual void PositionHandles();
376  int HighlightHandle(vtkProp* prop); // returns cell id
377  void HighlightFace(int cellId);
378  void HighlightOutline(int highlight);
379  virtual void ComputeNormals();
380  virtual void SizeHandles();
381 
382  // wireframe outline
386 
387  // the tensor ellipsoid and transforms
393 
394  // Do the picking
400 
401  // Transform the hexahedral points (used for rotations)
405 
406  // Support GetBounds() method
408 
409  // Properties used to control the appearance of selected objects and
410  // the manipulator in general.
418  virtual void CreateDefaultProperties();
419 
420  // Control the orientation of the normals
421  bool InsideOut;
424  void GenerateOutline();
426  void UpdateTensorFromWidget(); // tensor information updated from widget state
427  void UpdateWidgetFromTensor(); // widget state updated from tensor specification
428  void UpdateTensorEigenfunctions(double tensor[3][3]);
429 
430  // Helper methods
431  virtual void Translate(const double* p1, const double* p2);
432  virtual void Scale(const double* p1, const double* p2, int X, int Y);
433  virtual void Rotate(int X, int Y, const double* p1, const double* p2, const double* vpn);
434  void MovePlusXFace(const double* p1, const double* p2, bool entry);
435  void MoveMinusXFace(const double* p1, const double* p2, bool entry);
436  void MovePlusYFace(const double* p1, const double* p2, bool entry);
437  void MoveMinusYFace(const double* p1, const double* p2, bool entry);
438  void MovePlusZFace(const double* p1, const double* p2, bool entry);
439  void MoveMinusZFace(const double* p1, const double* p2, bool entry);
440  void UpdatePose(const double* p1, const double* d1, const double* p2, const double* d2);
441 
442  // Internal ivars for performance
445 
446  // The actual planes which are being manipulated
447  vtkPlane* Planes[6];
448 
449  //"dir" is the direction in which the face can be moved i.e. the axis passing
450  // through the center
451  void MoveFace(const double* p1, const double* p2, const double* dir, double* x1, double* x2,
452  double* x3, double* x4, double* x5);
453 
454  // Helper method to obtain the direction in which the face is to be moved.
455  // Handles special cases where some of the scale factors are 0.
456  void GetDirection(const double Nx[3], const double Ny[3], const double Nz[3], double dir[3]);
457 
458 private:
460  void operator=(const vtkTensorRepresentation&) = delete;
461 };
462 
463 VTK_ABI_NAMESPACE_END
464 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:49
void GetEigenvalues(double evals[3])
These are methods used to retrieve derived information about the tensor.
void SetTranslationAxisOff()
Toggles constraint translation axis on/off.
bool IsTranslationConstrained()
Returns true if ConstrainedAxis.
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for instances of this class.
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.
void OutlineFaceWiresOn()
Control the representation of the outline.
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:31
virtual int ComputeInteractionState(int X, int Y, int modify=0)
void TensorEllipsoidOff()
Indicate whether to show the tensor ellipsoid.
represent the position of a point in 3D space
vtkPolyDataMapper * OutlineMapper
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])
void SetXTranslationAxisOn()
Toggles constraint translation axis on/off.
void SetZTranslationAxisOn()
Toggles constraint translation axis on/off.
void GetEigenvector(int n, double ev[3])
These are methods used to retrieve derived information about the tensor.
implicit function for convex set of planes
Definition: vtkPlanes.h:41
vtkPolyDataMapper * EllipsoidMapper
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:50
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:71
void GetPosition(double pos[3])
Set/Get a position for the location of the tensor.
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
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.
class defining a representation for the vtkTensorWidget
void OutlineCursorWiresOn()
Control the representation of the outline.
perform various plane computations
Definition: vtkPlane.h:31
virtual void WidgetInteraction(double newEventPos[2])
void OutlineFaceWiresOff()
Control the representation of the outline.
void OutlineCursorWiresOff()
Control the representation of the outline.
#define VTK_SIZEHINT(...)
void SetYTranslationAxisOn()
Toggles constraint translation axis on/off.
vtkPolyDataMapper * HexFaceMapper
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 GetSymmetricTensor(double symTensor[6])
These are the basic methods used to define the tensor (these methods coordinate with the overloaded P...
vtkPolyDataMapper ** HandleMapper
void TensorEllipsoidOn()
Indicate whether to show the tensor ellipsoid.
ray-cast cell picker for all kinds of Prop3Ds
Definition: vtkCellPicker.h:62
#define VTK_MARSHALAUTO
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 GetTensor(double tensor[9])
These are the basic methods used to define the tensor (these methods coordinate with the overloaded P...
#define max(a, b)
represent and manipulate 3D points
Definition: vtkPoints.h:30