Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_MBD_COLLISION_DETECTION_COLLISION_HANDLERS_MBD_SDF_SPHERE_HANDLER_H
00002 #define OPENTISSUE_DYNAMICS_MBD_COLLISION_DETECTION_COLLISION_HANDLERS_MBD_SDF_SPHERE_HANDLER_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/collision/sdf/sdf.h>
00013 #include <OpenTissue/core/geometry/geometry_sphere.h>
00014 #include <OpenTissue/collision/collision_sphere_sdf.h>
00015
00016 namespace OpenTissue
00017 {
00018 namespace mbd
00019 {
00020 namespace collision_detection
00021 {
00022 template<typename mbd_types>
00023 struct SDFSphereHandler
00024 {
00025 typedef typename mbd_types::math_policy math_policy;
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::geometry::Sphere<math_policy> sphere_type;
00038 typedef OpenTissue::polymesh::PolyMesh<math_policy> mesh_type;
00039 typedef OpenTissue::grid::Grid<float,math_policy> grid_type;
00040 typedef OpenTissue::sdf::Geometry<mesh_type,grid_type> sdf_geometry_type;
00041
00042 typedef typename mbd_types::collision_info_type collision_info_type;
00043
00044 static bool test(
00045 sdf_geometry_type & sdf
00046 , sphere_type & sphere
00047 , collision_info_type & info
00048 )
00049 {
00050 coordsys_type BtoWCS;
00051 vector3_type r_b;
00052 quaternion_type Q_b;
00053 info.get_body_B()->get_position( r_b );
00054 info.get_body_B()->get_orientation( Q_b );
00055 BtoWCS = coordsys_type( r_b, Q_b );
00056
00057 coordsys_type AtoWCS;
00058 vector3_type r_a;
00059 quaternion_type Q_a;
00060 info.get_body_A()->get_position( r_a );
00061 info.get_body_A()->get_orientation( Q_a );
00062 AtoWCS = coordsys_type( r_a, Q_a );
00063
00064 info.get_contacts()->clear();
00065
00066 bool collision = OpenTissue::collision::sphere_sdf(BtoWCS,sphere,AtoWCS,sdf,*( info.get_contacts() ), info.get_envelope() );
00067
00068 for(typename contact_container::iterator cp = info.get_contacts()->begin();cp!=info.get_contacts()->end();++cp)
00069 {
00070 cp->init( info.get_body_A(), info.get_body_B(), cp->m_p, cp->m_n, cp->m_distance, info.get_material() );
00071 }
00072 return collision;
00073 }
00074
00075 static bool mirrowed_test(
00076 sphere_type & sphere
00077 , sdf_geometry_type & sdf
00078 , collision_info_type & info
00079 )
00080 {
00081 info.flip_bodies();
00082 return test( sdf, sphere, info);
00083 }
00084
00085
00086 };
00087
00088 }
00089 }
00090 }
00091
00092
00093 #endif