H3DHapticsDevice.h

Go to the documentation of this file.
00001 
00002 //    Copyright 2004, SenseGraphics AB
00003 //
00004 //    This file is part of H3D API.
00005 //
00006 //    H3D API is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    H3D API is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with H3D API; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 //
00020 //    A commercial license is also available. Please contact us at 
00021 //    www.sensegraphics.com for more information.
00022 //
00023 //
00027 //
00029 #ifndef __H3DHAPTICSDEVICE_H__
00030 #define __H3DHAPTICSDEVICE_H__
00031 
00032 #include "H3DApi.h"
00033 #include "FieldTemplates.h"
00034 #include "HapticShape.h"
00035 #include "HapticForceEffect.h"
00036 #include "SFNode.h"
00037 #include "Threads.h"
00038 #include "SFRotation.h"
00039 #include "SFFloat.h"
00040 #include "SFInt32.h"
00041 #include "SFBool.h"
00042 #include "SFMatrix4f.h"
00043 #include "SFVec3f.h"
00044 
00045 namespace H3D {
00046 
00058   class H3DAPI_API H3DHapticsDevice: public Node {
00059   public:
00060 
00063     class H3DAPI_API PosCalibration: 
00064       public SFMatrix4f {
00065     public:
00067       virtual void setValue( const Matrix4f &v, int id = 0 ) {
00068         SFMatrix4f::setValue( v, id );
00069         rt_pos_calibration = value;
00070         rt_inv_pos_rotation = rt_pos_calibration.getRotationPart().inverse();
00071       }
00072 
00074       inline virtual void update() {
00075         SFMatrix4f::update();
00076         rt_pos_calibration = value;
00077         rt_inv_pos_rotation = rt_pos_calibration.getRotationPart().inverse();
00078       }
00079 
00082       Matrix4f rt_pos_calibration;
00083       
00086       Matrix3f rt_inv_pos_rotation;
00087     };
00088 
00091     class H3DAPI_API OrnCalibration: 
00092       public SFRotation {
00093     public:
00095       inline virtual void setValue( const Rotation &v, int id = 0 ) {
00096         SFRotation::setValue( v, id );
00097         rt_orn_calibration = value;
00098       }
00099 
00101       virtual void update() {
00102         SFRotation::update();
00103         rt_orn_calibration = value;
00104       }
00105 
00108       Rotation rt_orn_calibration;
00109     };
00110 
00118     class H3DAPI_API TrackerPosition: 
00119       public TypedField< SFVec3f, Types< SFMatrix4f, SFVec3f > > {
00120       
00122       virtual void update() {
00123         const Matrix4f &m  = 
00124           static_cast< SFMatrix4f * >( routes_in[0] )->getValue();
00125         const Vec3f &d_pos = 
00126           static_cast< SFVec3f * >( routes_in[1] )->getValue();
00127         value = m * d_pos;
00128       }
00129     };
00130 
00138     class H3DAPI_API TrackerOrientation: 
00139       public TypedField< SFRotation, Types< SFRotation, SFRotation > > {
00140 
00141       virtual void update() {
00142         const Rotation &cal  = 
00143           static_cast< SFRotation * >( routes_in[0] )->getValue();
00144         const Rotation &d_orn = 
00145           static_cast< SFRotation * >( routes_in[1] )->getValue();
00146         value = cal * d_orn;
00147       }
00148   
00149     };
00150 
00160     class H3DAPI_API WeightedProxy:
00161       public TypedField< SFVec3f, Types< SFVec3f, SFVec3f, SFFloat > > {
00162       virtual void update() {
00163         const Vec3f &proxy_pos   = 
00164           static_cast< SFVec3f * >( routes_in[0] )->getValue();
00165         const Vec3f &tracker_pos = 
00166           static_cast< SFVec3f * >( routes_in[1] )->getValue();
00167         H3DFloat weighting = 
00168           static_cast< SFFloat * >( routes_in[2] )->getValue();
00169         value =  tracker_pos + weighting * ( proxy_pos - tracker_pos );
00170       }
00171     };
00172 
00174     H3DHapticsDevice( Inst< SFVec3f         > _devicePosition         = 0,
00175                    Inst< SFRotation      > _deviceOrientation      = 0,
00176                    Inst< TrackerPosition > _trackerPosition        = 0,
00177                    Inst< TrackerOrientation > _trackerOrientation  = 0,
00178                    Inst< PosCalibration  > _positionCalibration    = 0,
00179                    Inst< OrnCalibration  > _orientationCalibration = 0,
00180                    Inst< SFVec3f         > _proxyPosition          = 0,
00181                    Inst< WeightedProxy   > _weightedProxyPosition  = 0,     
00182                    Inst< SFFloat         > _proxyWeighting         = 0,
00183                    Inst< SFBool          > _main_button            = 0,
00184                    Inst< SFVec3f         > _force                  = 0,
00185                    Inst< SFVec3f         > _torque                 = 0,
00186                    Inst< SFInt32         > _inputDOF               = 0,
00187                    Inst< SFInt32         > _outputDOF              = 0,
00188                    Inst< SFInt32         > _hapticsRate            = 0,
00189                    Inst< SFNode          > _stylus                 = 0,
00190                    Inst< SFBool          > _initialized            = 0 );
00191 
00193     virtual ~H3DHapticsDevice() {
00194       disableDevice();
00195       if( thread )
00196         delete thread;
00197     }
00198 
00200     inline Vec3f getPreviousProxyPosition() { return previuos_proxy_pos; }
00201 
00204     virtual string defaultXMLContainerField() {
00205       return "device";
00206     }
00207 
00210     virtual void initDevice() {
00211       initialized->setValue( true );
00212     }
00213 
00215     inline PeriodicThreadBase *getThread() { return thread; }
00216 
00218     virtual void resetDevice() {}
00219 
00223     virtual void disableDevice() {
00224       initialized->setValue( false );
00225     }
00226 
00230     virtual void updateDeviceValues() {
00231       previuos_proxy_pos = proxyPosition->getValue();
00232     }
00233 
00238     virtual void preRender() {}
00239 
00243     virtual void postRender() {}
00244 
00245 #ifdef USE_HAPTICS
00251     virtual void renderShapes( const HapticShapeVector &shapes ) {};
00252 
00258     virtual void renderEffects( const HapticEffectVector &effects ) {};
00259 #endif
00260     
00267     auto_ptr< SFVec3f >    devicePosition;
00268 
00275     auto_ptr< SFRotation > deviceOrientation;
00276     
00282     auto_ptr< TrackerPosition >    trackerPosition;
00283 
00289     auto_ptr< TrackerOrientation > trackerOrientation;
00290 
00297     auto_ptr< PosCalibration > positionCalibration;
00298 
00306     auto_ptr< OrnCalibration > orientationCalibration;
00307 
00313     auto_ptr< SFVec3f >   proxyPosition;
00314 
00322     auto_ptr< SFVec3f >   weightedProxyPosition;
00323 
00333     auto_ptr< SFFloat >   proxyWeighting;
00334 
00340     auto_ptr< SFBool >   mainButton;
00341 
00348     auto_ptr< SFVec3f >    force;
00349 
00356     auto_ptr< SFVec3f >    torque;
00357 
00363     auto_ptr< SFInt32 >   inputDOF;
00364 
00370     auto_ptr< SFInt32 >   outputDOF;
00371 
00377     auto_ptr< SFInt32 >   hapticsRate;
00378     
00384     auto_ptr< SFNode > stylus;
00385 
00394     auto_ptr< SFBool > initialized;
00395     
00397     static H3DNodeDatabase database;
00398   protected:
00399     Vec3f previuos_proxy_pos;
00400 
00402     PeriodicThreadBase *thread;
00403   };
00404 }
00405 
00406 #endif

Generated on Thu Aug 24 12:38:32 2006 for H3D API by  doxygen 1.4.5