Go to the documentation of this file.00001 #ifndef OPENTISSUE_KINEMATICS_INVERSE_INVERSE_SET_DEFAULT_JOINT_SETTINGS_H
00002 #define OPENTISSUE_KINEMATICS_INVERSE_INVERSE_SET_DEFAULT_JOINT_SETTINGS_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/math_euler_angles.h>
00013
00014 #include <cmath>
00015 #include <cassert>
00016
00017 namespace OpenTissue
00018 {
00019 namespace kinematics
00020 {
00021 namespace inverse
00022 {
00023
00043 template<typename skeleton_type>
00044 inline void set_default_joint_settings( skeleton_type & skeleton )
00045 {
00046 using std::atan2;
00047
00048 typedef typename skeleton_type::bone_type bone_type;
00049 typedef typename skeleton_type::bone_iterator bone_iterator;
00050 typedef typename skeleton_type::bone_traits bone_traits;
00051 typedef typename skeleton_type::math_types math_types;
00052 typedef typename bone_traits::transform_type transform_type;
00053
00054 typedef typename math_types::value_traits value_traits;
00055 typedef typename math_types::vector3_type vector3_type;
00056 typedef typename math_types::quaternion_type quaternion_type;
00057 typedef typename math_types::real_type real_type;
00058
00059 bone_iterator bone = skeleton.begin();
00060 bone_iterator end = skeleton.end();
00061 for( ; bone!=end; ++bone)
00062 {
00063 transform_type const & T = bone->bind_pose();
00064
00065 if(bone->type() == bone_traits::hinge_type)
00066 {
00067 quaternion_type Q = T.Q();
00068 vector3_type u = unit( Q.v() );
00069
00070
00071
00072
00073 real_type ct2 = Q.s();
00074 real_type st2 = length( Q.v() );
00075 real_type theta = value_traits::zero();
00076 theta = value_traits::two()* atan2(st2,ct2);
00077
00078 bone->u() = u;
00079 bone->theta(0) = theta;
00080 }
00081 else if(bone->type() == bone_traits::slider_type)
00082 {
00083 vector3_type u = unit( T.T() );
00084 real_type theta = length( T.T() );
00085 bone->u() = u;
00086 bone->theta(0) = theta;
00087 }
00088 else if(bone->type() == bone_traits::ball_type)
00089 {
00090 real_type phi = value_traits::zero();
00091 real_type psi = value_traits::zero();
00092 real_type theta = value_traits::zero();
00093
00094 quaternion_type Q = T.Q();
00095
00096 OpenTissue::math::ZYZ_euler_angles(Q,phi,psi,theta);
00097
00098
00099 bone->theta(0) = phi;
00100 bone->theta(1) = psi;
00101 bone->theta(2) = theta;
00102
00103
00104 }
00105 else
00106 {
00107 assert(false || !"set_default_joint_settings(): unsupported joint type encountered!");
00108 }
00109
00110 }
00111 }
00112
00113 }
00114 }
00115 }
00116
00117
00118 #endif