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 =========================================================================*/ 00093 #ifndef __vtkSplineWidget_h 00094 #define __vtkSplineWidget_h 00095 00096 #include "vtk3DWidget.h" 00097 00098 class vtkActor; 00099 class vtkCellPicker; 00100 class vtkParametricSpline; 00101 class vtkParametricFunctionSource; 00102 class vtkPlaneSource; 00103 class vtkPoints; 00104 class vtkPolyData; 00105 class vtkProp; 00106 class vtkProperty; 00107 class vtkSphereSource; 00108 class vtkTransform; 00109 00110 #define VTK_PROJECTION_YZ 0 00111 #define VTK_PROJECTION_XZ 1 00112 #define VTK_PROJECTION_XY 2 00113 #define VTK_PROJECTION_OBLIQUE 3 00114 00115 class VTK_WIDGETS_EXPORT vtkSplineWidget : public vtk3DWidget 00116 { 00117 public: 00119 static vtkSplineWidget *New(); 00120 00121 vtkTypeMacro(vtkSplineWidget,vtk3DWidget); 00122 void PrintSelf(ostream& os, vtkIndent indent); 00123 00125 00126 virtual void SetEnabled(int); 00127 virtual void PlaceWidget(double bounds[6]); 00128 void PlaceWidget() 00129 {this->Superclass::PlaceWidget();} 00130 void PlaceWidget(double xmin, double xmax, double ymin, double ymax, 00131 double zmin, double zmax) 00132 {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);} 00134 00136 00142 vtkSetMacro(ProjectToPlane,int); 00143 vtkGetMacro(ProjectToPlane,int); 00144 vtkBooleanMacro(ProjectToPlane,int); 00146 00149 void SetPlaneSource(vtkPlaneSource* plane); 00150 00151 vtkSetClampMacro(ProjectionNormal,int,VTK_PROJECTION_YZ,VTK_PROJECTION_OBLIQUE); 00152 vtkGetMacro(ProjectionNormal,int); 00153 void SetProjectionNormalToXAxes() 00154 { this->SetProjectionNormal(0); } 00155 void SetProjectionNormalToYAxes() 00156 { this->SetProjectionNormal(1); } 00157 void SetProjectionNormalToZAxes() 00158 { this->SetProjectionNormal(2); } 00159 void SetProjectionNormalToOblique() 00160 { this->SetProjectionNormal(3); } 00161 00163 00168 void SetProjectionPosition(double position); 00169 vtkGetMacro(ProjectionPosition, double); 00171 00178 void GetPolyData(vtkPolyData *pd); 00179 00181 00184 virtual void SetHandleProperty(vtkProperty*); 00185 vtkGetObjectMacro(HandleProperty, vtkProperty); 00186 virtual void SetSelectedHandleProperty(vtkProperty*); 00187 vtkGetObjectMacro(SelectedHandleProperty, vtkProperty); 00189 00191 00193 virtual void SetLineProperty(vtkProperty*); 00194 vtkGetObjectMacro(LineProperty, vtkProperty); 00195 virtual void SetSelectedLineProperty(vtkProperty*); 00196 vtkGetObjectMacro(SelectedLineProperty, vtkProperty); 00198 00200 00201 virtual void SetNumberOfHandles(int npts); 00202 vtkGetMacro(NumberOfHandles, int); 00204 00206 00208 void SetResolution(int resolution); 00209 vtkGetMacro(Resolution,int); 00211 00213 00219 virtual void SetParametricSpline(vtkParametricSpline*); 00220 vtkGetObjectMacro(ParametricSpline,vtkParametricSpline); 00222 00224 00226 void SetHandlePosition(int handle, double x, double y, double z); 00227 void SetHandlePosition(int handle, double xyz[3]); 00228 void GetHandlePosition(int handle, double xyz[3]); 00229 double* GetHandlePosition(int handle); 00231 00233 00238 void SetClosed(int closed); 00239 vtkGetMacro(Closed,int); 00240 vtkBooleanMacro(Closed,int); 00242 00246 int IsClosed(); 00247 00251 double GetSummedLength(); 00252 00257 void InitializeHandles(vtkPoints* points); 00258 00260 00262 vtkSetClampMacro(ProcessEvents, int, 0, 1); 00263 vtkGetMacro(ProcessEvents, int); 00264 vtkBooleanMacro( ProcessEvents, int ); 00266 00267 protected: 00268 vtkSplineWidget(); 00269 ~vtkSplineWidget(); 00270 00271 //BTX - manage the state of the widget 00272 int State; 00273 enum WidgetState 00274 { 00275 Start=0, 00276 Moving, 00277 Scaling, 00278 Spinning, 00279 Inserting, 00280 Erasing, 00281 Outside 00282 }; 00283 //ETX 00284 00285 //handles the events 00286 static void ProcessEventsHandler(vtkObject* object, 00287 unsigned long event, 00288 void* clientdata, 00289 void* calldata); 00290 00291 // ProcessEventsHandler() dispatches to these methods. 00292 void OnLeftButtonDown(); 00293 void OnLeftButtonUp(); 00294 void OnMiddleButtonDown(); 00295 void OnMiddleButtonUp(); 00296 void OnRightButtonDown(); 00297 void OnRightButtonUp(); 00298 void OnMouseMove(); 00299 00300 // Controlling vars 00301 int ProjectionNormal; 00302 double ProjectionPosition; 00303 int ProjectToPlane; 00304 vtkPlaneSource* PlaneSource; 00305 00306 // Projection capabilities 00307 void ProjectPointsToPlane(); 00308 void ProjectPointsToOrthoPlane(); 00309 void ProjectPointsToObliquePlane(); 00310 00311 // The spline 00312 vtkParametricSpline *ParametricSpline; 00313 vtkParametricFunctionSource *ParametricFunctionSource; 00314 int NumberOfHandles; 00315 int Closed; 00316 void BuildRepresentation(); 00317 00318 // The line segments 00319 vtkActor *LineActor; 00320 void HighlightLine(int highlight); 00321 int Resolution; 00322 00323 // Glyphs representing hot spots (e.g., handles) 00324 vtkActor **Handle; 00325 vtkSphereSource **HandleGeometry; 00326 void Initialize(); 00327 int HighlightHandle(vtkProp *prop); //returns handle index or -1 on fail 00328 virtual void SizeHandles(); 00329 void InsertHandleOnLine(double* pos); 00330 void EraseHandle(const int&); 00331 00332 // Do the picking 00333 vtkCellPicker *HandlePicker; 00334 vtkCellPicker *LinePicker; 00335 vtkActor *CurrentHandle; 00336 int CurrentHandleIndex; 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