Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_MBD_COLLISION_DETECTION_MBD_EXHAUSTIVE_SEARCH_H
00002 #define OPENTISSUE_DYNAMICS_MBD_COLLISION_DETECTION_MBD_EXHAUSTIVE_SEARCH_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <list>
00013
00014 namespace OpenTissue
00015 {
00016 namespace mbd
00017 {
00018
00024 template<typename types>
00025 class ExhaustiveSearch
00026 {
00027 protected:
00028
00029
00030 typedef typename types::configuration_type configuration_type;
00031 typedef typename types::body_type body_type;
00032 typedef typename types::edge_type edge_type;
00033 typedef typename types::edge_ptr_container edge_ptr_container;
00034 typedef typename types::math_policy::real_type real_type;
00035 typedef typename types::math_policy::vector3_type vector3_type;
00036 typedef typename types::math_policy::matrix3x3_type matrix3x3_type;
00037
00038 protected:
00039
00040 configuration_type * m_configuration;
00041
00042
00043 public:
00044
00045 class node_traits
00046 {
00047 public:
00048 vector3_type m_es_pmin;
00049 vector3_type m_es_pmax;
00050 };
00051 class edge_traits { };
00052 class constraint_traits { };
00053
00054 public:
00055
00056 ExhaustiveSearch()
00057 : m_configuration(0)
00058 {}
00059
00060 public:
00061
00062 void clear()
00063 {
00064 this->m_configuration = 0;
00065 }
00066
00067 void init(configuration_type & configuration) { m_configuration = &configuration; };
00068 void add(body_type * ) { };
00069 void remove(body_type * ) { };
00070
00076 void run(edge_ptr_container & edges)
00077 {
00078 edges.clear();
00079 assert(m_configuration);
00080 typename configuration_type::body_iterator body1,body2,tmp;
00081 typename configuration_type::body_iterator begin = m_configuration->body_begin();
00082 typename configuration_type::body_iterator end = m_configuration->body_end();
00083 real_type envelope = m_configuration->get_collision_envelope();
00084
00085 for(body1 = begin; body1!=end; ++body1)
00086 {
00087 vector3_type r;
00088 matrix3x3_type R;
00089 body1->get_position(r);
00090 body1->get_orientation(R);
00091 body1->compute_collision_aabb(r,R,body1->m_es_pmin,body1->m_es_pmax,envelope);
00092 }
00093
00094 for(body1 = begin; body1!=end; ++body1)
00095 {
00096 tmp = body1; ++tmp;
00097 for(body2 = tmp; body2!=end; ++body2)
00098 {
00099 if(!body1->has_joint_to( &(*body2) ))
00100 {
00101 if(body1->m_es_pmin(0)> body2->m_es_pmax(0) || body2->m_es_pmin(0)>body1->m_es_pmax(0))
00102 continue;
00103 if(body1->m_es_pmin(1)> body2->m_es_pmax(1) || body2->m_es_pmin(1)>body1->m_es_pmax(1))
00104 continue;
00105 if(body1->m_es_pmin(2)> body2->m_es_pmax(2) || body2->m_es_pmin(2)>body1->m_es_pmax(2))
00106 continue;
00107 }
00108
00109 edge_type * edge = m_configuration->get_edge(&(*body1),&(*body2));
00110 if(!edge)
00111 edge = m_configuration->add(&(*body1),&(*body2));
00112 edges.push_back( edge );
00113 }
00114 }
00115 };
00116 };
00117
00118 }
00119 }
00120
00121
00122 #endif