VTK  9.3.20240722
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
41VTK_ABI_NAMESPACE_BEGIN
42class vtkActor;
44class vtkLineSource;
45class vtkSphereSource;
46class vtkCellPicker;
47class vtkProperty;
48class vtkPolyData;
49class vtkPoints;
52class vtkTransform;
53class vtkMatrix4x4;
54class vtkPlane;
55class vtkPlanes;
56class vtkBox;
57class vtkDoubleArray;
58
59class VTKINTERACTIONWIDGETS_EXPORT VTK_MARSHALAUTO vtkTensorRepresentation
61{
62public:
64
69 void PrintSelf(ostream& os, vtkIndent indent) override;
71
73
87 void SetTensor(double tensor[9]);
88 void SetSymmetricTensor(double symTensor[6]);
89 void GetTensor(double tensor[9]) { std::copy(this->Tensor, this->Tensor + 9, tensor); }
90 void GetSymmetricTensor(double symTensor[6])
91 {
92 symTensor[0] = this->Tensor[0];
93 symTensor[1] = this->Tensor[4];
94 symTensor[2] = this->Tensor[8];
95 symTensor[3] = this->Tensor[1];
96 symTensor[4] = this->Tensor[2];
97 symTensor[5] = this->Tensor[5];
98 }
100
102
107 void GetEigenvalues(double evals[3])
108 {
109 std::copy(this->Eigenvalues, this->Eigenvalues + 3, evals);
110 }
111 void GetEigenvector(int n, double ev[3])
112 {
113 n = (n < 0 ? 0 : (n > 2 ? 2 : n));
114 std::copy(this->Eigenvectors[n], this->Eigenvectors[n] + 3, ev);
115 }
117
119
124 void SetPosition(double pos[3]);
125 void GetPosition(double pos[3])
126 {
127 std::copy(this->TensorPosition, this->TensorPosition + 3, pos);
128 }
130
142
144
149 vtkGetObjectMacro(HandleProperty, vtkProperty);
150 vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
152
154
159 vtkGetObjectMacro(FaceProperty, vtkProperty);
160 vtkGetObjectMacro(SelectedFaceProperty, vtkProperty);
162
164
169 vtkGetObjectMacro(OutlineProperty, vtkProperty);
170 vtkGetObjectMacro(SelectedOutlineProperty, vtkProperty);
172
174
178 vtkGetObjectMacro(EllipsoidProperty, vtkProperty);
180
182
187 vtkGetMacro(OutlineFaceWires, bool);
188 void OutlineFaceWiresOn() { this->SetOutlineFaceWires(true); }
189 void OutlineFaceWiresOff() { this->SetOutlineFaceWires(false); }
191
193
199 vtkGetMacro(OutlineCursorWires, bool);
200 void OutlineCursorWiresOn() { this->SetOutlineCursorWires(true); }
201 void OutlineCursorWiresOff() { this->SetOutlineCursorWires(false); }
203
205
209 virtual void HandlesOn();
210 virtual void HandlesOff();
212
214
218 vtkGetMacro(TensorEllipsoid, bool);
219 void TensorEllipsoidOn() { this->SetTensorEllipsoid(true); }
220 void TensorEllipsoidOff() { this->SetTensorEllipsoid(false); }
222
229 void PlaceTensor(double tensor[9], double position[3]);
230
232
235 void PlaceWidget(double bounds[6]) override;
236 void BuildRepresentation() override;
237 int ComputeInteractionState(int X, int Y, int modify = 0) override;
238 void StartWidgetInteraction(double e[2]) override;
239 void WidgetInteraction(double e[2]) override;
240 double* GetBounds() VTK_SIZEHINT(6) override;
241 void StartComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
242 unsigned long event, void* calldata) override;
243 void ComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
244 unsigned long event, void* calldata) override;
245 int ComputeComplexInteractionState(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
246 unsigned long event, void* calldata, int modify = 0) override;
247 void EndComplexInteraction(vtkRenderWindowInteractor* iren, vtkAbstractWidget* widget,
248 unsigned long event, void* calldata) override;
250
252
255 void ReleaseGraphicsResources(vtkWindow*) override;
256 int RenderOpaqueGeometry(vtkViewport*) override;
257 int RenderTranslucentPolygonalGeometry(vtkViewport*) override;
258 vtkTypeBool HasTranslucentPolygonalGeometry() override;
260
261 // Used to manage the state of the widget
262 enum
263 {
264 Outside = 0,
273 Scaling
274 };
275
285 void SetInteractionState(int state);
286
288
292 vtkGetMacro(SnapToAxes, bool);
293 vtkSetMacro(SnapToAxes, bool);
295
297
304
305 /*
306 * Register internal Pickers within PickingManager
307 */
308 void RegisterPickers() override;
309
311
315 vtkGetMacro(TranslationAxis, int);
316 vtkSetClampMacro(TranslationAxis, int, -1, 2);
318
320
323 void SetXTranslationAxisOn() { this->TranslationAxis = Axis::XAxis; }
324 void SetYTranslationAxisOn() { this->TranslationAxis = Axis::YAxis; }
325 void SetZTranslationAxisOn() { this->TranslationAxis = Axis::ZAxis; }
326 void SetTranslationAxisOff() { this->TranslationAxis = Axis::NONE; }
328
330
333 bool IsTranslationConstrained() { return this->TranslationAxis != Axis::NONE; }
335
336protected:
339
340 // Core data
341 double Tensor[9]; // stored as 3x3 symmetric matrix
342 double Eigenvalues[3];
343 double Eigenvectors[3][3];
344 double TensorPosition[3];
345
346 // Manage how the representation appears
347 double LastEventPosition[3];
348 double LastEventOrientation[4];
349 double StartEventOrientation[4];
350 double SnappedEventOrientations[3][4];
351 bool SnappedOrientation[3];
353
354 // Constraint axis translation
356
357 // the hexahedron (6 faces)
361 vtkPoints* Points; // used by others as well
362 double N[6][3]; // the normals of the faces
363
364 // A face of the hexahedron
368
369 // glyphs representing hot spots (e.g., handles)
373 virtual void PositionHandles();
374 int HighlightHandle(vtkProp* prop); // returns cell id
375 void HighlightFace(int cellId);
376 void HighlightOutline(int highlight);
377 virtual void ComputeNormals();
378 virtual void SizeHandles();
379
380 // wireframe outline
384
385 // the tensor ellipsoid and transforms
391
392 // Do the picking
398
399 // Transform the hexahedral points (used for rotations)
403
404 // Support GetBounds() method
406
407 // Properties used to control the appearance of selected objects and
408 // the manipulator in general.
417
418 // Control the orientation of the normals
424 void UpdateTensorFromWidget(); // tensor information updated from widget state
425 void UpdateWidgetFromTensor(); // widget state updated from tensor specification
426 void UpdateTensorEigenfunctions(double tensor[3][3]);
427
428 // Helper methods
429 virtual void Translate(const double* p1, const double* p2);
430 virtual void Scale(const double* p1, const double* p2, int X, int Y);
431 virtual void Rotate(int X, int Y, const double* p1, const double* p2, const double* vpn);
432 void MovePlusXFace(const double* p1, const double* p2, bool entry);
433 void MoveMinusXFace(const double* p1, const double* p2, bool entry);
434 void MovePlusYFace(const double* p1, const double* p2, bool entry);
435 void MoveMinusYFace(const double* p1, const double* p2, bool entry);
436 void MovePlusZFace(const double* p1, const double* p2, bool entry);
437 void MoveMinusZFace(const double* p1, const double* p2, bool entry);
438 void UpdatePose(const double* p1, const double* d1, const double* p2, const double* d2);
439
440 // Internal ivars for performance
443
444 // The actual planes which are being manipulated
445 vtkPlane* Planes[6];
446
447 //"dir" is the direction in which the face can be moved i.e. the axis passing
448 // through the center
449 void MoveFace(const double* p1, const double* p2, const double* dir, double* x1, double* x2,
450 double* x3, double* x4, double* x5);
451
452 // Helper method to obtain the direction in which the face is to be moved.
453 // Handles special cases where some of the scale factors are 0.
454 void GetDirection(const double Nx[3], const double Ny[3], const double Nz[3], double dir[3]);
455
456private:
458 void operator=(const vtkTensorRepresentation&) = delete;
459};
460
461VTK_ABI_NAMESPACE_END
462#endif
define the API for widget / widget representation
represents an object (geometry & properties) in a rendered scene
Definition vtkActor.h:151
implicit function for a bounding box
Definition vtkBox.h:110
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:108
create a line defined by two end points
represent and manipulate 4x4 transformation matrices
perform various plane computations
Definition vtkPlane.h:135
implicit function for convex set of planes
Definition vtkPlanes.h:151
represent the position of a point in 3D space
represent and manipulate 3D points
Definition vtkPoints.h:139
Superclass for algorithms that produce only polydata as output.
map vtkPolyData to graphics primitives
concrete dataset represents vertices, lines, polygons, and triangle strips
abstract superclass for all actors, volumes and annotations
Definition vtkProp.h:66
represent surface properties of a geometric object
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
void TensorEllipsoidOn()
Indicate whether to show the tensor ellipsoid.
virtual void PositionHandles()
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.
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.
static vtkTensorRepresentation * New()
Standard methods for instantiation, obtaining type information, and printing.
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...
double * GetBounds() override
These are methods that satisfy vtkWidgetRepresentation's API.
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.
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
abstract specification for Viewports
Definition vtkViewport.h:65
abstract class defines interface between the widget and widget representation classes
window superclass for vtkRenderWindow
Definition vtkWindow.h:48
int vtkTypeBool
Definition vtkABI.h:64
#define VTK_SIZEHINT(...)
#define VTK_MARSHALAUTO