MOAB: Mesh Oriented datABase  (version 5.4.1)
MBMesquite::DomainUtil Namespace Reference

Functions

void bounding_box (const MsqVertex *coords, size_t num_coords, Vector3D &min, Vector3D &max)
double max_box_extent (const MsqVertex *vertex_array, size_t num_vertices)
void get_fixed_vertices (Mesh *mesh, const Mesh::VertexHandle *verts, size_t num_verts, std::vector< Mesh::VertexHandle > &fixed_verts, MsqError &err)
bool non_colinear_vertices (const MsqVertex *verts, size_t num_verts, Vector3D coords_out[3], double epsilon)
bool non_coplanar_vertices (const MsqVertex *verts, size_t num_verts, Vector3D coords_out[4], double epsilon)
double default_tolerance (const MsqVertex *vertex_array, size_t num_vertices)

Function Documentation

void MBMesquite::DomainUtil::bounding_box ( const MsqVertex *  coords,
size_t  num_coords,
Vector3D &  min,
Vector3D &  max 
)

Definition at line 43 of file DomainUtil.cpp.

Referenced by max_box_extent().

    {
        min = max = coords[0];
        for( size_t i = 1; i < num_coords; ++i )
        {
            for( int j = 0; j < 3; ++j )
            {
                if( coords[i][j] < min[j] ) min[j] = coords[i][j];
                if( coords[i][j] > max[j] ) max[j] = coords[i][j];
            }
        }
    }
double MBMesquite::DomainUtil::default_tolerance ( const MsqVertex *  vertex_array,
size_t  num_vertices 
) [inline]

Definition at line 54 of file DomainUtil.hpp.

References max_box_extent().

Referenced by MBMesquite::SphericalDomain::fit_vertices(), and MBMesquite::PlanarDomain::fit_vertices().

    {
        return 1e-3 * max_box_extent( vertex_array, num_vertices );
    }
void MBMesquite::DomainUtil::get_fixed_vertices ( Mesh *  mesh,
const Mesh::VertexHandle *  verts,
size_t  num_verts,
std::vector< Mesh::VertexHandle > &  fixed_verts,
MsqError &  err 
)

Definition at line 64 of file DomainUtil.cpp.

References fixed, MSQ_ERRRTN, and MBMesquite::Mesh::vertices_get_fixed_flag().

Referenced by MBMesquite::PlanarDomain::fit_vertices().

    {
        std::vector< bool > fixed( num_verts );
        mesh->vertices_get_fixed_flag( verts, fixed, num_verts, err );MSQ_ERRRTN( err );
        for( size_t i = 0; i < num_verts; ++i )
            if( fixed[i] ) fixed_verts.push_back( verts[i] );
    }
double MBMesquite::DomainUtil::max_box_extent ( const MsqVertex *  vertex_array,
size_t  num_vertices 
)

Definition at line 56 of file DomainUtil.cpp.

References bounding_box().

Referenced by default_tolerance().

    {
        Vector3D min, max;
        bounding_box( vertex_array, num_vertices, min, max );
        max -= min;
        return ( max[0] >= max[1] && max[0] >= max[2] ) ? max[0] : ( max[1] >= max[2] ) ? max[1] : max[2];
    }
bool MBMesquite::DomainUtil::non_colinear_vertices ( const MsqVertex *  verts,
size_t  num_verts,
Vector3D  coords_out[3],
double  epsilon 
)

Definition at line 76 of file DomainUtil.cpp.

References b, MBMesquite::Vector3D::length_squared(), MBMesquite::length_squared(), and t.

Referenced by MBMesquite::PlanarDomain::fit_vertices(), and non_coplanar_vertices().

    {
        // This function will attempt to find trhee non-colinear
        // vertices from the input list.  Further, it will attempt
        // to select three such vertices that are relatively far
        // apart so as to minimize rounding error in any calculation
        // using the results of this function.

        // Non-colinear, by definition, must be at least trhee unique points.
        if( num_verts < 3 ) return false;

        // Begin with the first input vertex
        size_t first_idx = 0;

        // Choose the vertex furthest from the initial one
        size_t second_idx = 1;
        double dist_sqr   = ( verts[first_idx] - verts[second_idx] ).length_squared();
        for( size_t i = 2; i < num_verts; ++i )
        {
            double ds = ( verts[second_idx] - verts[i] ).length_squared();
            if( ds > dist_sqr )
            {
                dist_sqr   = ds;
                second_idx = i;
            }
        }
        // fail if all vertices are coincident
        if( dist_sqr <= epsilon * epsilon ) return false;

        // re-select the first vertex as the one furthest from the second
        for( size_t i = 1; i < num_verts; ++i )
        {
            double ds = ( verts[second_idx] - verts[i] ).length_squared();
            if( ds > dist_sqr )
            {
                dist_sqr  = ds;
                first_idx = i;
            }
        }

        // select the third vertex as the one furthest from the line formed
        // by the first two vertices
        Vector3D b       = verts[first_idx];
        Vector3D m       = verts[second_idx] - b;
        Vector3D mx      = m * ( 1.0 / m.length_squared() );
        dist_sqr         = -1.0;
        size_t third_idx = 0;
        for( size_t i = 0; i < num_verts; ++i )
        {
            double t  = mx % ( verts[i] - b );
            double ds = ( ( b + t * m ) - verts[i] ).length_squared();
            if( ds > dist_sqr )
            {
                third_idx = i;
                dist_sqr  = ds;
            }
        }
        // fail if all vertices are colinear
        if( dist_sqr <= epsilon * epsilon ) return false;

        coords_out[0] = verts[first_idx];
        coords_out[1] = verts[second_idx];
        coords_out[2] = verts[third_idx];
        return true;
    }
bool MBMesquite::DomainUtil::non_coplanar_vertices ( const MsqVertex *  verts,
size_t  num_verts,
Vector3D  coords_out[4],
double  epsilon 
)

Definition at line 142 of file DomainUtil.cpp.

References dist(), MBMesquite::Vector3D::length(), and non_colinear_vertices().

Referenced by MBMesquite::SphericalDomain::fit_vertices().

    {
        // This function will attempt to find four non-coplanar
        // vertices from the input list.  Further, it will attempt
        // to select four such vertices that are relatively far
        // apart so as to minimize rounding error in any calculation
        // using the results of this function.

        // Non-coplanar, by definition, must be at least four unique points.
        if( num_verts < 4 ) return false;

        // Get three non-colinear vertices
        if( !non_colinear_vertices( verts, num_verts, coords_out, epsilon ) ) return false;

        // The plane of the first three vertices:
        Vector3D norm = ( coords_out[1] - coords_out[0] ) * ( coords_out[2] - coords_out[0] );
        norm /= norm.length();
        double d = -( norm % coords_out[0] );

        // Search for the fourth vertex that is furthest from the plane
        // of the first three
        double dist = -1.0;
        for( size_t i = 0; i < num_verts; ++i )
        {
            double disti = fabs( norm % verts[i] + d );
            if( disti > dist )
            {
                dist          = disti;
                coords_out[3] = verts[i];
            }
        }

        // fail if all vertices are colinear
        return ( dist > epsilon );
    }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines