Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_MBD_COLLISION_DETECTION_COLLISION_HANDLERS_MBD_SDF_SDF_HANDLER_H
00002 #define OPENTISSUE_DYNAMICS_MBD_COLLISION_DETECTION_COLLISION_HANDLERS_MBD_SDF_SDF_HANDLER_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/collision/collision_sdf_sdf.h>
00013
00014 namespace OpenTissue
00015 {
00016 namespace mbd
00017 {
00018 namespace collision_detection
00019 {
00020
00021 template<typename mbd_types>
00022 struct SDFSDFHandler
00023 {
00024 typedef typename mbd_types::math_policy math_policy;
00025
00026 typedef typename math_policy::real_type real_type;
00027 typedef typename math_policy::vector3_type vector3_type;
00028 typedef typename math_policy::quaternion_type quaternion_type;
00029 typedef typename math_policy::coordsys_type coordsys_type;
00030
00031 typedef typename mbd_types::body_type body_type;
00032 typedef typename mbd_types::material_type material_type;
00033 typedef typename mbd_types::contact_container contact_container;
00034 typedef typename mbd_types::contact_type contact_type;
00035 typedef typename mbd_types::node_traits node_traits;
00036
00037 typedef OpenTissue::polymesh::PolyMesh<math_policy> mesh_type;
00038 typedef OpenTissue::grid::Grid<float,math_policy> grid_type;
00039 typedef OpenTissue::sdf::Geometry<mesh_type,grid_type> sdf_geometry_type;
00040
00041 typedef typename mbd_types::collision_info_type collision_info_type;
00042
00043 static bool test(
00044 sdf_geometry_type & sdfA
00045 , sdf_geometry_type & sdfB
00046 , collision_info_type & info
00047 )
00048 {
00049 coordsys_type BtoWCS;
00050 coordsys_type AtoWCS;
00051 vector3_type r_a;
00052 vector3_type r_b;
00053 quaternion_type Q_a;
00054 quaternion_type Q_b;
00055 info.get_body_A()->get_position( r_a );
00056 info.get_body_A()->get_orientation( Q_a );
00057 info.get_body_B()->get_position( r_b );
00058 info.get_body_B()->get_orientation( Q_b );
00059 BtoWCS = coordsys_type( r_b, Q_b );
00060 AtoWCS = coordsys_type( r_a, Q_a );
00061
00062 info.get_contacts()->clear();
00063
00064 bool collision = OpenTissue::collision::sdf_sdf(AtoWCS,sdfA,BtoWCS,sdfB, *(info.get_contacts()) ,info.get_envelope() );
00065
00066 for(typename contact_container::iterator cp = info.get_contacts()->begin();cp!=info.get_contacts()->end();++cp)
00067 {
00068 cp->init( info.get_body_A(), info.get_body_B(), cp->m_p, cp->m_n, cp->m_distance, info.get_material() );
00069 }
00070 return collision;
00071 }
00072
00073
00074 };
00075
00076 }
00077 }
00078 }
00079
00080
00081 #endif