VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkBrokenLineWidget.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 __vtkBrokenLineWidget_h 00088 #define __vtkBrokenLineWidget_h 00089 00090 #include "vtkInteractionWidgetsModule.h" // For export macro 00091 #include "vtk3DWidget.h" 00092 00093 class vtkActor; 00094 class vtkCellPicker; 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 00105 #define VTK_PROJECTION_YZ 0 00106 #define VTK_PROJECTION_XZ 1 00107 #define VTK_PROJECTION_XY 2 00108 #define VTK_PROJECTION_OBLIQUE 3 00109 00110 class VTKINTERACTIONWIDGETS_EXPORT vtkBrokenLineWidget : public vtk3DWidget 00111 { 00112 public: 00114 static vtkBrokenLineWidget *New(); 00115 00116 vtkTypeMacro(vtkBrokenLineWidget,vtk3DWidget); 00117 void PrintSelf(ostream& os, vtkIndent indent); 00118 00120 00121 virtual void SetEnabled(int); 00122 virtual void PlaceWidget(double bounds[6]); 00123 void PlaceWidget() 00124 {this->Superclass::PlaceWidget();} 00125 void PlaceWidget(double xmin, double xmax, double ymin, double ymax, 00126 double zmin, double zmax) 00127 {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);} 00129 00131 00138 vtkSetMacro(ProjectToPlane,int); 00139 vtkGetMacro(ProjectToPlane,int); 00140 vtkBooleanMacro(ProjectToPlane,int); 00142 00145 void SetPlaneSource(vtkPlaneSource* plane); 00146 00147 vtkSetClampMacro(ProjectionNormal,int,VTK_PROJECTION_YZ,VTK_PROJECTION_OBLIQUE); 00148 vtkGetMacro(ProjectionNormal,int); 00149 void SetProjectionNormalToXAxes() 00150 { this->SetProjectionNormal(0); } 00151 void SetProjectionNormalToYAxes() 00152 { this->SetProjectionNormal(1); } 00153 void SetProjectionNormalToZAxes() 00154 { this->SetProjectionNormal(2); } 00155 void SetProjectionNormalToOblique() 00156 { this->SetProjectionNormal(3); } 00157 00159 00164 void SetProjectionPosition(double position); 00165 vtkGetMacro(ProjectionPosition, double); 00167 00174 void GetPolyData(vtkPolyData *pd); 00175 00177 00180 virtual void SetHandleProperty(vtkProperty*); 00181 vtkGetObjectMacro(HandleProperty, vtkProperty); 00182 virtual void SetSelectedHandleProperty(vtkProperty*); 00183 vtkGetObjectMacro(SelectedHandleProperty, vtkProperty); 00185 00187 00189 virtual void SetLineProperty(vtkProperty*); 00190 vtkGetObjectMacro(LineProperty, vtkProperty); 00191 virtual void SetSelectedLineProperty(vtkProperty*); 00192 vtkGetObjectMacro(SelectedLineProperty, vtkProperty); 00194 00196 00197 virtual void SetNumberOfHandles(int npts); 00198 vtkGetMacro(NumberOfHandles, int); 00200 00202 00204 void SetHandlePosition(int handle, double x, double y, double z); 00205 void SetHandlePosition(int handle, double xyz[3]); 00206 void GetHandlePosition(int handle, double xyz[3]); 00207 double* GetHandlePosition(int handle); 00209 00211 double GetSummedLength(); 00212 00215 void InitializeHandles(vtkPoints* points); 00216 00218 00220 vtkSetClampMacro(ProcessEvents, int, 0, 1); 00221 vtkGetMacro(ProcessEvents, int); 00222 vtkBooleanMacro( ProcessEvents, int ); 00224 00226 00228 vtkSetClampMacro(HandleSizeFactor, double, 0., 100.); 00229 vtkGetMacro(HandleSizeFactor, double); 00231 00232 protected: 00233 vtkBrokenLineWidget(); 00234 ~vtkBrokenLineWidget(); 00235 00236 //BTX - manage the state of the widget 00237 int State; 00238 enum WidgetState 00239 { 00240 Start=0, 00241 Moving, 00242 Scaling, 00243 Spinning, 00244 Inserting, 00245 Erasing, 00246 Outside 00247 }; 00248 //ETX 00249 00250 //handles the events 00251 static void ProcessEventsHandler(vtkObject* object, 00252 unsigned long event, 00253 void* clientdata, 00254 void* calldata); 00255 00256 // ProcessEventsHandler() dispatches to these methods. 00257 void OnLeftButtonDown(); 00258 void OnLeftButtonUp(); 00259 void OnMiddleButtonDown(); 00260 void OnMiddleButtonUp(); 00261 void OnRightButtonDown(); 00262 void OnRightButtonUp(); 00263 void OnMouseMove(); 00264 00265 // Controlling vars 00266 int ProjectionNormal; 00267 double ProjectionPosition; 00268 int ProjectToPlane; 00269 vtkPlaneSource* PlaneSource; 00270 00271 // Projection capabilities 00272 void ProjectPointsToPlane(); 00273 void ProjectPointsToOrthoPlane(); 00274 void ProjectPointsToObliquePlane(); 00275 00276 // The broken line 00277 vtkActor *LineActor; 00278 vtkPolyDataMapper *LineMapper; 00279 vtkLineSource *LineSource; 00280 void HighlightLine(int highlight); 00281 int NumberOfHandles; 00282 void BuildRepresentation(); 00283 00284 // Glyphs representing hot spots (e.g., handles) 00285 vtkActor **Handle; 00286 vtkSphereSource **HandleGeometry; 00287 void Initialize(); 00288 int HighlightHandle(vtkProp *prop); //returns handle index or -1 on fail 00289 virtual void SizeHandles(); 00290 void InsertHandleOnLine(double* pos); 00291 void EraseHandle(const int&); 00292 00293 // Do the picking 00294 vtkCellPicker *HandlePicker; 00295 vtkCellPicker *LinePicker; 00296 vtkActor *CurrentHandle; 00297 int CurrentHandleIndex; 00298 00299 // Register internal Pickers within PickingManager 00300 virtual void RegisterPickers(); 00301 00302 // Methods to manipulate the broken line. 00303 void MovePoint(double *p1, double *p2); 00304 void Scale(double *p1, double *p2, int X, int Y); 00305 void Translate(double *p1, double *p2); 00306 void Spin(double *p1, double *p2, double *vpn); 00307 00308 // Transform the control points (used for spinning) 00309 vtkTransform *Transform; 00310 00311 // Properties used to control the appearance of selected objects and 00312 // the manipulator in general. 00313 vtkProperty *HandleProperty; 00314 vtkProperty *SelectedHandleProperty; 00315 vtkProperty *LineProperty; 00316 vtkProperty *SelectedLineProperty; 00317 void CreateDefaultProperties(); 00318 00319 // For efficient spinning 00320 double Centroid[3]; 00321 void CalculateCentroid(); 00322 int ProcessEvents; 00323 00324 // Handle sizing factor 00325 double HandleSizeFactor; 00326 00327 private: 00328 vtkBrokenLineWidget(const vtkBrokenLineWidget&); //Not implemented 00329 void operator=(const vtkBrokenLineWidget&); //Not implemented 00330 }; 00331 00332 #endif