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