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

vtkBoxWidget.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkBoxWidget.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 =========================================================================*/
00099 #ifndef __vtkBoxWidget_h
00100 #define __vtkBoxWidget_h
00101 
00102 #include "vtk3DWidget.h"
00103 
00104 class vtkActor;
00105 class vtkCellPicker;
00106 class vtkPlanes;
00107 class vtkPoints;
00108 class vtkPolyData;
00109 class vtkPolyDataMapper;
00110 class vtkProp;
00111 class vtkProperty;
00112 class vtkSphereSource;
00113 class vtkTransform;
00114 
00115 class VTK_HYBRID_EXPORT vtkBoxWidget : public vtk3DWidget
00116 {
00117 public:
00119   static vtkBoxWidget *New();
00120 
00121   vtkTypeRevisionMacro(vtkBoxWidget,vtk3DWidget);
00122   void PrintSelf(ostream& os, vtkIndent indent);
00123 
00125 
00126   virtual void SetEnabled(int);
00127   virtual void PlaceWidget(double bounds[6]);
00128   void PlaceWidget()
00129     {this->Superclass::PlaceWidget();}
00130   void PlaceWidget(double xmin, double xmax, double ymin, double ymax, 
00131                    double zmin, double zmax)
00132     {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);}
00134 
00141   void GetPlanes(vtkPlanes *planes);
00142 
00144 
00147   vtkSetMacro(InsideOut,int);
00148   vtkGetMacro(InsideOut,int);
00149   vtkBooleanMacro(InsideOut,int);
00151 
00157   virtual void GetTransform(vtkTransform *t);
00158 
00163   virtual void SetTransform(vtkTransform* t);
00164 
00173   void GetPolyData(vtkPolyData *pd);
00174 
00176 
00178   vtkGetObjectMacro(HandleProperty,vtkProperty);
00179   vtkGetObjectMacro(SelectedHandleProperty,vtkProperty);
00181 
00183 
00185   void HandlesOn();
00186   void HandlesOff();
00188   
00190 
00192   vtkGetObjectMacro(FaceProperty,vtkProperty);
00193   vtkGetObjectMacro(SelectedFaceProperty,vtkProperty);
00195   
00197 
00199   vtkGetObjectMacro(OutlineProperty,vtkProperty);
00200   vtkGetObjectMacro(SelectedOutlineProperty,vtkProperty);
00202   
00204 
00206   void SetOutlineFaceWires(int);
00207   vtkGetMacro(OutlineFaceWires,int);
00208   void OutlineFaceWiresOn() {this->SetOutlineFaceWires(1);}
00209   void OutlineFaceWiresOff() {this->SetOutlineFaceWires(0);}
00211 
00213 
00216   void SetOutlineCursorWires(int);
00217   vtkGetMacro(OutlineCursorWires,int);
00218   void OutlineCursorWiresOn() {this->SetOutlineCursorWires(1);}
00219   void OutlineCursorWiresOff() {this->SetOutlineCursorWires(0);}
00221 
00223 
00225   vtkSetMacro(TranslationEnabled,int);
00226   vtkGetMacro(TranslationEnabled,int);
00227   vtkBooleanMacro(TranslationEnabled,int);
00228   vtkSetMacro(ScalingEnabled,int);
00229   vtkGetMacro(ScalingEnabled,int);
00230   vtkBooleanMacro(ScalingEnabled,int);
00231   vtkSetMacro(RotationEnabled,int);
00232   vtkGetMacro(RotationEnabled,int);
00233   vtkBooleanMacro(RotationEnabled,int);
00235 
00236 protected:
00237   vtkBoxWidget();
00238   ~vtkBoxWidget();
00239 
00240 //BTX - manage the state of the widget
00241   int State;
00242   enum WidgetState
00243   {
00244     Start=0,
00245     Moving,
00246     Scaling,
00247     Outside
00248   };
00249 //ETX
00250     
00251   // Handles the events
00252   static void ProcessEvents(vtkObject* object, 
00253                             unsigned long event,
00254                             void* clientdata, 
00255                             void* calldata);
00256 
00257   // ProcessEvents() dispatches to these methods.
00258   virtual void OnMouseMove();
00259   virtual void OnLeftButtonDown();
00260   virtual void OnLeftButtonUp();
00261   virtual void OnMiddleButtonDown();
00262   virtual void OnMiddleButtonUp();
00263   virtual void OnRightButtonDown();
00264   virtual void OnRightButtonUp();
00265   
00266   // the hexahedron (6 faces)
00267   vtkActor          *HexActor;
00268   vtkPolyDataMapper *HexMapper;
00269   vtkPolyData       *HexPolyData;
00270   vtkPoints         *Points;  //used by others as well
00271   double             N[6][3]; //the normals of the faces
00272 
00273   // A face of the hexahedron
00274   vtkActor          *HexFace;
00275   vtkPolyDataMapper *HexFaceMapper;
00276   vtkPolyData       *HexFacePolyData;
00277 
00278   // glyphs representing hot spots (e.g., handles)
00279   vtkActor          **Handle;
00280   vtkPolyDataMapper **HandleMapper;
00281   vtkSphereSource   **HandleGeometry;
00282   virtual void PositionHandles();
00283   int HighlightHandle(vtkProp *prop); //returns cell id
00284   void HighlightFace(int cellId);
00285   void HighlightOutline(int highlight);
00286   void ComputeNormals();
00287   virtual void SizeHandles();
00288   
00289   // wireframe outline
00290   vtkActor          *HexOutline;
00291   vtkPolyDataMapper *OutlineMapper;
00292   vtkPolyData       *OutlinePolyData;
00293 
00294   // Do the picking
00295   vtkCellPicker *HandlePicker;
00296   vtkCellPicker *HexPicker;
00297   vtkActor *CurrentHandle;
00298   int      CurrentHexFace;
00299   
00300   // Methods to manipulate the hexahedron.
00301   virtual void Translate(double *p1, double *p2);
00302   virtual void Scale(double *p1, double *p2, int X, int Y);
00303   virtual void Rotate(int X, int Y, double *p1, double *p2, double *vpn);
00304   void MovePlusXFace(double *p1, double *p2);
00305   void MoveMinusXFace(double *p1, double *p2);
00306   void MovePlusYFace(double *p1, double *p2);
00307   void MoveMinusYFace(double *p1, double *p2);
00308   void MovePlusZFace(double *p1, double *p2);
00309   void MoveMinusZFace(double *p1, double *p2);
00310 
00311   //"dir" is the direction in which the face can be moved i.e. the axis passing
00312   //through the center
00313   void MoveFace(double *p1, double *p2, double *dir, 
00314                 double *x1, double *x2, double *x3, double *x4,
00315                 double *x5);
00316   //Helper method to obtain the direction in which the face is to be moved.
00317   //Handles special cases where some of the scale factors are 0.
00318   void GetDirection(const double Nx[3],const double Ny[3], 
00319                     const double Nz[3], double dir[3]);
00320 
00321   // Transform the hexahedral points (used for rotations)
00322   vtkTransform *Transform;
00323   
00324   // Properties used to control the appearance of selected objects and
00325   // the manipulator in general.
00326   vtkProperty *HandleProperty;
00327   vtkProperty *SelectedHandleProperty;
00328   vtkProperty *FaceProperty;
00329   vtkProperty *SelectedFaceProperty;
00330   vtkProperty *OutlineProperty;
00331   vtkProperty *SelectedOutlineProperty;
00332   void CreateDefaultProperties();
00333   
00334   // Control the orientation of the normals
00335   int InsideOut;
00336   int OutlineFaceWires;
00337   int OutlineCursorWires;
00338   void GenerateOutline();
00339   
00340   // Control whether scaling, rotation, and translation are supported
00341   int TranslationEnabled;
00342   int ScalingEnabled;
00343   int RotationEnabled;
00344 
00345 private:
00346   vtkBoxWidget(const vtkBoxWidget&);  //Not implemented
00347   void operator=(const vtkBoxWidget&);  //Not implemented
00348 };
00349 
00350 #endif