Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_MBD_UTIL_MBD_SET_POSITION_VECTOR_H
00002 #define OPENTISSUE_DYNAMICS_MBD_UTIL_MBD_SET_POSITION_VECTOR_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/math_is_number.h>
00013
00014 namespace OpenTissue
00015 {
00016 namespace mbd
00017 {
00025 template<typename indirect_body_iterator,typename vector_type>
00026 void set_position_vector(indirect_body_iterator begin, indirect_body_iterator end, vector_type const & s)
00027 {
00028 typedef typename indirect_body_iterator::value_type body_type;
00029 typedef typename body_type::vector3_type vector3_type;
00030 typedef typename body_type::quaternion_type quaternion_type;
00031 typedef typename vector_type::size_type size_type;
00032 vector3_type r;
00033 quaternion_type q;
00034 size_type n = std::distance(begin,end);
00035
00036 assert(s.size() == 7*n || !"set_position_vector(): u has incorrect dimension");
00037
00038 typename vector_type::const_iterator sval = s.begin();
00039 for(indirect_body_iterator body = begin;body!=end;++body)
00040 {
00041 assert(body->is_active() || !"set_position_vector(): body was not active");
00042 r(0) = *sval++;
00043 r(1) = *sval++;
00044 r(2) = *sval++;
00045 q.s() = *sval++;
00046 q.v()(0) = *sval++;
00047 q.v()(1) = *sval++;
00048 q.v()(2) = *sval++;
00049 assert(is_number(r(0)) || !"set_position_vector(): non number encountered");
00050 assert(is_number(r(1)) || !"set_position_vector(): non number encountered");
00051 assert(is_number(r(2)) || !"set_position_vector(): non number encountered");
00052 assert(is_number(q.s()) || !"set_position_vector(): non number encountered");
00053 assert(is_number(q.v()(0)) || !"set_position_vector(): non number encountered");
00054 assert(is_number(q.v()(1)) || !"set_position_vector(): non number encountered");
00055 assert(is_number(q.v()(2)) || !"set_position_vector(): non number encountered");
00056 if(!body->is_scripted())
00057 {
00058 body->set_position(r);
00059 body->set_orientation(q);
00060 }
00061 }
00062 }
00063
00064 template<typename group_type,typename vector_type>
00065 void set_position_vector(group_type const & group, vector_type & s)
00066 {
00067 set_position_vector(group.body_begin(),group.body_end(),s);
00068 }
00069
00070 }
00071 }
00072
00073 #endif