1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkBiDimensionalRepresentation.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   vtkBiDimensionalRepresentation
17  * @brief   represent the vtkBiDimensionalWidget
18  *
19  * The vtkBiDimensionalRepresentation is used to represent the
20  * bi-dimensional measure of an object. This representation
21  * consists of two perpendicular lines defined by four
22  * vtkHandleRepresentations. The four handles can be independently
23  * manipulated consistent with the orthogonal constraint on the lines. (Note:
24  * the four points are referred to as Point1, Point2, Point3 and
25  * Point4. Point1 and Point2 define the first line; and Point3 and Point4
26  * define the second orthogonal line.) This particular class is an abstract
27  * class, contrete subclasses (e.g., vtkBiDimensionalRepresentation2D) actual
28  * implement the widget.
29  *
30  * To create this widget, you click to place the first two points. The third
31  * point is mirrored with the fourth point; when you place the third point
32  * (which is orthogonal to the lined defined by the first two points), the
33  * fourth point is dropped as well. After definition, the four points can be
34  * moved (in constrained fashion, preserving orthogonality). Further, the
35  * entire widget can be translated by grabbing the center point of the widget;
36  * each line can be moved along the other line; and the entire widget can be
37  * rotated around its center point.
38  *
39  * @sa
40  * vtkAngleWidget vtkHandleRepresentation vtkBiDimensionalRepresentation2D
41  */
42 
43 #ifndef vtkBiDimensionalRepresentation_h
44 #define vtkBiDimensionalRepresentation_h
45 
46 #include "vtkInteractionWidgetsModule.h" // For export macro
47 #include "vtkWidgetRepresentation.h"
48 
49 class vtkHandleRepresentation;
50 
51 class VTKINTERACTIONWIDGETS_EXPORT vtkBiDimensionalRepresentation : public vtkWidgetRepresentation
52 {
53 public:
54   ///@{
55   /**
56    * Standard VTK methods.
57    */
58   vtkTypeMacro(vtkBiDimensionalRepresentation, vtkWidgetRepresentation);
59   void PrintSelf(ostream& os, vtkIndent indent) override;
60   ///@}
61 
62   ///@{
63   /**
64    * Methods to Set/Get the coordinates of the four points defining
65    * this representation. Note that methods are available for both
66    * display and world coordinates.
67    */
68   virtual void SetPoint1WorldPosition(double pos[3]);
69   virtual void SetPoint2WorldPosition(double pos[3]);
70   virtual void SetPoint3WorldPosition(double pos[3]);
71   virtual void SetPoint4WorldPosition(double pos[3]);
72   virtual void GetPoint1WorldPosition(double pos[3]);
73   virtual void GetPoint2WorldPosition(double pos[3]);
74   virtual void GetPoint3WorldPosition(double pos[3]);
75   virtual void GetPoint4WorldPosition(double pos[3]);
76   virtual void SetPoint1DisplayPosition(double pos[3]);
77   virtual void SetPoint2DisplayPosition(double pos[3]);
78   virtual void SetPoint3DisplayPosition(double pos[3]);
79   virtual void SetPoint4DisplayPosition(double pos[3]);
80   virtual void GetPoint1DisplayPosition(double pos[3]);
81   virtual void GetPoint2DisplayPosition(double pos[3]);
82   virtual void GetPoint3DisplayPosition(double pos[3]);
83   virtual void GetPoint4DisplayPosition(double pos[3]);
84   ///@}
85 
86   ///@{
87   /**
88    * Set/Get the handle representations used within the
89    * vtkBiDimensionalRepresentation2D. (Note: properties can be set by
90    * grabbing these representations and setting the properties
91    * appropriately.)
92    */
93   vtkGetObjectMacro(Point1Representation, vtkHandleRepresentation);
94   vtkGetObjectMacro(Point2Representation, vtkHandleRepresentation);
95   vtkGetObjectMacro(Point3Representation, vtkHandleRepresentation);
96   vtkGetObjectMacro(Point4Representation, vtkHandleRepresentation);
97   ///@}
98 
99   ///@{
100   /**
101    * Special methods for turning off the lines that define the bi-dimensional
102    * measure. Generally these methods are used by the vtkBiDimensionalWidget to
103    * control the appearance of the widget. Note: turning off Line1 actually turns
104    * off Line1 and Line2.
105    */
106   vtkSetMacro(Line1Visibility, vtkTypeBool);
107   vtkGetMacro(Line1Visibility, vtkTypeBool);
108   vtkBooleanMacro(Line1Visibility, vtkTypeBool);
109   vtkSetMacro(Line2Visibility, vtkTypeBool);
110   vtkGetMacro(Line2Visibility, vtkTypeBool);
111   vtkBooleanMacro(Line2Visibility, vtkTypeBool);
112   ///@}
113 
114   ///@{
115   /**
116    * This method is used to specify the type of handle representation to use
117    * for the four internal vtkHandleRepresentations within
118    * vtkBiDimensionalRepresentation.  To use this method, create a dummy
119    * vtkHandleRepresentation (or subclass), and then invoke this method with
120    * this dummy. Then the vtkBiDimensionalRepresentation uses this dummy to
121    * clone four vtkHandleRepresentations of the same type. Make sure you set the
122    * handle representation before the widget is enabled. (The method
123    * InstantiateHandleRepresentation() is invoked by the vtkBiDimensionalWidget
124    * for the purposes of cloning.)
125    */
126   void SetHandleRepresentation(vtkHandleRepresentation* handle);
127   virtual void InstantiateHandleRepresentation();
128   ///@}
129 
130   ///@{
131   /**
132    * The tolerance representing the distance to the representation (in
133    * pixels) in which the cursor is considered near enough to the
134    * representation to be active.
135    */
136   vtkSetClampMacro(Tolerance, int, 1, 100);
137   vtkGetMacro(Tolerance, int);
138   ///@}
139 
140   /**
141    * Return the length of the line defined by (Point1,Point2). This is the
142    * distance in the world coordinate system.
143    */
144   virtual double GetLength1();
145 
146   /**
147    * Return the length of the line defined by (Point3,Point4). This is the
148    * distance in the world coordinate system.
149    */
150   virtual double GetLength2();
151 
152   ///@{
153   /**
154    * Specify the format to use for labelling the distance. Note that an empty
155    * string results in no label, or a format string without a "%" character
156    * will not print the distance value.
157    */
158   vtkSetStringMacro(LabelFormat);
159   vtkGetStringMacro(LabelFormat);
160   ///@}
161 
162   // Used to communicate about the state of the representation
163   enum
164   {
165     Outside = 0,
166     NearP1,
167     NearP2,
168     NearP3,
169     NearP4,
170     OnL1Inner,
171     OnL1Outer,
172     OnL2Inner,
173     OnL2Outer,
174     OnCenter
175   };
176 
177   ///@{
178   /**
179    * Toggle whether to display the label above or below the widget.
180    * Defaults to 1.
181    */
182   vtkSetMacro(ShowLabelAboveWidget, vtkTypeBool);
183   vtkGetMacro(ShowLabelAboveWidget, vtkTypeBool);
184   vtkBooleanMacro(ShowLabelAboveWidget, vtkTypeBool);
185   ///@}
186 
187   ///@{
188   /**
189    * Set/get the id to display in the label.
190    */
191   void SetID(vtkIdType id);
192   vtkGetMacro(ID, vtkIdType);
193   ///@}
194 
195   /**
196    * Get the text shown in the widget's label.
197    */
198   virtual char* GetLabelText() = 0;
199 
200   ///@{
201   /**
202    * Get the position of the widget's label in display coordinates.
203    */
204   virtual double* GetLabelPosition() = 0;
205   virtual void GetLabelPosition(double pos[3]) = 0;
206   virtual void GetWorldLabelPosition(double pos[3]) = 0;
207   ///@}
208 
209   ///@{
210   /**
211    * These are methods that satisfy vtkWidgetRepresentation's API.
212    */
213   virtual void StartWidgetDefinition(double e[2]) = 0;
214   virtual void Point2WidgetInteraction(double e[2]) = 0;
215   virtual void Point3WidgetInteraction(double e[2]) = 0;
216   virtual void StartWidgetManipulation(double e[2]) = 0;
217   ///@}
218 
219 protected:
220   vtkBiDimensionalRepresentation();
221   ~vtkBiDimensionalRepresentation() override;
222 
223   // Keep track if modifier is set
224   int Modifier;
225 
226   // The handle and the rep used to close the handles
227   vtkHandleRepresentation* HandleRepresentation;
228   vtkHandleRepresentation* Point1Representation;
229   vtkHandleRepresentation* Point2Representation;
230   vtkHandleRepresentation* Point3Representation;
231   vtkHandleRepresentation* Point4Representation;
232 
233   // Selection tolerance for the handles
234   int Tolerance;
235 
236   // Visibility of the lines
237   vtkTypeBool Line1Visibility;
238   vtkTypeBool Line2Visibility;
239 
240   vtkIdType ID;
241   int IDInitialized;
242 
243   // Internal variables
244   double P1World[3];
245   double P2World[3];
246   double P3World[3];
247   double P4World[3];
248   double P21World[3];
249   double P43World[3];
250   double T21;
251   double T43;
252   double CenterWorld[3];
253   double StartEventPositionWorld[4];
254 
255   // Format for printing the distance
256   char* LabelFormat;
257 
258   // toggle to determine whether to place text above or below widget
259   vtkTypeBool ShowLabelAboveWidget;
260 
261 private:
262   vtkBiDimensionalRepresentation(const vtkBiDimensionalRepresentation&) = delete;
263   void operator=(const vtkBiDimensionalRepresentation&) = delete;
264 };
265 
266 #endif
267