00001 /*========================================================================= 00002 00003 Program: MIMX Meshing Toolkit 00004 Module: $RCSfile: vtkMimxBoundingBoxWidget.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 vtkMimxBoundingBoxWidget - 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 vtkBoundingBoxWidget, like any 3D widget, 00033 // will work with the current interactor style. That is, if vtkBoundingBoxWidget 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 // vtkBoundingBoxWidget 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 // vtkMimxBoundingBoxWidget 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 vtkBoundingBoxWidget, 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 vtkMimxBoundingBoxWidget 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 __vtkMimxBoundingBoxWidget_h 00080 #define __vtkMimxBoundingBoxWidget_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 vtkBBWPWCallback; 00097 class vtkSphereSource; 00098 class vtkTransform; 00099 00100 class VTK_MIMXWIDGETS_EXPORT vtkMimxBoundingBoxWidget : public vtk3DWidget 00101 { 00102 public: 00103 // Description: 00104 // Instantiate the object. 00105 static vtkMimxBoundingBoxWidget *New(); 00106 00107 vtkTypeRevisionMacro(vtkMimxBoundingBoxWidget,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 void PlaceWidget() 00115 {this->Superclass::PlaceWidget();} 00116 void PlaceWidget(double xmin, double xmax, double ymin, double ymax, 00117 double zmin, double zmax) 00118 {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);} 00119 void SetPoint(int i, double x[3]); 00120 00121 // Description: 00122 // Get the planes describing the implicit function defined by the box 00123 // widget. The user must provide the instance of the class vtkPlanes. Note 00124 // that vtkPlanes is a subclass of vtkImplicitFunction, meaning that it can 00125 // be used by a variety of filters to perform clipping, cutting, and 00126 // selection of data. (The direction of the normals of the planes can be 00127 // reversed enabling the InsideOut flag.) 00128 void GetPlanes(vtkPlanes *planes); 00129 00130 // Description: 00131 // Set/Get the InsideOut flag. When off, the normals point out of the 00132 // box. When on, the normals point into the hexahedron. InsideOut 00133 // is off by default. 00134 vtkSetMacro(InsideOut,int); 00135 vtkGetMacro(InsideOut,int); 00136 vtkBooleanMacro(InsideOut,int); 00137 00138 // Description: 00139 // Retrieve a linear transform characterizing the transformation of the 00140 // box. Note that the transformation is relative to where PlaceWidget 00141 // was initially called. This method modifies the transform provided. The 00142 // transform can be used to control the position of vtkProp3D's, as well as 00143 // other transformation operations (e.g., vtkTranformPolyData). 00144 void GetTransform(vtkTransform *t); 00145 00146 // Description: 00147 // Grab the polydata (including points) that define the box widget. The 00148 // polydata consists of 6 quadrilateral faces and 15 points. The first 00149 // eight points define the eight corner vertices; the next six define the 00150 // -x,+x, -y,+y, -z,+z face points; and the final point (the 15th out of 15 00151 // points) defines the center of the hexahedron. These point values are 00152 // guaranteed to be up-to-date when either the InteractionEvent or 00153 // EndInteractionEvent events are invoked. The user provides the 00154 // vtkPolyData and the points and cells are added to it. 00155 void GetPolyData(vtkPolyData *pd); 00156 00157 // Description: 00158 // Get the handle properties (the little balls are the handles). The 00159 // properties of the handles when selected and normal can be 00160 // set. 00161 vtkGetObjectMacro(HandleProperty,vtkProperty); 00162 vtkGetObjectMacro(SelectedHandleProperty,vtkProperty); 00163 00164 // Description: 00165 // Get the face properties (the faces of the box). The 00166 // properties of the face when selected and normal can be 00167 // set. 00168 00169 // Description: 00170 // Get the outline properties (the outline of the box). The 00171 // properties of the outline when selected and normal can be 00172 // set. 00173 vtkGetObjectMacro(OutlineProperty,vtkProperty); 00174 vtkGetObjectMacro(SelectedOutlineProperty,vtkProperty); 00175 00176 // Description: 00177 // Control the representation of the outline. This flag enables 00178 // face wires. By default face wires are off. 00179 vtkSetMacro(OutlineFaceWires,int); 00180 vtkGetMacro(OutlineFaceWires,int); 00181 vtkBooleanMacro(OutlineFaceWires,int); 00182 00183 // Description: 00184 // Control the representation of the outline. This flag enables 00185 // the cursor lines running between the handles. By default cursor 00186 // wires are on. 00187 vtkSetMacro(OutlineCursorWires,int); 00188 vtkGetMacro(OutlineCursorWires,int); 00189 vtkBooleanMacro(OutlineCursorWires,int); 00190 00191 // Description: 00192 // Control the behavior of the widget. Translation, rotation, and 00193 // scaling can all be enabled and disabled. 00194 00195 protected: 00196 vtkMimxBoundingBoxWidget(); 00197 ~vtkMimxBoundingBoxWidget(); 00198 00199 //BTX - manage the state of the widget 00200 int State; 00201 enum WidgetState 00202 { 00203 Start=0, 00204 MovingHandle, 00205 Scaling, 00206 Outside 00207 }; 00208 //ETX 00209 00210 // Handles the events 00211 static void ProcessEvents(vtkObject* object, 00212 unsigned long event, 00213 void* clientdata, 00214 void* calldata); 00215 00216 // ProcessEvents() dispatches to these methods. 00217 void OnMouseMove(); 00218 void OnLeftButtonDown(); 00219 void OnLeftButtonUp(); 00220 void OnMiddleButtonDown(); 00221 void OnMiddleButtonUp(); 00222 void OnRightButtonDown(); 00223 void OnRightButtonUp(); 00224 vtkPoints *Points; //used by others as well 00225 00226 // the hexahedron (6 faces) 00227 vtkActor *HexActor; 00228 vtkPolyDataMapper *HexMapper; 00229 vtkPolyData *HexPolyData; 00230 00231 00232 // glyphs representing hot spots (e.g., handles) 00233 vtkCollection *Handle; 00234 // vtkActor **Handle; 00235 vtkCollection *HandleMapper; 00236 // vtkPolyDataMapper **HandleMapper; 00237 vtkCollection *HandleGeometry; 00238 // vtkSphereSource **HandleGeometry; 00239 void PositionHandles(); 00240 void HandlesOn(double length); 00241 void HandlesOff(); 00242 int HighlightHandle(vtkProp *prop); //returns cell id 00243 void HighlightOutline(int highlight); 00244 virtual void SizeHandles(); 00245 00246 // wireframe outline 00247 vtkActor *HexOutline; 00248 vtkPolyDataMapper *OutlineMapper; 00249 vtkPolyData *OutlinePolyData; 00250 00251 // Do the picking 00252 vtkCellPicker *HandlePicker; 00253 vtkCellPicker *HexPicker; 00254 vtkActor *CurrentHandle; 00255 00256 00257 // Properties used to control the appearance of selected objects and 00258 // the manipulator in general. 00259 vtkProperty *HandleProperty; 00260 vtkProperty *SelectedHandleProperty; 00261 vtkProperty *OutlineProperty; 00262 vtkProperty *SelectedOutlineProperty; 00263 void CreateDefaultProperties(); 00264 00265 // Control the orientation of the normals 00266 int InsideOut; 00267 int OutlineFaceWires; 00268 int OutlineCursorWires; 00269 void GenerateOutline(); 00270 // Pointwidget handles 00271 vtkCollection* PointWidget; 00272 //vtkModPointWidget *PointWidget1; 00273 vtkBBWPWCallback *PWCallback; 00274 vtkMimxModPointWidget *CurrentPointWidget; 00275 int ForwardEvent(unsigned long event); 00276 void EnablePointWidget(); 00277 void DisablePointWidget(); 00278 private: 00279 vtkMimxBoundingBoxWidget(const vtkMimxBoundingBoxWidget&); //Not implemented 00280 void operator=(const vtkMimxBoundingBoxWidget&); //Not implemented 00281 }; 00282 00283 #endif
1.6.1