Go to the documentation of this file.00001 #ifndef OPENTISSUE_COLLISION_GJK_GJK_REDUCE_EDGE_H
00002 #define OPENTISSUE_COLLISION_GJK_GJK_REDUCE_EDGE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/geometry/geometry_barycentric.h>
00013
00014 #include <OpenTissue/collision/gjk/gjk_simplex.h>
00015 #include <OpenTissue/collision/gjk/gjk_outside_vertex_edge_voronoi_plane.h>
00016
00017 namespace OpenTissue
00018 {
00019 namespace gjk
00020 {
00021
00022 namespace detail
00023 {
00024
00037 template< typename V >
00038 inline void reduce_edge( V const & p, Simplex<V> & S)
00039 {
00040 typedef typename V::value_type T;
00041 typedef typename V::value_traits value_traits;
00042
00043 int bit_A = 0;
00044 int bit_B = 0;
00045 size_t idx_A = 0u;
00046 size_t idx_B = 0u;
00047 get_used_indices( S.m_bitmask, idx_A, bit_A, idx_B, bit_B );
00048
00049 V const & A = S.m_v[idx_A];
00050 V const & B = S.m_v[idx_B];
00051
00052 bool const outside_AB = outside_vertex_edge_voronoi_plane( p, A, B );
00053 bool const outside_BA = outside_vertex_edge_voronoi_plane( p, B, A );
00054
00055 if(outside_AB)
00056 {
00057
00058 S.m_bitmask = bit_A;
00059 S.m_v[idx_B].clear();
00060 S.m_a[idx_B].clear();
00061 S.m_b[idx_B].clear();
00062 S.m_w[idx_A] = value_traits::one();
00063 S.m_w[idx_B] = value_traits::zero();
00064 return;
00065 }
00066 if(outside_BA)
00067 {
00068
00069 S.m_bitmask = bit_B;
00070 S.m_v[idx_A].clear();
00071 S.m_a[idx_A].clear();
00072 S.m_b[idx_A].clear();
00073 S.m_w[idx_A] = value_traits::zero();
00074 S.m_w[idx_B] = value_traits::one();
00075 return;
00076 }
00077 if(!outside_AB && !outside_BA)
00078 {
00079 OpenTissue::geometry::barycentric_geometric(A,B,p,S.m_w[idx_A],S.m_w[idx_B]);
00080 return;
00081 }
00082
00083 }
00084
00085 }
00086
00087 }
00088
00089 }
00090
00091
00092 #endif