Go to the documentation of this file.00001 #ifndef OPENTISSUE_COLLISION_COLLISION_PLANE_SDF_H
00002 #define OPENTISSUE_COLLISION_COLLISION_PLANE_SDF_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 namespace OpenTissue
00013 {
00014 namespace collision
00015 {
00016
00034 template<typename coordsys_type,typename plane_type,typename sdf_geometry_type,typename contact_point_container>
00035 bool plane_sdf(
00036 coordsys_type const & wcsP
00037 , plane_type const & plane
00038 , coordsys_type const & wcsG
00039 , sdf_geometry_type const & geometry
00040 , contact_point_container & contacts
00041 , double envelope = 0.01
00042 )
00043 {
00044 typedef typename contact_point_container::value_type contact_point_type;
00045 typedef typename coordsys_type::vector3_type vector3_type;
00046 typedef typename vector3_type::value_type real_type;
00047 typedef typename sdf_geometry_type::const_point_iterator const_point_iterator;
00048
00049 contacts.clear();
00050
00051 vector3_type c,n,n_wcs;
00052 coordsys_type GtoP;
00053 GtoP = model_update(wcsG,wcsP);
00054
00055 n = plane.n();
00056 n_wcs = n;
00057 wcsP.xform_vector(n_wcs);
00058
00059 bool collision = false;
00060
00061 const_point_iterator end = geometry.m_sampling.end();
00062 const_point_iterator p = geometry.m_sampling.begin();
00063
00064 real_type tst = boost::numeric_cast<real_type>( envelope );
00065
00066 for (;p!=end;++p)
00067 {
00068 c = (*p);
00069 GtoP.xform_point(c);
00070
00071 real_type dist = plane.signed_distance(c);
00072
00073 if(dist < tst)
00074 {
00075 c = (*p);
00076 wcsG.xform_point(c);
00077
00078 contact_point_type cp;
00079 cp.m_p = c;
00080 cp.m_n = n_wcs;
00081 cp.m_distance = dist;
00082 contacts.push_back(cp);
00083
00084 collision = true;
00085 }
00086 }
00087 return collision;
00088 }
00089
00090 }
00091
00092 }
00093
00094
00095 #endif