Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

Hybrid/vtkSplineWidget.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkSplineWidget.h,v $
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 __vtkSplineWidget_h
00088 #define __vtkSplineWidget_h
00089 
00090 #include "vtk3DWidget.h"
00091 
00092 class vtkActor;
00093 class vtkCellPicker;
00094 class vtkPlaneSource;
00095 class vtkPoints;
00096 class vtkPolyData;
00097 class vtkPolyDataMapper;
00098 class vtkProp;
00099 class vtkProperty;
00100 class vtkSphereSource;
00101 class vtkSpline;
00102 class vtkTransform;
00103 
00104 #define VTK_PROJECTION_YZ 0
00105 #define VTK_PROJECTION_XZ 1
00106 #define VTK_PROJECTION_XY 2
00107 #define VTK_PROJECTION_OBLIQUE 3
00108 
00109 class VTK_HYBRID_EXPORT vtkSplineWidget : public vtk3DWidget
00110 {
00111 public:
00113   static vtkSplineWidget *New();
00114 
00115   vtkTypeRevisionMacro(vtkSplineWidget,vtk3DWidget);
00116   void PrintSelf(ostream& os, vtkIndent indent);
00117 
00119 
00120   virtual void SetEnabled(int);
00121   virtual void PlaceWidget(double bounds[6]);
00122   void PlaceWidget()
00123     {this->Superclass::PlaceWidget();}
00124   void PlaceWidget(double xmin, double xmax, double ymin, double ymax, 
00125                    double zmin, double zmax)
00126     {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);}
00128 
00130 
00136   vtkSetMacro(ProjectToPlane,int);
00137   vtkGetMacro(ProjectToPlane,int);
00138   vtkBooleanMacro(ProjectToPlane,int);
00140 
00143   void SetPlaneSource(vtkPlaneSource* plane);
00144 
00145   vtkSetClampMacro(ProjectionNormal,int,VTK_PROJECTION_YZ,VTK_PROJECTION_OBLIQUE);
00146   vtkGetMacro(ProjectionNormal,int);
00147   void SetProjectionNormalToXAxes()
00148     { this->SetProjectionNormal(0); }
00149   void SetProjectionNormalToYAxes()
00150     { this->SetProjectionNormal(1); }
00151   void SetProjectionNormalToZAxes()
00152     { this->SetProjectionNormal(2); }
00153   void SetProjectionNormalToOblique()
00154     { this->SetProjectionNormal(3); }
00155 
00157 
00162   void SetProjectionPosition(double position);
00163   vtkGetMacro(ProjectionPosition, double);
00165 
00171   void GetPolyData(vtkPolyData *pd);
00172 
00174 
00177   virtual void SetHandleProperty(vtkProperty*);
00178   vtkGetObjectMacro(HandleProperty, vtkProperty);
00179   virtual void SetSelectedHandleProperty(vtkProperty*);
00180   vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
00182 
00184 
00186   virtual void SetLineProperty(vtkProperty*);
00187   vtkGetObjectMacro(LineProperty, vtkProperty);
00188   virtual void SetSelectedLineProperty(vtkProperty*);
00189   vtkGetObjectMacro(SelectedLineProperty, vtkProperty);
00191 
00193 
00194   virtual void SetNumberOfHandles(int npts);
00195   vtkGetMacro(NumberOfHandles, int);
00197 
00199 
00201   void SetResolution(int resolution);
00202   vtkGetMacro(Resolution,int);
00204 
00206 
00210   void SetXSpline(vtkSpline*);
00211   void SetYSpline(vtkSpline*);
00212   void SetZSpline(vtkSpline*);
00214 
00216 
00218   void SetHandlePosition(int handle, double x, double y, double z);
00219   void SetHandlePosition(int handle, double xyz[3]);
00220   void GetHandlePosition(int handle, double xyz[3]);
00221   double* GetHandlePosition(int handle);
00223 
00225 
00229   void SetClosed(int closed);
00230   vtkGetMacro(Closed,int);
00231   vtkBooleanMacro(Closed,int);
00233 
00237   double GetSummedLength();
00238 
00239 protected:
00240   vtkSplineWidget();
00241   ~vtkSplineWidget();
00242 
00243 //BTX - manage the state of the widget
00244   int State;
00245   enum WidgetState
00246   {
00247     Start=0,
00248     Moving,
00249     Scaling,
00250     Spinning,
00251     Outside
00252   };
00253 //ETX
00254 
00255   //handles the events
00256   static void ProcessEvents(vtkObject* object,
00257                             unsigned long event,
00258                             void* clientdata,
00259                             void* calldata);
00260 
00261   // ProcessEvents() dispatches to these methods.
00262   void OnLeftButtonDown();
00263   void OnLeftButtonUp();
00264   void OnMiddleButtonDown();
00265   void OnMiddleButtonUp();
00266   void OnRightButtonDown();
00267   void OnRightButtonUp();
00268   void OnMouseMove();
00269 
00270   // Controlling vars
00271   int   ProjectionNormal;
00272   double ProjectionPosition;
00273   int   ProjectToPlane;
00274   vtkPlaneSource* PlaneSource;
00275 
00276   // Projection capabilities
00277   void ProjectPointsToPlane();
00278   void ProjectPointsToOrthoPlane();
00279   void ProjectPointsToObliquePlane();
00280 
00281   // The spline
00282   vtkSpline *XSpline;
00283   vtkSpline *YSpline;
00284   vtkSpline *ZSpline;
00285   int NumberOfHandles;
00286   vtkSpline* CreateDefaultSpline();// default is vtkCardinalSpline
00287   int Closed;
00288   double Offset;
00289 
00290   // The line segments
00291   vtkActor          *LineActor;
00292   vtkPolyDataMapper *LineMapper;
00293   vtkPolyData       *LineData;
00294   void HighlightLine(int highlight);
00295   int NumberOfSplinePoints;
00296   int Resolution;
00297   double* SplinePositions;
00298 
00299   // Glyphs representing hot spots (e.g., handles)
00300   vtkActor          **Handle;
00301   vtkPolyDataMapper **HandleMapper;
00302   vtkSphereSource   **HandleGeometry;
00303   void Initialize();
00304   int  HighlightHandle(vtkProp *prop); //returns handle index or -1 on fail
00305   virtual void SizeHandles();
00306   void BuildRepresentation();
00307 
00308   // Do the picking
00309   vtkCellPicker *HandlePicker;
00310   vtkCellPicker *LinePicker;
00311   vtkActor *CurrentHandle;
00312   int CurrentHandleIndex;
00313 
00314   // Methods to manipulate the spline.
00315   void MovePoint(double *p1, double *p2);
00316   void Scale(double *p1, double *p2, int X, int Y);
00317   void Translate(double *p1, double *p2);
00318   void Spin(double *p1, double *p2, double *vpn);
00319 
00320   // Transform the control points (used for spinning)
00321   vtkTransform *Transform;
00322 
00323   // Properties used to control the appearance of selected objects and
00324   // the manipulator in general.
00325   vtkProperty *HandleProperty;
00326   vtkProperty *SelectedHandleProperty;
00327   vtkProperty *LineProperty;
00328   vtkProperty *SelectedLineProperty;
00329   void CreateDefaultProperties();
00330 
00331   // For efficient spinning
00332   double Centroid[3];
00333   void CalculateCentroid();
00334 
00335 private:
00336   vtkSplineWidget(const vtkSplineWidget&);  //Not implemented
00337   void operator=(const vtkSplineWidget&);  //Not implemented
00338 };
00339 
00340 #endif