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