Go to the documentation of this file.00001 #ifndef OPENTISSUE_COLLISION_COLLISION_SPHERE_SDF_H
00002 #define OPENTISSUE_COLLISION_COLLISION_SPHERE_SDF_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/containers/grid/util/grid_is_point_inside.h>
00013
00014 namespace OpenTissue
00015 {
00016 namespace collision
00017 {
00018
00031 template<typename coordsys_type,typename sdf_geometry_type,typename sphere_type,typename contact_point_container>
00032 bool sphere_sdf(
00033 coordsys_type & wcsS
00034 , sphere_type const & sphere
00035 , coordsys_type & wcsG
00036 , sdf_geometry_type const & geometry
00037 , contact_point_container & contacts
00038 , double envelope = 0.01
00039 )
00040 {
00041 typedef typename contact_point_container::value_type contact_point_type;
00042 typedef typename coordsys_type::vector3_type vector3_type;
00043 typedef typename vector3_type::value_type real_type;
00044
00045 contacts.clear();
00046
00047
00048 coordsys_type StoG;
00049 StoG = model_update(wcsS,wcsG);
00050 vector3_type c,p,n;
00051 c = sphere.center();
00052 StoG.xform_point( c );
00053
00054 if ( !OpenTissue::grid::is_point_inside( geometry.m_phi, c) )
00055 return false;
00056
00057 real_type distance = OpenTissue::grid::value_at_point( geometry.m_phi, c);
00058 if ( distance == geometry.m_phi.unused() )
00059 return false;
00060
00061 distance -= sphere.radius();
00062 real_type tst = boost::numeric_cast<real_type>( envelope );
00063 if(distance > tst)
00064 return false;
00065
00066 vector3_type gradient = OpenTissue::grid::gradient_at_point( geometry.m_phi, c );
00067 if ( gradient(0) == geometry.m_phi.unused() )
00068 return false;
00069
00070 gradient = unit(gradient);
00071 c = c - gradient*sphere.radius();
00072 wcsG.xform_vector( gradient );
00073 wcsG.xform_point( c );
00074
00075 contact_point_type cp;
00076 cp.m_p = c;
00077 cp.m_n = gradient;
00078 cp.m_distance = distance;
00079
00080 contacts.push_back( cp );
00081
00082 return true;
00083 }
00084
00085 }
00086 }
00087
00088
00089 #endif