- Main Page
- Classes
- Files

- Search for |

# ToolPosDetector.h

Go to the documentation of this file.

    00001 /*****************************
    00002 File:      ToolsPosDetector.h
    00003 Language:   C++ (header)
    00004 Project:    H3DNetworkingUtils
    00005 The contents of this file are subject to the Mozilla Public License
    00006 Version 1.1 (the "License"); you may not use this file except in
    00007 compliance with the License. You may obtain a copy of the License at
    00008 http://www.mozilla.org/MPL/
    00009
    00010 Software distributed under the License is distributed on an "AS IS"
    00011 basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
    00012 License for the specific language governing rights and limitations
    00013 under the License.
    00014
    00015 The Original Code is H3DNetworkingUtils v1.0.
    00016
    00017 The Initial Developer of the Original Code is CSIRO.
    00018 Portions created by the Initial Developer are Copyright (C) 1009 CSIRO. All Rights Reserved.
    00019 Contributor(s):
    00020     Chris Gunn  <Chris.Gunn@csiro.au> <ChrisJGunn@gmail.com>
    00021 ***************************/
    00022
    00025
    00026 #ifndef ToolPosDetector_H
    00027 #define ToolPosDetector_H
    00028
    00029 #include <H3D/X3DChildNode.h>
    00030 #include <H3D/TraverseInfo.h>
    00031 #include <H3D/SFBool.h>
    00032 #include <H3D/SFInt32.h>
    00033 #include <H3D/SFVec3f.h>
    00034 #include <H3D/ThreadSafeFields.h>
    00035 #include <H3DUtil/Threads.h>
    00036 #include <HAPI/HAPIForceEffect.h>
    00037 #include <H3DNetworkingUtils/lockwrap.h>
    00038
    00039 namespace H3DNetworkingUtils {
    00040
    00055
    00056 class H3D_NETWORKING_UTILS_DLL_SPEC  ToolPosDetector : public H3D::X3DChildNode {
    00057 public:
    00058   class ThreadSafeSFVec3f;
    00059
    00061   ToolPosDetector ( H3D::Inst< H3D::SFBool >  _enabled = 0,
    00062                     H3D::Inst< H3D::SFInt32 >  _deviceIndex = 0,
    00063                     H3D::Inst< ThreadSafeSFVec3f >  _globalPos = 0,
    00064                     H3D::Inst< ThreadSafeSFVec3f >  _localPos = 0);
    00065
    00068   class H3D_NETWORKING_UTILS_DLL_SPEC ThreadSafeSFVec3f : public H3D::SFVec3f {
    00069   public:
    00070      virtual void setValue(H3D::Vec3f const & v, int id = 0) {
    00071        my_lock.lock();
    00072        H3D::SFVec3f::setValue(v, id);
    00073        my_lock.unlock();
    00074     }
    00075     virtual void update() {
    00076        my_lock.lock();
    00077        H3D::SFVec3f::update();
    00078        my_lock.unlock();
    00079     }
    00080     virtual H3D::Vec3f const & getValue(int id = 0) {
    00081        my_lock.lock();
    00082        ret = H3D::SFVec3f::getValue(id);
    00083        my_lock.unlock();
    00084        return ret;
    00085     }
    00086     Mutex my_lock;
    00087     H3D::Vec3f ret;
    00088     bool in_set_value;
    00089   };
    00090
    00096   auto_ptr<H3D::SFBool        > enabled;
    00097
    00103   auto_ptr<H3D::SFInt32       > deviceIndex;
    00104
    00110   auto_ptr<ThreadSafeSFVec3f  > globalPos;
    00111
    00117   auto_ptr<ThreadSafeSFVec3f  > localPos;
    00118
    00120   static H3D::H3DNodeDatabase database;
    00121
    00122   virtual void traverseSG(H3D::TraverseInfo & ti);
    00123
    00124 protected:
    00125    // This is modelled on a force effect, but does not actually produce any
    00126    // force.  It is just a hook to get into the haptics cycle.
    00127    class Detector: public HAPI::HAPIForceEffect {
    00128    public:
    00129       Detector(ToolPosDetector * tpdP,
    00130                const H3D::Matrix4f & global_to_local,
    00131                int node_id);
    00132
    00133       HAPI::HAPIForceEffect::EffectOutput virtual calculateForces( const HAPI::HAPIForceEffect::EffectInput &input );
    00134
    00135    private:
    00136      H3D::AutoRef<ToolPosDetector> tpdP;
    00137      int node_id;
    00138      H3D::Matrix4f global_to_local;
    00139      H3D::H3DTime creation_time;
    00140    };
    00141
    00142  private:
    00143    H3D::H3DTime latest_creation_time; // Accessed from the haptics thread only!
    00144    //Detector * latest_detP;
    00145
    00146 };
    00147
    00148 }
    00149
    00150 #endif