1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkImplicitPlaneRepresentation.h 5 6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 7 All rights reserved. 8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 9 10 This software is distributed WITHOUT ANY WARRANTY; without even 11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 12 PURPOSE. See the above copyright notice for more information. 13 14 =========================================================================*/ 15 // .NAME vtkImplicitPlaneRepresentation - a class defining the representation for a vtkImplicitPlaneWidget2 16 // .SECTION Description 17 // This class is a concrete representation for the 18 // vtkImplicitPlaneWidget2. It represents an infinite plane defined by a 19 // normal and point in the context of a bounding box. Through interaction 20 // with the widget, the plane can be manipulated by adjusting the plane 21 // normal or moving the origin point. 22 // 23 // To use this representation, you normally define a (plane) origin and (plane) 24 // normal. The PlaceWidget() method is also used to initially position the 25 // representation. 26 27 // .SECTION Caveats 28 // This class, and vtkImplicitPlaneWidget2, are next generation VTK 29 // widgets. An earlier version of this functionality was defined in the 30 // class vtkImplicitPlaneWidget. 31 32 // .SECTION See Also 33 // vtkImplicitPlaneWidget2 vtkImplicitPlaneWidget 34 35 36 #ifndef vtkImplicitPlaneRepresentation_h 37 #define vtkImplicitPlaneRepresentation_h 38 39 #include "vtkInteractionWidgetsModule.h" // For export macro 40 #include "vtkWidgetRepresentation.h" 41 42 class vtkActor; 43 class vtkPolyDataMapper; 44 class vtkCellPicker; 45 class vtkConeSource; 46 class vtkLineSource; 47 class vtkSphereSource; 48 class vtkTubeFilter; 49 class vtkPlane; 50 class vtkCutter; 51 class vtkProperty; 52 class vtkImageData; 53 class vtkOutlineFilter; 54 class vtkFeatureEdges; 55 class vtkPolyData; 56 class vtkPolyDataAlgorithm; 57 class vtkTransform; 58 class vtkBox; 59 class vtkLookupTable; 60 61 class VTKINTERACTIONWIDGETS_EXPORT vtkImplicitPlaneRepresentation : public vtkWidgetRepresentation 62 { 63 public: 64 // Description: 65 // Instantiate the class. 66 static vtkImplicitPlaneRepresentation *New(); 67 68 // Description: 69 // Standard methods for the class. 70 vtkTypeMacro(vtkImplicitPlaneRepresentation,vtkWidgetRepresentation); 71 void PrintSelf(ostream& os, vtkIndent indent); 72 73 // Description: 74 // Get the origin of the plane. 75 void SetOrigin(double x, double y, double z); 76 void SetOrigin(double x[3]); 77 double* GetOrigin(); 78 void GetOrigin(double xyz[3]); 79 80 // Description: 81 // Get the normal to the plane. 82 void SetNormal(double x, double y, double z); 83 void SetNormal(double x[3]); 84 void SetNormalToCamera(); 85 double* GetNormal(); 86 void GetNormal(double xyz[3]); 87 88 // Description: 89 // Force the plane widget to be aligned with one of the x-y-z axes. 90 // If one axis is set on, the other two will be set off. 91 // Remember that when the state changes, a ModifiedEvent is invoked. 92 // This can be used to snap the plane to the axes if it is originally 93 // not aligned. 94 void SetNormalToXAxis(int); 95 vtkGetMacro(NormalToXAxis,int); 96 vtkBooleanMacro(NormalToXAxis,int); 97 void SetNormalToYAxis(int); 98 vtkGetMacro(NormalToYAxis,int); 99 vtkBooleanMacro(NormalToYAxis,int); 100 void SetNormalToZAxis(int); 101 vtkGetMacro(NormalToZAxis,int); 102 vtkBooleanMacro(NormalToZAxis,int); 103 104 // Description: 105 // If enabled, and a vtkCamera is available through the renderer, then 106 // LockNormalToCamera will cause the normal to follow the camera's 107 // normal. 108 virtual void SetLockNormalToCamera(int); 109 vtkGetMacro(LockNormalToCamera,int); 110 vtkBooleanMacro(LockNormalToCamera,int); 111 112 // Description: 113 // Turn on/off tubing of the wire outline of the plane. The tube thickens 114 // the line by wrapping with a vtkTubeFilter. 115 vtkSetMacro(Tubing,int); 116 vtkGetMacro(Tubing,int); 117 vtkBooleanMacro(Tubing,int); 118 119 // Description: 120 // Enable/disable the drawing of the plane. In some cases the plane 121 // interferes with the object that it is operating on (i.e., the 122 // plane interferes with the cut surface it produces producing 123 // z-buffer artifacts.) 124 void SetDrawPlane(int plane); 125 vtkGetMacro(DrawPlane,int); 126 vtkBooleanMacro(DrawPlane,int); 127 128 // Description: 129 // Turn on/off the ability to translate the bounding box by grabbing it 130 // with the left mouse button. 131 vtkSetMacro(OutlineTranslation,int); 132 vtkGetMacro(OutlineTranslation,int); 133 vtkBooleanMacro(OutlineTranslation,int); 134 135 // Description: 136 // Turn on/off the ability to move the widget outside of the bounds 137 // specified in the initial PlaceWidget() invocation. 138 vtkSetMacro(OutsideBounds,int); 139 vtkGetMacro(OutsideBounds,int); 140 vtkBooleanMacro(OutsideBounds,int); 141 142 // Description: 143 // Turn on/off the ability to scale the widget with the mouse. 144 vtkSetMacro(ScaleEnabled,int); 145 vtkGetMacro(ScaleEnabled,int); 146 vtkBooleanMacro(ScaleEnabled,int); 147 148 // Description: 149 // Grab the polydata that defines the plane. The polydata contains a single 150 // polygon that is clipped by the bounding box. 151 void GetPolyData(vtkPolyData *pd); 152 153 // Description: 154 // Satisfies superclass API. This returns a pointer to the underlying 155 // PolyData (which represents the plane). 156 vtkPolyDataAlgorithm* GetPolyDataAlgorithm(); 157 158 // Description: 159 // Get the implicit function for the plane. The user must provide the 160 // instance of the class vtkPlane. Note that vtkPlane is a subclass of 161 // vtkImplicitFunction, meaning that it can be used by a variety of filters 162 // to perform clipping, cutting, and selection of data. 163 void GetPlane(vtkPlane *plane); 164 165 // Description: 166 // Satisfies the superclass API. This will change the state of the widget 167 // to match changes that have been made to the underlying PolyDataSource 168 void UpdatePlacement(void); 169 170 // Description: 171 // Get the properties on the normal (line and cone). 172 vtkGetObjectMacro(NormalProperty,vtkProperty); 173 vtkGetObjectMacro(SelectedNormalProperty,vtkProperty); 174 175 // Description: 176 // Get the plane properties. The properties of the plane when selected 177 // and unselected can be manipulated. 178 vtkGetObjectMacro(PlaneProperty,vtkProperty); 179 vtkGetObjectMacro(SelectedPlaneProperty,vtkProperty); 180 181 // Description: 182 // Get the property of the outline. 183 vtkGetObjectMacro(OutlineProperty,vtkProperty); 184 vtkGetObjectMacro(SelectedOutlineProperty,vtkProperty); 185 186 // Description: 187 // Get the property of the intersection edges. (This property also 188 // applies to the edges when tubed.) 189 vtkGetObjectMacro(EdgesProperty,vtkProperty); 190 // Description 191 // Set color to the edge 192 void SetEdgeColor(vtkLookupTable*); 193 void SetEdgeColor(double, double, double); 194 void SetEdgeColor(double x[3]); 195 196 // Description: 197 // Specify a translation distance used by the BumpPlane() method. Note that the 198 // distance is normalized; it is the fraction of the length of the bounding 199 // box of the wire outline. 200 vtkSetClampMacro(BumpDistance,double,0.000001,1); 201 vtkGetMacro(BumpDistance,double); 202 203 // Description: 204 // Translate the plane in the direction of the normal by the 205 // specified BumpDistance. The dir parameter controls which 206 // direction the pushing occurs, either in the same direction 207 // as the normal, or when negative, in the opposite direction. 208 // The factor controls whether what percentage of the bump is 209 // used. 210 void BumpPlane(int dir, double factor); 211 212 // Description: 213 // Push the plane the distance specified along the normal. Positive 214 // values are in the direction of the normal; negative values are 215 // in the opposite direction of the normal. The distance value is 216 // expressed in world coordinates. 217 void PushPlane(double distance); 218 219 // Description: 220 // Methods to interface with the vtkSliderWidget. 221 virtual int ComputeInteractionState(int X, int Y, int modify=0); 222 virtual void PlaceWidget(double bounds[6]); 223 virtual void BuildRepresentation(); 224 virtual void StartWidgetInteraction(double eventPos[2]); 225 virtual void WidgetInteraction(double newEventPos[2]); 226 virtual void EndWidgetInteraction(double newEventPos[2]); 227 // Decsription: 228 // Methods supporting the rendering process. 229 virtual double *GetBounds(); 230 virtual void GetActors(vtkPropCollection *pc); 231 virtual void ReleaseGraphicsResources(vtkWindow*); 232 virtual int RenderOpaqueGeometry(vtkViewport*); 233 virtual int RenderTranslucentPolygonalGeometry(vtkViewport*); 234 virtual int HasTranslucentPolygonalGeometry(); 235 236 //BTX - manage the state of the widget 237 enum _InteractionState 238 { 239 Outside=0, 240 Moving, 241 MovingOutline, 242 MovingOrigin, 243 Rotating, 244 Pushing, 245 Scaling 246 }; 247 //ETX 248 249 // Description: 250 // The interaction state may be set from a widget (e.g., 251 // vtkImplicitPlaneWidget2) or other object. This controls how the 252 // interaction with the widget proceeds. Normally this method is used as 253 // part of a handshaking process with the widget: First 254 // ComputeInteractionState() is invoked that returns a state based on 255 // geometric considerations (i.e., cursor near a widget feature), then 256 // based on events, the widget may modify this further. 257 vtkSetClampMacro(InteractionState,int,Outside,Scaling); 258 259 // Description: 260 // Sets the visual appearance of the representation based on the 261 // state it is in. This state is usually the same as InteractionState. 262 virtual void SetRepresentationState(int); 263 vtkGetMacro(RepresentationState, int); 264 265 protected: 266 vtkImplicitPlaneRepresentation(); 267 ~vtkImplicitPlaneRepresentation(); 268 269 int RepresentationState; 270 271 // Keep track of event positions 272 double LastEventPosition[3]; 273 274 // Controlling ivars 275 int NormalToXAxis; 276 int NormalToYAxis; 277 int NormalToZAxis; 278 279 // Locking normal to camera 280 int LockNormalToCamera; 281 282 // Controlling the push operation 283 double BumpDistance; 284 285 // The actual plane which is being manipulated 286 vtkPlane *Plane; 287 288 // The bounding box is represented by a single voxel image data 289 vtkImageData *Box; 290 vtkOutlineFilter *Outline; 291 vtkPolyDataMapper *OutlineMapper; 292 vtkActor *OutlineActor; 293 void HighlightOutline(int highlight); 294 int OutlineTranslation; //whether the outline can be moved 295 int ScaleEnabled; //whether the widget can be scaled 296 int OutsideBounds; //whether the widget can be moved outside input's bounds 297 298 // The cut plane is produced with a vtkCutter 299 vtkCutter *Cutter; 300 vtkPolyDataMapper *CutMapper; 301 vtkActor *CutActor; 302 int DrawPlane; 303 void HighlightPlane(int highlight); 304 305 // Optional tubes are represented by extracting boundary edges and tubing 306 vtkFeatureEdges *Edges; 307 vtkTubeFilter *EdgesTuber; 308 vtkPolyDataMapper *EdgesMapper; 309 vtkActor *EdgesActor; 310 int Tubing; //control whether tubing is on 311 312 // The + normal cone 313 vtkConeSource *ConeSource; 314 vtkPolyDataMapper *ConeMapper; 315 vtkActor *ConeActor; 316 void HighlightNormal(int highlight); 317 318 // The + normal line 319 vtkLineSource *LineSource; 320 vtkPolyDataMapper *LineMapper; 321 vtkActor *LineActor; 322 323 // The - normal cone 324 vtkConeSource *ConeSource2; 325 vtkPolyDataMapper *ConeMapper2; 326 vtkActor *ConeActor2; 327 328 // The - normal line 329 vtkLineSource *LineSource2; 330 vtkPolyDataMapper *LineMapper2; 331 vtkActor *LineActor2; 332 333 // The origin positioning handle 334 vtkSphereSource *Sphere; 335 vtkPolyDataMapper *SphereMapper; 336 vtkActor *SphereActor; 337 338 // Do the picking 339 vtkCellPicker *Picker; 340 341 // Register internal Pickers within PickingManager 342 virtual void RegisterPickers(); 343 344 // Transform the normal (used for rotation) 345 vtkTransform *Transform; 346 347 // Methods to manipulate the plane 348 void ConstrainOrigin(double x[3]); 349 void Rotate(double X, double Y, double *p1, double *p2, double *vpn); 350 void TranslatePlane(double *p1, double *p2); 351 void TranslateOutline(double *p1, double *p2); 352 void TranslateOrigin(double *p1, double *p2); 353 void Push(double *p1, double *p2); 354 void Scale(double *p1, double *p2, double X, double Y); 355 void SizeHandles(); 356 357 // Properties used to control the appearance of selected objects and 358 // the manipulator in general. 359 vtkProperty *NormalProperty; 360 vtkProperty *SelectedNormalProperty; 361 vtkProperty *PlaneProperty; 362 vtkProperty *SelectedPlaneProperty; 363 vtkProperty *OutlineProperty; 364 vtkProperty *SelectedOutlineProperty; 365 vtkProperty *EdgesProperty; 366 void CreateDefaultProperties(); 367 368 void GeneratePlane(); 369 370 // Support GetBounds() method 371 vtkBox *BoundingBox; 372 373 private: 374 vtkImplicitPlaneRepresentation(const vtkImplicitPlaneRepresentation&); //Not implemented 375 void operator=(const vtkImplicitPlaneRepresentation&); //Not implemented 376 }; 377 378 #endif 379