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