ArticulatedHierarchyContainer.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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 };
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 }
00237
00238 }
00239
00240 }
00241
00242 #endif
00243