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 =========================================================================*/ 00087 #ifndef __vtkPlaneWidget_h 00088 #define __vtkPlaneWidget_h 00089 00090 #include "vtkPolyDataSourceWidget.h" 00091 00092 class vtkActor; 00093 class vtkCellPicker; 00094 class vtkConeSource; 00095 class vtkLineSource; 00096 class vtkPlaneSource; 00097 class vtkPoints; 00098 class vtkPolyData; 00099 class vtkPolyDataMapper; 00100 class vtkProp; 00101 class vtkProperty; 00102 class vtkSphereSource; 00103 class vtkTransform; 00104 class vtkPlane; 00105 00106 #define VTK_PLANE_OFF 0 00107 #define VTK_PLANE_OUTLINE 1 00108 #define VTK_PLANE_WIREFRAME 2 00109 #define VTK_PLANE_SURFACE 3 00110 00111 class VTK_WIDGETS_EXPORT vtkPlaneWidget : public vtkPolyDataSourceWidget 00112 { 00113 public: 00115 static vtkPlaneWidget *New(); 00116 00117 vtkTypeMacro(vtkPlaneWidget,vtkPolyDataSourceWidget); 00118 void PrintSelf(ostream& os, vtkIndent indent); 00119 00121 00122 virtual void SetEnabled(int); 00123 virtual void PlaceWidget(double bounds[6]); 00124 void PlaceWidget() 00125 {this->Superclass::PlaceWidget();} 00126 void PlaceWidget(double xmin, double xmax, double ymin, double ymax, 00127 double zmin, double zmax) 00128 {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);} 00130 00132 00133 void SetResolution(int r); 00134 int GetResolution(); 00136 00138 00139 void SetOrigin(double x, double y, double z); 00140 void SetOrigin(double x[3]); 00141 double* GetOrigin(); 00142 void GetOrigin(double xyz[3]); 00144 00146 00148 void SetPoint1(double x, double y, double z); 00149 void SetPoint1(double x[3]); 00150 double* GetPoint1(); 00151 void GetPoint1(double xyz[3]); 00153 00155 00157 void SetPoint2(double x, double y, double z); 00158 void SetPoint2(double x[3]); 00159 double* GetPoint2(); 00160 void GetPoint2(double xyz[3]); 00162 00164 00165 void SetCenter(double x, double y, double z); 00166 void SetCenter(double x[3]); 00167 double* GetCenter(); 00168 void GetCenter(double xyz[3]); 00170 00172 00173 void SetNormal(double x, double y, double z); 00174 void SetNormal(double x[3]); 00175 double* GetNormal(); 00176 void GetNormal(double xyz[3]); 00178 00180 00185 vtkSetClampMacro(Representation,int,VTK_PLANE_OFF,VTK_PLANE_SURFACE); 00186 vtkGetMacro(Representation,int); 00187 void SetRepresentationToOff() 00188 {this->SetRepresentation(VTK_PLANE_OFF);} 00189 void SetRepresentationToOutline() 00190 {this->SetRepresentation(VTK_PLANE_OUTLINE);} 00191 void SetRepresentationToWireframe() 00192 {this->SetRepresentation(VTK_PLANE_WIREFRAME);} 00193 void SetRepresentationToSurface() 00194 {this->SetRepresentation(VTK_PLANE_SURFACE);} 00196 00198 00202 vtkSetMacro(NormalToXAxis,int); 00203 vtkGetMacro(NormalToXAxis,int); 00204 vtkBooleanMacro(NormalToXAxis,int); 00205 vtkSetMacro(NormalToYAxis,int); 00206 vtkGetMacro(NormalToYAxis,int); 00207 vtkBooleanMacro(NormalToYAxis,int); 00208 vtkSetMacro(NormalToZAxis,int); 00209 vtkGetMacro(NormalToZAxis,int); 00210 vtkBooleanMacro(NormalToZAxis,int); 00212 00220 void GetPolyData(vtkPolyData *pd); 00221 00227 void GetPlane(vtkPlane *plane); 00228 00234 vtkPolyDataAlgorithm* GetPolyDataAlgorithm(); 00235 00238 void UpdatePlacement(void); 00239 00241 00244 vtkGetObjectMacro(HandleProperty,vtkProperty); 00245 vtkGetObjectMacro(SelectedHandleProperty,vtkProperty); 00247 00249 00251 virtual void SetPlaneProperty(vtkProperty*); 00252 vtkGetObjectMacro(PlaneProperty,vtkProperty); 00253 vtkGetObjectMacro(SelectedPlaneProperty,vtkProperty); 00255 00256 protected: 00257 vtkPlaneWidget(); 00258 ~vtkPlaneWidget(); 00259 00260 //BTX - manage the state of the widget 00261 int State; 00262 enum WidgetState 00263 { 00264 Start=0, 00265 Moving, 00266 Scaling, 00267 Pushing, 00268 Rotating, 00269 Spinning, 00270 Outside 00271 }; 00272 //ETX 00273 00274 //handles the events 00275 static void ProcessEvents(vtkObject* object, 00276 unsigned long event, 00277 void* clientdata, 00278 void* calldata); 00279 00280 // ProcessEvents() dispatches to these methods. 00281 void OnLeftButtonDown(); 00282 void OnLeftButtonUp(); 00283 void OnMiddleButtonDown(); 00284 void OnMiddleButtonUp(); 00285 void OnRightButtonDown(); 00286 void OnRightButtonUp(); 00287 void OnMouseMove(); 00288 00289 // controlling ivars 00290 int NormalToXAxis; 00291 int NormalToYAxis; 00292 int NormalToZAxis; 00293 int Representation; 00294 void SelectRepresentation(); 00295 00296 // the plane 00297 vtkActor *PlaneActor; 00298 vtkPolyDataMapper *PlaneMapper; 00299 vtkPlaneSource *PlaneSource; 00300 vtkPolyData *PlaneOutline; 00301 void HighlightPlane(int highlight); 00302 00303 // glyphs representing hot spots (e.g., handles) 00304 vtkActor **Handle; 00305 vtkPolyDataMapper **HandleMapper; 00306 vtkSphereSource **HandleGeometry; 00307 void PositionHandles(); 00308 void HandlesOn(double length); 00309 void HandlesOff(); 00310 int HighlightHandle(vtkProp *prop); //returns cell id 00311 virtual void SizeHandles(); 00312 00313 // the normal cone 00314 vtkActor *ConeActor; 00315 vtkPolyDataMapper *ConeMapper; 00316 vtkConeSource *ConeSource; 00317 void HighlightNormal(int highlight); 00318 00319 // the normal line 00320 vtkActor *LineActor; 00321 vtkPolyDataMapper *LineMapper; 00322 vtkLineSource *LineSource; 00323 00324 // the normal cone 00325 vtkActor *ConeActor2; 00326 vtkPolyDataMapper *ConeMapper2; 00327 vtkConeSource *ConeSource2; 00328 00329 // the normal line 00330 vtkActor *LineActor2; 00331 vtkPolyDataMapper *LineMapper2; 00332 vtkLineSource *LineSource2; 00333 00334 // Do the picking 00335 vtkCellPicker *HandlePicker; 00336 vtkCellPicker *PlanePicker; 00337 vtkActor *CurrentHandle; 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