vtkMimxModPointWidget.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003 Program:   MIMX Meshing Toolkit
00004 Module:    $RCSfile: vtkMimxModPointWidget.h,v $
00005 Language:  C++
00006 Date:      $Date: 2007/07/12 14:15:21 $
00007 Version:   $Revision: 1.8 $
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 vtkMimxModPointWidget - position a point in 3D space
00025 
00026 // .SECTION Description
00027 // This 3D widget allows the user to position a point in 3D space using a 3D
00028 // cursor. The cursor has an outline bounding box, axes-aligned cross-hairs,
00029 // and axes shadows. (The outline and shadows can be turned off.) Any of
00030 // these can be turned off. A nice feature of the object is that the
00031 // vtkMimxModPointWidget, like any 3D widget, will work with the current interactor
00032 // style. That is, if vtkModPointWidget does not handle an event, then all other
00033 // registered observers (including the interactor style) have an opportunity
00034 // to process the event. Otherwise, the vtkModPointWidget will terminate the
00035 // processing of the event that it handles.
00036 //
00037 // To use this object, just invoke SetInteractor() with the argument of the
00038 // method a vtkRenderWindowInteractor.  You may also wish to invoke
00039 // "PlaceWidget()" to initially position the widget. The interactor will act
00040 // normally until the "i" key (for "interactor") is pressed, at which point
00041 // the vtkMimxModPointWidget will appear. (See superclass documentation for
00042 // information about changing this behavior.) To move the point, the user can
00043 // grab (left mouse) on any widget line and "slide" the point into
00044 // position. Scaling is achieved by using the right mouse button "up" the
00045 // render window (makes the widget bigger) or "down" the render window (makes
00046 // the widget smaller). To translate the widget use the middle mouse button.
00047 // (Note: all of the translation interactions can be constrained to one of
00048 // the x-y-z axes by using the "shift" key.) The vtkModPointWidget produces as
00049 // output a polydata with a single point and a vertex cell.
00050 //
00051 // Some additional features of this class include the ability to control the
00052 // rendered properties of the widget. You can set the properties of the
00053 // selected and unselected representations of the parts of the widget. For
00054 // example, you can set the property of the 3D cursor in its normal and
00055 // selected states.
00056 
00057 // .SECTION Caveats
00058 // Note that widget can be picked even when it is "behind" other actors.
00059 // This is an intended feature and not a bug.
00060 //
00061 
00062 // The constrained translation/sliding action (i.e., when the "shift" key is
00063 // depressed) along the axes is based on a combination of a "hot" spot around
00064 // the cursor focus plus the initial mouse motion after selection. That is,
00065 // if the user selects an axis outside of the hot spot, then the motion is
00066 // constrained along that axis. If the user selects the point widget near the
00067 // focus (within the hot spot), the initial motion defines a vector which is
00068 // compared to the x-y-z axes. The motion is constrained to the axis that is
00069 // most parallel to the initial motion vector.
00070 // 
00071 
00072 // .SECTION See Also
00073 // vtk3DWidget vtkLineWidget vtkBoxWidget vtkPlaneWidget
00074 
00075 
00076 
00077 #ifndef __vtkMimxModPointWidget_h
00078 #define __vtkMimxModPointWidget_h
00079 
00080 #include "vtk3DWidget.h"
00081 #include "vtkCursor3D.h" // Needed for faster access to the Cursor3D
00082 #include "vtkMimxWidgetsWin32Header.h"
00083 
00084 
00085 class vtkActor;
00086 class vtkPolyDataMapper;
00087 class vtkCellPicker;
00088 class vtkPolyData;
00089 class vtkProperty;
00090 
00091 class VTK_MIMXWIDGETS_EXPORT vtkMimxModPointWidget : public vtk3DWidget
00092 {
00093 public:
00094         // Description:
00095         // Instantiate this widget
00096         static vtkMimxModPointWidget *New();
00097 
00098         vtkTypeRevisionMacro(vtkMimxModPointWidget,vtk3DWidget);
00099         void PrintSelf(ostream& os, vtkIndent indent);
00100 
00101         // Description:
00102         // Methods that satisfy the superclass' API.
00103         virtual void SetEnabled(int);
00104         virtual void PlaceWidget(double bounds[6]);
00105         void PlaceWidget()
00106         {this->Superclass::PlaceWidget();}
00107 
00108         void PlaceWidget(double xmin, double xmax, double ymin, double ymax, 
00109                 double zmin, double zmax)
00110         {this->Superclass::PlaceWidget(xmin,xmax,ymin,ymax,zmin,zmax);}
00111 
00112         // Description:
00113         // Grab the polydata (including points) that defines the point. A
00114         // single point and a vertex compose the vtkPolyData.
00115         void GetPolyData(vtkPolyData *pd);
00116 
00117         // Description:
00118         // Set/Get the position of the point. Note that if the position is set
00119         // outside of the bounding box, it will be clamped to the boundary of
00120         // the bounding box.
00121         void SetPosition(double x, double y, double z)
00122         {this->Cursor3D->SetFocalPoint(x,y,z);}
00123 
00124         void SetPosition(double x[3])
00125         {this->SetPosition(x[0],x[1],x[2]);}
00126 
00127         double* GetPosition() 
00128         {return this->Cursor3D->GetFocalPoint();}
00129 
00130         void GetPosition(double xyz[3]) 
00131         {this->Cursor3D->GetFocalPoint(xyz);}
00132 
00133         // Description:
00134         // Turn on/off the wireframe bounding box.
00135         void SetOutline(int o)
00136         {this->Cursor3D->SetOutline(o);}
00137 
00138         int GetOutline()
00139         {return this->Cursor3D->GetOutline();}
00140 
00141         void OutlineOn()
00142         {this->Cursor3D->OutlineOn();}
00143 
00144         void OutlineOff()
00145         {this->Cursor3D->OutlineOff();}
00146 
00147         // Description:
00148         // Turn on/off the wireframe x-shadows.
00149         void SetXShadows(int o)
00150         {this->Cursor3D->SetXShadows(o);}
00151 
00152         int GetXShadows()
00153         {return this->Cursor3D->GetXShadows();}
00154 
00155         void XShadowsOn()
00156         {this->Cursor3D->XShadowsOn();}
00157 
00158         void XShadowsOff()
00159         {this->Cursor3D->XShadowsOff();}
00160 
00161 
00162 
00163         // Description:
00164         // Turn on/off the wireframe y-shadows.
00165         void SetYShadows(int o)
00166         {this->Cursor3D->SetYShadows(o);}
00167 
00168         int GetYShadows()
00169         {return this->Cursor3D->GetYShadows();}
00170 
00171         void YShadowsOn()
00172         {this->Cursor3D->YShadowsOn();}
00173 
00174         void YShadowsOff()
00175         {this->Cursor3D->YShadowsOff();}
00176 
00177 
00178 
00179         // Description:
00180         // Turn on/off the wireframe z-shadows.
00181         void SetZShadows(int o)
00182         {this->Cursor3D->SetZShadows(o);}
00183 
00184         int GetZShadows()
00185         {return this->Cursor3D->GetZShadows();}
00186 
00187         void ZShadowsOn()
00188         {this->Cursor3D->ZShadowsOn();}
00189 
00190         void ZShadowsOff()
00191         {this->Cursor3D->ZShadowsOff();}
00192 
00193 
00194 
00195         // Description:
00196         // If translation mode is on, as the widget is moved the bounding box,
00197         // shadows, and cursor are all translated simultaneously as the point
00198         // moves.
00199         void SetTranslationMode(int mode)
00200         { this->Cursor3D->SetTranslationMode(mode); this->Cursor3D->Update(); }
00201 
00202         int GetTranslationMode()
00203         { return this->Cursor3D->GetTranslationMode(); }
00204 
00205         void TranslationModeOn()
00206         { this->SetTranslationMode(1); }
00207 
00208         void TranslationModeOff()
00209         { this->SetTranslationMode(0); }
00210 
00211 
00212 
00213         // Description:
00214         // Convenience methods to turn outline and shadows on and off.
00215         void AllOn()
00216         {
00217                 this->OutlineOn();
00218                 this->XShadowsOn();
00219                 this->YShadowsOn();
00220                 this->ZShadowsOn();
00221         }
00222 
00223         void AllOff()
00224         {
00225                 this->OutlineOff();
00226                 this->XShadowsOff();
00227                 this->YShadowsOff();
00228                 this->ZShadowsOff();
00229         }
00230 
00231 
00232 
00233         // Description:
00234         // Get the handle properties (the little balls are the handles). The 
00235         // properties of the handles when selected and normal can be 
00236         // set.
00237         vtkGetObjectMacro(Property,vtkProperty);
00238         vtkGetObjectMacro(SelectedProperty,vtkProperty);
00239 
00240         // Description:
00241         // Set the "hot spot" size; i.e., the region around the focus, in which the
00242         // motion vector is used to control the constrained sliding action. Note the
00243         // size is specified as a fraction of the length of the diagonal of the 
00244         // point widget's bounding box.
00245         vtkSetClampMacro(HotSpotSize,double,0.0,1.0);
00246         vtkGetMacro(HotSpotSize,double);
00247 
00248         static void ProcessEvents(vtkObject* object,
00249                                   unsigned long event,
00250                                   void* clientdata,
00251                                   void* calldata);
00252 
00253 
00254 
00255 protected:
00256         vtkMimxModPointWidget();
00257         ~vtkMimxModPointWidget();
00258 
00259 
00260 
00261         //BTX - manage the state of the widget
00262         friend class vtkLineWidget;
00263         friend class vtkPolyDataWidget;
00264         friend class vtkUnstructuredGridWidget;
00265         int State;
00266         enum WidgetState
00267         {
00268                 Start=0,
00269                 Moving,
00270                 Scaling,
00271                 Translating,
00272                 Outside
00273         };
00274 
00275         //ETX
00276         // Handles the events
00277 //      static void ProcessEvents(vtkObject* object, 
00278 //              unsigned long event,
00279 //              void* clientdata, 
00280 //              void* calldata);
00281 
00282         // ProcessEvents() dispatches to these methods.
00283         virtual void OnMouseMove();
00284         virtual void OnLeftButtonDown();
00285         virtual void OnLeftButtonUp();
00286         virtual void OnMiddleButtonDown();
00287         virtual void OnMiddleButtonUp();
00288         virtual void OnRightButtonDown();
00289         virtual void OnRightButtonUp();
00290 
00291         // the cursor3D
00292         vtkActor          *Actor;
00293         vtkPolyDataMapper *Mapper;
00294         vtkCursor3D       *Cursor3D;
00295         void Highlight(int highlight);
00296 
00297         // Do the picking
00298         vtkCellPicker *CursorPicker;
00299 
00300         // Methods to manipulate the cursor
00301         int ConstraintAxis;
00302         void Translate(double *p1, double *p2);
00303         void Scale(double *p1, double *p2, int X, int Y);
00304         void MoveFocus(double *p1, double *p2);
00305         int TranslationMode;
00306 
00307         // Properties used to control the appearance of selected objects and
00308         // the manipulator in general.
00309         vtkProperty *Property;
00310         vtkProperty *SelectedProperty;
00311         void CreateDefaultProperties();
00312 
00313         // The size of the hot spot.
00314         double HotSpotSize;
00315         int DetermineConstraintAxis(int constraint, double *x);
00316         int WaitingForMotion;
00317         int WaitCount;
00318 
00319 
00320 
00321 private:
00322         vtkMimxModPointWidget(const vtkMimxModPointWidget&);  //Not implemented
00323         void operator=(const vtkMimxModPointWidget&);  //Not implemented
00324 
00325 };
00326 #endif
00327 
00328 

Generated on 6 Apr 2011 for Slicer3 by  doxygen 1.6.1