VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkSplineRepresentation.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 =========================================================================*/ 00030 #ifndef __vtkSplineRepresentation_h 00031 #define __vtkSplineRepresentation_h 00032 00033 #include "vtkWidgetRepresentation.h" 00034 00035 class vtkActor; 00036 class vtkCellPicker; 00037 class vtkDoubleArray; 00038 class vtkParametricFunctionSource; 00039 class vtkParametricSpline; 00040 class vtkPlaneSource; 00041 class vtkPoints; 00042 class vtkPolyData; 00043 class vtkProp; 00044 class vtkProperty; 00045 class vtkSphereSource; 00046 class vtkTransform; 00047 00048 #define VTK_PROJECTION_YZ 0 00049 #define VTK_PROJECTION_XZ 1 00050 #define VTK_PROJECTION_XY 2 00051 #define VTK_PROJECTION_OBLIQUE 3 00052 class VTK_WIDGETS_EXPORT vtkSplineRepresentation : public vtkWidgetRepresentation 00053 { 00054 public: 00055 static vtkSplineRepresentation* New(); 00056 vtkTypeMacro(vtkSplineRepresentation, vtkWidgetRepresentation); 00057 void PrintSelf(ostream& os, vtkIndent indent); 00058 //BTX 00059 // Used to manage the InteractionState of the widget 00060 enum _InteractionState { 00061 Outside=0, 00062 OnHandle, 00063 OnLine, 00064 Moving, 00065 Scaling, 00066 Spinning, 00067 Inserting, 00068 Erasing 00069 }; 00070 //ETX 00071 00072 vtkSetMacro(InteractionState, int); 00073 00075 00082 vtkSetMacro(ProjectToPlane,int); 00083 vtkGetMacro(ProjectToPlane,int); 00084 vtkBooleanMacro(ProjectToPlane,int); 00086 00089 void SetPlaneSource(vtkPlaneSource* plane); 00090 00091 vtkSetClampMacro(ProjectionNormal,int,VTK_PROJECTION_YZ,VTK_PROJECTION_OBLIQUE); 00092 vtkGetMacro(ProjectionNormal,int); 00093 void SetProjectionNormalToXAxes() 00094 { this->SetProjectionNormal(0); } 00095 void SetProjectionNormalToYAxes() 00096 { this->SetProjectionNormal(1); } 00097 void SetProjectionNormalToZAxes() 00098 { this->SetProjectionNormal(2); } 00099 void SetProjectionNormalToOblique() 00100 { this->SetProjectionNormal(3); } 00101 00103 00108 void SetProjectionPosition(double position); 00109 vtkGetMacro(ProjectionPosition, double); 00111 00118 void GetPolyData(vtkPolyData *pd); 00119 00121 00124 vtkGetObjectMacro(HandleProperty, vtkProperty); 00125 vtkGetObjectMacro(SelectedHandleProperty, vtkProperty); 00127 00129 00131 vtkGetObjectMacro(LineProperty, vtkProperty); 00132 vtkGetObjectMacro(SelectedLineProperty, vtkProperty); 00134 00136 00137 virtual void SetNumberOfHandles(int npts); 00138 vtkGetMacro(NumberOfHandles, int); 00140 00142 00144 void SetResolution(int resolution); 00145 vtkGetMacro(Resolution,int); 00147 00149 00155 virtual void SetParametricSpline(vtkParametricSpline*); 00156 vtkGetObjectMacro(ParametricSpline,vtkParametricSpline); 00158 00160 00162 void SetHandlePosition(int handle, double x, double y, double z); 00163 void SetHandlePosition(int handle, double xyz[3]); 00164 void GetHandlePosition(int handle, double xyz[3]); 00165 double* GetHandlePosition(int handle); 00166 vtkDoubleArray* GetHandlePositions(); 00168 00170 00175 void SetClosed(int closed); 00176 vtkGetMacro(Closed,int); 00177 vtkBooleanMacro(Closed,int); 00179 00183 int IsClosed(); 00184 00188 double GetSummedLength(); 00189 00194 void InitializeHandles(vtkPoints* points); 00195 00197 00200 virtual void BuildRepresentation(); 00201 virtual int ComputeInteractionState(int X, int Y, int modify=0); 00202 virtual void StartWidgetInteraction(double e[2]); 00203 virtual void WidgetInteraction(double e[2]); 00204 virtual void EndWidgetInteraction(double e[2]); 00205 virtual double *GetBounds(); 00207 00209 00210 virtual void ReleaseGraphicsResources(vtkWindow*); 00211 virtual int RenderOpaqueGeometry(vtkViewport*); 00212 virtual int RenderTranslucentPolygonalGeometry(vtkViewport*); 00213 virtual int RenderOverlay(vtkViewport*); 00214 virtual int HasTranslucentPolygonalGeometry(); 00216 00219 void SetLineColor(double r, double g, double b); 00220 00221 //BTX 00222 protected: 00223 vtkSplineRepresentation(); 00224 ~vtkSplineRepresentation(); 00225 00226 double LastEventPosition[3]; 00227 double Bounds[6]; 00228 00229 // Controlling vars 00230 int ProjectionNormal; 00231 double ProjectionPosition; 00232 int ProjectToPlane; 00233 vtkPlaneSource* PlaneSource; 00234 00235 // Projection capabilities 00236 void ProjectPointsToPlane(); 00237 void ProjectPointsToOrthoPlane(); 00238 void ProjectPointsToObliquePlane(); 00239 00240 // The spline 00241 vtkParametricSpline *ParametricSpline; 00242 vtkParametricFunctionSource *ParametricFunctionSource; 00243 int NumberOfHandles; 00244 int Closed; 00245 00246 // The line segments 00247 vtkActor *LineActor; 00248 void HighlightLine(int highlight); 00249 int Resolution; 00250 00251 // Glyphs representing hot spots (e.g., handles) 00252 vtkActor **Handle; 00253 vtkSphereSource **HandleGeometry; 00254 void Initialize(); 00255 int HighlightHandle(vtkProp *prop); //returns handle index or -1 on fail 00256 virtual void SizeHandles(); 00257 void InsertHandleOnLine(double* pos); 00258 void EraseHandle(const int&); 00259 00260 // Do the picking 00261 vtkCellPicker *HandlePicker; 00262 vtkCellPicker *LinePicker; 00263 double LastPickPosition[3]; 00264 vtkActor *CurrentHandle; 00265 int CurrentHandleIndex; 00266 00267 // Methods to manipulate the spline. 00268 void MovePoint(double *p1, double *p2); 00269 void Scale(double *p1, double *p2, int X, int Y); 00270 void Translate(double *p1, double *p2); 00271 void Spin(double *p1, double *p2, double *vpn); 00272 00273 // Transform the control points (used for spinning) 00274 vtkTransform *Transform; 00275 00276 // Properties used to control the appearance of selected objects and 00277 // the manipulator in general. 00278 vtkProperty *HandleProperty; 00279 vtkProperty *SelectedHandleProperty; 00280 vtkProperty *LineProperty; 00281 vtkProperty *SelectedLineProperty; 00282 void CreateDefaultProperties(); 00283 00284 // For efficient spinning 00285 double Centroid[3]; 00286 void CalculateCentroid(); 00287 00288 private: 00289 vtkSplineRepresentation(const vtkSplineRepresentation&); // Not implemented. 00290 void operator=(const vtkSplineRepresentation&); // Not implemented. 00291 //ETX 00292 }; 00293 00294 #endif 00295 00296