VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkSplineWidget.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00089 #ifndef __vtkSplineWidget_h 00090 #define __vtkSplineWidget_h 00091 00092 #include "vtkInteractionWidgetsModule.h" // For export macro 00093 #include "vtk3DWidget.h" 00094 00095 class vtkActor; 00096 class vtkCellPicker; 00097 class vtkParametricSpline; 00098 class vtkParametricFunctionSource; 00099 class vtkPlaneSource; 00100 class vtkPoints; 00101 class vtkPolyData; 00102 class vtkProp; 00103 class vtkProperty; 00104 class vtkSphereSource; 00105 class vtkTransform; 00106 00107 #define VTK_PROJECTION_YZ 0 00108 #define VTK_PROJECTION_XZ 1 00109 #define VTK_PROJECTION_XY 2 00110 #define VTK_PROJECTION_OBLIQUE 3 00111 00112 class VTKINTERACTIONWIDGETS_EXPORT vtkSplineWidget : public vtk3DWidget 00113 { 00114 public: 00116 static vtkSplineWidget *New(); 00117 00118 vtkTypeMacro(vtkSplineWidget,vtk3DWidget); 00119 void PrintSelf(ostream& os, vtkIndent indent); 00120 00122 00123 virtual void SetEnabled(int); 00124 virtual void PlaceWidget(double bounds[6]); 00125 void PlaceWidget() 00126 {this->Superclass::PlaceWidget();} 00127 void PlaceWidget(double xmin, double xmax, double ymin, double ymax, 00128 double zmin, double zmax) 00129 {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);} 00131 00133 00139 vtkSetMacro(ProjectToPlane,int); 00140 vtkGetMacro(ProjectToPlane,int); 00141 vtkBooleanMacro(ProjectToPlane,int); 00143 00146 void SetPlaneSource(vtkPlaneSource* plane); 00147 00148 vtkSetClampMacro(ProjectionNormal,int,VTK_PROJECTION_YZ,VTK_PROJECTION_OBLIQUE); 00149 vtkGetMacro(ProjectionNormal,int); 00150 void SetProjectionNormalToXAxes() 00151 { this->SetProjectionNormal(0); } 00152 void SetProjectionNormalToYAxes() 00153 { this->SetProjectionNormal(1); } 00154 void SetProjectionNormalToZAxes() 00155 { this->SetProjectionNormal(2); } 00156 void SetProjectionNormalToOblique() 00157 { this->SetProjectionNormal(3); } 00158 00160 00165 void SetProjectionPosition(double position); 00166 vtkGetMacro(ProjectionPosition, double); 00168 00175 void GetPolyData(vtkPolyData *pd); 00176 00178 00181 virtual void SetHandleProperty(vtkProperty*); 00182 vtkGetObjectMacro(HandleProperty, vtkProperty); 00183 virtual void SetSelectedHandleProperty(vtkProperty*); 00184 vtkGetObjectMacro(SelectedHandleProperty, vtkProperty); 00186 00188 00190 virtual void SetLineProperty(vtkProperty*); 00191 vtkGetObjectMacro(LineProperty, vtkProperty); 00192 virtual void SetSelectedLineProperty(vtkProperty*); 00193 vtkGetObjectMacro(SelectedLineProperty, vtkProperty); 00195 00197 00198 virtual void SetNumberOfHandles(int npts); 00199 vtkGetMacro(NumberOfHandles, int); 00201 00203 00205 void SetResolution(int resolution); 00206 vtkGetMacro(Resolution,int); 00208 00210 00216 virtual void SetParametricSpline(vtkParametricSpline*); 00217 vtkGetObjectMacro(ParametricSpline,vtkParametricSpline); 00219 00221 00223 void SetHandlePosition(int handle, double x, double y, double z); 00224 void SetHandlePosition(int handle, double xyz[3]); 00225 void GetHandlePosition(int handle, double xyz[3]); 00226 double* GetHandlePosition(int handle); 00228 00230 00235 void SetClosed(int closed); 00236 vtkGetMacro(Closed,int); 00237 vtkBooleanMacro(Closed,int); 00239 00243 int IsClosed(); 00244 00248 double GetSummedLength(); 00249 00254 void InitializeHandles(vtkPoints* points); 00255 00257 00259 vtkSetClampMacro(ProcessEvents, int, 0, 1); 00260 vtkGetMacro(ProcessEvents, int); 00261 vtkBooleanMacro( ProcessEvents, int ); 00263 00264 protected: 00265 vtkSplineWidget(); 00266 ~vtkSplineWidget(); 00267 00268 //BTX - manage the state of the widget 00269 int State; 00270 enum WidgetState 00271 { 00272 Start=0, 00273 Moving, 00274 Scaling, 00275 Spinning, 00276 Inserting, 00277 Erasing, 00278 Outside 00279 }; 00280 //ETX 00281 00282 //handles the events 00283 static void ProcessEventsHandler(vtkObject* object, 00284 unsigned long event, 00285 void* clientdata, 00286 void* calldata); 00287 00288 // ProcessEventsHandler() dispatches to these methods. 00289 void OnLeftButtonDown(); 00290 void OnLeftButtonUp(); 00291 void OnMiddleButtonDown(); 00292 void OnMiddleButtonUp(); 00293 void OnRightButtonDown(); 00294 void OnRightButtonUp(); 00295 void OnMouseMove(); 00296 00297 // Controlling vars 00298 int ProjectionNormal; 00299 double ProjectionPosition; 00300 int ProjectToPlane; 00301 vtkPlaneSource* PlaneSource; 00302 00303 // Projection capabilities 00304 void ProjectPointsToPlane(); 00305 void ProjectPointsToOrthoPlane(); 00306 void ProjectPointsToObliquePlane(); 00307 00308 // The spline 00309 vtkParametricSpline *ParametricSpline; 00310 vtkParametricFunctionSource *ParametricFunctionSource; 00311 int NumberOfHandles; 00312 int Closed; 00313 void BuildRepresentation(); 00314 00315 // The line segments 00316 vtkActor *LineActor; 00317 void HighlightLine(int highlight); 00318 int Resolution; 00319 00320 // Glyphs representing hot spots (e.g., handles) 00321 vtkActor **Handle; 00322 vtkSphereSource **HandleGeometry; 00323 void Initialize(); 00324 int HighlightHandle(vtkProp *prop); //returns handle index or -1 on fail 00325 virtual void SizeHandles(); 00326 void InsertHandleOnLine(double* pos); 00327 void EraseHandle(const int&); 00328 00329 // Do the picking 00330 vtkCellPicker *HandlePicker; 00331 vtkCellPicker *LinePicker; 00332 vtkActor *CurrentHandle; 00333 int CurrentHandleIndex; 00334 00335 // Register internal Pickers within PickingManager 00336 virtual void RegisterPickers(); 00337 00338 // Methods to manipulate the spline. 00339 void MovePoint(double *p1, double *p2); 00340 void Scale(double *p1, double *p2, int X, int Y); 00341 void Translate(double *p1, double *p2); 00342 void Spin(double *p1, double *p2, double *vpn); 00343 00344 // Transform the control points (used for spinning) 00345 vtkTransform *Transform; 00346 00347 // Properties used to control the appearance of selected objects and 00348 // the manipulator in general. 00349 vtkProperty *HandleProperty; 00350 vtkProperty *SelectedHandleProperty; 00351 vtkProperty *LineProperty; 00352 vtkProperty *SelectedLineProperty; 00353 void CreateDefaultProperties(); 00354 00355 // For efficient spinning 00356 double Centroid[3]; 00357 void CalculateCentroid(); 00358 int ProcessEvents; 00359 00360 private: 00361 vtkSplineWidget(const vtkSplineWidget&); //Not implemented 00362 void operator=(const vtkSplineWidget&); //Not implemented 00363 }; 00364 00365 #endif