Go to the documentation of this file.00001 #ifndef OPENTISSUE_KINEMATICS_INVERSE_INVERSE_COMPUTE_WEIGHTED_DIFFERENCE_H
00002 #define OPENTISSUE_KINEMATICS_INVERSE_INVERSE_COMPUTE_WEIGHTED_DIFFERENCE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/big/big_types.h>
00013
00014 #include <cassert>
00015
00016 namespace OpenTissue
00017 {
00018 namespace kinematics
00019 {
00020 namespace inverse
00021 {
00022
00035 template<typename chain_iterator, typename T>
00036 inline void compute_weighted_difference(
00037 chain_iterator const & begin
00038 , chain_iterator const & end
00039 , ublas::vector<T> & delta
00040 )
00041 {
00042 using ublas::subrange;
00043
00044 typedef typename chain_iterator::value_type chain_type;
00045 typedef typename chain_type::bone_traits bone_traits;
00046 typedef typename chain_type::vector3_type vector3_type;
00047 typedef ublas::vector<T> vector_type;
00048 typedef ublas::vector_range<vector_type> vector_range;
00049
00050 size_t index = 0u;
00051 size_t N = 0u;
00052
00053 chain_iterator chain = begin;
00054
00055 for(; chain!=end; ++chain)
00056 N += chain->get_goal_dimension();
00057
00058 if(delta.size() != N)
00059 delta.resize(N);
00060
00061 for(chain = begin; chain!=end; ++chain)
00062 {
00063 assert( chain->get_goal_dimension()==3 || chain->get_goal_dimension()==9 || !"compute_weighted_difference(): only goals of dimension 3 or 9 are currently supported");
00064
00065 vector_range sub_delta = subrange(delta,index,(index+chain->get_goal_dimension()));
00066
00067 vector3_type delta_p = chain->p_global() - bone_traits::transform_point( chain->get_end_effector()->absolute(), chain->p_local() );
00068
00069 sub_delta(0) = chain->weight_p() * delta_p[0];
00070 sub_delta(1) = chain->weight_p() * delta_p[1];
00071 sub_delta(2) = chain->weight_p() * delta_p[2];
00072
00073 if( chain->get_goal_dimension() == 9u )
00074 {
00075 vector3_type delta_x = chain->x_global() - bone_traits::transform_vector( chain->get_end_effector()->absolute(), chain->x_local() );
00076 vector3_type delta_y = chain->y_global() - bone_traits::transform_vector( chain->get_end_effector()->absolute(), chain->y_local() );
00077
00078 sub_delta(3) = chain->weight_x() * delta_x(0);
00079 sub_delta(4) = chain->weight_x() * delta_x(1);
00080 sub_delta(5) = chain->weight_x() * delta_x(2);
00081
00082 sub_delta(6) = chain->weight_y() * delta_y(0);
00083 sub_delta(7) = chain->weight_y() * delta_y(1);
00084 sub_delta(8) = chain->weight_y() * delta_y(2);
00085 }
00086
00087 index += chain->get_goal_dimension();
00088 }
00089 }
00090
00091 }
00092 }
00093 }
00094
00095
00096 #endif