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