1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkAxesTransformRepresentation.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   vtkAxesTransformRepresentation
17  * @brief   represent the vtkAxesTransformWidget
18  *
19  * The vtkAxesTransformRepresentation is a representation for the
20  * vtkAxesTransformWidget. This representation consists of a origin sphere
21  * with three tubed axes with cones at the end of the axes. In addition an
22  * optional label provides delta values of motion. Note that this particular
23  * widget draws its representation in 3D space, so the widget can be
24  * occluded.
25  * @sa
26  * vtkDistanceWidget vtkDistanceRepresentation vtkDistanceRepresentation2D
27  */
28 
29 #ifndef vtkAxesTransformRepresentation_h
30 #define vtkAxesTransformRepresentation_h
31 
32 #include "vtkInteractionWidgetsModule.h" // For export macro
33 #include "vtkWidgetRepresentation.h"
34 
35 class vtkHandleRepresentation;
36 class vtkPoints;
37 class vtkPolyData;
38 class vtkPolyDataMapper;
39 class vtkActor;
40 class vtkVectorText;
41 class vtkFollower;
42 class vtkBox;
43 class vtkCylinderSource;
44 class vtkGlyph3D;
45 class vtkDoubleArray;
46 class vtkTransformPolyDataFilter;
47 class vtkProperty;
48 
49 class VTKINTERACTIONWIDGETS_EXPORT vtkAxesTransformRepresentation : public vtkWidgetRepresentation
50 {
51 public:
52   /**
53    * Instantiate class.
54    */
55   static vtkAxesTransformRepresentation* New();
56 
57   ///@{
58   /**
59    * Standard VTK methods.
60    */
61   vtkTypeMacro(vtkAxesTransformRepresentation, vtkWidgetRepresentation);
62   void PrintSelf(ostream& os, vtkIndent indent) override;
63   ///@}
64 
65   ///@{
66   /**
67    * Set/Get the two handle representations used for the
68    * vtkAxesTransformWidget. (Note: properties can be set by grabbing these
69    * representations and setting the properties appropriately.)
70    */
71   vtkGetObjectMacro(OriginRepresentation, vtkHandleRepresentation);
72   vtkGetObjectMacro(SelectionRepresentation, vtkHandleRepresentation);
73   ///@}
74 
75   ///@{
76   /**
77    * Methods to Set/Get the coordinates of the two points defining
78    * this representation. Note that methods are available for both
79    * display and world coordinates.
80    */
81   double* GetOriginWorldPosition();
82   void GetOriginWorldPosition(double pos[3]);
83   void SetOriginWorldPosition(double pos[3]);
84   void SetOriginDisplayPosition(double pos[3]);
85   void GetOriginDisplayPosition(double pos[3]);
86   ///@}
87 
88   /**
89    * Specify a scale to control the size of the widget. Large values make the
90    * the widget larger.
91    */
92 
93   ///@{
94   /**
95    * The tolerance representing the distance to the widget (in pixels) in
96    * which the cursor is considered near enough to the end points of
97    * the widget to be active.
98    */
99   vtkSetClampMacro(Tolerance, int, 1, 100);
100   vtkGetMacro(Tolerance, int);
101   ///@}
102 
103   ///@{
104   /**
105    * Specify the format to use for labelling information during
106    * transformation. Note that an empty string results in no label, or a
107    * format string without a "%" character will not print numeric values.
108    */
109   vtkSetStringMacro(LabelFormat);
110   vtkGetStringMacro(LabelFormat);
111   ///@}
112 
113   /**
114    * Enum used to communicate interaction state.
115    */
116   enum
117   {
118     Outside = 0,
119     OnOrigin,
120     OnX,
121     OnY,
122     OnZ,
123     OnXEnd,
124     OnYEnd,
125     OnZEnd
126   };
127 
128   ///@{
129   /**
130    * The interaction state may be set from a widget (e.g., vtkLineWidget2) or
131    * other object. This controls how the interaction with the widget
132    * proceeds. Normally this method is used as part of a handshaking
133    * process with the widget: First ComputeInteractionState() is invoked that
134    * returns a state based on geometric considerations (i.e., cursor near a
135    * widget feature), then based on events, the widget may modify this
136    * further.
137    */
138   vtkSetClampMacro(InteractionState, int, Outside, OnZEnd);
139   ///@}
140 
141   ///@{
142   /**
143    * Method to satisfy superclasses' API.
144    */
145   void BuildRepresentation() override;
146   int ComputeInteractionState(int X, int Y, int modify = 0) override;
147   void StartWidgetInteraction(double e[2]) override;
148   void WidgetInteraction(double e[2]) override;
149   double* GetBounds() override;
150   ///@}
151 
152   ///@{
153   /**
154    * Methods required by vtkProp superclass.
155    */
156   void ReleaseGraphicsResources(vtkWindow* w) override;
157   int RenderOpaqueGeometry(vtkViewport* viewport) override;
158   int RenderTranslucentPolygonalGeometry(vtkViewport* viewport) override;
159   ///@}
160 
161   ///@{
162   /**
163    * Scale text (font size along each dimension). This helps control
164    * the appearance of the 3D text.
165    */
SetLabelScale(double x,double y,double z)166   void SetLabelScale(double x, double y, double z)
167   {
168     double scale[3];
169     scale[0] = x;
170     scale[1] = y;
171     scale[2] = z;
172     this->SetLabelScale(scale);
173   }
174   virtual void SetLabelScale(double scale[3]);
175   virtual double* GetLabelScale();
176   ///@}
177 
178   /**
179    * Get the distance annotation property
180    */
181   virtual vtkProperty* GetLabelProperty();
182 
183 protected:
184   vtkAxesTransformRepresentation();
185   ~vtkAxesTransformRepresentation() override;
186 
187   // The handle and the rep used to close the handles
188   vtkHandleRepresentation* OriginRepresentation;
189   vtkHandleRepresentation* SelectionRepresentation;
190 
191   // Selection tolerance for the handles
192   int Tolerance;
193 
194   // Format for printing the distance
195   char* LabelFormat;
196 
197   // The line
198   vtkPoints* LinePoints;
199   vtkPolyData* LinePolyData;
200   vtkPolyDataMapper* LineMapper;
201   vtkActor* LineActor;
202 
203   // The distance label
204   vtkVectorText* LabelText;
205   vtkPolyDataMapper* LabelMapper;
206   vtkFollower* LabelActor;
207 
208   // The 3D disk tick marks
209   vtkPoints* GlyphPoints;
210   vtkDoubleArray* GlyphVectors;
211   vtkPolyData* GlyphPolyData;
212   vtkCylinderSource* GlyphCylinder;
213   vtkTransformPolyDataFilter* GlyphXForm;
214   vtkGlyph3D* Glyph3D;
215   vtkPolyDataMapper* GlyphMapper;
216   vtkActor* GlyphActor;
217 
218   // Support GetBounds() method
219   vtkBox* BoundingBox;
220 
221   double LastEventPosition[3];
222 
223 private:
224   vtkAxesTransformRepresentation(const vtkAxesTransformRepresentation&) = delete;
225   void operator=(const vtkAxesTransformRepresentation&) = delete;
226 };
227 
228 #endif
229