Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_PSYS_COLLISION_PSYS_SDF_H
00002 #define OPENTISSUE_DYNAMICS_PSYS_COLLISION_PSYS_SDF_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/containers/grid/util/grid_gradient_at_point.h>
00013 #include <OpenTissue/core/containers/grid/util/grid_value_at_point.h>
00014 #include <cassert>
00015
00016 namespace OpenTissue
00017 {
00018 namespace psys
00019 {
00020
00024 template<typename particle_system_type, typename sdf_geometry_type, typename contact_point_container>
00025 void collision_psys_sdf(
00026 particle_system_type & system
00027 , sdf_geometry_type const & sdf
00028 , contact_point_container & contacts
00029 )
00030 {
00031 typedef typename particle_system_type::real_type real_type;
00032 typedef typename particle_system_type::vector3_type vector3_type;
00033 typedef typename contact_point_container::value_type contact_point_type;
00034 typedef typename particle_system_type::particle_iterator particle_iterator;
00035
00036 vector3_type gradient( 0, 0, 0 );
00037 vector3_type r;
00038
00039 particle_iterator p = system.particle_begin();
00040 particle_iterator end = system.particle_end();
00041 for(;p!=end;++p)
00042 {
00043 vector3_type pos = p->position();
00044
00045
00046 if(!OpenTissue::grid::is_point_inside(sdf.m_phi, pos))
00047 continue;
00048
00049 real_type dist = OpenTissue::grid::value_at_point(sdf.m_phi, pos);
00050 if ( dist == sdf.m_phi.unused() )
00051 continue;
00052
00053 if(dist > 0)
00054 continue;
00055
00056 vector3_type gradient = OpenTissue::grid::gradient_at_point( sdf.m_phi, pos);
00057 if ( gradient(0) == sdf.m_phi.unused() )
00058 continue;
00059
00060 gradient = unit(gradient);
00061
00062 contact_point_type cp;
00063 cp.m_A0 = &(*p);
00064 cp.m_a0 = real_type();
00065 cp.m_p = pos;
00066 cp.m_n = unit(gradient);
00067 cp.m_distance = -dist;
00068 contacts.push_back(cp);
00069
00070 }
00071 }
00072
00073 }
00074 }
00075
00076 #endif // OPENTISSUE_DYNAMICS_PSYS_COLLISION_PSYS_SDF_H