ArticulatedHierarchyContainer.h

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This library is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU Lesser General Public License as published by    *
00007 * the Free Software Foundation; either version 2.1 of the License, or (at     *
00008 * your option) any later version.                                             *
00009 *                                                                             *
00010 * This library is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
00013 * for more details.                                                           *
00014 *                                                                             *
00015 * You should have received a copy of the GNU Lesser General Public License    *
00016 * along with this library; if not, write to the Free Software Foundation,     *
00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
00018 *******************************************************************************
00019 *                               SOFA :: Modules                               *
00020 *                                                                             *
00021 * Authors: The SOFA Team and external contributors (see Authors.txt)          *
00022 *                                                                             *
00023 * Contact information: contact@sofa-framework.org                             *
00024 ******************************************************************************/
00025 #ifndef SOFA_COMPONENT_CONTAINER_ARTICULATEDHIERARCHYCONTAINER_H
00026 #define SOFA_COMPONENT_CONTAINER_ARTICULATEDHIERARCHYCONTAINER_H
00027 
00028 #include <sofa/core/objectmodel/BaseObject.h>
00029 #include <sofa/defaulttype/VecTypes.h>
00030 #include <sofa/simulation/tree/GNode.h>
00031 #include <sofa/helper/io/bvh/BVHLoader.h>
00032 #include <sofa/component/MechanicalObject.h>
00033 #include <sofa/defaulttype/RigidTypes.h>
00034 
00035 namespace sofa
00036 {
00037 
00038 namespace component
00039 {
00040 
00041 namespace container
00042 {
00043 
00044 using namespace sofa::defaulttype;
00045 using namespace sofa::simulation::tree;
00046 
00052 class ArticulatedHierarchyContainer : public virtual core::objectmodel::BaseObject
00053 {
00054 public:
00055 
00066 class ArticulationCenter : public virtual core::objectmodel::BaseObject
00067 {
00068 public:
00069 
00075     class Articulation : public virtual core::objectmodel::BaseObject
00076     {
00077     public:
00078 
00087         Articulation();
00088         ~Articulation(){};
00089 
00093         Data<Vector3> axis;
00098         Data<bool> rotation;
00103         Data<bool> translation;
00107         Data<int> articulationIndex;
00108 
00109         std::vector<double> motion;
00110     };
00111 
00122     ArticulationCenter();
00123     ~ArticulationCenter(){};
00124 
00129     Data<int> parentIndex;
00134     Data<int> childIndex;
00140     Data<Vector3> globalPosition;
00144     Data<Vector3> posOnParent;
00148     Data<Vector3> posOnChild;
00156     Data<int> articulationProcess;
00157 
00158     
00159     vector<Articulation*> articulations;
00160     
00161     Vector3 posOnChildGlobal(Quat localToGlobal)
00162     {
00163         Vector3 result = localToGlobal.rotate(posOnChild.getValue());
00164         return result;
00165     }
00166 
00167     Vector3 initTranslateChild(Quat objectRotation)
00168     {
00169         Vector3 PAParent = posOnParent.getValue() - Vector3(0,0,0);
00170         Vector3 PAChild = posOnChild.getValue() - Vector3(0,0,0);
00171         return objectRotation.rotate(PAParent - PAChild);
00172     }
00173 
00174     Vector3 translateChild(Quat object1Rotation, Quat object2Rotation)
00175     {
00176         Vector3 APChild = Vector3(0,0,0) - posOnChild.getValue();
00177         Vector3 AP1 = object2Rotation.rotate(APChild);
00178         Vector3 AP2 = object1Rotation.rotate(AP1);
00179         return AP2 - AP1;
00180     }
00181 
00182     Vector3 correctPosChild(Vector3 object1Pos, Quat object1Rot, Vector3 object2Pos, Quat object2Rot)
00183     {
00184         Vector3 result;
00185         Vector3 PAParent = posOnParent.getValue() - Vector3(0,0,0);
00186         Vector3 PAChild = posOnChild.getValue() - Vector3(0,0,0);
00187         Vector3 A1 = object1Pos + object1Rot.rotate(PAParent);
00188         Vector3 A2 = object2Pos + object2Rot.rotate(PAChild);
00189         
00190         result = A1 - A2;
00191 
00192         return result;
00193 
00194     }
00195 
00196     vector<Articulation*> getArticulations();
00197     
00198     Quat OrientationArticulationCenter;
00199     Vector3 DisplacementArticulationCenter;
00200     Vector3 Disp_Rotation;
00201     
00202     
00203 }; // end ArticulationCenter
00204 
00205     ArticulatedHierarchyContainer();
00206 
00207     ~ArticulatedHierarchyContainer(){}
00208 
00209     
00210 
00211     void init();
00212 
00213     void setFilename(std::string f){filename.setValue(f);}
00214     
00215     vector<ArticulationCenter*> getArticulationCenters();
00216     ArticulationCenter* getArticulationCenterAsChild(int index);
00217     vector<ArticulationCenter*> getAcendantList(int index);
00218 
00219     vector<ArticulationCenter*> articulationCenters;
00220     vector<ArticulationCenter*> acendantList;
00221 
00222     bool chargedFromFile;
00223     int numOfFrames;
00224     double dtbvh;
00225 
00226   protected:
00227     Data<std::string> filename;
00228 private:
00229 
00230     
00231     unsigned int id;
00232     sofa::helper::io::bvh::BVHJoint* joint;
00233     void buildCenterArticulationsTree(sofa::helper::io::bvh::BVHJoint*, int id_buf, const char* name, simulation::tree::GNode* node);
00234 };
00235 
00236 } // namespace container
00237 
00238 } // namespace component
00239 
00240 } // namespace sofa
00241 
00242 #endif
00243 

Generated on Sun Nov 23 02:48:31 2008 for Sofa by  doxygen 1.5.7.1