VTK
dox/Widgets/vtkImplicitPlaneWidget.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkImplicitPlaneWidget.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 =========================================================================*/
00076 #ifndef __vtkImplicitPlaneWidget_h
00077 #define __vtkImplicitPlaneWidget_h
00078 
00079 #include "vtkPolyDataSourceWidget.h"
00080 
00081 class vtkActor;
00082 class vtkPolyDataMapper;
00083 class vtkCellPicker;
00084 class vtkConeSource;
00085 class vtkLineSource;
00086 class vtkSphereSource;
00087 class vtkTubeFilter;
00088 class vtkPlane;
00089 class vtkCutter;
00090 class vtkProperty;
00091 class vtkImageData;
00092 class vtkOutlineFilter;
00093 class vtkFeatureEdges;
00094 class vtkPolyData;
00095 class vtkTransform;
00096 
00097 class VTK_WIDGETS_EXPORT vtkImplicitPlaneWidget : public vtkPolyDataSourceWidget
00098 {
00099 public:
00101   static vtkImplicitPlaneWidget *New();
00102 
00103   vtkTypeMacro(vtkImplicitPlaneWidget,vtkPolyDataSourceWidget);
00104   void PrintSelf(ostream& os, vtkIndent indent);
00105 
00107 
00108   virtual void SetEnabled(int);
00109   virtual void PlaceWidget(double bounds[6]);
00110   void PlaceWidget()
00111     {this->Superclass::PlaceWidget();}
00112   void PlaceWidget(double xmin, double xmax, double ymin, double ymax,
00113                    double zmin, double zmax)
00114     {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);}
00116 
00118 
00119   virtual void SetOrigin(double x, double y, double z);
00120   virtual void SetOrigin(double x[3]);
00121   double* GetOrigin();
00122   void GetOrigin(double xyz[3]);
00124 
00126 
00127   void SetNormal(double x, double y, double z);
00128   void SetNormal(double x[3]);
00129   double* GetNormal();
00130   void GetNormal(double xyz[3]);
00132 
00134 
00138   void SetNormalToXAxis(int);
00139   vtkGetMacro(NormalToXAxis,int);
00140   vtkBooleanMacro(NormalToXAxis,int);
00141   void SetNormalToYAxis(int);
00142   vtkGetMacro(NormalToYAxis,int);
00143   vtkBooleanMacro(NormalToYAxis,int);
00144   void SetNormalToZAxis(int);
00145   vtkGetMacro(NormalToZAxis,int);
00146   vtkBooleanMacro(NormalToZAxis,int);
00148 
00150 
00152   vtkSetMacro(Tubing,int);
00153   vtkGetMacro(Tubing,int);
00154   vtkBooleanMacro(Tubing,int);
00156 
00158 
00162   void SetDrawPlane(int plane);
00163   vtkGetMacro(DrawPlane,int);
00164   vtkBooleanMacro(DrawPlane,int);
00166 
00168 
00170   vtkSetMacro(OutlineTranslation,int);
00171   vtkGetMacro(OutlineTranslation,int);
00172   vtkBooleanMacro(OutlineTranslation,int);
00174 
00176 
00178   vtkSetMacro(OutsideBounds,int);
00179   vtkGetMacro(OutsideBounds,int);
00180   vtkBooleanMacro(OutsideBounds,int);
00182 
00184 
00185   vtkSetMacro(ScaleEnabled,int);
00186   vtkGetMacro(ScaleEnabled,int);
00187   vtkBooleanMacro(ScaleEnabled,int);
00189 
00191 
00193   vtkSetMacro(OriginTranslation,int);
00194   vtkGetMacro(OriginTranslation,int);
00195   vtkBooleanMacro(OriginTranslation,int);
00197 
00199 
00201   vtkSetClampMacro(DiagonalRatio,double,0,2);
00202   vtkGetMacro(DiagonalRatio,double);
00204 
00207   void GetPolyData(vtkPolyData *pd);
00208 
00211   vtkPolyDataAlgorithm* GetPolyDataAlgorithm();
00212 
00217   void GetPlane(vtkPlane *plane);
00218 
00222   void UpdatePlacement();
00223 
00225   virtual void SizeHandles();
00226 
00228 
00229   vtkGetObjectMacro(NormalProperty,vtkProperty);
00230   vtkGetObjectMacro(SelectedNormalProperty,vtkProperty);
00232 
00234 
00236   vtkGetObjectMacro(PlaneProperty,vtkProperty);
00237   vtkGetObjectMacro(SelectedPlaneProperty,vtkProperty);
00239 
00241 
00242   vtkGetObjectMacro(OutlineProperty,vtkProperty);
00243   vtkGetObjectMacro(SelectedOutlineProperty,vtkProperty);
00245 
00247 
00249   vtkGetObjectMacro(EdgesProperty,vtkProperty);
00251 
00252 protected:
00253   vtkImplicitPlaneWidget();
00254   ~vtkImplicitPlaneWidget();
00255 
00256 //BTX - manage the state of the widget
00257   int State;
00258   enum WidgetState
00259   {
00260     Start=0,
00261     MovingPlane,
00262     MovingOutline,
00263     MovingOrigin,
00264     Scaling,
00265     Pushing,
00266     Rotating,
00267     Outside
00268   };
00269 //ETX
00270 
00271   //handles the events
00272   static void ProcessEvents(vtkObject* object, unsigned long event,
00273                             void* clientdata, void* calldata);
00274 
00275   // ProcessEvents() dispatches to these methods.
00276   void OnLeftButtonDown();
00277   void OnLeftButtonUp();
00278   void OnMiddleButtonDown();
00279   void OnMiddleButtonUp();
00280   void OnRightButtonDown();
00281   void OnRightButtonUp();
00282   void OnMouseMove();
00283 
00284   // Controlling ivars
00285   int NormalToXAxis;
00286   int NormalToYAxis;
00287   int NormalToZAxis;
00288   void UpdateRepresentation();
00289 
00290   // The actual plane which is being manipulated
00291   vtkPlane *Plane;
00292 
00293   // The bounding box is represented by a single voxel image data
00294   vtkImageData      *Box;
00295   vtkOutlineFilter  *Outline;
00296   vtkPolyDataMapper *OutlineMapper;
00297   vtkActor          *OutlineActor;
00298   void HighlightOutline(int highlight);
00299   int OutlineTranslation; //whether the outline can be moved
00300   int ScaleEnabled; //whether the widget can be scaled
00301   int OutsideBounds; //whether the widget can be moved outside input's bounds
00302 
00303   // The cut plane is produced with a vtkCutter
00304   vtkCutter         *Cutter;
00305   vtkPolyDataMapper *CutMapper;
00306   vtkActor          *CutActor;
00307   int               DrawPlane;
00308   virtual void HighlightPlane(int highlight);
00309 
00310   // Optional tubes are represented by extracting boundary edges and tubing
00311   vtkFeatureEdges   *Edges;
00312   vtkTubeFilter     *EdgesTuber;
00313   vtkPolyDataMapper *EdgesMapper;
00314   vtkActor          *EdgesActor;
00315   int               Tubing; //control whether tubing is on
00316 
00317   // Control final length of the arrow:
00318   double DiagonalRatio;
00319 
00320   // The + normal cone
00321   vtkConeSource     *ConeSource;
00322   vtkPolyDataMapper *ConeMapper;
00323   vtkActor          *ConeActor;
00324   void HighlightNormal(int highlight);
00325 
00326   // The + normal line
00327   vtkLineSource     *LineSource;
00328   vtkPolyDataMapper *LineMapper;
00329   vtkActor          *LineActor;
00330 
00331   // The - normal cone
00332   vtkConeSource     *ConeSource2;
00333   vtkPolyDataMapper *ConeMapper2;
00334   vtkActor          *ConeActor2;
00335 
00336   // The - normal line
00337   vtkLineSource     *LineSource2;
00338   vtkPolyDataMapper *LineMapper2;
00339   vtkActor          *LineActor2;
00340 
00341   // The origin positioning handle
00342   vtkSphereSource   *Sphere;
00343   vtkPolyDataMapper *SphereMapper;
00344   vtkActor          *SphereActor;
00345   int OriginTranslation; //whether the origin (sphere) can be moved
00346 
00347   // Do the picking
00348   vtkCellPicker *Picker;
00349 
00350   // Transform the normal (used for rotation)
00351   vtkTransform *Transform;
00352 
00353   // Methods to manipulate the plane
00354   void ConstrainOrigin(double x[3]);
00355   void Rotate(int X, int Y, double *p1, double *p2, double *vpn);
00356   void TranslatePlane(double *p1, double *p2);
00357   void TranslateOutline(double *p1, double *p2);
00358   void TranslateOrigin(double *p1, double *p2);
00359   void Push(double *p1, double *p2);
00360   void Scale(double *p1, double *p2, int X, int Y);
00361 
00362   // Properties used to control the appearance of selected objects and
00363   // the manipulator in general.
00364   vtkProperty *NormalProperty;
00365   vtkProperty *SelectedNormalProperty;
00366   vtkProperty *PlaneProperty;
00367   vtkProperty *SelectedPlaneProperty;
00368   vtkProperty *OutlineProperty;
00369   vtkProperty *SelectedOutlineProperty;
00370   vtkProperty *EdgesProperty;
00371   void CreateDefaultProperties();
00372 
00373   void GeneratePlane();
00374 
00375 private:
00376   vtkImplicitPlaneWidget(const vtkImplicitPlaneWidget&);  //Not implemented
00377   void operator=(const vtkImplicitPlaneWidget&);  //Not implemented
00378 };
00379 
00380 #endif