Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_MBD_COLLISION_DETECTION_COLLISION_HANDLERS_MBD_SDF_PLANE_HANDLER_H
00002 #define OPENTISSUE_DYNAMICS_MBD_COLLISION_DETECTION_COLLISION_HANDLERS_MBD_SDF_PLANE_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_plane.h>
00014 #include <OpenTissue/collision/collision_plane_sdf.h>
00015
00016 namespace OpenTissue
00017 {
00018 namespace mbd
00019 {
00020 namespace collision_detection
00021 {
00022 template<typename mbd_types>
00023 struct SDFPlaneHandler
00024 {
00025 typedef typename mbd_types::math_policy math_policy;
00026
00027 typedef typename math_policy::real_type real_type;
00028 typedef typename math_policy::vector3_type vector3_type;
00029 typedef typename math_policy::quaternion_type quaternion_type;
00030 typedef typename math_policy::coordsys_type coordsys_type;
00031
00032 typedef typename mbd_types::body_type body_type;
00033 typedef typename mbd_types::material_type material_type;
00034 typedef typename mbd_types::contact_container contact_container;
00035 typedef typename mbd_types::contact_type contact_type;
00036 typedef typename mbd_types::node_traits node_traits;
00037
00038 typedef OpenTissue::geometry::Plane<math_policy> plane_type;
00039 typedef OpenTissue::polymesh::PolyMesh<math_policy> mesh_type;
00040 typedef OpenTissue::grid::Grid<float,math_policy> grid_type;
00041 typedef OpenTissue::sdf::Geometry<mesh_type,grid_type> sdf_geometry_type;
00042
00043 typedef typename mbd_types::collision_info_type collision_info_type;
00044
00045
00046 static bool test(
00047 sdf_geometry_type & sdf
00048 , plane_type & plane
00049 , collision_info_type & info
00050 )
00051 {
00052 coordsys_type BtoWCS;
00053 coordsys_type AtoWCS;
00054 vector3_type r_a;
00055 vector3_type r_b;
00056 quaternion_type Q_a;
00057 quaternion_type Q_b;
00058 info.get_body_A()->get_position( r_a );
00059 info.get_body_A()->get_orientation( Q_a );
00060 info.get_body_B()->get_position( r_b );
00061 info.get_body_B()->get_orientation( Q_b );
00062 BtoWCS = coordsys_type( r_b, Q_b );
00063 AtoWCS = coordsys_type( r_a, Q_a );
00064
00065 info.get_contacts()->clear();
00066
00067 bool collision = OpenTissue::collision::plane_sdf(BtoWCS, plane, AtoWCS, sdf, *( info.get_contacts() ), info.get_envelope() );
00068
00069 for(typename contact_container::iterator cp = info.get_contacts()->begin();cp!=info.get_contacts()->end();++cp)
00070 {
00071 cp->init( info.get_body_B(), info.get_body_A(), cp->m_p, cp->m_n, cp->m_distance, info.get_material() );
00072 }
00073 return collision;
00074 }
00075
00076 static bool mirrowed_test(
00077 plane_type & plane
00078 , sdf_geometry_type & sdf
00079 , collision_info_type & info
00080 )
00081 {
00082 info.flip_bodies();
00083 return test( sdf, plane, info);
00084 }
00085
00086 };
00087
00088 }
00089 }
00090 }
00091
00092
00093 #endif