00001 /*========================================================================= 00002 00003 Program: MIMX Meshing Toolkit 00004 Module: $RCSfile: vtkMimxExtractEdgeWidget.h,v $ 00005 Language: C++ 00006 00007 Date: $Date: 2008/07/06 20:30:13 $ 00008 Version: $Revision: 1.7 $ 00009 00010 00011 Musculoskeletal Imaging, Modelling and Experimentation (MIMX) 00012 Center for Computer Aided Design 00013 The University of Iowa 00014 Iowa City, IA 52242 00015 http://www.ccad.uiowa.edu/mimx/ 00016 00017 Copyright (c) The University of Iowa. All rights reserved. 00018 See MIMXCopyright.txt or http://www.ccad.uiowa.edu/mimx/Copyright.htm for details. 00019 00020 This software is distributed WITHOUT ANY WARRANTY; without even 00021 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00022 PURPOSE. See the above copyright notices for more information. 00023 00024 =========================================================================*/ 00025 // .NAME vtkMimxExtractEdgeWidget - orthogonal hexahedron 3D widget 00026 // .SECTION Description 00027 // This 3D widget defines a region of interest that is represented by an 00028 // arbitrarily oriented hexahedron with interior face angles of 90 degrees 00029 // (orthogonal faces). The object creates 7 handles that can be moused on and 00030 // manipulated. The first six correspond to the six faces, the seventh is in 00031 // the center of the hexahedron. In addition, a bounding box outline is shown, 00032 // the "faces" of which can be selected for object rotation or scaling. A 00033 // nice feature of the object is that the vtkMimxExtractEdgeWidget, like any 3D widget, 00034 // will work with the current interactor style. That is, if vtkMimxExtractEdgeWidget does 00035 // not handle an event, then all other registered observers (including the 00036 // interactor style) have an opportunity to process the event. Otherwise, the 00037 // vtkMimxExtractEdgeWidget will terminate the processing of the event that it handles. 00038 // 00039 // To use this object, just invoke SetInteractor() with the argument of the 00040 // method a vtkRenderWindowInteractor. You may also wish to invoke 00041 // "PlaceWidget()" to initially position the widget. The interactor will act 00042 // normally until the "i" key (for "interactor") is pressed, at which point the 00043 // vtkMimxExtractEdgeWidget will appear. (See superclass documentation for information 00044 // about changing this behavior.) By grabbing the six face handles (use the 00045 // left mouse button), faces can be moved. By grabbing the center handle 00046 // (with the left mouse button), the entire hexahedron can be 00047 // translated. (Translation can also be employed by using the 00048 // "shift-left-mouse-button" combination inside of the widget.) Scaling is 00049 // achieved by using the right mouse button "up" the render window (makes the 00050 // widget bigger) or "down" the render window (makes the widget smaller). To 00051 // rotate vtkMimxExtractEdgeWidget, pick a face (but not a face handle) and move the left 00052 // mouse. (Note: the mouse button must be held down during manipulation.) 00053 // Events that occur outside of the widget (i.e., no part of the widget is 00054 // picked) are propagated to any other registered obsevers (such as the 00055 // interaction style). Turn off the widget by pressing the "i" key again. 00056 // (See the superclass documentation on key press activiation.) 00057 // 00058 // The vtkMimxExtractEdgeWidget is very flexible. It can be used to select, cut, clip, or 00059 // perform any other operation that depends on an implicit function (use the 00060 // GetPlanes() method); or it can be used to transform objects using a linear 00061 // transformation (use the GetTransform() method). Typical usage of the 00062 // widget is to make use of the StartInteractionEvent, InteractionEvent, and 00063 // EndInteractionEvent events. The InteractionEvent is called on mouse 00064 // motion; the other two events are called on button down and button up 00065 // (either left or right button). 00066 // 00067 // Some additional features of this class include the ability to control the 00068 // rendered properties of the widget. You can set the properties of the 00069 // selected and unselected representations of the parts of the widget. For 00070 // example, you can set the property for the handles, faces, and outline in 00071 // their normal and selected states. 00072 00073 // .SECTION Caveats 00074 // Note that handles can be picked even when they are "behind" other actors. 00075 // This is an intended feature and not a bug. 00076 // 00077 // The box widget can be oriented by specifying a transformation matrix. 00078 // This transformation is applied to the initial bounding box as defined by 00079 // the PlaceWidget() method. DO NOT ASSUME that the transformation is applied 00080 // to a unit box centered at the origin; this is wrong! 00081 00082 // .SECTION See Also 00083 // vtk3DWidget vtkPointWidget vtkLineWidget vtkPlaneWidget 00084 // vtkImplicitPlaneWidget vtkImagePlaneWidget 00085 00086 #ifndef __vtkMimxExtractEdgeWidget_h 00087 #define __vtkMimxExtractEdgeWidget_h 00088 00089 #include "vtk3DWidget.h" 00090 #include "vtkActor.h" 00091 #include "vtkMimxWidgetsWin32Header.h" 00092 00093 00094 class vtkActor; 00095 class vtkCellPicker; 00096 class vtkPlanes; 00097 class vtkPoints; 00098 class vtkPolyData; 00099 class vtkPolyDataMapper; 00100 class vtkProp; 00101 class vtkProperty; 00102 class vtkSphereSource; 00103 class vtkTransform; 00104 class vtkUnstructuredGrid; 00105 class vtkIdList; 00106 00107 class VTK_MIMXWIDGETS_EXPORT vtkMimxExtractEdgeWidget : public vtk3DWidget 00108 { 00109 public: 00110 // Description: 00111 // Instantiate the object. 00112 static vtkMimxExtractEdgeWidget *New(); 00113 00114 vtkTypeRevisionMacro(vtkMimxExtractEdgeWidget,vtk3DWidget); 00115 void PrintSelf(ostream& os, vtkIndent indent); 00116 00117 // Description: 00118 // Methods that satisfy the superclass' API. 00119 virtual void SetEnabled(int); 00120 virtual void PlaceWidget(double bounds[6]); 00121 void PlaceWidget() 00122 {this->Superclass::PlaceWidget();} 00123 void PlaceWidget(double xmin, double xmax, double ymin, double ymax, 00124 double zmin, double zmax) 00125 {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);} 00126 00127 // Description: 00128 // Get the planes describing the implicit function defined by the box 00129 // widget. The user must provide the instance of the class vtkPlanes. Note 00130 // that vtkPlanes is a subclass of vtkImplicitFunction, meaning that it can 00131 // be used by a variety of filters to perform clipping, cutting, and 00132 // selection of data. (The direction of the normals of the planes can be 00133 // reversed enabling the InsideOut flag.) 00134 //void GetPlanes(vtkPlanes *planes); 00135 00136 // Description: 00137 // Set/Get the InsideOut flag. When off, the normals point out of the 00138 // box. When on, the normals point into the hexahedron. InsideOut 00139 // is off by default. 00140 //vtkSetMacro(InsideOut,int); 00141 //vtkGetMacro(InsideOut,int); 00142 //vtkBooleanMacro(InsideOut,int); 00143 00144 // Description: 00145 // Retrieve a linear transform characterizing the transformation of the 00146 // box. Note that the transformation is relative to where PlaceWidget 00147 // was initially called. This method modifies the transform provided. The 00148 // transform can be used to control the position of vtkProp3D's, as well as 00149 // other transformation operations (e.g., vtkTranformPolyData). 00150 //virtual void GetTransform(vtkTransform *t); 00151 00152 // Description: 00153 // Set the position, scale and orientation of the box widget using the 00154 // transform specified. Note that the transformation is relative to 00155 // where PlaceWidget was initially called (i.e., the original bounding 00156 // box). 00157 //virtual void SetTransform(vtkTransform* t); 00158 00159 // Description: 00160 // Grab the polydata (including points) that define the box widget. The 00161 // polydata consists of 6 quadrilateral faces and 15 points. The first 00162 // eight points define the eight corner vertices; the next six define the 00163 // -x,+x, -y,+y, -z,+z face points; and the final point (the 15th out of 15 00164 // points) defines the center of the hexahedron. These point values are 00165 // guaranteed to be up-to-date when either the InteractionEvent or 00166 // EndInteractionEvent events are invoked. The user provides the 00167 // vtkPolyData and the points and cells are added to it. 00168 //void GetPolyData(vtkPolyData *pd); 00169 00170 // Description: 00171 // Get the handle properties (the little balls are the handles). The 00172 // properties of the handles when selected and normal can be 00173 // set. 00174 //vtkGetObjectMacro(HandleProperty,vtkProperty); 00175 //vtkGetObjectMacro(SelectedHandleProperty,vtkProperty); 00176 00177 // Description: 00178 // Switches handles (the spheres) on or off by manipulating the actor 00179 // visibility. 00180 //void HandlesOn(); 00181 //void HandlesOff(); 00182 00183 // Description: 00184 // Get the face properties (the faces of the box). The 00185 // properties of the face when selected and normal can be 00186 // set. 00187 //vtkGetObjectMacro(FaceProperty,vtkProperty); 00188 //vtkGetObjectMacro(SelectedFaceProperty,vtkProperty); 00189 00190 // Description: 00191 // Get the outline properties (the outline of the box). The 00192 // properties of the outline when selected and normal can be 00193 // set. 00194 //vtkGetObjectMacro(OutlineProperty,vtkProperty); 00195 //vtkGetObjectMacro(SelectedOutlineProperty,vtkProperty); 00196 00197 // Description: 00198 // Control the representation of the outline. This flag enables 00199 // face wires. By default face wires are off. 00200 //void SetOutlineFaceWires(int); 00201 //vtkGetMacro(OutlineFaceWires,int); 00202 //void OutlineFaceWiresOn() {this->SetOutlineFaceWires(1);} 00203 //void OutlineFaceWiresOff() {this->SetOutlineFaceWires(0);} 00204 00205 // Description: 00206 // Control the representation of the outline. This flag enables 00207 // the cursor lines running between the handles. By default cursor 00208 // wires are on. 00209 /* void SetOutlineCursorWires(int); 00210 vtkGetMacro(OutlineCursorWires,int); 00211 void OutlineCursorWiresOn() {this->SetOutlineCursorWires(1);} 00212 void OutlineCursorWiresOff() {this->SetOutlineCursorWires(0);}*/ 00213 00214 // Description: 00215 // Control the behavior of the widget. Translation, rotation, and 00216 // scaling can all be enabled and disabled. 00217 //vtkSetMacro(TranslationEnabled,int); 00218 //vtkGetMacro(TranslationEnabled,int); 00219 //vtkBooleanMacro(TranslationEnabled,int); 00220 //vtkSetMacro(ScalingEnabled,int); 00221 //vtkGetMacro(ScalingEnabled,int); 00222 //vtkBooleanMacro(ScalingEnabled,int); 00223 //vtkSetMacro(RotationEnabled,int); 00224 //vtkGetMacro(RotationEnabled,int); 00225 //vtkBooleanMacro(RotationEnabled,int); 00226 virtual void SetInput(vtkDataSet*); 00227 vtkGetMacro(EdgePoints, vtkIdList*); 00228 vtkSetObjectMacro(InputActor, vtkActor); 00229 vtkGetObjectMacro(EdgePointsCompleteGrid, vtkIdList); 00230 protected: 00231 vtkMimxExtractEdgeWidget(); 00232 ~vtkMimxExtractEdgeWidget(); 00233 vtkUnstructuredGrid *UGrid; 00234 vtkIdList *EdgePoints; 00235 vtkIdList *EdgePointsCompleteGrid; 00236 //BTX - manage the state of the widget 00237 int State; 00238 enum WidgetState 00239 { 00240 Start=0, 00241 Moving, 00242 //Scaling, 00243 Outside 00244 }; 00245 //ETX 00246 00247 // Handles the events 00248 static void ProcessEvents(vtkObject* object, 00249 unsigned long event, 00250 void* clientdata, 00251 void* calldata); 00252 00253 // ProcessEvents() dispatches to these methods. 00254 virtual void OnMouseMove(); 00255 virtual void OnLeftButtonDown(); 00256 virtual void OnLeftButtonUp(); 00257 virtual void OnMiddleButtonDown(); 00258 virtual void OnMiddleButtonUp(); 00259 void ExtractEdge(); 00260 void Initialize(); 00261 virtual void OnRightButtonDown(); 00262 virtual void OnRightButtonUp(); 00263 00264 // the hexahedron (6 faces) 00265 vtkActor *EdgeActor; 00266 vtkPolyDataMapper *EdgeMapper; 00267 vtkPolyData *EdgePolyData; 00268 //vtkPoints *Points; //used by others as well 00269 //double N[6][3]; //the normals of the faces 00270 00271 // A face of the hexahedron 00272 /* vtkActor *HexFace; 00273 vtkPolyDataMapper *HexFaceMapper; 00274 vtkPolyData *HexFacePolyData;*/ 00275 00276 // glyphs representing hot spots (e.g., handles) 00277 //vtkActor **Handle; 00278 //vtkPolyDataMapper **HandleMapper; 00279 //vtkSphereSource **HandleGeometry; 00280 //virtual void PositionHandles(); 00281 //int HighlightHandle(vtkProp *prop); //returns cell id 00282 //void HighlightFace(int cellId); 00283 //void HighlightOutline(int highlight); 00284 //void ComputeNormals(); 00285 //virtual void SizeHandles(); 00286 00287 // wireframe outline 00288 /* vtkActor *HexOutline; 00289 vtkPolyDataMapper *OutlineMapper; 00290 vtkPolyData *OutlinePolyData;*/ 00291 00292 // Do the picking 00293 //vtkCellPicker *HandlePicker; 00294 vtkCellPicker *EdgePicker; 00295 vtkActor *InputActor; 00296 /* vtkActor *CurrentHandle; 00297 int CurrentHexFace;*/ 00298 00299 // Methods to manipulate the hexahedron. 00300 /* virtual void Translate(double *p1, double *p2); 00301 virtual void Scale(double *p1, double *p2, int X, int Y); 00302 virtual void Rotate(int X, int Y, double *p1, double *p2, double *vpn); 00303 void MovePlusXFace(double *p1, double *p2); 00304 void MoveMinusXFace(double *p1, double *p2); 00305 void MovePlusYFace(double *p1, double *p2); 00306 void MoveMinusYFace(double *p1, double *p2); 00307 void MovePlusZFace(double *p1, double *p2); 00308 void MoveMinusZFace(double *p1, double *p2);*/ 00309 00310 //"dir" is the direction in which the face can be moved i.e. the axis passing 00311 //through the center 00312 //void MoveFace(double *p1, double *p2, double *dir, 00313 // double *x1, double *x2, double *x3, double *x4, 00314 // double *x5); 00317 //void GetDirection(const double Nx[3],const double Ny[3], 00318 // const double Nz[3], double dir[3]); 00319 00320 // Transform the hexahedral points (used for rotations) 00321 //vtkTransform *Transform; 00322 // 00325 //vtkProperty *HandleProperty; 00326 //vtkProperty *SelectedHandleProperty; 00327 //vtkProperty *FaceProperty; 00328 //vtkProperty *SelectedFaceProperty; 00329 //vtkProperty *OutlineProperty; 00330 //vtkProperty *SelectedOutlineProperty; 00331 //void CreateDefaultProperties(); 00332 00333 // Control the orientation of the normals 00334 //int InsideOut; 00335 //int OutlineFaceWires; 00336 //int OutlineCursorWires; 00337 //void GenerateOutline(); 00338 00339 // Control whether scaling, rotation, and translation are supported 00340 //int TranslationEnabled; 00341 //int ScalingEnabled; 00342 //int RotationEnabled; 00343 int PickStatus; 00344 private: 00345 vtkMimxExtractEdgeWidget(const vtkMimxExtractEdgeWidget&); //Not implemented 00346 void operator=(const vtkMimxExtractEdgeWidget&); //Not implemented 00347 }; 00348 00349 #endif
1.6.1