1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkAxesActor.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 =========================================================================*/
15 /**
16  * @class   vtkAxesActor
17  * @brief   a 3D axes representation
18  *
19  * vtkAxesActor is a hybrid 2D/3D actor used to represent 3D axes in a scene.
20  * The user can define the geometry to use for the shaft or the tip, and the
21  * user can set the text for the three axes. The text will appear to follow the
22  * camera since it is implemented by means of vtkCaptionActor2D.  All of the
23  * functionality of the underlying vtkCaptionActor2D objects are accessible so
24  * that, for instance, the font attributes of the axes text can be manipulated
25  * through vtkTextProperty. Since this class inherits from vtkProp3D, one can
26  * apply a user transform to the underlying geometry and the positioning of the
27  * labels. For example, a rotation transform could be used to generate a
28  * left-handed axes representation.
29  *
30  * @par Thanks:
31  * Thanks to Goodwin Lawlor for posting a tcl script which featured the
32  * use of vtkCaptionActor2D to implement the text labels.  This class is
33  * based on Paraview's vtkPVAxesActor.
34  *
35  * @warning
36  * vtkAxesActor is primarily intended for use with vtkOrientationMarkerWidget.
37  * The bounds of this actor are calculated as though the geometry of the axes
38  * were symmetric: that is, although only positive axes are visible, bounds
39  * are calculated as though negative axes are present too.  This is done
40  * intentionally to implement functionality of the camera update mechanism
41  * in vtkOrientationMarkerWidget.
42  *
43  * @sa
44  * vtkAnnotatedCubeActor vtkOrientationMarkerWidget vtkCaptionActor2D
45  * vtkTextProperty
46 */
47 
48 #ifndef vtkAxesActor_h
49 #define vtkAxesActor_h
50 
51 #include "vtkRenderingAnnotationModule.h" // For export macro
52 #include "vtkProp3D.h"
53 
54 class vtkActor;
55 class vtkCaptionActor2D;
56 class vtkConeSource;
57 class vtkCylinderSource;
58 class vtkLineSource;
59 class vtkPolyData;
60 class vtkPropCollection;
61 class vtkProperty;
62 class vtkRenderer;
63 class vtkSphereSource;
64 
65 class VTKRENDERINGANNOTATION_EXPORT vtkAxesActor : public vtkProp3D
66 {
67 public:
68   static vtkAxesActor *New();
69   vtkTypeMacro(vtkAxesActor,vtkProp3D);
70   void PrintSelf(ostream& os, vtkIndent indent) override;
71 
72   /**
73    * For some exporters and other other operations we must be
74    * able to collect all the actors or volumes. These methods
75    * are used in that process.
76    */
77   void GetActors(vtkPropCollection *) override;
78 
79   //@{
80   /**
81    * Support the standard render methods.
82    */
83   int RenderOpaqueGeometry(vtkViewport *viewport) override;
84   int RenderTranslucentPolygonalGeometry(vtkViewport *viewport) override;
85   int RenderOverlay(vtkViewport *viewport) override;
86   //@}
87 
88   /**
89    * Does this prop have some translucent polygonal geometry?
90    */
91   vtkTypeBool HasTranslucentPolygonalGeometry() override;
92 
93   /**
94    * Shallow copy of an axes actor. Overloads the virtual vtkProp method.
95    */
96   void ShallowCopy(vtkProp *prop) override;
97 
98   /**
99    * Release any graphics resources that are being consumed by this actor.
100    * The parameter window could be used to determine which graphic
101    * resources to release.
102    */
103   void ReleaseGraphicsResources(vtkWindow *) override;
104 
105   //@{
106   /**
107    * Get the bounds for this Actor as (Xmin,Xmax,Ymin,Ymax,Zmin,Zmax). (The
108    * method GetBounds(double bounds[6]) is available from the superclass.)
109    */
110   void GetBounds(double bounds[6]);
111   double *GetBounds() VTK_SIZEHINT(6) override;
112   //@}
113 
114   /**
115    * Get the actors mtime plus consider its properties and texture if set.
116    */
117   vtkMTimeType GetMTime() override;
118 
119   /**
120    * Return the mtime of anything that would cause the rendered image to
121    * appear differently. Usually this involves checking the mtime of the
122    * prop plus anything else it depends on such as properties, textures
123    * etc.
124    */
125   vtkMTimeType GetRedrawMTime() override;
126 
127   //@{
128   /**
129    * Set the total length of the axes in 3 dimensions.
130    */
SetTotalLength(double v[3])131   void SetTotalLength( double v[3] )
132     { this->SetTotalLength( v[0], v[1], v[2] ); }
133   void SetTotalLength( double x, double y, double z );
134   vtkGetVectorMacro( TotalLength, double, 3 );
135   //@}
136 
137   //@{
138   /**
139    * Set the normalized (0-1) length of the shaft.
140    */
SetNormalizedShaftLength(double v[3])141   void SetNormalizedShaftLength( double v[3] )
142     { this->SetNormalizedShaftLength( v[0], v[1], v[2] ); }
143   void SetNormalizedShaftLength( double x, double y, double z );
144   vtkGetVectorMacro( NormalizedShaftLength, double, 3 );
145   //@}
146 
147   //@{
148   /**
149    * Set the normalized (0-1) length of the tip.  Normally, this would be
150    * 1 - the normalized length of the shaft.
151    */
SetNormalizedTipLength(double v[3])152   void SetNormalizedTipLength( double v[3] )
153     { this->SetNormalizedTipLength( v[0], v[1], v[2] ); }
154   void SetNormalizedTipLength( double x, double y, double z );
155   vtkGetVectorMacro( NormalizedTipLength, double, 3 );
156   //@}
157 
158   //@{
159   /**
160    * Set the normalized (0-1) position of the label along the length of
161    * the shaft.  A value > 1 is permissible.
162    */
SetNormalizedLabelPosition(double v[3])163   void SetNormalizedLabelPosition( double v[3] )
164     { this->SetNormalizedLabelPosition( v[0], v[1], v[2] ); }
165   void SetNormalizedLabelPosition( double x, double y, double z );
166   vtkGetVectorMacro( NormalizedLabelPosition, double, 3 );
167   //@}
168 
169   //@{
170   /**
171    * Set/get the resolution of the pieces of the axes actor.
172    */
173   vtkSetClampMacro(ConeResolution, int, 3, 128);
174   vtkGetMacro(ConeResolution, int);
175   vtkSetClampMacro(SphereResolution, int, 3, 128);
176   vtkGetMacro(SphereResolution, int);
177   vtkSetClampMacro(CylinderResolution, int, 3, 128);
178   vtkGetMacro(CylinderResolution, int);
179   //@}
180 
181   //@{
182   /**
183    * Set/get the radius of the pieces of the axes actor.
184    */
185   vtkSetClampMacro(ConeRadius, double, 0, VTK_FLOAT_MAX);
186   vtkGetMacro(ConeRadius, double);
187   vtkSetClampMacro(SphereRadius, double, 0, VTK_FLOAT_MAX);
188   vtkGetMacro(SphereRadius, double);
189   vtkSetClampMacro(CylinderRadius, double, 0, VTK_FLOAT_MAX);
190   vtkGetMacro(CylinderRadius, double);
191   //@}
192 
193   //@{
194   /**
195    * Set the type of the shaft to a cylinder, line, or user defined geometry.
196    */
197   void SetShaftType( int type );
SetShaftTypeToCylinder()198   void SetShaftTypeToCylinder()
199     { this->SetShaftType( vtkAxesActor::CYLINDER_SHAFT ); }
SetShaftTypeToLine()200   void SetShaftTypeToLine()
201     { this->SetShaftType( vtkAxesActor::LINE_SHAFT ); }
SetShaftTypeToUserDefined()202   void SetShaftTypeToUserDefined()
203     { this->SetShaftType( vtkAxesActor::USER_DEFINED_SHAFT ); }
204   vtkGetMacro(ShaftType, int);
205   //@}
206 
207   //@{
208   /**
209    * Set the type of the tip to a cone, sphere, or user defined geometry.
210    */
211   void SetTipType( int type );
SetTipTypeToCone()212   void SetTipTypeToCone()
213     { this->SetTipType( vtkAxesActor::CONE_TIP ); }
SetTipTypeToSphere()214   void SetTipTypeToSphere()
215     { this->SetTipType( vtkAxesActor::SPHERE_TIP ); }
SetTipTypeToUserDefined()216   void SetTipTypeToUserDefined()
217     { this->SetTipType( vtkAxesActor::USER_DEFINED_TIP ); }
218   vtkGetMacro(TipType, int);
219   //@}
220 
221   //@{
222   /**
223    * Set the user defined tip polydata.
224    */
225   void SetUserDefinedTip( vtkPolyData * );
226   vtkGetObjectMacro( UserDefinedTip, vtkPolyData );
227   //@}
228 
229   //@{
230   /**
231    * Set the user defined shaft polydata.
232    */
233   void SetUserDefinedShaft( vtkPolyData * );
234   vtkGetObjectMacro( UserDefinedShaft, vtkPolyData );
235   //@}
236 
237   //@{
238   /**
239    * Get the tip properties.
240    */
241   vtkProperty *GetXAxisTipProperty();
242   vtkProperty *GetYAxisTipProperty();
243   vtkProperty *GetZAxisTipProperty();
244   //@}
245 
246   //@{
247   /**
248    * Get the shaft properties.
249    */
250   vtkProperty *GetXAxisShaftProperty();
251   vtkProperty *GetYAxisShaftProperty();
252   vtkProperty *GetZAxisShaftProperty();
253   //@}
254 
255   /**
256    * Retrieve handles to the X, Y and Z axis (so that you can set their text
257    * properties for example)
258    */
GetXAxisCaptionActor2D()259   vtkCaptionActor2D *GetXAxisCaptionActor2D()
260     {return this->XAxisLabel;}
GetYAxisCaptionActor2D()261   vtkCaptionActor2D *GetYAxisCaptionActor2D()
262     {return this->YAxisLabel;}
GetZAxisCaptionActor2D()263   vtkCaptionActor2D *GetZAxisCaptionActor2D()
264     {return this->ZAxisLabel;}
265 
266   //@{
267   /**
268    * Set/get the label text.
269    */
270   vtkSetStringMacro( XAxisLabelText );
271   vtkGetStringMacro( XAxisLabelText );
272   vtkSetStringMacro( YAxisLabelText );
273   vtkGetStringMacro( YAxisLabelText );
274   vtkSetStringMacro( ZAxisLabelText );
275   vtkGetStringMacro( ZAxisLabelText );
276   //@}
277 
278   //@{
279   /**
280    * Enable/disable drawing the axis labels.
281    */
282   vtkSetMacro(AxisLabels, vtkTypeBool);
283   vtkGetMacro(AxisLabels, vtkTypeBool);
284   vtkBooleanMacro(AxisLabels, vtkTypeBool);
285   //@}
286 
287   enum
288   {
289     CYLINDER_SHAFT,
290     LINE_SHAFT,
291     USER_DEFINED_SHAFT
292   };
293 
294   enum
295   {
296     CONE_TIP,
297     SPHERE_TIP,
298     USER_DEFINED_TIP
299   };
300 
301 protected:
302   vtkAxesActor();
303   ~vtkAxesActor() override;
304 
305   vtkCylinderSource *CylinderSource;
306   vtkLineSource     *LineSource;
307   vtkConeSource     *ConeSource;
308   vtkSphereSource   *SphereSource;
309 
310   vtkActor          *XAxisShaft;
311   vtkActor          *YAxisShaft;
312   vtkActor          *ZAxisShaft;
313 
314   vtkActor          *XAxisTip;
315   vtkActor          *YAxisTip;
316   vtkActor          *ZAxisTip;
317 
318   void               UpdateProps();
319 
320   double             TotalLength[3];
321   double             NormalizedShaftLength[3];
322   double             NormalizedTipLength[3];
323   double             NormalizedLabelPosition[3];
324 
325   int                ShaftType;
326   int                TipType;
327 
328   vtkPolyData       *UserDefinedTip;
329   vtkPolyData       *UserDefinedShaft;
330 
331   char              *XAxisLabelText;
332   char              *YAxisLabelText;
333   char              *ZAxisLabelText;
334 
335   vtkCaptionActor2D *XAxisLabel;
336   vtkCaptionActor2D *YAxisLabel;
337   vtkCaptionActor2D *ZAxisLabel;
338 
339   vtkTypeBool        AxisLabels;
340 
341 
342   int                ConeResolution;
343   int                SphereResolution;
344   int                CylinderResolution;
345 
346   double             ConeRadius;
347   double             SphereRadius;
348   double             CylinderRadius;
349 
350 private:
351   vtkAxesActor(const vtkAxesActor&) = delete;
352   void operator=(const vtkAxesActor&) = delete;
353 };
354 
355 #endif
356 
357