VTK
vtkSplineRepresentation.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkSplineRepresentation.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 =========================================================================*/
30 #ifndef __vtkSplineRepresentation_h
31 #define __vtkSplineRepresentation_h
32 
33 #include "vtkInteractionWidgetsModule.h" // For export macro
35 
36 class vtkActor;
37 class vtkCellPicker;
38 class vtkDoubleArray;
41 class vtkPlaneSource;
42 class vtkPoints;
43 class vtkPolyData;
44 class vtkProp;
45 class vtkProperty;
46 class vtkSphereSource;
47 class vtkTransform;
48 
49 #define VTK_PROJECTION_YZ 0
50 #define VTK_PROJECTION_XZ 1
51 #define VTK_PROJECTION_XY 2
52 #define VTK_PROJECTION_OBLIQUE 3
53 class VTKINTERACTIONWIDGETS_EXPORT vtkSplineRepresentation : public vtkWidgetRepresentation
54 {
55 public:
56  static vtkSplineRepresentation* New();
58  void PrintSelf(ostream& os, vtkIndent indent);
59 //BTX
60  // Used to manage the InteractionState of the widget
62  Outside=0,
69  Erasing
70  };
71 //ETX
72 
73  vtkSetMacro(InteractionState, int);
74 
76 
83  vtkSetMacro(ProjectToPlane,int);
84  vtkGetMacro(ProjectToPlane,int);
85  vtkBooleanMacro(ProjectToPlane,int);
87 
90  void SetPlaneSource(vtkPlaneSource* plane);
91 
92  vtkSetClampMacro(ProjectionNormal,int,VTK_PROJECTION_YZ,VTK_PROJECTION_OBLIQUE);
93  vtkGetMacro(ProjectionNormal,int);
94  void SetProjectionNormalToXAxes()
95  { this->SetProjectionNormal(0); }
96  void SetProjectionNormalToYAxes()
97  { this->SetProjectionNormal(1); }
98  void SetProjectionNormalToZAxes()
99  { this->SetProjectionNormal(2); }
100  void SetProjectionNormalToOblique()
101  { this->SetProjectionNormal(3); }
102 
104 
109  void SetProjectionPosition(double position);
110  vtkGetMacro(ProjectionPosition, double);
112 
119  void GetPolyData(vtkPolyData *pd);
120 
122 
125  vtkGetObjectMacro(HandleProperty, vtkProperty);
126  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
128 
130 
132  vtkGetObjectMacro(LineProperty, vtkProperty);
133  vtkGetObjectMacro(SelectedLineProperty, vtkProperty);
135 
137 
138  virtual void SetNumberOfHandles(int npts);
139  vtkGetMacro(NumberOfHandles, int);
141 
143 
145  void SetResolution(int resolution);
146  vtkGetMacro(Resolution,int);
148 
150 
156  virtual void SetParametricSpline(vtkParametricSpline*);
157  vtkGetObjectMacro(ParametricSpline,vtkParametricSpline);
159 
161 
163  void SetHandlePosition(int handle, double x, double y, double z);
164  void SetHandlePosition(int handle, double xyz[3]);
165  void GetHandlePosition(int handle, double xyz[3]);
166  double* GetHandlePosition(int handle);
167  vtkDoubleArray* GetHandlePositions();
169 
171 
176  void SetClosed(int closed);
177  vtkGetMacro(Closed,int);
178  vtkBooleanMacro(Closed,int);
180 
184  int IsClosed();
185 
189  double GetSummedLength();
190 
195  void InitializeHandles(vtkPoints* points);
196 
198 
201  virtual void BuildRepresentation();
202  virtual int ComputeInteractionState(int X, int Y, int modify=0);
203  virtual void StartWidgetInteraction(double e[2]);
204  virtual void WidgetInteraction(double e[2]);
205  virtual void EndWidgetInteraction(double e[2]);
206  virtual double *GetBounds();
208 
210 
211  virtual void ReleaseGraphicsResources(vtkWindow*);
212  virtual int RenderOpaqueGeometry(vtkViewport*);
214  virtual int RenderOverlay(vtkViewport*);
215  virtual int HasTranslucentPolygonalGeometry();
217 
220  void SetLineColor(double r, double g, double b);
221 
222 //BTX
223 protected:
226 
227  double LastEventPosition[3];
228  double Bounds[6];
229 
230  // Controlling vars
235 
236  // Projection capabilities
237  void ProjectPointsToPlane();
238  void ProjectPointsToOrthoPlane();
239  void ProjectPointsToObliquePlane();
240 
241  // The spline
245  int Closed;
246 
247  // The line segments
249  void HighlightLine(int highlight);
251 
252  // Glyphs representing hot spots (e.g., handles)
255  void Initialize();
256  int HighlightHandle(vtkProp *prop); //returns handle index or -1 on fail
257  virtual void SizeHandles();
258  void InsertHandleOnLine(double* pos);
259  void EraseHandle(const int&);
260 
261  // Do the picking
264  double LastPickPosition[3];
267 
268  // Methods to manipulate the spline.
269  void MovePoint(double *p1, double *p2);
270  void Scale(double *p1, double *p2, int X, int Y);
271  void Translate(double *p1, double *p2);
272  void Spin(double *p1, double *p2, double *vpn);
273 
274  // Transform the control points (used for spinning)
276 
277  // Properties used to control the appearance of selected objects and
278  // the manipulator in general.
283  void CreateDefaultProperties();
284 
285  // For efficient spinning
286  double Centroid[3];
287  void CalculateCentroid();
288 
289 private:
290  vtkSplineRepresentation(const vtkSplineRepresentation&); // Not implemented.
291  void operator=(const vtkSplineRepresentation&); // Not implemented.
292 //ETX
293 };
294 
295 #endif
296 
297