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 "vtkInteractionWidgetsModule.h" // For export macro 00034 #include "vtkWidgetRepresentation.h" 00035 00036 class vtkActor; 00037 class vtkCellPicker; 00038 class vtkDoubleArray; 00039 class vtkParametricFunctionSource; 00040 class vtkParametricSpline; 00041 class vtkPlaneSource; 00042 class vtkPoints; 00043 class vtkPolyData; 00044 class vtkProp; 00045 class vtkProperty; 00046 class vtkSphereSource; 00047 class vtkTransform; 00048 00049 #define VTK_PROJECTION_YZ 0 00050 #define VTK_PROJECTION_XZ 1 00051 #define VTK_PROJECTION_XY 2 00052 #define VTK_PROJECTION_OBLIQUE 3 00053 class VTKINTERACTIONWIDGETS_EXPORT vtkSplineRepresentation : public vtkWidgetRepresentation 00054 { 00055 public: 00056 static vtkSplineRepresentation* New(); 00057 vtkTypeMacro(vtkSplineRepresentation, vtkWidgetRepresentation); 00058 void PrintSelf(ostream& os, vtkIndent indent); 00059 //BTX 00060 // Used to manage the InteractionState of the widget 00061 enum _InteractionState { 00062 Outside=0, 00063 OnHandle, 00064 OnLine, 00065 Moving, 00066 Scaling, 00067 Spinning, 00068 Inserting, 00069 Erasing 00070 }; 00071 //ETX 00072 00073 vtkSetMacro(InteractionState, int); 00074 00076 00083 vtkSetMacro(ProjectToPlane,int); 00084 vtkGetMacro(ProjectToPlane,int); 00085 vtkBooleanMacro(ProjectToPlane,int); 00087 00090 void SetPlaneSource(vtkPlaneSource* plane); 00091 00092 vtkSetClampMacro(ProjectionNormal,int,VTK_PROJECTION_YZ,VTK_PROJECTION_OBLIQUE); 00093 vtkGetMacro(ProjectionNormal,int); 00094 void SetProjectionNormalToXAxes() 00095 { this->SetProjectionNormal(0); } 00096 void SetProjectionNormalToYAxes() 00097 { this->SetProjectionNormal(1); } 00098 void SetProjectionNormalToZAxes() 00099 { this->SetProjectionNormal(2); } 00100 void SetProjectionNormalToOblique() 00101 { this->SetProjectionNormal(3); } 00102 00104 00109 void SetProjectionPosition(double position); 00110 vtkGetMacro(ProjectionPosition, double); 00112 00119 void GetPolyData(vtkPolyData *pd); 00120 00122 00125 vtkGetObjectMacro(HandleProperty, vtkProperty); 00126 vtkGetObjectMacro(SelectedHandleProperty, vtkProperty); 00128 00130 00132 vtkGetObjectMacro(LineProperty, vtkProperty); 00133 vtkGetObjectMacro(SelectedLineProperty, vtkProperty); 00135 00137 00138 virtual void SetNumberOfHandles(int npts); 00139 vtkGetMacro(NumberOfHandles, int); 00141 00143 00145 void SetResolution(int resolution); 00146 vtkGetMacro(Resolution,int); 00148 00150 00156 virtual void SetParametricSpline(vtkParametricSpline*); 00157 vtkGetObjectMacro(ParametricSpline,vtkParametricSpline); 00159 00161 00163 void SetHandlePosition(int handle, double x, double y, double z); 00164 void SetHandlePosition(int handle, double xyz[3]); 00165 void GetHandlePosition(int handle, double xyz[3]); 00166 double* GetHandlePosition(int handle); 00167 vtkDoubleArray* GetHandlePositions(); 00169 00171 00176 void SetClosed(int closed); 00177 vtkGetMacro(Closed,int); 00178 vtkBooleanMacro(Closed,int); 00180 00184 int IsClosed(); 00185 00189 double GetSummedLength(); 00190 00195 void InitializeHandles(vtkPoints* points); 00196 00198 00201 virtual void BuildRepresentation(); 00202 virtual int ComputeInteractionState(int X, int Y, int modify=0); 00203 virtual void StartWidgetInteraction(double e[2]); 00204 virtual void WidgetInteraction(double e[2]); 00205 virtual void EndWidgetInteraction(double e[2]); 00206 virtual double *GetBounds(); 00208 00210 00211 virtual void ReleaseGraphicsResources(vtkWindow*); 00212 virtual int RenderOpaqueGeometry(vtkViewport*); 00213 virtual int RenderTranslucentPolygonalGeometry(vtkViewport*); 00214 virtual int RenderOverlay(vtkViewport*); 00215 virtual int HasTranslucentPolygonalGeometry(); 00217 00220 void SetLineColor(double r, double g, double b); 00221 00222 //BTX 00223 protected: 00224 vtkSplineRepresentation(); 00225 ~vtkSplineRepresentation(); 00226 00227 double LastEventPosition[3]; 00228 double Bounds[6]; 00229 00230 // Controlling vars 00231 int ProjectionNormal; 00232 double ProjectionPosition; 00233 int ProjectToPlane; 00234 vtkPlaneSource* PlaneSource; 00235 00236 // Projection capabilities 00237 void ProjectPointsToPlane(); 00238 void ProjectPointsToOrthoPlane(); 00239 void ProjectPointsToObliquePlane(); 00240 00241 // The spline 00242 vtkParametricSpline *ParametricSpline; 00243 vtkParametricFunctionSource *ParametricFunctionSource; 00244 int NumberOfHandles; 00245 int Closed; 00246 00247 // The line segments 00248 vtkActor *LineActor; 00249 void HighlightLine(int highlight); 00250 int Resolution; 00251 00252 // Glyphs representing hot spots (e.g., handles) 00253 vtkActor **Handle; 00254 vtkSphereSource **HandleGeometry; 00255 void Initialize(); 00256 int HighlightHandle(vtkProp *prop); //returns handle index or -1 on fail 00257 virtual void SizeHandles(); 00258 void InsertHandleOnLine(double* pos); 00259 void EraseHandle(const int&); 00260 00261 // Do the picking 00262 vtkCellPicker *HandlePicker; 00263 vtkCellPicker *LinePicker; 00264 double LastPickPosition[3]; 00265 vtkActor *CurrentHandle; 00266 int CurrentHandleIndex; 00267 00268 // Register internal Pickers within PickingManager 00269 virtual void RegisterPickers(); 00270 00271 // Methods to manipulate the spline. 00272 void MovePoint(double *p1, double *p2); 00273 void Scale(double *p1, double *p2, int X, int Y); 00274 void Translate(double *p1, double *p2); 00275 void Spin(double *p1, double *p2, double *vpn); 00276 00277 // Transform the control points (used for spinning) 00278 vtkTransform *Transform; 00279 00280 // Properties used to control the appearance of selected objects and 00281 // the manipulator in general. 00282 vtkProperty *HandleProperty; 00283 vtkProperty *SelectedHandleProperty; 00284 vtkProperty *LineProperty; 00285 vtkProperty *SelectedLineProperty; 00286 void CreateDefaultProperties(); 00287 00288 // For efficient spinning 00289 double Centroid[3]; 00290 void CalculateCentroid(); 00291 00292 private: 00293 vtkSplineRepresentation(const vtkSplineRepresentation&); // Not implemented. 00294 void operator=(const vtkSplineRepresentation&); // Not implemented. 00295 //ETX 00296 }; 00297 00298 #endif 00299 00300