VTK
dox/Widgets/vtkBrokenLineWidget.h
Go to the documentation of this file.
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 =========================================================================*/
00089 #ifndef __vtkBrokenLineWidget_h
00090 #define __vtkBrokenLineWidget_h
00091 
00092 #include "vtk3DWidget.h"
00093 
00094 class vtkActor;
00095 class vtkCellPicker;
00096 class vtkLineSource;
00097 class vtkPlaneSource;
00098 class vtkPoints;
00099 class vtkPolyData;
00100 class vtkPolyDataMapper;
00101 class vtkProp;
00102 class vtkProperty;
00103 class vtkSphereSource;
00104 class vtkTransform;
00105 
00106 #define VTK_PROJECTION_YZ 0
00107 #define VTK_PROJECTION_XZ 1
00108 #define VTK_PROJECTION_XY 2
00109 #define VTK_PROJECTION_OBLIQUE 3
00110 
00111 class VTK_WIDGETS_EXPORT vtkBrokenLineWidget : public vtk3DWidget
00112 {
00113 public:
00115   static vtkBrokenLineWidget *New();
00116 
00117   vtkTypeMacro(vtkBrokenLineWidget,vtk3DWidget);
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 
00139   vtkSetMacro(ProjectToPlane,int);
00140   vtkGetMacro(ProjectToPlane,int);
00141   vtkBooleanMacro(ProjectToPlane,int);
00143 
00146   void SetPlaneSource(vtkPlaneSource* plane);
00147 
00148   vtkSetClampMacro(ProjectionNormal,int,VTK_PROJECTION_YZ,VTK_PROJECTION_OBLIQUE);
00149   vtkGetMacro(ProjectionNormal,int);
00150   void SetProjectionNormalToXAxes()
00151     { this->SetProjectionNormal(0); }
00152   void SetProjectionNormalToYAxes()
00153     { this->SetProjectionNormal(1); }
00154   void SetProjectionNormalToZAxes()
00155     { this->SetProjectionNormal(2); }
00156   void SetProjectionNormalToOblique()
00157     { this->SetProjectionNormal(3); }
00158 
00160 
00165   void SetProjectionPosition(double position);
00166   vtkGetMacro(ProjectionPosition, double);
00168 
00175   void GetPolyData(vtkPolyData *pd);
00176 
00178 
00181   virtual void SetHandleProperty(vtkProperty*);
00182   vtkGetObjectMacro(HandleProperty, vtkProperty);
00183   virtual void SetSelectedHandleProperty(vtkProperty*);
00184   vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
00186 
00188 
00190   virtual void SetLineProperty(vtkProperty*);
00191   vtkGetObjectMacro(LineProperty, vtkProperty);
00192   virtual void SetSelectedLineProperty(vtkProperty*);
00193   vtkGetObjectMacro(SelectedLineProperty, vtkProperty);
00195 
00197 
00198   virtual void SetNumberOfHandles(int npts);
00199   vtkGetMacro(NumberOfHandles, int);
00201 
00203 
00205   void SetHandlePosition(int handle, double x, double y, double z);
00206   void SetHandlePosition(int handle, double xyz[3]);
00207   void GetHandlePosition(int handle, double xyz[3]);
00208   double* GetHandlePosition(int handle);
00210 
00212   double GetSummedLength();
00213 
00216   void InitializeHandles(vtkPoints* points);
00217 
00219 
00221   vtkSetClampMacro(ProcessEvents, int, 0, 1);
00222   vtkGetMacro(ProcessEvents, int);
00223   vtkBooleanMacro( ProcessEvents, int );
00225 
00227 
00229   vtkSetClampMacro(HandleSizeFactor, double, 0., 100.);
00230   vtkGetMacro(HandleSizeFactor, double);
00232 
00233 protected:
00234   vtkBrokenLineWidget();
00235   ~vtkBrokenLineWidget();
00236 
00237 //BTX - manage the state of the widget
00238   int State;
00239   enum WidgetState
00240   {
00241     Start=0,
00242     Moving,
00243     Scaling,
00244     Spinning,
00245     Inserting,
00246     Erasing,
00247     Outside
00248   };
00249 //ETX
00250 
00251   //handles the events
00252   static void ProcessEventsHandler(vtkObject* object,
00253                                    unsigned long event,
00254                                    void* clientdata,
00255                                    void* calldata);
00256 
00257   // ProcessEventsHandler() dispatches to these methods.
00258   void OnLeftButtonDown();
00259   void OnLeftButtonUp();
00260   void OnMiddleButtonDown();
00261   void OnMiddleButtonUp();
00262   void OnRightButtonDown();
00263   void OnRightButtonUp();
00264   void OnMouseMove();
00265 
00266   // Controlling vars
00267   int   ProjectionNormal;
00268   double ProjectionPosition;
00269   int   ProjectToPlane;
00270   vtkPlaneSource* PlaneSource;
00271 
00272   // Projection capabilities
00273   void ProjectPointsToPlane();
00274   void ProjectPointsToOrthoPlane();
00275   void ProjectPointsToObliquePlane();
00276 
00277   // The broken line
00278   vtkActor          *LineActor;
00279   vtkPolyDataMapper *LineMapper;
00280   vtkLineSource     *LineSource;
00281   void HighlightLine(int highlight);
00282   int NumberOfHandles;
00283   void BuildRepresentation();
00284 
00285   // Glyphs representing hot spots (e.g., handles)
00286   vtkActor          **Handle;
00287   vtkSphereSource   **HandleGeometry;
00288   void Initialize();
00289   int  HighlightHandle(vtkProp *prop); //returns handle index or -1 on fail
00290   virtual void SizeHandles();
00291   void InsertHandleOnLine(double* pos);
00292   void EraseHandle(const int&);
00293 
00294   // Do the picking
00295   vtkCellPicker *HandlePicker;
00296   vtkCellPicker *LinePicker;
00297   vtkActor *CurrentHandle;
00298   int CurrentHandleIndex;
00299 
00300   // Methods to manipulate the broken line.
00301   void MovePoint(double *p1, double *p2);
00302   void Scale(double *p1, double *p2, int X, int Y);
00303   void Translate(double *p1, double *p2);
00304   void Spin(double *p1, double *p2, double *vpn);
00305 
00306   // Transform the control points (used for spinning)
00307   vtkTransform *Transform;
00308 
00309   // Properties used to control the appearance of selected objects and
00310   // the manipulator in general.
00311   vtkProperty *HandleProperty;
00312   vtkProperty *SelectedHandleProperty;
00313   vtkProperty *LineProperty;
00314   vtkProperty *SelectedLineProperty;
00315   void CreateDefaultProperties();
00316 
00317   // For efficient spinning
00318   double Centroid[3];
00319   void CalculateCentroid();
00320   int  ProcessEvents;
00321 
00322   // Handle sizing factor
00323   double HandleSizeFactor;
00324 
00325 private:
00326   vtkBrokenLineWidget(const vtkBrokenLineWidget&);  //Not implemented
00327   void operator=(const vtkBrokenLineWidget&);  //Not implemented
00328 };
00329 
00330 #endif