VTK  9.0.20201030
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 =========================================================================*/
43 #ifndef vtkTensorRepresentation_h
44 #define vtkTensorRepresentation_h
45 
46 #include "vtkInteractionWidgetsModule.h" // For export macro
48 
49 class vtkActor;
50 class vtkPolyDataMapper;
51 class vtkLineSource;
52 class vtkSphereSource;
53 class vtkCellPicker;
54 class vtkProperty;
55 class vtkPolyData;
56 class vtkPoints;
59 class vtkTransform;
60 class vtkMatrix4x4;
61 class vtkPlane;
62 class vtkPlanes;
63 class vtkBox;
64 class vtkDoubleArray;
65 
66 class VTKINTERACTIONWIDGETS_EXPORT vtkTensorRepresentation : public vtkWidgetRepresentation
67 {
68 public:
70 
73  static vtkTensorRepresentation* New();
75  void PrintSelf(ostream& os, vtkIndent indent) override;
77 
79 
93  void SetTensor(double tensor[9]);
94  void SetSymmetricTensor(double symTensor[6]);
95  void GetTensor(double tensor[9]) { std::copy(this->Tensor, this->Tensor + 9, tensor); }
96  void GetSymmetricTensor(double symTensor[6])
97  {
98  symTensor[0] = this->Tensor[0];
99  symTensor[1] = this->Tensor[4];
100  symTensor[2] = this->Tensor[8];
101  symTensor[3] = this->Tensor[1];
102  symTensor[4] = this->Tensor[2];
103  symTensor[5] = this->Tensor[5];
104  }
106 
108 
113  void GetEigenvalues(double evals[3])
114  {
115  std::copy(this->Eigenvalues, this->Eigenvalues + 3, evals);
116  }
117  void GetEigenvector(int n, double ev[3])
118  {
119  n = (n < 0 ? 0 : (n > 2 ? 2 : n));
120  std::copy(this->Eigenvectors[n], this->Eigenvectors[n] + 3, ev);
121  }
123 
125 
130  void SetPosition(double pos[3]);
131  void GetPosition(double pos[3])
132  {
133  std::copy(this->TensorPosition, this->TensorPosition + 3, pos);
134  }
136 
147  void GetPolyData(vtkPolyData* pd);
148 
150 
155  vtkGetObjectMacro(HandleProperty, vtkProperty);
156  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
158 
160 
165  vtkGetObjectMacro(FaceProperty, vtkProperty);
166  vtkGetObjectMacro(SelectedFaceProperty, vtkProperty);
168 
170 
175  vtkGetObjectMacro(OutlineProperty, vtkProperty);
176  vtkGetObjectMacro(SelectedOutlineProperty, vtkProperty);
178 
180 
184  vtkGetObjectMacro(EllipsoidProperty, vtkProperty);
186 
188 
192  void SetOutlineFaceWires(bool);
193  vtkGetMacro(OutlineFaceWires, bool);
194  void OutlineFaceWiresOn() { this->SetOutlineFaceWires(true); }
195  void OutlineFaceWiresOff() { this->SetOutlineFaceWires(false); }
197 
199 
204  void SetOutlineCursorWires(bool);
205  vtkGetMacro(OutlineCursorWires, bool);
206  void OutlineCursorWiresOn() { this->SetOutlineCursorWires(true); }
207  void OutlineCursorWiresOff() { this->SetOutlineCursorWires(false); }
209 
211 
215  virtual void HandlesOn();
216  virtual void HandlesOff();
218 
220 
223  void SetTensorEllipsoid(bool);
224  vtkGetMacro(TensorEllipsoid, bool);
225  void TensorEllipsoidOn() { this->SetTensorEllipsoid(true); }
226  void TensorEllipsoidOff() { this->SetTensorEllipsoid(false); }
228 
235  void PlaceTensor(double tensor[9], double position[3]);
236 
238 
241  void PlaceWidget(double bounds[6]) override;
242  void BuildRepresentation() override;
243  int ComputeInteractionState(int X, int Y, int modify = 0) override;
244  void StartWidgetInteraction(double e[2]) override;
245  void WidgetInteraction(double e[2]) override;
246  double* GetBounds() VTK_SIZEHINT(6) override;
247  void StartComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
248  unsigned long event, void* calldata) override;
249  void ComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
250  unsigned long event, void* calldata) override;
251  int ComputeComplexInteractionState(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
252  unsigned long event, void* calldata, int modify = 0) override;
253  void EndComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
254  unsigned long event, void* calldata) override;
256 
258 
261  void ReleaseGraphicsResources(vtkWindow*) override;
262  int RenderOpaqueGeometry(vtkViewport*) override;
263  int RenderTranslucentPolygonalGeometry(vtkViewport*) override;
264  vtkTypeBool HasTranslucentPolygonalGeometry() override;
266 
267  // Used to manage the state of the widget
268  enum
269  {
270  Outside = 0,
279  Scaling
280  };
281 
291  void SetInteractionState(int state);
292 
294 
298  vtkGetMacro(SnapToAxes, bool);
299  vtkSetMacro(SnapToAxes, bool);
301 
303 
307  void StepForward();
308  void StepBackward();
310 
311  /*
312  * Register internal Pickers within PickingManager
313  */
314  void RegisterPickers() override;
315 
317 
321  vtkGetMacro(TranslationAxis, int);
322  vtkSetClampMacro(TranslationAxis, int, -1, 2);
324 
326 
329  void SetXTranslationAxisOn() { this->TranslationAxis = Axis::XAxis; }
330  void SetYTranslationAxisOn() { this->TranslationAxis = Axis::YAxis; }
331  void SetZTranslationAxisOn() { this->TranslationAxis = Axis::ZAxis; }
332  void SetTranslationAxisOff() { this->TranslationAxis = Axis::NONE; }
334 
336 
339  bool IsTranslationConstrained() { return this->TranslationAxis != Axis::NONE; }
341 
342 protected:
344  ~vtkTensorRepresentation() override;
345 
346  // Core data
347  double Tensor[9]; // stored as 3x3 symmetric matrix
348  double Eigenvalues[3];
349  double Eigenvectors[3][3];
350  double TensorPosition[3];
351 
352  // Manage how the representation appears
353  double LastEventPosition[3];
354  double LastEventOrientation[4];
355  double StartEventOrientation[4];
356  double SnappedEventOrientations[3][4];
357  bool SnappedOrientation[3];
359 
360  // Constraint axis translation
362 
363  // the hexahedron (6 faces)
367  vtkPoints* Points; // used by others as well
368  double N[6][3]; // the normals of the faces
369 
370  // A face of the hexahedron
374 
375  // glyphs representing hot spots (e.g., handles)
379  virtual void PositionHandles();
380  int HighlightHandle(vtkProp* prop); // returns cell id
381  void HighlightFace(int cellId);
382  void HighlightOutline(int highlight);
383  virtual void ComputeNormals();
384  virtual void SizeHandles();
385 
386  // wireframe outline
390 
391  // the tensor ellipsoid and transforms
397 
398  // Do the picking
404 
405  // Transform the hexahedral points (used for rotations)
409 
410  // Support GetBounds() method
412 
413  // Properties used to control the appearance of selected objects and
414  // the manipulator in general.
422  virtual void CreateDefaultProperties();
423 
424  // Control the orientation of the normals
425  bool InsideOut;
428  void GenerateOutline();
430  void UpdateTensorFromWidget(); // tensor information updated from widget state
431  void UpdateWidgetFromTensor(); // widget state updated from tensor specification
432  void UpdateTensorEigenfunctions(double tensor[3][3]);
433 
434  // Helper methods
435  virtual void Translate(const double* p1, const double* p2);
436  virtual void Scale(const double* p1, const double* p2, int X, int Y);
437  virtual void Rotate(int X, int Y, const double* p1, const double* p2, const double* vpn);
438  void MovePlusXFace(const double* p1, const double* p2, bool entry);
439  void MoveMinusXFace(const double* p1, const double* p2, bool entry);
440  void MovePlusYFace(const double* p1, const double* p2, bool entry);
441  void MoveMinusYFace(const double* p1, const double* p2, bool entry);
442  void MovePlusZFace(const double* p1, const double* p2, bool entry);
443  void MoveMinusZFace(const double* p1, const double* p2, bool entry);
444  void UpdatePose(const double* p1, const double* d1, const double* p2, const double* d2);
445 
446  // Internal ivars for performance
449 
450  // The actual planes which are being manipulated
451  vtkPlane* Planes[6];
452 
453  //"dir" is the direction in which the face can be moved i.e. the axis passing
454  // through the center
455  void MoveFace(const double* p1, const double* p2, const double* dir, double* x1, double* x2,
456  double* x3, double* x4, double* x5);
457 
458  // Helper method to obtain the direction in which the face is to be moved.
459  // Handles special cases where some of the scale factors are 0.
460  void GetDirection(const double Nx[3], const double Ny[3], const double Nz[3], double dir[3]);
461 
462 private:
464  void operator=(const vtkTensorRepresentation&) = delete;
465 };
466 
467 #endif
vtkPolyDataMapper
map vtkPolyData to graphics primitives
Definition: vtkPolyDataMapper.h:36
vtkPoints
represent and manipulate 3D points
Definition: vtkPoints.h:33
vtkWidgetRepresentation::StartWidgetInteraction
virtual void StartWidgetInteraction(double eventPos[2])
Definition: vtkWidgetRepresentation.h:135
vtkTensorRepresentation::MoveF0
Definition: vtkTensorRepresentation.h:271
vtkWidgetRepresentation.h
vtkPlane
perform various plane computations
Definition: vtkPlane.h:33
vtkTensorRepresentation::EllipsoidTransform
vtkTransform * EllipsoidTransform
Definition: vtkTensorRepresentation.h:393
vtkTensorRepresentation::Translating
Definition: vtkTensorRepresentation.h:277
vtkTensorRepresentation::GetEigenvalues
void GetEigenvalues(double evals[3])
These are methods used to retrieve derived information about the tensor.
Definition: vtkTensorRepresentation.h:113
vtkTensorRepresentation::HexFacePolyData
vtkPolyData * HexFacePolyData
Definition: vtkTensorRepresentation.h:373
vtkTensorRepresentation::SetTranslationAxisOff
void SetTranslationAxisOff()
Definition: vtkTensorRepresentation.h:332
vtkTensorRepresentation::HexFace
vtkActor * HexFace
Definition: vtkTensorRepresentation.h:371
vtkTensorRepresentation::OutlineMapper
vtkPolyDataMapper * OutlineMapper
Definition: vtkTensorRepresentation.h:388
vtkTensorRepresentation::GetTensor
void GetTensor(double tensor[9])
Definition: vtkTensorRepresentation.h:95
vtkTensorRepresentation::TmpPoints
vtkPoints * TmpPoints
Definition: vtkTensorRepresentation.h:408
vtkPointHandleRepresentation3D
represent the position of a point in 3D space
Definition: vtkPointHandleRepresentation3D.h:40
vtkTensorRepresentation::MoveF3
Definition: vtkTensorRepresentation.h:274
vtkTensorRepresentation::TensorEllipsoid
bool TensorEllipsoid
Definition: vtkTensorRepresentation.h:429
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkTensorRepresentation::GetEigenvector
void GetEigenvector(int n, double ev[3])
Definition: vtkTensorRepresentation.h:117
vtkTensorRepresentation::SetZTranslationAxisOn
void SetZTranslationAxisOn()
Definition: vtkTensorRepresentation.h:331
vtkTensorRepresentation::SetXTranslationAxisOn
void SetXTranslationAxisOn()
Toggles constraint translation axis on/off.
Definition: vtkTensorRepresentation.h:329
vtkTensorRepresentation::TranslationAxis
int TranslationAxis
Definition: vtkTensorRepresentation.h:361
vtkWidgetRepresentation
abstract class defines interface between the widget and widget representation classes
Definition: vtkWidgetRepresentation.h:59
vtkTensorRepresentation::OutlineProperty
vtkProperty * OutlineProperty
Definition: vtkTensorRepresentation.h:419
vtkTensorRepresentation::OutlineFaceWiresOn
void OutlineFaceWiresOn()
Definition: vtkTensorRepresentation.h:194
vtkTensorRepresentation::FaceProperty
vtkProperty * FaceProperty
Definition: vtkTensorRepresentation.h:417
vtkX3D::dir
Definition: vtkX3D.h:330
vtkWidgetRepresentation::BuildRepresentation
virtual void BuildRepresentation()=0
vtkTensorRepresentation::OutlinePolyData
vtkPolyData * OutlinePolyData
Definition: vtkTensorRepresentation.h:389
vtkPlanes
implicit function for convex set of planes
Definition: vtkPlanes.h:49
vtkTensorRepresentation::EllipsoidMatrix
vtkMatrix4x4 * EllipsoidMatrix
Definition: vtkTensorRepresentation.h:394
vtkTransform
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:54
vtkTensorRepresentation::CurrentHexFace
int CurrentHexFace
Definition: vtkTensorRepresentation.h:402
vtkWindow
window superclass for vtkRenderWindow
Definition: vtkWindow.h:38
vtkTensorRepresentation::InsideOut
bool InsideOut
Definition: vtkTensorRepresentation.h:425
vtkTensorRepresentation::Handle
vtkActor ** Handle
Definition: vtkTensorRepresentation.h:376
vtkTensorRepresentation::EllipsoidSource
vtkSphereSource * EllipsoidSource
Definition: vtkTensorRepresentation.h:396
vtkAbstractWidget
define the API for widget / widget representation
Definition: vtkAbstractWidget.h:65
vtkX3D::position
Definition: vtkX3D.h:267
vtkWidgetRepresentation::WidgetInteraction
virtual void WidgetInteraction(double newEventPos[2])
Definition: vtkWidgetRepresentation.h:136
vtkWidgetRepresentation::GetBounds
double * GetBounds() override
Methods to make this class behave as a vtkProp.
Definition: vtkWidgetRepresentation.h:208
vtkTensorRepresentation::HandlePicker
vtkCellPicker * HandlePicker
Definition: vtkTensorRepresentation.h:399
vtkTensorRepresentation::EllipsoidMapper
vtkPolyDataMapper * EllipsoidMapper
Definition: vtkTensorRepresentation.h:395
vtkTensorRepresentation::HexActor
vtkActor * HexActor
Definition: vtkTensorRepresentation.h:364
VTK_SIZEHINT
#define VTK_SIZEHINT(...)
Definition: vtkWrappingHints.h:45
vtkTensorRepresentation::HexMapper
vtkPolyDataMapper * HexMapper
Definition: vtkTensorRepresentation.h:365
vtkTensorRepresentation::MoveF2
Definition: vtkTensorRepresentation.h:273
vtkTensorRepresentation::GetPosition
void GetPosition(double pos[3])
Definition: vtkTensorRepresentation.h:131
vtkSphereSource
create a polygonal sphere centered at the origin
Definition: vtkSphereSource.h:41
vtkTensorRepresentation::Rotating
Definition: vtkTensorRepresentation.h:278
vtkTensorRepresentation::OutlineFaceWires
bool OutlineFaceWires
Definition: vtkTensorRepresentation.h:426
vtkTensorRepresentation::OutlineCursorWiresOn
void OutlineCursorWiresOn()
Definition: vtkTensorRepresentation.h:206
vtkActor
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:45
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkMatrix4x4
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:35
vtkWidgetRepresentation::RegisterPickers
virtual void RegisterPickers()
Register internal Pickers in the Picking Manager.
vtkTensorRepresentation::MoveF1
Definition: vtkTensorRepresentation.h:272
vtkTensorRepresentation::HandleMapper
vtkPolyDataMapper ** HandleMapper
Definition: vtkTensorRepresentation.h:377
vtkLineSource
create a line defined by two end points
Definition: vtkLineSource.h:60
vtkTensorRepresentation::PlaneNormals
vtkDoubleArray * PlaneNormals
Definition: vtkTensorRepresentation.h:448
vtkTensorRepresentation::LastPicker
vtkCellPicker * LastPicker
Definition: vtkTensorRepresentation.h:403
vtkRenderWindowInteractor
platform-independent render window interaction including picking and frame rate control.
Definition: vtkRenderWindowInteractor.h:82
vtkTensorRepresentation::SnapToAxes
bool SnapToAxes
Definition: vtkTensorRepresentation.h:358
vtkTensorRepresentation::HexFaceMapper
vtkPolyDataMapper * HexFaceMapper
Definition: vtkTensorRepresentation.h:372
vtkViewport
abstract specification for Viewports
Definition: vtkViewport.h:44
vtkTensorRepresentation::MoveF4
Definition: vtkTensorRepresentation.h:275
vtkTensorRepresentation::OutlineCursorWiresOff
void OutlineCursorWiresOff()
Definition: vtkTensorRepresentation.h:207
vtkTensorRepresentation::GetSymmetricTensor
void GetSymmetricTensor(double symTensor[6])
Definition: vtkTensorRepresentation.h:96
vtkTensorRepresentation::SelectedOutlineProperty
vtkProperty * SelectedOutlineProperty
Definition: vtkTensorRepresentation.h:420
vtkProp
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:56
vtkWidgetRepresentation::PlaceWidget
virtual void PlaceWidget(double *vtkNotUsed(bounds[6]))
The following is a suggested API for widget representations.
vtkTensorRepresentation::SetYTranslationAxisOn
void SetYTranslationAxisOn()
Definition: vtkTensorRepresentation.h:330
vtkBox
implicit function for a bounding box
Definition: vtkBox.h:38
vtkTensorRepresentation::Points
vtkPoints * Points
Definition: vtkTensorRepresentation.h:367
vtkTensorRepresentation::TensorEllipsoidOn
void TensorEllipsoidOn()
Definition: vtkTensorRepresentation.h:225
vtkTensorRepresentation::OutlineFaceWiresOff
void OutlineFaceWiresOff()
Definition: vtkTensorRepresentation.h:195
vtkTensorRepresentation::BoundingBox
vtkBox * BoundingBox
Definition: vtkTensorRepresentation.h:411
vtkTensorRepresentation::PlanePoints
vtkPoints * PlanePoints
Definition: vtkTensorRepresentation.h:447
vtkTensorRepresentation::HexPolyData
vtkPolyData * HexPolyData
Definition: vtkTensorRepresentation.h:366
vtkTensorRepresentation::Matrix
vtkMatrix4x4 * Matrix
Definition: vtkTensorRepresentation.h:407
vtkTensorRepresentation::CurrentHandle
vtkActor * CurrentHandle
Definition: vtkTensorRepresentation.h:401
vtkTensorRepresentation::MoveF5
Definition: vtkTensorRepresentation.h:276
vtkTensorRepresentation::HandleGeometry
vtkSphereSource ** HandleGeometry
Definition: vtkTensorRepresentation.h:378
vtkTensorRepresentation::Transform
vtkTransform * Transform
Definition: vtkTensorRepresentation.h:406
vtkPolyData
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:85
vtkTensorRepresentation
class defining a representation for the vtkTensorWidget
Definition: vtkTensorRepresentation.h:66
vtkTensorRepresentation::EllipsoidActor
vtkActor * EllipsoidActor
Definition: vtkTensorRepresentation.h:392
vtkTensorRepresentation::OutlineCursorWires
bool OutlineCursorWires
Definition: vtkTensorRepresentation.h:427
vtkDoubleArray
dynamic, self-adjusting array of double
Definition: vtkDoubleArray.h:35
vtkTensorRepresentation::SelectedFaceProperty
vtkProperty * SelectedFaceProperty
Definition: vtkTensorRepresentation.h:418
vtkTensorRepresentation::HandleProperty
vtkProperty * HandleProperty
Definition: vtkTensorRepresentation.h:415
vtkProperty
represent surface properties of a geometric object
Definition: vtkProperty.h:61
vtkCellPicker
ray-cast cell picker for all kinds of Prop3Ds
Definition: vtkCellPicker.h:66
vtkTensorRepresentation::SelectedHandleProperty
vtkProperty * SelectedHandleProperty
Definition: vtkTensorRepresentation.h:416
vtkTensorRepresentation::HexPicker
vtkCellPicker * HexPicker
Definition: vtkTensorRepresentation.h:400
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkTensorRepresentation::IsTranslationConstrained
bool IsTranslationConstrained()
Returns true if ContrainedAxis.
Definition: vtkTensorRepresentation.h:339
vtkTensorRepresentation::EllipsoidProperty
vtkProperty * EllipsoidProperty
Definition: vtkTensorRepresentation.h:421
vtkWidgetRepresentation::ComputeInteractionState
virtual int ComputeInteractionState(int X, int Y, int modify=0)
vtkTensorRepresentation::HexOutline
vtkActor * HexOutline
Definition: vtkTensorRepresentation.h:387
vtkTensorRepresentation::TensorEllipsoidOff
void TensorEllipsoidOff()
Definition: vtkTensorRepresentation.h:226
vtkWidgetRepresentation::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkPolyDataAlgorithm
Superclass for algorithms that produce only polydata as output.
Definition: vtkPolyDataAlgorithm.h:41