MOAB: Mesh Oriented datABase  (version 5.4.1)
shape_improver.cpp File Reference
#include "TestUtil.hpp"
#include "ShapeImprover.hpp"
#include "QualityAssessor.hpp"
#include "MeshImpl.hpp"
#include "MsqError.hpp"
#include "PlanarDomain.hpp"
#include "IdealWeightInverseMeanRatio.hpp"
#include <iostream>
#include <cstdlib>
#include <cstring>
+ Include dependency graph for shape_improver.cpp:

Go to the source code of this file.

Functions

void usage (const char *argv0, bool help=false)
int main (int argc, char *argv[])

Variables

std::string DEFAULT_INPUT = "unittest/mesquite/2D/vtk/quads/tangled/inverted-hole-1.vtk"

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 67 of file shape_improver.cpp.

References MBMesquite::QualityAssessor::add_quality_assessment(), DEFAULT_INPUT, MBMesquite::QualityAssessor::Assessor::get_average(), MBMesquite::QualityAssessor::get_results(), MBMesquite::QualityAssessor::Assessor::get_stddev(), input_file, MBMesquite::QualityAssessor::invalid_elements(), mesh, MBMesquite::Wrapper::quality_assessor(), MBMesquite::MeshImpl::read_vtk(), MBMesquite::IQInterface::run_instructions(), usage, MBMesquite::MeshImpl::write_vtk(), and MBMesquite::PlanarDomain::XY.

{
    const char* input_file  = 0;
    const char* output_file = 0;
    for( int i = 1; i < argc; ++i )
    {
        if( !strcmp( "-h", argv[i] ) )
            usage( argv[0], true );
        else if( !input_file )
            input_file = argv[i];
        else if( !output_file )
            output_file = argv[i];
        else
            usage( argv[0] );
    }
    if( !input_file ) input_file = DEFAULT_INPUT.c_str();

    MsqError err;
    MeshImpl mesh;
    mesh.read_vtk( input_file, err );
    if( err )
    {
        std::cerr << err << std::endl << input_file << ": failed to read file" << std::endl;
        return 3;
    }

    PlanarDomain plane( PlanarDomain::XY );
#ifdef TEST_OLD_WRAPPER
    ShapeImprovementWrapper smoother;
#else
    ShapeImprover smoother;
#endif
    IdealWeightInverseMeanRatio extra_metric;
    smoother.quality_assessor().add_quality_assessment( &extra_metric );
    MeshDomainAssoc mesh_and_domain = MeshDomainAssoc( &mesh, &plane );
    smoother.run_instructions( &mesh_and_domain, err );
    if( err )
    {
        std::cerr << err << std::endl << input_file << ": smoother failed" << std::endl;
        return 2;
    }

    if( output_file )
    {
        mesh.write_vtk( output_file, err );
        if( err )
        {
            std::cerr << err << std::endl << output_file << ": failed to write file" << std::endl;
            return 3;
        }
    }

    if( smoother.quality_assessor().invalid_elements() )
    {
        std::cerr << "Resulting mesh contains invalid elements: untangler did not succeed" << std::endl;
        return 4;
    }

    const QualityAssessor::Assessor* quality = smoother.quality_assessor().get_results( &extra_metric );
    if( !quality )
    {
        std::cerr << "Failed to get quality stats for IMR metric" << std::endl;
        return 2;
    }

    if( fabs( 1 - quality->get_average() ) > 1e-3 )
    {
        std::cerr << "Average quality is not optimal." << std::endl;
        return 4;
    }

    if( quality->get_stddev() > 1e-3 )
    {
        std::cerr << "Not all elements have optimal quality." << std::endl;
        return 4;
    }

    return 0;
}
void usage ( const char *  argv0,
bool  help = false 
)

Definition at line 52 of file shape_improver.cpp.

References DEFAULT_INPUT, and help().

{
    std::ostream& str = help ? std::cout : std::cerr;
    str << "Usage: " << argv0 << "[input_file] [output_file]" << std::endl;
    str << "Usage: " << argv0 << "-h" << std::endl;
    if( help )
    {
        str << "Default input file: " << DEFAULT_INPUT << std::endl
            << "Default output file: (none)" << std::endl
            << "Input meshes are expected to lie in the XY-plane" << std::endl
            << "Input meshes are expected to be smoothable to ideal elements" << std::endl;
    }
    exit( !help );
}

Variable Documentation

std::string DEFAULT_INPUT = "unittest/mesquite/2D/vtk/quads/tangled/inverted-hole-1.vtk"

Definition at line 50 of file shape_improver.cpp.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines