Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_VERSATILE_VERSATILE_COLLISION_POLICY_H
00002 #define OPENTISSUE_DYNAMICS_VERSATILE_VERSATILE_COLLISION_POLICY_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/collision/spatial_hashing/spatial_hashing.h>
00013
00014 namespace OpenTissue
00015 {
00016 namespace versatile
00017 {
00018 namespace detail
00019 {
00020
00021 template<typename versatile_types>
00022 class collision_policy
00023 {
00024 public:
00025 typedef typename versatile_types::node_type data_type;
00026 typedef typename versatile_types::tetrahedron_type query_type;
00027 typedef typename versatile_types::value_traits value_traits;
00028 typedef typename versatile_types::real_type real_type;
00029 typedef typename versatile_types::vector3_type vector3_type;
00030 typedef OpenTissue::spatial_hashing::GridHashFunction hash_function;
00031
00032
00033
00034
00035 typedef OpenTissue::spatial_hashing::Grid< vector3_type, math::Vector3<int>, data_type, hash_function> hash_grid;
00036
00037 protected:
00038
00039 class ResultType
00040 {
00041 public:
00042 data_type * m_data;
00043 query_type * m_query;
00044 real_type m_w0;
00045 real_type m_w1;
00046 real_type m_w2;
00047 real_type m_w3;
00048 };
00049
00050 public:
00051
00052 typedef ResultType result_type;
00053 typedef std::list<result_type> result_container;
00054
00055 public:
00056
00057 vector3_type position(data_type const & data)const {return data.position();}
00058 vector3_type min_coord(query_type const & query)const {return query.min();}
00059 vector3_type max_coord(query_type const & query)const {return query.max();}
00060
00061 void reset(result_container & ) {}
00062
00063 void report(data_type const & data, query_type const & query,result_container & results)
00064 {
00065
00066 if( data.owner()==query.owner()
00067 &&
00068 ( data.idx()==query.i()->idx() || data.idx()==query.j()->idx() || data.idx()==query.k()->idx() || data.idx()==query.m()->idx() )
00069 )
00070 return;
00071
00072 vector3_type const & pi = query.i()->m_coord;
00073 vector3_type const & pj = query.j()->m_coord;
00074 vector3_type const & pk = query.k()->m_coord;
00075 vector3_type const & pm = query.m()->m_coord;
00076 vector3_type const & p = data.m_coord;
00077
00078 real_type const delta = boost::numeric_cast<real_type>( 10e-5 );
00079
00080 real_type lower = - delta;
00081 real_type upper = value_traits::one() + delta;
00082 result_type result;
00083
00084
00085 OpenTissue::geometry::barycentric_algebraic(pi,pj,pk,pm,p,result.m_w0,result.m_w1,result.m_w2,result.m_w3);
00086 if(
00087 (result.m_w0>lower)&&(result.m_w0<upper)
00088 &&
00089 (result.m_w1>lower)&&(result.m_w1<upper)
00090 &&
00091 (result.m_w2>lower)&&(result.m_w2<upper)
00092 &&
00093 (result.m_w3>lower)&&(result.m_w3<upper)
00094 )
00095 {
00096 result.m_data = const_cast<data_type*>( &data );
00097 result.m_query = const_cast<query_type*>( &query );
00098 results.push_back( result );
00099 return;
00100 }
00101 }
00102 };
00103
00104 }
00105 }
00106 }
00107
00108
00109 #endif