H3DThreadedHapticsDevice.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 __H3DTHREADEDHAPTICSDEVICE_H__
00030 #define __H3DTHREADEDHAPTICSDEVICE_H__
00031 
00032 #include "H3DHapticsDevice.h"
00033 #include "ThreadSafeFields.h"
00034 
00035 namespace H3D {
00036 
00051   class H3DAPI_API H3DThreadedHapticsDevice: public H3DHapticsDevice {
00052   public:
00053 
00055     H3DThreadedHapticsDevice( 
00056           Inst< ThreadSafeSField< SFVec3f > > _devicePosition = 0,
00057           Inst< ThreadSafeSField< SFRotation > > _deviceOrientation      = 0,
00058           Inst< TrackerPosition > _trackerPosition        = 0,
00059           Inst< TrackerOrientation > _trackerOrientation  = 0,
00060           Inst< PosCalibration  > _positionCalibration    = 0,
00061           Inst< OrnCalibration  > _orientationCalibration = 0,
00062           Inst< SFVec3f         > _proxyPosition          = 0,
00063           Inst< WeightedProxy   > _weightedProxyPosition  = 0,     
00064           Inst< SFFloat         > _proxyWeighting         = 0,
00065           Inst< ThreadSafeSField< SFBool > > _main_button = 0,
00066           Inst< ThreadSafeSField< SFVec3f > > _force      = 0,
00067           Inst< ThreadSafeSField< SFVec3f > > _torque     = 0,
00068           Inst< SFInt32         > _inputDOF               = 0,
00069           Inst< SFInt32         > _outputDOF              = 0,
00070           Inst< SFInt32         > _hapticsRate            = 0,
00071           Inst< SFNode          > _stylus                 = 0,
00072           Inst< SFBool          > _initialized            = 0 );
00073 
00075     virtual ~H3DThreadedHapticsDevice() {
00076       disableDevice();
00077     }
00078 
00081     virtual void initDevice();
00082 
00086     virtual void disableDevice();
00087 
00088 #ifdef USE_HAPTICS
00094     virtual void renderShapes( const HapticShapeVector &shapes ) {};
00095 
00101     virtual void renderEffects( const HapticEffectVector &effects );
00102 #endif
00103     
00105     static H3DNodeDatabase database;
00106 
00107 #ifdef USE_HAPTICS
00110     inline HapticEffectVector &getCurrentForceEffects() {
00111       return current_force_effects;
00112     }
00113 
00116     inline HapticEffectVector &getLastForceEffects() {
00117       return last_force_effects;
00118     }
00119 #endif
00120 
00124     virtual void updateDeviceValues();
00125 
00126   protected:
00129     virtual Vec3f getPosition() = 0;
00130 
00133     virtual Vec3f getVelocity() = 0;
00134 
00137     virtual Rotation getOrientation() = 0;
00138 
00141     virtual bool getButtonStatus() = 0;
00142 
00145     virtual void sendForce( const Vec3f &f ) = 0;
00146 
00149     virtual void sendTorque( const Vec3f &f ) = 0;
00150 
00151 #ifdef USE_HAPTICS
00152     // the force effects that are currently rendered in the realtime loop.
00153     // Should not be changed directly from the scenegraph loop but instead
00154     // use the renderEffects function to set the effects.
00155     HapticEffectVector current_force_effects;
00156 
00157     // the force effects that was current in the last scene graph loop.
00158     HapticEffectVector last_force_effects;
00159 
00160     // the shapes that are currently being rendered in the realtime loop.
00161     HapticShapeVector current_shapes;
00162 #endif
00163 
00164     unsigned int nr_haptics_loops;
00165 
00166     // The time of the last call to updateDeviceValues.
00167     TimeStamp last_update_values;
00168 
00171     TimeStamp last_effect_change;
00172     
00174     TimeStamp last_loop_time;
00175 
00177     static PeriodicThread::CallbackCode forceEffectCallback( void *data );
00178 
00181     static PeriodicThread::CallbackCode changeForceEffects( void *_data ); 
00182   };
00183 }
00184 
00185 #endif

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