VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkPlaneWidget.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 =========================================================================*/ 00083 #ifndef __vtkPlaneWidget_h 00084 #define __vtkPlaneWidget_h 00085 00086 #include "vtkInteractionWidgetsModule.h" // For export macro 00087 #include "vtkPolyDataSourceWidget.h" 00088 00089 class vtkActor; 00090 class vtkCellPicker; 00091 class vtkConeSource; 00092 class vtkLineSource; 00093 class vtkPlaneSource; 00094 class vtkPoints; 00095 class vtkPolyData; 00096 class vtkPolyDataMapper; 00097 class vtkProp; 00098 class vtkProperty; 00099 class vtkSphereSource; 00100 class vtkTransform; 00101 class vtkPlane; 00102 00103 #define VTK_PLANE_OFF 0 00104 #define VTK_PLANE_OUTLINE 1 00105 #define VTK_PLANE_WIREFRAME 2 00106 #define VTK_PLANE_SURFACE 3 00107 00108 class VTKINTERACTIONWIDGETS_EXPORT vtkPlaneWidget : public vtkPolyDataSourceWidget 00109 { 00110 public: 00112 static vtkPlaneWidget *New(); 00113 00114 vtkTypeMacro(vtkPlaneWidget,vtkPolyDataSourceWidget); 00115 void PrintSelf(ostream& os, vtkIndent indent); 00116 00118 00119 virtual void SetEnabled(int); 00120 virtual void PlaceWidget(double bounds[6]); 00121 void PlaceWidget() 00122 {this->Superclass::PlaceWidget();} 00123 void PlaceWidget(double xmin, double xmax, double ymin, double ymax, 00124 double zmin, double zmax) 00125 {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);} 00127 00129 00130 void SetResolution(int r); 00131 int GetResolution(); 00133 00135 00136 void SetOrigin(double x, double y, double z); 00137 void SetOrigin(double x[3]); 00138 double* GetOrigin(); 00139 void GetOrigin(double xyz[3]); 00141 00143 00145 void SetPoint1(double x, double y, double z); 00146 void SetPoint1(double x[3]); 00147 double* GetPoint1(); 00148 void GetPoint1(double xyz[3]); 00150 00152 00154 void SetPoint2(double x, double y, double z); 00155 void SetPoint2(double x[3]); 00156 double* GetPoint2(); 00157 void GetPoint2(double xyz[3]); 00159 00161 00162 void SetCenter(double x, double y, double z); 00163 void SetCenter(double x[3]); 00164 double* GetCenter(); 00165 void GetCenter(double xyz[3]); 00167 00169 00170 void SetNormal(double x, double y, double z); 00171 void SetNormal(double x[3]); 00172 double* GetNormal(); 00173 void GetNormal(double xyz[3]); 00175 00177 00182 vtkSetClampMacro(Representation,int,VTK_PLANE_OFF,VTK_PLANE_SURFACE); 00183 vtkGetMacro(Representation,int); 00184 void SetRepresentationToOff() 00185 {this->SetRepresentation(VTK_PLANE_OFF);} 00186 void SetRepresentationToOutline() 00187 {this->SetRepresentation(VTK_PLANE_OUTLINE);} 00188 void SetRepresentationToWireframe() 00189 {this->SetRepresentation(VTK_PLANE_WIREFRAME);} 00190 void SetRepresentationToSurface() 00191 {this->SetRepresentation(VTK_PLANE_SURFACE);} 00193 00195 00199 vtkSetMacro(NormalToXAxis,int); 00200 vtkGetMacro(NormalToXAxis,int); 00201 vtkBooleanMacro(NormalToXAxis,int); 00202 vtkSetMacro(NormalToYAxis,int); 00203 vtkGetMacro(NormalToYAxis,int); 00204 vtkBooleanMacro(NormalToYAxis,int); 00205 vtkSetMacro(NormalToZAxis,int); 00206 vtkGetMacro(NormalToZAxis,int); 00207 vtkBooleanMacro(NormalToZAxis,int); 00209 00217 void GetPolyData(vtkPolyData *pd); 00218 00224 void GetPlane(vtkPlane *plane); 00225 00231 vtkPolyDataAlgorithm* GetPolyDataAlgorithm(); 00232 00235 void UpdatePlacement(void); 00236 00238 00241 vtkGetObjectMacro(HandleProperty,vtkProperty); 00242 vtkGetObjectMacro(SelectedHandleProperty,vtkProperty); 00244 00246 00248 virtual void SetPlaneProperty(vtkProperty*); 00249 vtkGetObjectMacro(PlaneProperty,vtkProperty); 00250 vtkGetObjectMacro(SelectedPlaneProperty,vtkProperty); 00252 00253 protected: 00254 vtkPlaneWidget(); 00255 ~vtkPlaneWidget(); 00256 00257 //BTX - manage the state of the widget 00258 int State; 00259 enum WidgetState 00260 { 00261 Start=0, 00262 Moving, 00263 Scaling, 00264 Pushing, 00265 Rotating, 00266 Spinning, 00267 Outside 00268 }; 00269 //ETX 00270 00271 //handles the events 00272 static void ProcessEvents(vtkObject* object, 00273 unsigned long event, 00274 void* clientdata, 00275 void* calldata); 00276 00277 // ProcessEvents() dispatches to these methods. 00278 void OnLeftButtonDown(); 00279 void OnLeftButtonUp(); 00280 void OnMiddleButtonDown(); 00281 void OnMiddleButtonUp(); 00282 void OnRightButtonDown(); 00283 void OnRightButtonUp(); 00284 void OnMouseMove(); 00285 00286 // controlling ivars 00287 int NormalToXAxis; 00288 int NormalToYAxis; 00289 int NormalToZAxis; 00290 int Representation; 00291 void SelectRepresentation(); 00292 00293 // the plane 00294 vtkActor *PlaneActor; 00295 vtkPolyDataMapper *PlaneMapper; 00296 vtkPlaneSource *PlaneSource; 00297 vtkPolyData *PlaneOutline; 00298 void HighlightPlane(int highlight); 00299 00300 // glyphs representing hot spots (e.g., handles) 00301 vtkActor **Handle; 00302 vtkPolyDataMapper **HandleMapper; 00303 vtkSphereSource **HandleGeometry; 00304 void PositionHandles(); 00305 void HandlesOn(double length); 00306 void HandlesOff(); 00307 int HighlightHandle(vtkProp *prop); //returns cell id 00308 virtual void SizeHandles(); 00309 00310 // the normal cone 00311 vtkActor *ConeActor; 00312 vtkPolyDataMapper *ConeMapper; 00313 vtkConeSource *ConeSource; 00314 void HighlightNormal(int highlight); 00315 00316 // the normal line 00317 vtkActor *LineActor; 00318 vtkPolyDataMapper *LineMapper; 00319 vtkLineSource *LineSource; 00320 00321 // the normal cone 00322 vtkActor *ConeActor2; 00323 vtkPolyDataMapper *ConeMapper2; 00324 vtkConeSource *ConeSource2; 00325 00326 // the normal line 00327 vtkActor *LineActor2; 00328 vtkPolyDataMapper *LineMapper2; 00329 vtkLineSource *LineSource2; 00330 00331 // Do the picking 00332 vtkCellPicker *HandlePicker; 00333 vtkCellPicker *PlanePicker; 00334 vtkActor *CurrentHandle; 00335 00336 // Register internal Pickers within PickingManager 00337 virtual void RegisterPickers(); 00338 00339 // Methods to manipulate the hexahedron. 00340 void MoveOrigin(double *p1, double *p2); 00341 void MovePoint1(double *p1, double *p2); 00342 void MovePoint2(double *p1, double *p2); 00343 void MovePoint3(double *p1, double *p2); 00344 void Rotate(int X, int Y, double *p1, double *p2, double *vpn); 00345 void Spin(double *p1, double *p2); 00346 void Scale(double *p1, double *p2, int X, int Y); 00347 void Translate(double *p1, double *p2); 00348 void Push(double *p1, double *p2); 00349 00350 // Plane normal, normalized 00351 double Normal[3]; 00352 00353 // Transform the hexahedral points (used for rotations) 00354 vtkTransform *Transform; 00355 00356 // Properties used to control the appearance of selected objects and 00357 // the manipulator in general. 00358 vtkProperty *HandleProperty; 00359 vtkProperty *SelectedHandleProperty; 00360 vtkProperty *PlaneProperty; 00361 vtkProperty *SelectedPlaneProperty; 00362 void CreateDefaultProperties(); 00363 00364 void GeneratePlane(); 00365 00366 int LastPickValid; 00367 double HandleSizeFactor; 00368 00369 private: 00370 vtkPlaneWidget(const vtkPlaneWidget&); //Not implemented 00371 void operator=(const vtkPlaneWidget&); //Not implemented 00372 }; 00373 00374 #endif