VTK
/Users/kitware/Dashboards/MyTests/VTK_BLD_Release_docs/Utilities/Doxygen/dox/Interaction/Widgets/vtkImageTracerWidget.h
Go to the documentation of this file.
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 "vtkInteractionWidgetsModule.h" // For export macro
00066 #include "vtk3DWidget.h"
00067 
00068 class vtkAbstractPropPicker;
00069 class vtkActor;
00070 class vtkCellArray;
00071 class vtkCellPicker;
00072 class vtkFloatArray;
00073 class vtkGlyphSource2D;
00074 class vtkPoints;
00075 class vtkPolyData;
00076 class vtkProp;
00077 class vtkProperty;
00078 class vtkPropPicker;
00079 class vtkTransform;
00080 class vtkTransformPolyDataFilter;
00081 
00082 #define VTK_ITW_PROJECTION_YZ 0
00083 #define VTK_ITW_PROJECTION_XZ 1
00084 #define VTK_ITW_PROJECTION_XY 2
00085 #define VTK_ITW_SNAP_CELLS    0
00086 #define VTK_ITW_SNAP_POINTS   1
00087 
00088 class VTKINTERACTIONWIDGETS_EXPORT vtkImageTracerWidget : public vtk3DWidget
00089 {
00090 public:
00092   static vtkImageTracerWidget *New();
00093 
00094   vtkTypeMacro(vtkImageTracerWidget,vtk3DWidget);
00095   void PrintSelf(ostream& os, vtkIndent indent);
00096 
00098 
00099   virtual void SetEnabled(int);
00100   virtual void PlaceWidget(double bounds[6]);
00101   void PlaceWidget()
00102     {this->Superclass::PlaceWidget();}
00103   void PlaceWidget(double xmin, double xmax, double ymin, double ymax,
00104                    double zmin, double zmax)
00105     {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);}
00107 
00109 
00112   virtual void SetHandleProperty(vtkProperty*);
00113   vtkGetObjectMacro(HandleProperty, vtkProperty);
00114   virtual void SetSelectedHandleProperty(vtkProperty*);
00115   vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
00117 
00119 
00121   virtual void SetLineProperty(vtkProperty*);
00122   vtkGetObjectMacro(LineProperty, vtkProperty);
00123   virtual void SetSelectedLineProperty(vtkProperty*);
00124   vtkGetObjectMacro(SelectedLineProperty, vtkProperty);
00126 
00128   void SetViewProp(vtkProp* prop);
00129 
00131 
00132   vtkSetMacro(ProjectToPlane,int);
00133   vtkGetMacro(ProjectToPlane,int);
00134   vtkBooleanMacro(ProjectToPlane,int);
00136 
00138 
00142   vtkSetClampMacro(ProjectionNormal,int,VTK_ITW_PROJECTION_YZ,VTK_ITW_PROJECTION_XY);
00143   vtkGetMacro(ProjectionNormal,int);
00144   void SetProjectionNormalToXAxes()
00145     { this->SetProjectionNormal(0); }
00146   void SetProjectionNormalToYAxes()
00147     { this->SetProjectionNormal(1); }
00148   void SetProjectionNormalToZAxes()
00149     { this->SetProjectionNormal(2); }
00151 
00153 
00158   void SetProjectionPosition(double position);
00159   vtkGetMacro(ProjectionPosition,double);
00161 
00163 
00164   void SetSnapToImage(int snap);
00165   vtkGetMacro(SnapToImage,int);
00166   vtkBooleanMacro(SnapToImage,int);
00168 
00170 
00172   vtkSetMacro(AutoClose,int);
00173   vtkGetMacro(AutoClose,int);
00174   vtkBooleanMacro(AutoClose,int);
00176 
00178 
00181   vtkSetMacro(CaptureRadius,double);
00182   vtkGetMacro(CaptureRadius,double);
00184 
00190   void GetPath(vtkPolyData *pd);
00191 
00193   vtkGlyphSource2D* GetGlyphSource() { return this->HandleGenerator; }
00194 
00196 
00198   vtkSetClampMacro(ImageSnapType,int,VTK_ITW_SNAP_CELLS,VTK_ITW_SNAP_POINTS);
00199   vtkGetMacro(ImageSnapType,int);
00201 
00203 
00205   void SetHandlePosition(int handle, double xyz[3]);
00206   void SetHandlePosition(int handle, double x, double y, double z);
00207   void GetHandlePosition(int handle, double xyz[3]);
00208   double* GetHandlePosition(int handle);
00210 
00212 
00213   vtkGetMacro(NumberOfHandles,int);
00215 
00217 
00218   void SetInteraction(int interact);
00219   vtkGetMacro(Interaction,int);
00220   vtkBooleanMacro(Interaction,int);
00222 
00226   void InitializeHandles(vtkPoints*);
00227 
00229   int IsClosed();
00230 
00232 
00233   vtkSetMacro(HandleLeftMouseButton,int);
00234   vtkGetMacro(HandleLeftMouseButton,int);
00235   vtkBooleanMacro(HandleLeftMouseButton,int);
00236   vtkSetMacro(HandleMiddleMouseButton,int);
00237   vtkGetMacro(HandleMiddleMouseButton,int);
00238   vtkBooleanMacro(HandleMiddleMouseButton,int);
00239   vtkSetMacro(HandleRightMouseButton,int);
00240   vtkGetMacro(HandleRightMouseButton,int);
00241   vtkBooleanMacro(HandleRightMouseButton,int);
00243 
00244 #ifdef VTK_WORKAROUND_WINDOWS_MANGLE
00245 # define SetPropA SetProp
00246 # define SetPropW SetProp
00247 #endif
00248 
00251   VTK_LEGACY(void SetProp(vtkProp* prop));
00252 
00253 #ifdef VTK_WORKAROUND_WINDOWS_MANGLE
00254 # undef SetPropA
00255 # undef SetPropW
00256   //BTX
00257   VTK_LEGACY(void SetPropA(vtkProp*));
00258   VTK_LEGACY(void SetPropW(vtkProp*));
00259   //ETX
00260 #endif
00261 
00262 protected:
00263   vtkImageTracerWidget();
00264   ~vtkImageTracerWidget();
00265 
00266 //BTX - manage the state of the widget
00267   int State;
00268   enum WidgetState
00269   {
00270     Start=0,
00271     Tracing,
00272     Snapping,
00273     Erasing,
00274     Inserting,
00275     Moving,
00276     Translating,
00277     Outside
00278   };
00279 //ETX
00280 
00281   //handles the events
00282   static void ProcessEvents(vtkObject* object,
00283                             unsigned long event,
00284                             void* clientdata,
00285                             void* calldata);
00286 
00287   // ProcessEvents() dispatches to these methods.
00288   void OnLeftButtonDown();
00289   void OnLeftButtonUp();
00290   void OnMiddleButtonDown();
00291   void OnMiddleButtonUp();
00292   void OnRightButtonDown();
00293   void OnRightButtonUp();
00294   void OnMouseMove();
00295 
00296   void AddObservers();
00297 
00298   // Controlling ivars
00299   int    Interaction;
00300   int    ProjectionNormal;
00301   double ProjectionPosition;
00302   int    ProjectToPlane;
00303   int    ImageSnapType;
00304   int    SnapToImage;
00305   double CaptureRadius; // tolerance for auto path close
00306   int    AutoClose;
00307   int    IsSnapping;
00308   int    LastX;
00309   int    LastY;
00310 
00311   void  Trace(int , int );
00312   void  Snap(double* );
00313   void  MovePoint(const double* , const double* );
00314   void  Translate(const double* , const double* );
00315   void  ClosePath();
00316 
00317   // 2D glyphs representing hot spots (e.g., handles)
00318   vtkActor          **Handle;
00319   vtkPolyData       **HandleGeometry;
00320   vtkGlyphSource2D   *HandleGenerator;
00321 
00322   // Transforms required as 2D glyphs are generated in the x-y plane
00323   vtkTransformPolyDataFilter *TransformFilter;
00324   vtkTransform               *Transform;
00325   vtkFloatArray              *TemporaryHandlePoints;
00326 
00327   void AppendHandles(double*);
00328   void ResetHandles();
00329   void AllocateHandles(const int& );
00330   void AdjustHandlePosition(const int& , double*);
00331   int  HighlightHandle(vtkProp* ); // returns handle index or -1 on fail
00332   void EraseHandle(const int& );
00333   virtual void SizeHandles();
00334   void InsertHandleOnLine(double* );
00335 
00336   int NumberOfHandles;
00337   vtkActor *CurrentHandle;
00338   int CurrentHandleIndex;
00339 
00340   vtkProp       *ViewProp;    // the prop we want to pick on
00341   vtkPropPicker *PropPicker;  // the prop's picker
00342 
00343   // Representation of the line
00344   vtkPoints         *LinePoints;
00345   vtkCellArray      *LineCells;
00346   vtkActor          *LineActor;
00347   vtkPolyData       *LineData;
00348   vtkIdType          CurrentPoints[2];
00349 
00350   void HighlightLine(const int& );
00351   void BuildLinesFromHandles();
00352   void ResetLine(double* );
00353   void AppendLine(double* );
00354   int  PickCount;
00355 
00356   // Do the picking of the handles and the lines
00357   vtkCellPicker *HandlePicker;
00358   vtkCellPicker *LinePicker;
00359   vtkAbstractPropPicker* CurrentPicker;
00360 
00361   // Register internal Pickers within PickingManager
00362   virtual void RegisterPickers();
00363 
00364   // Properties used to control the appearance of selected objects and
00365   // the manipulator in general.
00366   vtkProperty *HandleProperty;
00367   vtkProperty *SelectedHandleProperty;
00368   vtkProperty *LineProperty;
00369   vtkProperty *SelectedLineProperty;
00370   void CreateDefaultProperties();
00371 
00372   // Enable/Disable mouse button events
00373   int HandleLeftMouseButton;
00374   int HandleMiddleMouseButton;
00375   int HandleRightMouseButton;
00376 
00377 private:
00378   vtkImageTracerWidget(const vtkImageTracerWidget&);  //Not implemented
00379   void operator=(const vtkImageTracerWidget&);  //Not implemented
00380 };
00381 
00382 #endif