eltopo3d/dynamicsurface.cpp
// ---------------------------------------------------------
///
/// Compute the unsigned distance to the surface.
///
// ---------------------------------------------------------
Compute the unsigned distance to the surface.
Compute the unsigned distance to the surface .
double DynamicSurface::distance_to_surface( const Vec3d& p, size_t& closest_triangle ) const
{
    double padding = m_aabb_padding;
    double min_distance = BIG_DOUBLE;
    while ( min_distance == BIG_DOUBLE )
    {
        Vec3d xmin( p - Vec3d( padding ) );
        Vec3d xmax( p + Vec3d( padding ) );
        std::vector<size_t> nearby_triangles;   
        m_broad_phase->get_potential_triangle_collisions( xmin, xmax, true, true, nearby_triangles );
        for ( size_t j = 0; j < nearby_triangles.size(); ++j )
        {
            const Vec3st& tri = m_mesh.get_triangle( nearby_triangles[j] );
            if ( tri[0] == tri[1] || tri[1] == tri[2] || tri[0] == tri[2] ) { continue; }
            double curr_distance;
            check_point_triangle_proximity( p, get_position(tri[0]), get_position(tri[1]), get_position(tri[2]), curr_distance );
            if ( curr_distance < padding )
            {   
                min_distance = min( min_distance, curr_distance );
                closest_triangle = nearby_triangles[j];
            }
        }
        padding *= 2.0;
    }
    return min_distance;
}
double DynamicSurface :: distance_to_surface ( const Vec3d & p , size_t & closest_triangle ) const { double padding = m_aabb_padding ; double min_distance = BIG_DOUBLE ; while ( min_distance == BIG_DOUBLE ) { Vec3d xmin ( p - Vec3d ( padding ) ) ; Vec3d xmax ( p + Vec3d ( padding ) ) ; std :: vector < size_t > nearby_triangles ; m_broad_phase -> get_potential_triangle_collisions ( xmin , xmax , true , true , nearby_triangles ) ; for ( size_t j = 0 ; j < nearby_triangles . size ( ) ; ++ j ) { const Vec3st & tri = m_mesh . get_triangle ( nearby_triangles [ j ] ) ; if ( tri [ 0 ] == tri [ 1 ] || tri [ 1 ] == tri [ 2 ] || tri [ 0 ] == tri [ 2 ] ) { continue ; } double curr_distance ; check_point_triangle_proximity ( p , get_position ( tri [ 0 ] ) , get_position ( tri [ 1 ] ) , get_position ( tri [ 2 ] ) , curr_distance ) ; if ( curr_distance < padding ) { min_distance = min ( min_distance , curr_distance ) ; closest_triangle = nearby_triangles [ j ] ; } } padding *= 2.0 ; } return min_distance ; }
Compute the unsigned distance to the surface.
Compute the unsigned distance to the surface .