MOAB: Mesh Oriented datABase  (version 5.4.1)
untangle.cpp File Reference

tast untangle wrapper More...

#include "TestUtil.hpp"
#include "MeshImpl.hpp"
#include "MsqError.hpp"
#include "MsqVertex.hpp"
#include "PlanarDomain.hpp"
#include "UntangleWrapper.hpp"
#include "QualityAssessor.hpp"
#include <iostream>
#include <cstdlib>
+ Include dependency graph for untangle.cpp:

Go to the source code of this file.

Functions

int uwt (bool skip, UntangleWrapper::UntangleMetric metric, const char *input_file, int expected_number_of_remaining_inverted_elems, bool flip_domain=false)
void usage (const char *argv0)
void help (const char *argv0)
int main (int argc, char *argv[])
const char * tostr (UntangleWrapper::UntangleMetric m)

Variables

std::string VTK_2D_DIR = "unittest/mesquite/2D/vtk/"
bool brief_output = false
bool write_output = false
double mu_sigma = -1
double beta = -1

Detailed Description

tast untangle wrapper

Author:
Jason Kraftcheck

Definition in file untangle.cpp.


Function Documentation

void help ( const char *  argv0)

Definition at line 67 of file untangle.cpp.

{
    std::cout << "Usage: " << argv0 << " [-<flags>] [-c <sigma>] [-b <beta>]" << std::endl
              << "Flags: -q : brief output" << std::endl
              << "       -w : write result meshes" << std::endl
              << "       -B : skip tests using untangle beta target metric" << std::endl
              << "       -Z : skip tests using size untangle target metric" << std::endl
              << "       -P : skip tests using shapesize untangle target metric" << std::endl
              << "       -H : skip tests using 'tangled_horse1.vtk' as input" << std::endl
              << "       -Q : skip tests using 'hole_in_square_tanglap.vtk' as input" << std::endl
              << "       -I : skip tests using 'inverted-hole-2.vtk' as input" << std::endl
              << "       -S : skip tests using 'shest_grid32.vtk' as input" << std::endl
              << "       -c : specify sigma value for untangle metrics" << std::endl
              << "       -b : specify beta value for untangle beta metric" << std::endl
              << std::endl;
}
int main ( int  argc,
char *  argv[] 
)

Definition at line 84 of file untangle.cpp.

References MBMesquite::UntangleWrapper::BETA, beta, brief_output, help(), mu_sigma, MBMesquite::UntangleWrapper::SHAPESIZE, MBMesquite::UntangleWrapper::SIZE, usage, uwt(), and write_output.

