root/juggler/branches/2.2/modules/gadgeteer/gadget/Type/Glove.h
| Revision 19729, 4.9 kB (checked in by patrick, 2 years ago) | |
|---|---|
| |
| Line | |
|---|---|
| 1 | /*************** <auto-copyright.pl BEGIN do not edit this line> ************** |
| 2 | * |
| 3 | * VR Juggler is (C) Copyright 1998-2007 by Iowa State University |
| 4 | * |
| 5 | * Original Authors: |
| 6 | * Allen Bierbaum, Christopher Just, |
| 7 | * Patrick Hartling, Kevin Meinert, |
| 8 | * Carolina Cruz-Neira, Albert Baker |
| 9 | * |
| 10 | * This library is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU Library General Public |
| 12 | * License as published by the Free Software Foundation; either |
| 13 | * version 2 of the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This library is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * Library General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Library General Public |
| 21 | * License along with this library; if not, write to the |
| 22 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 23 | * Boston, MA 02111-1307, USA. |
| 24 | * |
| 25 | *************** <auto-copyright.pl END do not edit this line> ***************/ |
| 26 | |
| 27 | #ifndef _GADGET_GLOVE_H_ |
| 28 | #define _GADGET_GLOVE_H_ |
| 29 | |
| 30 | #include <gadget/gadgetConfig.h> |
| 31 | #include <gadget/Type/GloveData.h> |
| 32 | #include <gadget/Type/DigitalData.h> /* For getGloveDataFromDigitalData */ |
| 33 | #include <gadget/Type/SampleBuffer.h> |
| 34 | #include <gadget/Type/PositionInterface.h> |
| 35 | #include <boost/concept_check.hpp> |
| 36 | #include <gmtl/Vec.h> |
| 37 | #include <gmtl/Matrix.h> |
| 38 | #include <vpr/IO/SerializableObject.h> |
| 39 | |
| 40 | namespace gadget |
| 41 | { |
| 42 | |
| 43 | const unsigned short MSG_DATA_GLOVE = 520; |
| 44 | |
| 45 | /** \class Glove Glove.h gadget/Type/Glove.h |
| 46 | * |
| 47 | * This is the abstract base glove class. |
| 48 | * It specifies the interface to all glove objects in the system. |
| 49 | * Gadgeteer will deal only with gloves using this interface. |
| 50 | */ |
| 51 | class GADGET_CLASS_API Glove : public vpr::SerializableObject |
| 52 | { |
| 53 | public: |
| 54 | typedef gadget::SampleBuffer<GloveData> SampleBuffer_t; |
| 55 | |
| 56 | public: |
| 57 | Glove(); |
| 58 | |
| 59 | virtual ~Glove() |
| 60 | { |
| 61 | /* Do nothing. */ ; |
| 62 | } |
| 63 | |
| 64 | virtual bool config(jccl::ConfigElementPtr element); |
| 65 | |
| 66 | public: |
| 67 | /** @name Data access functions */ |
| 68 | //@{ |
| 69 | /** |
| 70 | * Returns a vector ponting "out" of the component. |
| 71 | * Can be used for selection, etc. |
| 72 | */ |
| 73 | gmtl::Vec3f getTipVector(GloveData::GloveComponent component, int devNum); |
| 74 | |
| 75 | /** |
| 76 | * Return the transform matrix of the component tip of the specified |
| 77 | * component. |
| 78 | */ |
| 79 | gmtl::Matrix44f getTipTransform(GloveData::GloveComponent component, |
| 80 | int devNum); |
| 81 | |
| 82 | /** |
| 83 | * Returns the transform matrix of the specified joint in world space. |
| 84 | */ |
| 85 | gmtl::Matrix44f getJointTransform(GloveData::GloveComponent component, |
| 86 | GloveData::GloveJoint joint, int devNum); |
| 87 | |
| 88 | /** Returns a copy of the glove data struct. */ |
| 89 | GloveData getGloveData(int devNum); |
| 90 | //@} |
| 91 | |
| 92 | /** @name Buffer functions */ |
| 93 | //@{ |
| 94 | /** |
| 95 | * Helper method to add a sample to the sample buffers. |
| 96 | * This MUST be called by all glove devices to add a new sample. |
| 97 | * The data samples passed in will then be modified by any local filters. |
| 98 | * |
| 99 | * @post Sample is added to the buffers and the local filters are run on |
| 100 | * that sample. |
| 101 | */ |
| 102 | void addGloveSample(const std::vector< GloveData >& gloveSample) |
| 103 | { |
| 104 | // Locks and then swaps the indices. |
| 105 | mGloveSamples.lock(); |
| 106 | mGloveSamples.addSample(gloveSample); |
| 107 | mGloveSamples.unlock(); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Swap the glove data buffers. |
| 112 | * @post If ready has values, then copy values from ready to stable |
| 113 | * if not, then stable keeps its old values |
| 114 | */ |
| 115 | void swapGloveBuffers() |
| 116 | { |
| 117 | mGloveSamples.swapBuffers(); |
| 118 | } |
| 119 | |
| 120 | const SampleBuffer_t::buffer_t& getGloveDataBuffer() |
| 121 | { |
| 122 | return mGloveSamples.stableBuffer(); |
| 123 | } |
| 124 | //@} |
| 125 | |
| 126 | virtual std::string getInputTypeName() |
| 127 | { |
| 128 | return std::string("Glove"); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Serializes this object into the given object writer. |
| 133 | * |
| 134 | * @param writer The object writer to which this object will be serialized. |
| 135 | * |
| 136 | * @throw vpr::IOException is thrown if serialization fails. |
| 137 | */ |
| 138 | virtual void writeObject(vpr::ObjectWriter* writer); |
| 139 | |
| 140 | /** |
| 141 | * De-serializes this object. |
| 142 | * |
| 143 | * @param reader The object reader from which this object will be |
| 144 | * de-serialized. |
| 145 | * |
| 146 | * @throw vpr::IOException is thrown if de-serialization fails. |
| 147 | */ |
| 148 | virtual void readObject(vpr::ObjectReader* reader); |
| 149 | |
| 150 | /** Utility function to generate GloveData from DigitalData. */ |
| 151 | std::vector<GloveData> getGloveDataFromDigitalData(const std::vector<DigitalData>& digitalData); |
| 152 | |
| 153 | protected: |
| 154 | Glove(const gadget::Glove& g) : vpr::SerializableObject(g) {;} |
| 155 | void operator=(const gadget::Glove&) {;} |
| 156 | |
| 157 | SampleBuffer_t mGloveSamples; /**< Glove samples */ |
| 158 | GloveData mDefaultValue; /**< Default glove data to return */ |
| 159 | |
| 160 | std::vector<PositionInterface> mGlovePositions; |
| 161 | }; |
| 162 | |
| 163 | } // End of gadget namespace |
| 164 | |
| 165 | #endif |
Note: See TracBrowser for help on using the browser.
