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