{
    bool skip_beta  = false;
    bool skip_size  = false;
    bool skip_shape = false;
    bool skip_horse = false;
    bool skip_hole  = false;
    bool skip_invrt = false;
    bool skip_shest = false;
    std::list< double* > expected;

    for( int i = 1; i < argc; ++i )
    {
        if( !expected.empty() )
        {
            char* endptr;
            *expected.front() = strtod( argv[i], &endptr );
            if( *endptr || *expected.front() <= 0 )
            {
                std::cerr << "Expected positive number, found \"" << argv[i] << '"' << std::endl;
                usage( argv[0] );
                return 1;
            }
            expected.pop_front();
        }
        else if( argv[i][0] == '-' && argv[i][1] )
        {
            for( int j = 1; argv[i][j]; ++j )
            {
                switch( argv[i][j] )
                {
                    case 'q':
                        brief_output = true;
                        break;
                    case 'w':
                        write_output = true;
                        break;
                    case 'B':
                        skip_beta = true;
                        break;
                    case 'Z':
                        skip_size = true;
                        break;
                    case 'P':
                        skip_shape = true;
                        break;
                    case 'H':
                        skip_horse = true;
                        break;
                    case 'Q':
                        skip_hole = true;
                        break;
                    case 'I':
                        skip_invrt = true;
                        break;
                    case 'S':
                        skip_shest = true;
                        break;
                    case 'c':
                        expected.push_back( &mu_sigma );
                        break;
                    case 'b':
                        expected.push_back( &beta );
                        break;
                    case 'h':
                        help( argv[0] );
                        return 0;
                    default:
                        std::cerr << "Invalid flag: -" << argv[i][j] << std::endl;
                        usage( argv[0] );
                        return 1;
                }
            }
        }
        else
        {
            std::cerr << "Unexpected argument: \"" << argv[i] << '"' << std::endl;
            usage( argv[0] );
            return 1;
        }
    }

    int result = 0;

    result += uwt( skip_beta || skip_horse, UntangleWrapper::BETA, "quads/tangled/tangled_horse1.vtk", 0 );
    result += uwt( skip_beta || skip_hole, UntangleWrapper::BETA, "quads/tangled/hole_in_square_tanglap.vtk", 0, true );
    result += uwt( skip_beta || skip_invrt, UntangleWrapper::BETA, "quads/tangled/inverted-hole-2.vtk", 0 );
    result += uwt( skip_beta || skip_shest, UntangleWrapper::BETA, "quads/untangled/shest_grid32.vtk", 0 );

    result += uwt( skip_size || skip_horse, UntangleWrapper::SIZE, "quads/tangled/tangled_horse1.vtk", 0 );
    result += uwt( skip_size || skip_hole, UntangleWrapper::SIZE, "quads/tangled/hole_in_square_tanglap.vtk", 6, true );
    result += uwt( skip_size || skip_invrt, UntangleWrapper::SIZE, "quads/tangled/inverted-hole-2.vtk", 0 );
    result += uwt( skip_size || skip_shest, UntangleWrapper::SIZE, "quads/untangled/shest_grid32.vtk", 0 );

    result += uwt( skip_shape || skip_horse, UntangleWrapper::SHAPESIZE, "quads/tangled/tangled_horse1.vtk", 0 );
    result +=
        uwt( skip_shape || skip_hole, UntangleWrapper::SHAPESIZE, "quads/tangled/hole_in_square_tanglap.vtk", 0, true );
    result += uwt( skip_shape || skip_invrt, UntangleWrapper::SHAPESIZE, "quads/tangled/inverted-hole-2.vtk", 8 );
    result += uwt( skip_shape || skip_shest, UntangleWrapper::SHAPESIZE, "quads/untangled/shest_grid32.vtk", 0 );

    return result;
}

Definition at line 187 of file untangle.cpp.

References MBMesquite::UntangleWrapper::BETA, MBMesquite::BETA, MBMesquite::UntangleWrapper::SHAPESIZE, and MBMesquite::UntangleWrapper::SIZE.

Referenced by uwt().

{
    static const char BETA[]      = "BETA";
    static const char SIZE[]      = "SIZE";
    static const char SHAPESIZE[] = "SHAPESIZE";
    switch( m )
    {
        case UntangleWrapper::BETA:
            return BETA;
        case UntangleWrapper::SIZE:
            return SIZE;
        case UntangleWrapper::SHAPESIZE:
            return SHAPESIZE;
    }
    return 0;
}
void usage ( const char *  argv0)

Definition at line 62 of file untangle.cpp.

{
    std::cerr << "Usage: " << argv0 << " [-<flags>] [-c <sigma>] [-b <beta>]" << std::endl
              << "       " << argv0 << " -h" << std::endl;
}
int uwt ( bool  skip,
UntangleWrapper::UntangleMetric  metric,
const char *  input_file,
int  expected_number_of_remaining_inverted_elems,
bool  flip_domain = false 
)

Definition at line 204 of file untangle.cpp.

