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