Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

Hybrid/vtkPlaneWidget.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkPlaneWidget.h,v $
00005   Language:  C++
00006 
00007   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
00008   All rights reserved.
00009   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00010 
00011      This software is distributed WITHOUT ANY WARRANTY; without even 
00012      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00013      PURPOSE.  See the above copyright notice for more information.
00014 
00015 =========================================================================*/
00102 #ifndef __vtkPlaneWidget_h
00103 #define __vtkPlaneWidget_h
00104 
00105 #include "vtkPolyDataSourceWidget.h"
00106 
00107 class vtkActor;
00108 class vtkCellPicker;
00109 class vtkConeSource;
00110 class vtkLineSource;
00111 class vtkPlaneSource;
00112 class vtkPoints;
00113 class vtkPolyData;
00114 class vtkPolyDataMapper;
00115 class vtkProp;
00116 class vtkProperty;
00117 class vtkSphereSource;
00118 class vtkTransform;
00119 class vtkPlane;
00120 
00121 #define VTK_PLANE_OFF 0
00122 #define VTK_PLANE_OUTLINE 1
00123 #define VTK_PLANE_WIREFRAME 2
00124 #define VTK_PLANE_SURFACE 3
00125 
00126 class VTK_HYBRID_EXPORT vtkPlaneWidget : public vtkPolyDataSourceWidget
00127 {
00128 public:
00130   static vtkPlaneWidget *New();
00131 
00132   vtkTypeRevisionMacro(vtkPlaneWidget,vtkPolyDataSourceWidget);
00133   void PrintSelf(ostream& os, vtkIndent indent);
00134 
00136 
00137   virtual void SetEnabled(int);
00138   virtual void PlaceWidget(float bounds[6]);
00139   void PlaceWidget()
00140     {this->Superclass::PlaceWidget();}
00142 
00144 
00145   void SetResolution(int r);
00146   int GetResolution();
00148 
00150 
00151   void SetOrigin(float x, float y, float z);
00152   void SetOrigin(float x[3]);
00153   float* GetOrigin();
00154   void GetOrigin(float xyz[3]);
00156 
00158 
00160   void SetPoint1(float x, float y, float z);
00161   void SetPoint1(float x[3]);
00162   float* GetPoint1();
00163   void GetPoint1(float xyz[3]);
00165   
00167 
00169   void SetPoint2(float x, float y, float z);
00170   void SetPoint2(float x[3]);
00171   float* GetPoint2();
00172   void GetPoint2(float xyz[3]);
00174 
00176 
00177   void SetCenter(float x, float y, float z);
00178   void SetCenter(float x[3]);
00179   float* GetCenter();
00180   void GetCenter(float xyz[3]);
00182 
00184 
00185   void SetNormal(float x, float y, float z);
00186   void SetNormal(float x[3]);
00187   float* GetNormal();
00188   void GetNormal(float xyz[3]);
00190   
00192 
00197   vtkSetClampMacro(Representation,int,VTK_PLANE_OFF,VTK_PLANE_SURFACE);
00198   vtkGetMacro(Representation,int);
00199   void SetRepresentationToOff()
00200     {this->SetRepresentation(VTK_PLANE_OFF);}
00201   void SetRepresentationToOutline()
00202     {this->SetRepresentation(VTK_PLANE_OUTLINE);}
00203   void SetRepresentationToWireframe()
00204     {this->SetRepresentation(VTK_PLANE_WIREFRAME);}
00205   void SetRepresentationToSurface()
00206     {this->SetRepresentation(VTK_PLANE_SURFACE);}
00208 
00210 
00214   vtkSetMacro(NormalToXAxis,int);
00215   vtkGetMacro(NormalToXAxis,int);
00216   vtkBooleanMacro(NormalToXAxis,int);
00217   vtkSetMacro(NormalToYAxis,int);
00218   vtkGetMacro(NormalToYAxis,int);
00219   vtkBooleanMacro(NormalToYAxis,int);
00220   vtkSetMacro(NormalToZAxis,int);
00221   vtkGetMacro(NormalToZAxis,int);
00222   vtkBooleanMacro(NormalToZAxis,int);
00224 
00232   void GetPolyData(vtkPolyData *pd);
00233 
00239   void GetPlane(vtkPlane *plane);
00240 
00246   vtkPolyDataSource* GetPolyDataSource();
00247    
00250   void UpdatePlacement(void);
00251 
00253 
00256   vtkGetObjectMacro(HandleProperty,vtkProperty);
00257   vtkGetObjectMacro(SelectedHandleProperty,vtkProperty);
00259   
00261 
00263   virtual void SetPlaneProperty(vtkProperty*);
00264   vtkGetObjectMacro(PlaneProperty,vtkProperty);
00265   vtkGetObjectMacro(SelectedPlaneProperty,vtkProperty);
00267   
00268 protected:
00269   vtkPlaneWidget();
00270   ~vtkPlaneWidget();
00271 
00272 //BTX - manage the state of the widget
00273   int State;
00274   enum WidgetState
00275   {
00276     Start=0,
00277     Moving,
00278     Scaling,
00279     Pushing,
00280     Rotating,
00281     Outside
00282   };
00283 //ETX
00284     
00285   //handles the events
00286   static void ProcessEvents(vtkObject* object, 
00287                             unsigned long event,
00288                             void* clientdata, 
00289                             void* calldata);
00290 
00291   // ProcessEvents() 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 ivars
00301   int NormalToXAxis;
00302   int NormalToYAxis;
00303   int NormalToZAxis;
00304   int Representation;
00305   void SelectRepresentation();
00306 
00307   // the plane
00308   vtkActor          *PlaneActor;
00309   vtkPolyDataMapper *PlaneMapper;
00310   vtkPlaneSource    *PlaneSource;
00311   vtkPolyData       *PlaneOutline;
00312   void HighlightPlane(int highlight);
00313 
00314   // glyphs representing hot spots (e.g., handles)
00315   vtkActor          **Handle;
00316   vtkPolyDataMapper **HandleMapper;
00317   vtkSphereSource   **HandleGeometry;
00318   void PositionHandles();
00319   void HandlesOn(double length);
00320   void HandlesOff();
00321   int HighlightHandle(vtkProp *prop); //returns cell id
00322   virtual void SizeHandles();
00323   
00324   // the normal cone
00325   vtkActor          *ConeActor;
00326   vtkPolyDataMapper *ConeMapper;
00327   vtkConeSource     *ConeSource;
00328   void HighlightNormal(int highlight);
00329 
00330   // the normal line
00331   vtkActor          *LineActor;
00332   vtkPolyDataMapper *LineMapper;
00333   vtkLineSource     *LineSource;
00334 
00335   // the normal cone
00336   vtkActor          *ConeActor2;
00337   vtkPolyDataMapper *ConeMapper2;
00338   vtkConeSource     *ConeSource2;
00339 
00340   // the normal line
00341   vtkActor          *LineActor2;
00342   vtkPolyDataMapper *LineMapper2;
00343   vtkLineSource     *LineSource2;
00344 
00345   // Do the picking
00346   vtkCellPicker *HandlePicker;
00347   vtkCellPicker *PlanePicker;
00348   vtkActor *CurrentHandle;
00349   
00350   // Methods to manipulate the hexahedron.
00351   void MoveOrigin(double *p1, double *p2);
00352   void MovePoint1(double *p1, double *p2);
00353   void MovePoint2(double *p1, double *p2);
00354   void MovePoint3(double *p1, double *p2);
00355   void Rotate(int X, int Y, double *p1, double *p2, double *vpn);
00356   void Scale(double *p1, double *p2, int X, int Y);
00357   void Translate(double *p1, double *p2);
00358   void Push(double *p1, double *p2);
00359   
00360   // Plane normal, normalized
00361   float Normal[3];
00362 
00363   // Transform the hexahedral points (used for rotations)
00364   vtkTransform *Transform;
00365   
00366   // Properties used to control the appearance of selected objects and
00367   // the manipulator in general.
00368   vtkProperty *HandleProperty;
00369   vtkProperty *SelectedHandleProperty;
00370   vtkProperty *PlaneProperty;
00371   vtkProperty *SelectedPlaneProperty;
00372   void CreateDefaultProperties();
00373   
00374   void GeneratePlane();
00375   
00376 private:
00377   vtkPlaneWidget(const vtkPlaneWidget&);  //Not implemented
00378   void operator=(const vtkPlaneWidget&);  //Not implemented
00379 };
00380 
00381 #endif