1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkCompassRepresentation.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 /*-------------------------------------------------------------------------
17   Copyright 2008 Sandia Corporation.
18   Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
19   the U.S. Government retains certain rights in this software.
20 -------------------------------------------------------------------------*/
21 
22 /**
23  * @class   vtkCompassRepresentation
24  * @brief   provide a compass
25  *
26  * This class is used to represent and render a compass.
27  */
28 
29 #ifndef vtkCompassRepresentation_h
30 #define vtkCompassRepresentation_h
31 
32 #include "vtkCenteredSliderRepresentation.h" // to use in a SP
33 #include "vtkContinuousValueWidgetRepresentation.h"
34 #include "vtkCoordinate.h"       // For vtkViewportCoordinateMacro
35 #include "vtkGeovisCoreModule.h" // For export macro
36 #include "vtkSmartPointer.h"     // used for SmartPointers
37 
38 class vtkActor2D;
39 class vtkPoints;
40 class vtkCellArray;
41 class vtkPolyData;
42 class vtkPolyDataMapper2D;
43 class vtkCoordinate;
44 class vtkProperty2D;
45 class vtkPropCollection;
46 class vtkWindow;
47 class vtkViewport;
48 class vtkTransform;
49 class vtkTransformPolyDataFilter;
50 class vtkTextProperty;
51 class vtkTextActor;
52 
53 class VTKGEOVISCORE_EXPORT vtkCompassRepresentation : public vtkContinuousValueWidgetRepresentation
54 {
55 public:
56   /**
57    * Instantiate the class.
58    */
59   static vtkCompassRepresentation* New();
60 
61   ///@{
62   /**
63    * Standard methods for the class.
64    */
65   vtkTypeMacro(vtkCompassRepresentation, vtkContinuousValueWidgetRepresentation);
66   void PrintSelf(ostream& os, vtkIndent indent) override;
67   ///@}
68 
69   /**
70    * Position the first end point of the slider. Note that this point is an
71    * instance of vtkCoordinate, meaning that Point 1 can be specified in a
72    * variety of coordinate systems, and can even be relative to another
73    * point. To set the point, you'll want to get the Point1Coordinate and
74    * then invoke the necessary methods to put it into the correct coordinate
75    * system and set the correct initial value.
76    */
77   vtkCoordinate* GetPoint1Coordinate();
78 
79   /**
80    * Position the second end point of the slider. Note that this point is an
81    * instance of vtkCoordinate, meaning that Point 1 can be specified in a
82    * variety of coordinate systems, and can even be relative to another
83    * point. To set the point, you'll want to get the Point2Coordinate and
84    * then invoke the necessary methods to put it into the correct coordinate
85    * system and set the correct initial value.
86    */
87   vtkCoordinate* GetPoint2Coordinate();
88 
89   ///@{
90   /**
91    * Get the slider properties. The properties of the slider when selected
92    * and unselected can be manipulated.
93    */
94   vtkGetObjectMacro(RingProperty, vtkProperty2D);
95   ///@}
96 
97   ///@{
98   /**
99    * Get the selection property. This property is used to modify the
100    * appearance of selected objects (e.g., the slider).
101    */
102   vtkGetObjectMacro(SelectedProperty, vtkProperty2D);
103   ///@}
104 
105   ///@{
106   /**
107    * Set/Get the properties for the label and title text.
108    */
109   vtkGetObjectMacro(LabelProperty, vtkTextProperty);
110   ///@}
111 
112   ///@{
113   /**
114    * Methods to interface with the vtkSliderWidget. The PlaceWidget() method
115    * assumes that the parameter bounds[6] specifies the location in display
116    * space where the widget should be placed.
117    */
118   void PlaceWidget(double bounds[6]) override;
119   void BuildRepresentation() override;
120   void StartWidgetInteraction(double eventPos[2]) override;
121   void WidgetInteraction(double eventPos[2]) override;
122   virtual void TiltWidgetInteraction(double eventPos[2]);
123   virtual void DistanceWidgetInteraction(double eventPos[2]);
124   int ComputeInteractionState(int X, int Y, int modify = 0) override;
125   void Highlight(int) override;
126   ///@}
127 
128   ///@{
129   /**
130    * Methods supporting the rendering process.
131    */
132   void GetActors(vtkPropCollection*) override;
133   void ReleaseGraphicsResources(vtkWindow*) override;
134   int RenderOverlay(vtkViewport*) override;
135   int RenderOpaqueGeometry(vtkViewport*) override;
136   ///@}
137 
138   virtual void SetHeading(double value);
139   virtual double GetHeading();
140   virtual void SetTilt(double value);
141   virtual double GetTilt();
142   virtual void UpdateTilt(double time);
143   virtual void EndTilt();
144   virtual void SetDistance(double value);
145   virtual double GetDistance();
146   virtual void UpdateDistance(double time);
147   virtual void EndDistance();
148   void SetRenderer(vtkRenderer* ren) override;
149 
150   // Enums are used to describe what is selected
151   enum _InteractionState
152   {
153     Outside = 0,
154     Inside,
155     Adjusting,
156     TiltDown,
157     TiltUp,
158     TiltAdjusting,
159     DistanceOut,
160     DistanceIn,
161     DistanceAdjusting
162   };
163 
164 protected:
165   vtkCompassRepresentation();
166   ~vtkCompassRepresentation() override;
167 
168   // Positioning the widget
169   vtkCoordinate* Point1Coordinate;
170   vtkCoordinate* Point2Coordinate;
171 
172   // radius values
173   double InnerRadius;
174   double OuterRadius;
175 
176   // tilt and distance rep
177 
178   vtkSmartPointer<vtkCenteredSliderRepresentation> TiltRepresentation;
179   vtkSmartPointer<vtkCenteredSliderRepresentation> DistanceRepresentation;
180 
181   // Define the geometry. It is constructed in canaonical position
182   // along the x-axis and then rotated into position.
183   vtkTransform* XForm;
184   vtkPoints* Points;
185 
186   vtkPolyData* Ring;
187   vtkTransformPolyDataFilter* RingXForm;
188   vtkPolyDataMapper2D* RingMapper;
189   vtkActor2D* RingActor;
190   vtkProperty2D* RingProperty;
191 
192   vtkPolyDataMapper2D* BackdropMapper;
193   vtkActor2D* Backdrop;
194 
195   vtkTextProperty* LabelProperty;
196   vtkTextActor* LabelActor;
197   vtkTextProperty* StatusProperty;
198   vtkTextActor* StatusActor;
199 
200   vtkProperty2D* SelectedProperty;
201 
202   // build the tube geometry
203   void BuildRing();
204   void BuildBackdrop();
205 
206   // used for positioning etc
207   void GetCenterAndUnitRadius(int center[2], double& radius);
208 
209   int HighlightState;
210 
211   double Heading;
212   double Tilt;
213   double Distance;
214 
215 private:
216   vtkCompassRepresentation(const vtkCompassRepresentation&) = delete;
217   void operator=(const vtkCompassRepresentation&) = delete;
218 };
219 
220 #endif
221