1 | /*========================================================================= |
---|
2 | |
---|
3 | Program: Visualization Toolkit |
---|
4 | Module: vtkRpAxisFollower.cxx |
---|
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 | =========================================================================*/ |
---|
15 | // .NAME vtkRpAxisFollower - a subclass of vtkFollower that ensures that |
---|
16 | // data is always parallel to the axis defined by a vtkRpAxisActor. |
---|
17 | // .SECTION Description |
---|
18 | // vtkRpAxisFollower is a subclass of vtkFollower that always follows its |
---|
19 | // specified axis. More specifically it will not change its position or scale, |
---|
20 | // but it will continually update its orientation so that it is aliged with the |
---|
21 | // axis and facing at angle to the camera to provide maximum visibilty. |
---|
22 | // This is typically used for text labels for 3d plots. |
---|
23 | // .SECTION see also |
---|
24 | // vtkActor vtkFollower vtkCamera vtkRpAxisActor vtkCubeAxesActor |
---|
25 | |
---|
26 | |
---|
27 | #ifndef vtkRpAxisFollower_h |
---|
28 | #define vtkRpAxisFollower_h |
---|
29 | |
---|
30 | #include "vtkRenderingAnnotationModule.h" // For export macro |
---|
31 | #include "vtkFollower.h" |
---|
32 | |
---|
33 | #include "vtkWeakPointer.h" // For vtkWeakPointer |
---|
34 | |
---|
35 | // Forward declarations. |
---|
36 | class vtkRpAxisActor; |
---|
37 | class vtkRenderer; |
---|
38 | |
---|
39 | class VTKRENDERINGANNOTATION_EXPORT vtkRpAxisFollower : public vtkFollower |
---|
40 | { |
---|
41 | public: |
---|
42 | vtkTypeMacro(vtkRpAxisFollower,vtkFollower); |
---|
43 | virtual void PrintSelf(ostream& os, vtkIndent indent); |
---|
44 | |
---|
45 | // Description: |
---|
46 | // Creates a follower with no camera set |
---|
47 | static vtkRpAxisFollower *New(); |
---|
48 | |
---|
49 | // Description: |
---|
50 | // Set axis that needs to be followed. |
---|
51 | virtual void SetAxis(vtkRpAxisActor*); |
---|
52 | virtual vtkRpAxisActor* GetAxis(); |
---|
53 | |
---|
54 | // Description: |
---|
55 | // Set/Get state of auto center mode where additional |
---|
56 | // translation will be added to make sure the underlying |
---|
57 | // geometry has its pivot point at the center of its bounds. |
---|
58 | vtkSetMacro(AutoCenter, int); |
---|
59 | vtkGetMacro(AutoCenter, int); |
---|
60 | vtkBooleanMacro(AutoCenter, int); |
---|
61 | |
---|
62 | // Description: |
---|
63 | // Enable / disable use of distance based LOD. If enabled the actor |
---|
64 | // will not be visible at a certain distance from the camera. |
---|
65 | // Default is false. |
---|
66 | vtkSetMacro(EnableDistanceLOD, int); |
---|
67 | vtkGetMacro(EnableDistanceLOD, int); |
---|
68 | |
---|
69 | // Description: |
---|
70 | // Set distance LOD threshold (0.0 - 1.0).This determines at what fraction |
---|
71 | // of camera far clip range, actor is not visible. |
---|
72 | // Default is 0.80. |
---|
73 | vtkSetClampMacro(DistanceLODThreshold, double, 0.0, 1.0); |
---|
74 | vtkGetMacro(DistanceLODThreshold, double); |
---|
75 | |
---|
76 | // Description: |
---|
77 | // Enable / disable use of view angle based LOD. If enabled the actor |
---|
78 | // will not be visible at a certain view angle. |
---|
79 | // Default is true. |
---|
80 | vtkSetMacro(EnableViewAngleLOD, int); |
---|
81 | vtkGetMacro(EnableViewAngleLOD, int); |
---|
82 | |
---|
83 | // Description: |
---|
84 | // Set view angle LOD threshold (0.0 - 1.0).This determines at what view |
---|
85 | // angle to geometry will make the geometry not visibile. |
---|
86 | // Default is 0.34. |
---|
87 | vtkSetClampMacro(ViewAngleLODThreshold, double, 0.0, 1.0); |
---|
88 | vtkGetMacro(ViewAngleLODThreshold, double); |
---|
89 | |
---|
90 | // Description: |
---|
91 | // Set/Get the desired screen offset from the axis. |
---|
92 | vtkSetMacro(ScreenOffset, double); |
---|
93 | vtkGetMacro(ScreenOffset, double); |
---|
94 | |
---|
95 | // Description: |
---|
96 | // This causes the actor to be rendered. It in turn will render the actor's |
---|
97 | // property, texture map and then mapper. If a property hasn't been |
---|
98 | // assigned, then the actor will create one automatically. |
---|
99 | virtual int RenderOpaqueGeometry(vtkViewport *viewport); |
---|
100 | virtual int RenderTranslucentPolygonalGeometry(vtkViewport *viewport); |
---|
101 | virtual void Render(vtkRenderer *ren); |
---|
102 | |
---|
103 | // Description: |
---|
104 | // Generate the matrix based on ivars. This method overloads its superclasses |
---|
105 | // ComputeMatrix() method due to the special vtkFollower matrix operations. |
---|
106 | virtual void ComputeTransformMatrix(vtkRenderer *ren); |
---|
107 | |
---|
108 | // Description: |
---|
109 | // Shallow copy of a follower. Overloads the virtual vtkProp method. |
---|
110 | void ShallowCopy(vtkProp *prop); |
---|
111 | |
---|
112 | // Description: |
---|
113 | // Calculate scale factor to maintain same size of a object |
---|
114 | // on the screen. |
---|
115 | static double AutoScale(vtkViewport *viewport, vtkCamera * camera, |
---|
116 | double screenSize, double position[3]); |
---|
117 | |
---|
118 | protected: |
---|
119 | vtkRpAxisFollower(); |
---|
120 | ~vtkRpAxisFollower(); |
---|
121 | |
---|
122 | void CalculateOrthogonalVectors(double Rx[3], double Ry[3], double Rz[3], |
---|
123 | vtkRpAxisActor *axis1, double *dop, |
---|
124 | vtkRenderer *ren); |
---|
125 | |
---|
126 | |
---|
127 | void ComputeRotationAndTranlation(vtkRenderer *ren, double translation[3], |
---|
128 | double Rx[3], double Ry[3], double Rz[3], |
---|
129 | vtkRpAxisActor *axis); |
---|
130 | |
---|
131 | // \NOTE: Not used as of now. |
---|
132 | void ComputerAutoCenterTranslation(const double& autoScaleFactor, |
---|
133 | double translation[3]); |
---|
134 | |
---|
135 | |
---|
136 | int TestDistanceVisibility(); |
---|
137 | void ExecuteViewAngleVisibility(double normal[3]); |
---|
138 | |
---|
139 | bool IsTextUpsideDown(double* a, double* b); |
---|
140 | |
---|
141 | int AutoCenter; |
---|
142 | |
---|
143 | int EnableDistanceLOD; |
---|
144 | double DistanceLODThreshold; |
---|
145 | |
---|
146 | int EnableViewAngleLOD; |
---|
147 | double ViewAngleLODThreshold; |
---|
148 | |
---|
149 | double ScreenOffset; |
---|
150 | |
---|
151 | vtkWeakPointer<vtkRpAxisActor> Axis; |
---|
152 | |
---|
153 | |
---|
154 | private: |
---|
155 | |
---|
156 | int TextUpsideDown; |
---|
157 | int VisibleAtCurrentViewAngle; |
---|
158 | |
---|
159 | vtkRpAxisFollower(const vtkRpAxisFollower&); // Not implemented. |
---|
160 | void operator =(const vtkRpAxisFollower&); // Not implemented. |
---|
161 | |
---|
162 | // hide the two parameter Render() method from the user and the compiler. |
---|
163 | virtual void Render(vtkRenderer *, vtkMapper *) {} |
---|
164 | |
---|
165 | //Internal matrices to avoid New/Delete for performance reasons |
---|
166 | vtkMatrix4x4 *InternalMatrix; |
---|
167 | |
---|
168 | }; |
---|
169 | |
---|
170 | #endif // vtkRpAxisFollower_h |
---|