VTK  9.3.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 
40 VTK_ABI_NAMESPACE_BEGIN
41 class vtkActor;
42 class vtkPolyDataMapper;
43 class vtkLineSource;
44 class vtkSphereSource;
45 class vtkCellPicker;
46 class vtkProperty;
47 class vtkPolyData;
48 class vtkPoints;
51 class vtkTransform;
52 class vtkMatrix4x4;
53 class vtkPlane;
54 class vtkPlanes;
55 class vtkBox;
56 class vtkDoubleArray;
57 
58 class VTKINTERACTIONWIDGETS_EXPORT vtkTensorRepresentation : public vtkWidgetRepresentation
59 {
60 public:
62 
65  static vtkTensorRepresentation* New();
67  void PrintSelf(ostream& os, vtkIndent indent) override;
69 
71 
85  void SetTensor(double tensor[9]);
86  void SetSymmetricTensor(double symTensor[6]);
87  void GetTensor(double tensor[9]) { std::copy(this->Tensor, this->Tensor + 9, tensor); }
88  void GetSymmetricTensor(double symTensor[6])
89  {
90  symTensor[0] = this->Tensor[0];
91  symTensor[1] = this->Tensor[4];
92  symTensor[2] = this->Tensor[8];
93  symTensor[3] = this->Tensor[1];
94  symTensor[4] = this->Tensor[2];
95  symTensor[5] = this->Tensor[5];
96  }
98 
100 
105  void GetEigenvalues(double evals[3])
106  {
107  std::copy(this->Eigenvalues, this->Eigenvalues + 3, evals);
108  }
109  void GetEigenvector(int n, double ev[3])
110  {
111  n = (n < 0 ? 0 : (n > 2 ? 2 : n));
112  std::copy(this->Eigenvectors[n], this->Eigenvectors[n] + 3, ev);
113  }
115 
117 
122  void SetPosition(double pos[3]);
123  void GetPosition(double pos[3])
124  {
125  std::copy(this->TensorPosition, this->TensorPosition + 3, pos);
126  }
128 
139  void GetPolyData(vtkPolyData* pd);
140 
142 
147  vtkGetObjectMacro(HandleProperty, vtkProperty);
148  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
150 
152 
157  vtkGetObjectMacro(FaceProperty, vtkProperty);
158  vtkGetObjectMacro(SelectedFaceProperty, vtkProperty);
160 
162 
167  vtkGetObjectMacro(OutlineProperty, vtkProperty);
168  vtkGetObjectMacro(SelectedOutlineProperty, vtkProperty);
170 
172 
176  vtkGetObjectMacro(EllipsoidProperty, vtkProperty);
178 
180 
184  void SetOutlineFaceWires(bool);
185  vtkGetMacro(OutlineFaceWires, bool);
186  void OutlineFaceWiresOn() { this->SetOutlineFaceWires(true); }
187  void OutlineFaceWiresOff() { this->SetOutlineFaceWires(false); }
189 
191 
196  void SetOutlineCursorWires(bool);
197  vtkGetMacro(OutlineCursorWires, bool);
198  void OutlineCursorWiresOn() { this->SetOutlineCursorWires(true); }
199  void OutlineCursorWiresOff() { this->SetOutlineCursorWires(false); }
201 
203 
207  virtual void HandlesOn();
208  virtual void HandlesOff();
210 
212 
215  void SetTensorEllipsoid(bool);
216  vtkGetMacro(TensorEllipsoid, bool);
217  void TensorEllipsoidOn() { this->SetTensorEllipsoid(true); }
218  void TensorEllipsoidOff() { this->SetTensorEllipsoid(false); }
220 
227  void PlaceTensor(double tensor[9], double position[3]);
228 
230 
233  void PlaceWidget(double bounds[6]) override;
234  void BuildRepresentation() override;
235  int ComputeInteractionState(int X, int Y, int modify = 0) override;
236  void StartWidgetInteraction(double e[2]) override;
237  void WidgetInteraction(double e[2]) override;
238  double* GetBounds() VTK_SIZEHINT(6) override;
239  void StartComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
240  unsigned long event, void* calldata) override;
241  void ComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
242  unsigned long event, void* calldata) override;
243  int ComputeComplexInteractionState(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
244  unsigned long event, void* calldata, int modify = 0) override;
245  void EndComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
246  unsigned long event, void* calldata) override;
248 
250 
253  void ReleaseGraphicsResources(vtkWindow*) override;
254  int RenderOpaqueGeometry(vtkViewport*) override;
255  int RenderTranslucentPolygonalGeometry(vtkViewport*) override;
256  vtkTypeBool HasTranslucentPolygonalGeometry() override;
258 
259  // Used to manage the state of the widget
260  enum
261  {
262  Outside = 0,
271  Scaling
272  };
273 
283  void SetInteractionState(int state);
284 
286 
290  vtkGetMacro(SnapToAxes, bool);
291  vtkSetMacro(SnapToAxes, bool);
293 
295 
299  void StepForward();
300  void StepBackward();
302 
303  /*
304  * Register internal Pickers within PickingManager
305  */
306  void RegisterPickers() override;
307 
309 
313  vtkGetMacro(TranslationAxis, int);
314  vtkSetClampMacro(TranslationAxis, int, -1, 2);
316 
318 
321  void SetXTranslationAxisOn() { this->TranslationAxis = Axis::XAxis; }
322  void SetYTranslationAxisOn() { this->TranslationAxis = Axis::YAxis; }
323  void SetZTranslationAxisOn() { this->TranslationAxis = Axis::ZAxis; }
324  void SetTranslationAxisOff() { this->TranslationAxis = Axis::NONE; }
326 
328 
331  bool IsTranslationConstrained() { return this->TranslationAxis != Axis::NONE; }
333 
334 protected:
336  ~vtkTensorRepresentation() override;
337 
338  // Core data
339  double Tensor[9]; // stored as 3x3 symmetric matrix
340  double Eigenvalues[3];
341  double Eigenvectors[3][3];
342  double TensorPosition[3];
343 
344  // Manage how the representation appears
345  double LastEventPosition[3];
346  double LastEventOrientation[4];
347  double StartEventOrientation[4];
348  double SnappedEventOrientations[3][4];
349  bool SnappedOrientation[3];
351 
352  // Constraint axis translation
354 
355  // the hexahedron (6 faces)
359  vtkPoints* Points; // used by others as well
360  double N[6][3]; // the normals of the faces
361 
362  // A face of the hexahedron
366 
367  // glyphs representing hot spots (e.g., handles)
371  virtual void PositionHandles();
372  int HighlightHandle(vtkProp* prop); // returns cell id
373  void HighlightFace(int cellId);
374  void HighlightOutline(int highlight);
375  virtual void ComputeNormals();
376  virtual void SizeHandles();
377 
378  // wireframe outline
382 
383  // the tensor ellipsoid and transforms
389 
390  // Do the picking
396 
397  // Transform the hexahedral points (used for rotations)
401 
402  // Support GetBounds() method
404 
405  // Properties used to control the appearance of selected objects and
406  // the manipulator in general.
414  virtual void CreateDefaultProperties();
415 
416  // Control the orientation of the normals
417  bool InsideOut;
420  void GenerateOutline();
422  void UpdateTensorFromWidget(); // tensor information updated from widget state
423  void UpdateWidgetFromTensor(); // widget state updated from tensor specification
424  void UpdateTensorEigenfunctions(double tensor[3][3]);
425 
426  // Helper methods
427  virtual void Translate(const double* p1, const double* p2);
428  virtual void Scale(const double* p1, const double* p2, int X, int Y);
429  virtual void Rotate(int X, int Y, const double* p1, const double* p2, const double* vpn);
430  void MovePlusXFace(const double* p1, const double* p2, bool entry);
431  void MoveMinusXFace(const double* p1, const double* p2, bool entry);
432  void MovePlusYFace(const double* p1, const double* p2, bool entry);
433  void MoveMinusYFace(const double* p1, const double* p2, bool entry);
434  void MovePlusZFace(const double* p1, const double* p2, bool entry);
435  void MoveMinusZFace(const double* p1, const double* p2, bool entry);
436  void UpdatePose(const double* p1, const double* d1, const double* p2, const double* d2);
437 
438  // Internal ivars for performance
441 
442  // The actual planes which are being manipulated
443  vtkPlane* Planes[6];
444 
445  //"dir" is the direction in which the face can be moved i.e. the axis passing
446  // through the center
447  void MoveFace(const double* p1, const double* p2, const double* dir, double* x1, double* x2,
448  double* x3, double* x4, double* x5);
449 
450  // Helper method to obtain the direction in which the face is to be moved.
451  // Handles special cases where some of the scale factors are 0.
452  void GetDirection(const double Nx[3], const double Ny[3], const double Nz[3], double dir[3]);
453 
454 private:
456  void operator=(const vtkTensorRepresentation&) = delete;
457 };
458 
459 VTK_ABI_NAMESPACE_END
460 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:45
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:40
void OutlineFaceWiresOn()
Control the representation of the outline.
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:30
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 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:44
represent surface properties of a geometric object
Definition: vtkProperty.h:56
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:49
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:79
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:27
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:25
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:52
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:61
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...
represent and manipulate 3D points
Definition: vtkPoints.h:28