References MBMesquite::arrptr(), MBMesquite::UntangleWrapper::BETA, beta, brief_output, MBMesquite::MsqError::clear(), MBMesquite::QualityAssessor::disable_printing_results(), MBMesquite::MeshImpl::get_all_vertices(), MBMesquite::QualityAssessor::get_inverted_element_count(), input_file, mesh, mu_sigma, MBMesquite::Wrapper::quality_assessor(), MBMesquite::MeshImpl::read_vtk(), MBMesquite::IQInterface::run_instructions(), MBMesquite::UntangleWrapper::set_metric_constant(), MBMesquite::UntangleWrapper::set_vertex_movement_limit_factor(), tostr(), MBMesquite::MeshImpl::vertices_get_coordinates(), VTK_2D_DIR, write_output, and MBMesquite::MeshImpl::write_vtk().

Referenced by main().

{
    if( skip ) return 0;

    if( !brief_output ) std::cout << std::endl << "**********************************************" << std::endl;
    std::cout << "Running \"" << input_file_base << "\" for " << tostr( metric ) << std::endl;
    if( !brief_output ) std::cout << "**********************************************" << std::endl << std::endl;

    // get mesh
    MsqError err;
    MeshImpl mesh;
    std::string input_file( VTK_2D_DIR );
    input_file += input_file_base;
    mesh.read_vtk( input_file.c_str(), err );
    if( err )
    {
        std::cerr << err << std::endl;
        std::cerr << "ERROR: " << input_file << " : failed to read file" << std::endl;
        return 1;
    }
    // get domain
    std::vector< Mesh::VertexHandle > verts;
    mesh.get_all_vertices( verts, err );
    if( err || verts.empty() ) abort();
    MsqVertex coords;
    mesh.vertices_get_coordinates( arrptr( verts ), &coords, 1, err );
    if( err ) abort();
    Vector3D norm( 0, 0, flip_domain ? -1 : 1 );
    PlanarDomain domain( norm, coords );
    // run wrapper
    UntangleWrapper wrapper( metric );
    wrapper.set_vertex_movement_limit_factor( 0.005 );
    double constant = ( metric == UntangleWrapper::BETA ) ? beta : mu_sigma;
    if( constant > 0 ) wrapper.set_metric_constant( constant );
    if( brief_output ) wrapper.quality_assessor().disable_printing_results();
    MeshDomainAssoc mesh_and_domain = MeshDomainAssoc( &mesh, &domain );
    wrapper.run_instructions( &mesh_and_domain, err );
    if( err )
    {
        std::cerr << err << std::endl;
        std::cerr << "ERROR: optimization failed" << std::endl;
        return 1;
    }
    // write output file
    if( write_output )
    {
        std::string result_file( tostr( metric ) );
        result_file += "-";
        result_file += input_file_base;
        mesh.write_vtk( result_file.c_str(), err );
        if( err )
        {
            std::cerr << err << std::endl;
            std::cerr << "ERROR: " << result_file << " : failed to write file" << std::endl;
            err.clear();
        }
        else
        {
            std::cerr << "Wrote file: " << result_file << std::endl;
        }
    }

    // test number of inverted elements
    int count, junk;
    wrapper.quality_assessor().get_inverted_element_count( count, junk, err );
    if( err ) abort();
    if( count < expected )
    {
        std::cout << "WARNING: expected " << expected << " inverted elements but finished with only " << count
                  << std::endl
                  << "Test needs to be updated?" << std::endl
                  << std::endl;
        return 0;
    }
    else if( count == expected )
    {
        std::cout << "Completed with " << count << " inverted elements remaining" << std::endl << std::endl;
        return 0;
    }
    else
    {
        std::cerr << "ERROR: expected " << expected << " inverted elements but finished with " << count << std::endl
                  << std::endl;
        return 1;
    }
}

Variable Documentation

bool brief_output = false

Definition at line 57 of file untangle.cpp.

double mu_sigma = -1

Definition at line 59 of file untangle.cpp.

Referenced by main(), and uwt().

std::string VTK_2D_DIR = "unittest/mesquite/2D/vtk/"

Definition at line 47 of file untangle.cpp.

Referenced by uwt().

bool write_output = false

Definition at line 58 of file untangle.cpp.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines