Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_MBD_UTIL_MBD_GET_POSITION_VECTOR_H
00002 #define OPENTISSUE_DYNAMICS_MBD_UTIL_MBD_GET_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 {
00018
00031 template<typename indirect_body_iterator,typename vector_type>
00032 void get_position_vector(indirect_body_iterator begin, indirect_body_iterator end, vector_type & s)
00033 {
00034 typedef typename indirect_body_iterator::value_type body_type;
00035 typedef typename body_type::math_policy math_policy;
00036 typedef typename body_type::vector3_type vector3_type;
00037 typedef typename body_type::quaternion_type quaternion_type;
00038 typedef typename vector_type::size_type size_type;
00039
00040 vector3_type r;
00041 quaternion_type Q;
00042
00043 size_type n = std::distance(begin,end);
00044
00045 math_policy::resize( s, 7*n);
00046
00047 typename vector_type::iterator sval = s.begin();
00048 for(indirect_body_iterator body = begin;body!=end;++body)
00049 {
00050 assert(body->is_active() || !"get_position_vector(): body was not active");
00051
00052 body->get_position(r);
00053 body->get_orientation(Q);
00054
00055 assert(is_number(r(0)) || !"get_position_vector(): non number encountered");
00056 assert(is_number(r(1)) || !"get_position_vector(): non number encountered");
00057 assert(is_number(r(2)) || !"get_position_vector(): non number encountered");
00058 assert(is_number(Q.s()) || !"get_position_vector(): non number encountered");
00059 assert(is_number(Q.v()(0)) || !"get_position_vector(): non number encountered");
00060 assert(is_number(Q.v()(1)) || !"get_position_vector(): non number encountered");
00061 assert(is_number(Q.v()(2)) || !"get_position_vector(): non number encountered");
00062
00063 *sval++ = r(0);
00064 *sval++ = r(1);
00065 *sval++ = r(2);
00066 *sval++ = Q.s();
00067 *sval++ = Q.v()(0);
00068 *sval++ = Q.v()(1);
00069 *sval++ = Q.v()(2);
00070 }
00071 }
00072
00073 template<typename group_type,typename vector_type>
00074 void get_position_vector(group_type const & group, vector_type & s)
00075 {
00076 get_position_vector(group.body_begin(),group.body_end(),s);
00077 }
00078
00079 }
00080 }
00081
00082 #endif