Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_MBD_UTIL_MBD_SET_VELOCITY_VECTOR_H
00002 #define OPENTISSUE_DYNAMICS_MBD_UTIL_MBD_SET_VELOCITY_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_velocity_vector(indirect_body_iterator begin, indirect_body_iterator end, vector_type const & u)
00027 {
00028 typedef typename indirect_body_iterator::value_type body_type;
00029 typedef typename body_type::vector3_type vector3_type;
00030 typedef typename vector_type::size_type size_type;
00031
00032 vector3_type V,W;
00033 size_type n = std::distance(begin,end);
00034
00035 assert(u.size() == 6*n || !"set_velocity_vector(): u has incorrect dimension");
00036
00037 typename vector_type::const_iterator uval = u.begin();
00038 for(indirect_body_iterator body = begin;body!=end;++body)
00039 {
00040 assert(body->is_active() || !"set_velocity_vector(): body was not active");
00041 V(0) = *uval++;
00042 V(1) = *uval++;
00043 V(2) = *uval++;
00044 W(0) = *uval++;
00045 W(1) = *uval++;
00046 W(2) = *uval++;
00047 assert(is_number(V(0)) || !"set_velocity_vector(): non number encountered");
00048 assert(is_number(V(1)) || !"set_velocity_vector(): non number encountered");
00049 assert(is_number(V(2)) || !"set_velocity_vector(): non number encountered");
00050 assert(is_number(W(0)) || !"set_velocity_vector(): non number encountered");
00051 assert(is_number(W(1)) || !"set_velocity_vector(): non number encountered");
00052 assert(is_number(W(2)) || !"set_velocity_vector(): non number encountered");
00053 if(!body->is_scripted())
00054 {
00055 body->set_velocity(V);
00056 body->set_spin(W);
00057 }
00058 }
00059 }
00060
00061 template<typename group_type,typename vector_type>
00062 void set_velocity_vector(group_type const & group, vector_type & u)
00063 {
00064 set_velocity_vector(group.body_begin(),group.body_end(),u);
00065 }
00066
00067 }
00068 }
00069
00070 #endif