VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: $RCSfile: vtkImageTracerWidget.h,v $ 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 =========================================================================*/ 00059 #ifndef __vtkImageTracerWidget_h 00060 #define __vtkImageTracerWidget_h 00061 00062 #include "vtk3DWidget.h" 00063 00064 class vtkAbstractPropPicker; 00065 class vtkActor; 00066 class vtkCellArray; 00067 class vtkCellPicker; 00068 class vtkFloatArray; 00069 class vtkGlyphSource2D; 00070 class vtkPoints; 00071 class vtkPolyData; 00072 class vtkProp; 00073 class vtkProperty; 00074 class vtkPropPicker; 00075 class vtkTransform; 00076 class vtkTransformPolyDataFilter; 00077 00078 #define VTK_ITW_PROJECTION_YZ 0 00079 #define VTK_ITW_PROJECTION_XZ 1 00080 #define VTK_ITW_PROJECTION_XY 2 00081 #define VTK_ITW_SNAP_CELLS 0 00082 #define VTK_ITW_SNAP_POINTS 1 00083 00084 class VTK_WIDGETS_EXPORT vtkImageTracerWidget : public vtk3DWidget 00085 { 00086 public: 00088 static vtkImageTracerWidget *New(); 00089 00090 vtkTypeRevisionMacro(vtkImageTracerWidget,vtk3DWidget); 00091 void PrintSelf(ostream& os, vtkIndent indent); 00092 00094 00095 virtual void SetEnabled(int); 00096 virtual void PlaceWidget(double bounds[6]); 00097 void PlaceWidget() 00098 {this->Superclass::PlaceWidget();} 00099 void PlaceWidget(double xmin, double xmax, double ymin, double ymax, 00100 double zmin, double zmax) 00101 {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);} 00103 00105 00108 virtual void SetHandleProperty(vtkProperty*); 00109 vtkGetObjectMacro(HandleProperty, vtkProperty); 00110 virtual void SetSelectedHandleProperty(vtkProperty*); 00111 vtkGetObjectMacro(SelectedHandleProperty, vtkProperty); 00113 00115 00117 virtual void SetLineProperty(vtkProperty*); 00118 vtkGetObjectMacro(LineProperty, vtkProperty); 00119 virtual void SetSelectedLineProperty(vtkProperty*); 00120 vtkGetObjectMacro(SelectedLineProperty, vtkProperty); 00122 00124 void SetViewProp(vtkProp* prop); 00125 00127 00128 vtkSetMacro(ProjectToPlane,int); 00129 vtkGetMacro(ProjectToPlane,int); 00130 vtkBooleanMacro(ProjectToPlane,int); 00132 00134 00138 vtkSetClampMacro(ProjectionNormal,int,VTK_ITW_PROJECTION_YZ,VTK_ITW_PROJECTION_XY); 00139 vtkGetMacro(ProjectionNormal,int); 00140 void SetProjectionNormalToXAxes() 00141 { this->SetProjectionNormal(0); } 00142 void SetProjectionNormalToYAxes() 00143 { this->SetProjectionNormal(1); } 00144 void SetProjectionNormalToZAxes() 00145 { this->SetProjectionNormal(2); } 00147 00149 00154 void SetProjectionPosition(double position); 00155 vtkGetMacro(ProjectionPosition,double); 00157 00159 00160 void SetSnapToImage(int snap); 00161 vtkGetMacro(SnapToImage,int); 00162 vtkBooleanMacro(SnapToImage,int); 00164 00166 00168 vtkSetMacro(AutoClose,int); 00169 vtkGetMacro(AutoClose,int); 00170 vtkBooleanMacro(AutoClose,int); 00172 00174 00177 vtkSetMacro(CaptureRadius,double); 00178 vtkGetMacro(CaptureRadius,double); 00180 00186 void GetPath(vtkPolyData *pd); 00187 00189 vtkGlyphSource2D* GetGlyphSource() { return this->HandleGenerator; } 00190 00192 00194 vtkSetClampMacro(ImageSnapType,int,VTK_ITW_SNAP_CELLS,VTK_ITW_SNAP_POINTS); 00195 vtkGetMacro(ImageSnapType,int); 00197 00199 00201 void SetHandlePosition(int handle, double xyz[3]); 00202 void SetHandlePosition(int handle, double x, double y, double z); 00203 void GetHandlePosition(int handle, double xyz[3]); 00204 double* GetHandlePosition(int handle); 00206 00208 00209 vtkGetMacro(NumberOfHandles,int); 00211 00213 00214 void SetInteraction(int interact); 00215 vtkGetMacro(Interaction,int); 00216 vtkBooleanMacro(Interaction,int); 00218 00222 void InitializeHandles(vtkPoints*); 00223 00225 int IsClosed(); 00226 00227 #ifdef VTK_WORKAROUND_WINDOWS_MANGLE 00228 # define SetPropA SetProp 00229 # define SetPropW SetProp 00230 #endif 00231 00234 VTK_LEGACY(void SetProp(vtkProp* prop)); 00235 00236 #ifdef VTK_WORKAROUND_WINDOWS_MANGLE 00237 # undef SetPropA 00238 # undef SetPropW 00239 //BTX 00240 VTK_LEGACY(void SetPropA(vtkProp*)); 00241 VTK_LEGACY(void SetPropW(vtkProp*)); 00242 //ETX 00243 #endif 00244 00245 protected: 00246 vtkImageTracerWidget(); 00247 ~vtkImageTracerWidget(); 00248 00249 //BTX - manage the state of the widget 00250 int State; 00251 enum WidgetState 00252 { 00253 Start=0, 00254 Tracing, 00255 Snapping, 00256 Erasing, 00257 Inserting, 00258 Moving, 00259 Translating, 00260 Outside 00261 }; 00262 //ETX 00263 00264 //handles the events 00265 static void ProcessEvents(vtkObject* object, 00266 unsigned long event, 00267 void* clientdata, 00268 void* calldata); 00269 00270 // ProcessEvents() dispatches to these methods. 00271 void OnLeftButtonDown(); 00272 void OnLeftButtonUp(); 00273 void OnMiddleButtonDown(); 00274 void OnMiddleButtonUp(); 00275 void OnRightButtonDown(); 00276 void OnRightButtonUp(); 00277 void OnMouseMove(); 00278 00279 void AddObservers(); 00280 00281 // Controlling ivars 00282 int Interaction; 00283 int ProjectionNormal; 00284 double ProjectionPosition; 00285 int ProjectToPlane; 00286 int ImageSnapType; 00287 int SnapToImage; 00288 double CaptureRadius; // tolerance for auto path close 00289 int AutoClose; 00290 int IsSnapping; 00291 int LastX; 00292 int LastY; 00293 00294 void Trace(int , int ); 00295 void Snap(double* ); 00296 void MovePoint(const double* , const double* ); 00297 void Translate(const double* , const double* ); 00298 void ClosePath(); 00299 00300 // 2D glyphs representing hot spots (e.g., handles) 00301 vtkActor **Handle; 00302 vtkPolyData **HandleGeometry; 00303 vtkGlyphSource2D *HandleGenerator; 00304 00305 // Transforms required as 2D glyphs are generated in the x-y plane 00306 vtkTransformPolyDataFilter *TransformFilter; 00307 vtkTransform *Transform; 00308 vtkFloatArray *TemporaryHandlePoints; 00309 00310 void AppendHandles(double*); 00311 void ResetHandles(); 00312 void AllocateHandles(const int& ); 00313 void AdjustHandlePosition(const int& , double*); 00314 int HighlightHandle(vtkProp* ); // returns handle index or -1 on fail 00315 void EraseHandle(const int& ); 00316 virtual void SizeHandles(); 00317 void InsertHandleOnLine(double* ); 00318 00319 int NumberOfHandles; 00320 vtkActor *CurrentHandle; 00321 int CurrentHandleIndex; 00322 00323 vtkProp *ViewProp; // the prop we want to pick on 00324 vtkPropPicker *PropPicker; // the prop's picker 00325 00326 // Representation of the line 00327 vtkPoints *LinePoints; 00328 vtkCellArray *LineCells; 00329 vtkActor *LineActor; 00330 vtkPolyData *LineData; 00331 vtkIdType CurrentPoints[2]; 00332 00333 void HighlightLine(const int& ); 00334 void BuildLinesFromHandles(); 00335 void ResetLine(double* ); 00336 void AppendLine(double* ); 00337 int PickCount; 00338 00339 // Do the picking of the handles and the lines 00340 vtkCellPicker *HandlePicker; 00341 vtkCellPicker *LinePicker; 00342 vtkAbstractPropPicker* CurrentPicker; 00343 00344 // Properties used to control the appearance of selected objects and 00345 // the manipulator in general. 00346 vtkProperty *HandleProperty; 00347 vtkProperty *SelectedHandleProperty; 00348 vtkProperty *LineProperty; 00349 vtkProperty *SelectedLineProperty; 00350 void CreateDefaultProperties(); 00351 00352 private: 00353 vtkImageTracerWidget(const vtkImageTracerWidget&); //Not implemented 00354 void operator=(const vtkImageTracerWidget&); //Not implemented 00355 }; 00356 00357 #endif