Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_MULIBODY_CD_MBD_GEOMETRY_DISPATCHER_H
00002 #define OPENTISSUE_DYNAMICS_MULIBODY_CD_MBD_GEOMETRY_DISPATCHER_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/math_constants.h>
00013
00014 #include <OpenTissue/utility/dispatchers/dispatchers_dynamic_table_dispatcher.h>
00015
00016 namespace OpenTissue
00017 {
00018 namespace mbd
00019 {
00020
00034 template<typename mbd_types>
00035 class GeometryDispatcher
00036 {
00037 public:
00038
00039 class node_traits { };
00040 class edge_traits { };
00041 class constraint_traits {};
00042
00043 protected:
00044
00045 typedef typename mbd_types::configuration_type configuration_type;
00046 typedef typename mbd_types::geometry_type geometry_type;
00047 typedef typename mbd_types::collision_info_type collision_info_type;
00048 typedef typename mbd_types::body_type body_type;
00049 typedef typename mbd_types::edge_type edge_type;
00050
00051 typedef OpenTissue::utility::dispatchers::DynamicTableDispatcher<geometry_type, false, bool, collision_info_type> dispatcher_type;
00052
00053 protected:
00054
00055 dispatcher_type m_dispatcher;
00056 configuration_type * m_configuration;
00057
00058 public:
00059
00060 GeometryDispatcher()
00061 : m_configuration(0)
00062 {}
00063
00064 public:
00065
00073 template < class T1, class T2 >
00074 void bind( bool (*f)(T1&, T2&, collision_info_type&) )
00075 {
00076 m_dispatcher.bind( f );
00077 }
00078
00086 bool run( edge_type * edge )
00087 {
00088 assert(m_configuration || !"GeometryDispatcher::run(): configuration was NULL");
00089 assert(edge || !"GeometryDispatcher::run(): edge was NULL");
00090
00091 collision_info_type info( edge->get_body_A(), edge->get_body_B(), m_configuration->get_collision_envelope(), edge->get_material(), edge->get_contacts() );
00092
00093 geometry_type & geometry_A = *(edge->get_body_A()->get_geometry());
00094 geometry_type & geometry_B = *(edge->get_body_B()->get_geometry());
00095
00096 return m_dispatcher(geometry_A, geometry_B, info);
00097 }
00098
00099 public:
00100
00101 void add(body_type * ){}
00102 void remove(body_type * ){}
00103
00104 void clear()
00105 {
00106
00107 this->m_configuration = 0;
00108 }
00109
00110 void init( configuration_type & configuration )
00111 {
00112 clear();
00113 m_configuration = &configuration;
00114 }
00115
00116 };
00117
00118 }
00119 }
00120
00121
00122 #endif