VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkImplicitPlaneRepresentation.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 =========================================================================*/ 00040 #ifndef __vtkImplicitPlaneRepresentation_h 00041 #define __vtkImplicitPlaneRepresentation_h 00042 00043 #include "vtkInteractionWidgetsModule.h" // For export macro 00044 #include "vtkWidgetRepresentation.h" 00045 00046 class vtkActor; 00047 class vtkPolyDataMapper; 00048 class vtkCellPicker; 00049 class vtkConeSource; 00050 class vtkLineSource; 00051 class vtkSphereSource; 00052 class vtkTubeFilter; 00053 class vtkPlane; 00054 class vtkCutter; 00055 class vtkProperty; 00056 class vtkImageData; 00057 class vtkOutlineFilter; 00058 class vtkFeatureEdges; 00059 class vtkPolyData; 00060 class vtkPolyDataAlgorithm; 00061 class vtkTransform; 00062 class vtkBox; 00063 class vtkLookupTable; 00064 00065 class VTKINTERACTIONWIDGETS_EXPORT vtkImplicitPlaneRepresentation : public vtkWidgetRepresentation 00066 { 00067 public: 00069 static vtkImplicitPlaneRepresentation *New(); 00070 00072 00073 vtkTypeMacro(vtkImplicitPlaneRepresentation,vtkWidgetRepresentation); 00074 void PrintSelf(ostream& os, vtkIndent indent); 00076 00078 00079 void SetOrigin(double x, double y, double z); 00080 void SetOrigin(double x[3]); 00081 double* GetOrigin(); 00082 void GetOrigin(double xyz[3]); 00084 00086 00087 void SetNormal(double x, double y, double z); 00088 void SetNormal(double x[3]); 00089 void SetNormalToCamera(); 00090 double* GetNormal(); 00091 void GetNormal(double xyz[3]); 00093 00095 00099 void SetNormalToXAxis(int); 00100 vtkGetMacro(NormalToXAxis,int); 00101 vtkBooleanMacro(NormalToXAxis,int); 00102 void SetNormalToYAxis(int); 00103 vtkGetMacro(NormalToYAxis,int); 00104 vtkBooleanMacro(NormalToYAxis,int); 00105 void SetNormalToZAxis(int); 00106 vtkGetMacro(NormalToZAxis,int); 00107 vtkBooleanMacro(NormalToZAxis,int); 00109 00111 00114 virtual void SetLockNormalToCamera(int); 00115 vtkGetMacro(LockNormalToCamera,int); 00116 vtkBooleanMacro(LockNormalToCamera,int); 00118 00120 00122 vtkSetMacro(Tubing,int); 00123 vtkGetMacro(Tubing,int); 00124 vtkBooleanMacro(Tubing,int); 00126 00128 00132 void SetDrawPlane(int plane); 00133 vtkGetMacro(DrawPlane,int); 00134 vtkBooleanMacro(DrawPlane,int); 00136 00138 00140 vtkSetMacro(OutlineTranslation,int); 00141 vtkGetMacro(OutlineTranslation,int); 00142 vtkBooleanMacro(OutlineTranslation,int); 00144 00146 00148 vtkSetMacro(OutsideBounds,int); 00149 vtkGetMacro(OutsideBounds,int); 00150 vtkBooleanMacro(OutsideBounds,int); 00152 00154 00155 vtkSetMacro(ScaleEnabled,int); 00156 vtkGetMacro(ScaleEnabled,int); 00157 vtkBooleanMacro(ScaleEnabled,int); 00159 00162 void GetPolyData(vtkPolyData *pd); 00163 00166 vtkPolyDataAlgorithm* GetPolyDataAlgorithm(); 00167 00172 void GetPlane(vtkPlane *plane); 00173 00177 void UpdatePlacement(void); 00178 00180 00181 vtkGetObjectMacro(NormalProperty,vtkProperty); 00182 vtkGetObjectMacro(SelectedNormalProperty,vtkProperty); 00184 00186 00188 vtkGetObjectMacro(PlaneProperty,vtkProperty); 00189 vtkGetObjectMacro(SelectedPlaneProperty,vtkProperty); 00191 00193 00194 vtkGetObjectMacro(OutlineProperty,vtkProperty); 00195 vtkGetObjectMacro(SelectedOutlineProperty,vtkProperty); 00197 00199 00201 vtkGetObjectMacro(EdgesProperty,vtkProperty); 00203 00204 00205 void SetEdgeColor(vtkLookupTable*); 00206 void SetEdgeColor(double, double, double); 00207 void SetEdgeColor(double x[3]); 00209 00211 00214 vtkSetClampMacro(BumpDistance,double,0.000001,1); 00215 vtkGetMacro(BumpDistance,double); 00217 00223 void BumpPlane(int dir, double factor); 00224 00229 void PushPlane(double distance); 00230 00232 00233 virtual int ComputeInteractionState(int X, int Y, int modify=0); 00234 virtual void PlaceWidget(double bounds[6]); 00235 virtual void BuildRepresentation(); 00236 virtual void StartWidgetInteraction(double eventPos[2]); 00237 virtual void WidgetInteraction(double newEventPos[2]); 00238 virtual void EndWidgetInteraction(double newEventPos[2]); 00240 00241 00242 virtual double *GetBounds(); 00243 virtual void GetActors(vtkPropCollection *pc); 00244 virtual void ReleaseGraphicsResources(vtkWindow*); 00245 virtual int RenderOpaqueGeometry(vtkViewport*); 00246 virtual int RenderTranslucentPolygonalGeometry(vtkViewport*); 00247 virtual int HasTranslucentPolygonalGeometry(); 00249 00250 //BTX - manage the state of the widget 00251 enum _InteractionState 00252 { 00253 Outside=0, 00254 Moving, 00255 MovingOutline, 00256 MovingOrigin, 00257 Rotating, 00258 Pushing, 00259 Scaling 00260 }; 00261 //ETX 00262 00264 00271 vtkSetClampMacro(InteractionState,int,Outside,Scaling); 00273 00275 00277 virtual void SetRepresentationState(int); 00278 vtkGetMacro(RepresentationState, int); 00280 00281 protected: 00282 vtkImplicitPlaneRepresentation(); 00283 ~vtkImplicitPlaneRepresentation(); 00284 00285 int RepresentationState; 00286 00287 // Keep track of event positions 00288 double LastEventPosition[3]; 00289 00290 // Controlling ivars 00291 int NormalToXAxis; 00292 int NormalToYAxis; 00293 int NormalToZAxis; 00294 00295 // Locking normal to camera 00296 int LockNormalToCamera; 00297 00298 // Controlling the push operation 00299 double BumpDistance; 00300 00301 // The actual plane which is being manipulated 00302 vtkPlane *Plane; 00303 00304 // The bounding box is represented by a single voxel image data 00305 vtkImageData *Box; 00306 vtkOutlineFilter *Outline; 00307 vtkPolyDataMapper *OutlineMapper; 00308 vtkActor *OutlineActor; 00309 void HighlightOutline(int highlight); 00310 int OutlineTranslation; //whether the outline can be moved 00311 int ScaleEnabled; //whether the widget can be scaled 00312 int OutsideBounds; //whether the widget can be moved outside input's bounds 00313 00314 // The cut plane is produced with a vtkCutter 00315 vtkCutter *Cutter; 00316 vtkPolyDataMapper *CutMapper; 00317 vtkActor *CutActor; 00318 int DrawPlane; 00319 void HighlightPlane(int highlight); 00320 00321 // Optional tubes are represented by extracting boundary edges and tubing 00322 vtkFeatureEdges *Edges; 00323 vtkTubeFilter *EdgesTuber; 00324 vtkPolyDataMapper *EdgesMapper; 00325 vtkActor *EdgesActor; 00326 int Tubing; //control whether tubing is on 00327 00328 // The + normal cone 00329 vtkConeSource *ConeSource; 00330 vtkPolyDataMapper *ConeMapper; 00331 vtkActor *ConeActor; 00332 void HighlightNormal(int highlight); 00333 00334 // The + normal line 00335 vtkLineSource *LineSource; 00336 vtkPolyDataMapper *LineMapper; 00337 vtkActor *LineActor; 00338 00339 // The - normal cone 00340 vtkConeSource *ConeSource2; 00341 vtkPolyDataMapper *ConeMapper2; 00342 vtkActor *ConeActor2; 00343 00344 // The - normal line 00345 vtkLineSource *LineSource2; 00346 vtkPolyDataMapper *LineMapper2; 00347 vtkActor *LineActor2; 00348 00349 // The origin positioning handle 00350 vtkSphereSource *Sphere; 00351 vtkPolyDataMapper *SphereMapper; 00352 vtkActor *SphereActor; 00353 00354 // Do the picking 00355 vtkCellPicker *Picker; 00356 00357 // Register internal Pickers within PickingManager 00358 virtual void RegisterPickers(); 00359 00360 // Transform the normal (used for rotation) 00361 vtkTransform *Transform; 00362 00363 // Methods to manipulate the plane 00364 void ConstrainOrigin(double x[3]); 00365 void Rotate(double X, double Y, double *p1, double *p2, double *vpn); 00366 void TranslatePlane(double *p1, double *p2); 00367 void TranslateOutline(double *p1, double *p2); 00368 void TranslateOrigin(double *p1, double *p2); 00369 void Push(double *p1, double *p2); 00370 void Scale(double *p1, double *p2, double X, double Y); 00371 void SizeHandles(); 00372 00373 // Properties used to control the appearance of selected objects and 00374 // the manipulator in general. 00375 vtkProperty *NormalProperty; 00376 vtkProperty *SelectedNormalProperty; 00377 vtkProperty *PlaneProperty; 00378 vtkProperty *SelectedPlaneProperty; 00379 vtkProperty *OutlineProperty; 00380 vtkProperty *SelectedOutlineProperty; 00381 vtkProperty *EdgesProperty; 00382 void CreateDefaultProperties(); 00383 00384 void GeneratePlane(); 00385 00386 // Support GetBounds() method 00387 vtkBox *BoundingBox; 00388 00389 private: 00390 vtkImplicitPlaneRepresentation(const vtkImplicitPlaneRepresentation&); //Not implemented 00391 void operator=(const vtkImplicitPlaneRepresentation&); //Not implemented 00392 }; 00393 00394 #endif