VTK
dox/Widgets/vtkBoxRepresentation.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkBoxRepresentation.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 =========================================================================*/
00038 #ifndef __vtkBoxRepresentation_h
00039 #define __vtkBoxRepresentation_h
00040 
00041 #include "vtkWidgetRepresentation.h"
00042 
00043 class vtkActor;
00044 class vtkPolyDataMapper;
00045 class vtkLineSource;
00046 class vtkSphereSource;
00047 class vtkCellPicker;
00048 class vtkProperty;
00049 class vtkPolyData;
00050 class vtkPoints;
00051 class vtkPolyDataAlgorithm;
00052 class vtkPointHandleRepresentation3D;
00053 class vtkTransform;
00054 class vtkPlanes;
00055 class vtkBox;
00056 class vtkDoubleArray;
00057 class vtkMatrix4x4;
00058 
00059 
00060 class VTK_WIDGETS_EXPORT vtkBoxRepresentation : public vtkWidgetRepresentation
00061 {
00062 public:
00064   static vtkBoxRepresentation *New();
00065 
00067 
00068   vtkTypeMacro(vtkBoxRepresentation,vtkWidgetRepresentation);
00069   void PrintSelf(ostream& os, vtkIndent indent);
00071 
00078   void GetPlanes(vtkPlanes *planes);
00079 
00081 
00085   vtkSetMacro(InsideOut,int);
00086   vtkGetMacro(InsideOut,int);
00087   vtkBooleanMacro(InsideOut,int);
00089 
00095   virtual void GetTransform(vtkTransform *t);
00096 
00101   virtual void SetTransform(vtkTransform* t);
00102 
00112   void GetPolyData(vtkPolyData *pd);
00113 
00115 
00117   vtkGetObjectMacro(HandleProperty,vtkProperty);
00118   vtkGetObjectMacro(SelectedHandleProperty,vtkProperty);
00120 
00122 
00124   vtkGetObjectMacro(FaceProperty,vtkProperty);
00125   vtkGetObjectMacro(SelectedFaceProperty,vtkProperty);
00127   
00129 
00131   vtkGetObjectMacro(OutlineProperty,vtkProperty);
00132   vtkGetObjectMacro(SelectedOutlineProperty,vtkProperty);
00134   
00136 
00138   void SetOutlineFaceWires(int);
00139   vtkGetMacro(OutlineFaceWires,int);
00140   void OutlineFaceWiresOn() {this->SetOutlineFaceWires(1);}
00141   void OutlineFaceWiresOff() {this->SetOutlineFaceWires(0);}
00143 
00145 
00148   void SetOutlineCursorWires(int);
00149   vtkGetMacro(OutlineCursorWires,int);
00150   void OutlineCursorWiresOn() {this->SetOutlineCursorWires(1);}
00151   void OutlineCursorWiresOff() {this->SetOutlineCursorWires(0);}
00153 
00155 
00157   virtual void HandlesOn();
00158   virtual void HandlesOff();
00160   
00162 
00163   virtual void PlaceWidget(double bounds[6]);
00164   virtual void BuildRepresentation();
00165   virtual int  ComputeInteractionState(int X, int Y, int modify=0);
00166   virtual void StartWidgetInteraction(double e[2]);
00167   virtual void WidgetInteraction(double e[2]);
00168   virtual double *GetBounds();
00170   
00172 
00173   virtual void ReleaseGraphicsResources(vtkWindow*);
00174   virtual int  RenderOpaqueGeometry(vtkViewport*);
00175   virtual int  RenderTranslucentPolygonalGeometry(vtkViewport*);
00176   virtual int  HasTranslucentPolygonalGeometry();
00178   
00179 //BTX - used to manage the state of the widget
00180   enum {Outside=0,MoveF0,MoveF1,MoveF2,MoveF3,MoveF4,MoveF5,Translating,Rotating,Scaling};
00181 //ETX
00182 
00190   void SetInteractionState(int state);
00191 
00192 protected:
00193   vtkBoxRepresentation();
00194   ~vtkBoxRepresentation();
00195 
00196   // Manage how the representation appears
00197   double LastEventPosition[3];
00198   
00199   // the hexahedron (6 faces)
00200   vtkActor          *HexActor;
00201   vtkPolyDataMapper *HexMapper;
00202   vtkPolyData       *HexPolyData;
00203   vtkPoints         *Points;  //used by others as well
00204   double             N[6][3]; //the normals of the faces
00205 
00206   // A face of the hexahedron
00207   vtkActor          *HexFace;
00208   vtkPolyDataMapper *HexFaceMapper;
00209   vtkPolyData       *HexFacePolyData;
00210 
00211   // glyphs representing hot spots (e.g., handles)
00212   vtkActor          **Handle;
00213   vtkPolyDataMapper **HandleMapper;
00214   vtkSphereSource   **HandleGeometry;
00215   virtual void PositionHandles();
00216   int HighlightHandle(vtkProp *prop); //returns cell id
00217   void HighlightFace(int cellId);
00218   void HighlightOutline(int highlight);
00219   virtual void ComputeNormals();
00220   virtual void SizeHandles();
00221   
00222   // wireframe outline
00223   vtkActor          *HexOutline;
00224   vtkPolyDataMapper *OutlineMapper;
00225   vtkPolyData       *OutlinePolyData;
00226 
00227   // Do the picking
00228   vtkCellPicker *HandlePicker;
00229   vtkCellPicker *HexPicker;
00230   vtkActor *CurrentHandle;
00231   int      CurrentHexFace;
00232   vtkCellPicker *LastPicker;
00233   
00234   // Transform the hexahedral points (used for rotations)
00235   vtkTransform *Transform;
00236   
00237   // Support GetBounds() method
00238   vtkBox *BoundingBox;
00239   
00240   // Properties used to control the appearance of selected objects and
00241   // the manipulator in general.
00242   vtkProperty *HandleProperty;
00243   vtkProperty *SelectedHandleProperty;
00244   vtkProperty *FaceProperty;
00245   vtkProperty *SelectedFaceProperty;
00246   vtkProperty *OutlineProperty;
00247   vtkProperty *SelectedOutlineProperty;
00248   virtual void CreateDefaultProperties();
00249   
00250   // Control the orientation of the normals
00251   int InsideOut;
00252   int OutlineFaceWires;
00253   int OutlineCursorWires;
00254   void GenerateOutline();
00255   
00256   // Helper methods
00257   virtual void Translate(double *p1, double *p2);
00258   virtual void Scale(double *p1, double *p2, int X, int Y);
00259   virtual void Rotate(int X, int Y, double *p1, double *p2, double *vpn);
00260   void MovePlusXFace(double *p1, double *p2);
00261   void MoveMinusXFace(double *p1, double *p2);
00262   void MovePlusYFace(double *p1, double *p2);
00263   void MoveMinusYFace(double *p1, double *p2);
00264   void MovePlusZFace(double *p1, double *p2);
00265   void MoveMinusZFace(double *p1, double *p2);
00266 
00267   // Internal ivars for performance
00268   vtkPoints      *PlanePoints;
00269   vtkDoubleArray *PlaneNormals;
00270   vtkMatrix4x4   *Matrix;
00271 
00272   //"dir" is the direction in which the face can be moved i.e. the axis passing
00273   //through the center
00274   void MoveFace(double *p1, double *p2, double *dir, 
00275                 double *x1, double *x2, double *x3, double *x4,
00276                 double *x5);
00277   //Helper method to obtain the direction in which the face is to be moved.
00278   //Handles special cases where some of the scale factors are 0.
00279   void GetDirection(const double Nx[3],const double Ny[3], 
00280                     const double Nz[3], double dir[3]);
00281 
00282 
00283 private:
00284   vtkBoxRepresentation(const vtkBoxRepresentation&);  //Not implemented
00285   void operator=(const vtkBoxRepresentation&);  //Not implemented
00286 };
00287 
00288 #endif