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