MOAB: Mesh Oriented datABase  (version 5.4.1)
deforming.cpp File Reference
#include "TestUtil.hpp"
#include "Mesquite.hpp"
#include "DeformingDomainWrapper.hpp"
#include "MeshImpl.hpp"
#include "MsqError.hpp"
#include "MeshDomain1D.hpp"
#include "PlanarDomain.hpp"
#include "QualityAssessor.hpp"
#include "MsqVertex.hpp"
#include <iostream>
#include <cstdlib>
#include <algorithm>
+ Include dependency graph for deforming.cpp:

Go to the source code of this file.

Defines

#define CHKMESH(COND, ERR)

Functions

void usage (const char *argv0)
void classify_boundary (Mesh *mesh, Mesh::VertexHandle corners_out[4], std::vector< Mesh::VertexHandle > curves_out[4], MsqError &err)
void cond_write_file (MeshImpl &mesh, const char *filename)
int main (int argc, char *argv[])

Variables

std::string INPUT_FILE = "/sph-10-zsquare.vtk"
const double Z = 7.0
const double HD = 4.5

Define Documentation

#define CHKMESH (   COND,
  ERR 
)
Value:
do                                                                               \
    {                                                                                \
        if( !( COND ) )                                                              \
        {                                                                            \
            MSQ_SETERR( err )( "Unexpected mesh topology", MsqError::INVALID_MESH ); \
            return;                                                                  \
        }                                                                            \
    } while( false )

Definition at line 179 of file deforming.cpp.


Function Documentation

void classify_boundary ( Mesh mesh,
Mesh::VertexHandle  corners_out[4],
std::vector< Mesh::VertexHandle curves_out[4],
MsqError err 
)
void cond_write_file ( MeshImpl mesh,
const char *  filename 
)

Definition at line 69 of file deforming.cpp.

References MSQ_CHKERR, and MBMesquite::MeshImpl::write_vtk().

Referenced by main().

{
    if( filename )
    {
        MsqPrintError err( std::cerr );
        mesh.write_vtk( filename, err );
        if( MSQ_CHKERR( err ) )
        {
            std::cerr << filename << ": failed to write file" << std::endl;
            exit( 1 );
        }
        std::cout << "Wrote file: " << filename << std::endl;
    }
}
int main ( int  argc,
char *  argv[] 
)

Definition at line 84 of file deforming.cpp.

References classify_boundary(), cond_write_file(), corners, fixed, HD, INPUT_FILE, MBMesquite::QualityAssessor::invalid_elements(), mesh, MSQ_CHKERR, MBMesquite::DeformingCurveSmoother::PROPORTIONAL, MBMesquite::Wrapper::quality_assessor(), MBMesquite::MeshImpl::read_vtk(), MBMesquite::IQInterface::run_instructions(), size, MBMesquite::DeformingCurveSmoother::smooth_curve(), MBMesquite::DeformingDomainWrapper::store_initial_mesh(), MBMesquite::DeformingCurveSmoother::store_initial_mesh(), usage, MBMesquite::MeshImpl::vertex_set_coordinates(), MBMesquite::MeshImpl::vertices_set_fixed_flag(), MBMesquite::PlanarDomain::XY, and MBMesquite::MeshWriter::Z.

{
    const char* deformed_file = 0;
    const char* smoothed_file = 0;
    const char* tag_file      = 0;
    struct
    {
        const char* flag;
        const char** name_ptr;
    } flags[] = { { "-d", &deformed_file }, { "-t", &tag_file }, { "-f", &smoothed_file }, { 0, 0 } };

    for( int i = 1; i < argc; ++i )
    {
        int j;
        for( j = 0; flags[j].flag && strcmp( flags[j].flag, argv[i] ); ++j )
            ;
        if( !flags[j].flag )
        {
            std::cerr << "Invalid argument: \"" << argv[i] << '"' << std::endl;
            usage( argv[0] );
        }
        else if( ++i == argc )
        {
            std::cerr << "Expected argument following \"" << argv[i - 1] << '"' << std::endl;
            usage( argv[0] );
        }
        *( flags[j].name_ptr ) = argv[i];
    }

    // load mesh
    MsqPrintError err( std::cerr );
    MeshImpl mesh;
    mesh.read_vtk( INPUT_FILE.c_str(), err );
    if( MSQ_CHKERR( err ) ) return 1;

    // find boundary vertices
    std::vector< Mesh::VertexHandle > curves[4];
    Mesh::VertexHandle corners[4];
    classify_boundary( &mesh, corners, curves, err );
    if( MSQ_CHKERR( err ) ) return 1;

    // new, "deformed" domain will be an 2HDx2HD planar square
    const double corner_coords[][3] = { { -HD, -HD, Z }, { HD, -HD, Z }, { HD, HD, Z }, { -HD, HD, Z } };
    LineDomain lines[4]             = { LineDomain( Vector3D( corner_coords[0] ), Vector3D( 1, 0, 0 ) ),
                            LineDomain( Vector3D( corner_coords[1] ), Vector3D( 0, 1, 0 ) ),
                            LineDomain( Vector3D( corner_coords[2] ), Vector3D( -1, 0, 0 ) ),
                            LineDomain( Vector3D( corner_coords[3] ), Vector3D( 0, -1, 0 ) ) };
    PlanarDomain surface( PlanarDomain::XY, Z );

    // save initial mesh state
    DeformingCurveSmoother curve_tool;
    for( int i = 0; i < 4; ++i )
    {
        curve_tool.store_initial_mesh( &mesh, &curves[i][0], curves[i].size(), &lines[i], err );
        if( MSQ_CHKERR( err ) ) return 1;
    }
    DeformingDomainWrapper wrapper;
    wrapper.store_initial_mesh( &mesh, err );
    if( MSQ_CHKERR( err ) ) return 1;

    cond_write_file( mesh, tag_file );

    // move corner vertices to new location
    for( int i = 0; i < 4; ++i )
    {
        Vector3D vect( corner_coords[i] );
        mesh.vertex_set_coordinates( corners[i], vect, err );
        if( MSQ_CHKERR( err ) ) return 1;
    }
    std::vector< bool > fixed( 4, true );
    mesh.vertices_set_fixed_flag( corners, fixed, 4, err );
    if( MSQ_CHKERR( err ) ) return 1;

    // smooth curves
    for( int i = 0; i < 4; ++i )
    {
        curve_tool.smooth_curve( &mesh, &curves[i][0], curves[i].size(), &lines[i],
                                 DeformingCurveSmoother::PROPORTIONAL, err );
        if( MSQ_CHKERR( err ) ) return 1;
        fixed.resize( curves[i].size(), true );
        mesh.vertices_set_fixed_flag( &curves[i][0], fixed, curves[i].size(), err );
        if( MSQ_CHKERR( err ) ) return 1;
    }

    cond_write_file( mesh, deformed_file );

    // smooth surface mesh
    MeshDomainAssoc mesh_and_domain = MeshDomainAssoc( &mesh, &surface );
    wrapper.run_instructions( &mesh_and_domain, err );
    if( MSQ_CHKERR( err ) ) return 1;

    cond_write_file( mesh, smoothed_file );
    return wrapper.quality_assessor().invalid_elements();
}
void usage ( const char *  argv0)

Definition at line 54 of file deforming.cpp.

{
    std::cerr << "Usage: " << argv0 << " [-t <file>] [-d <file>] [-f <file>]" << std::endl
              << "\t-t : write initial mesh with tags containing reference mesh" << std::endl
              << "\t-d : write file containing deformed mesh with smoothed curves " << std::endl
              << "\t-f : write file containing final mesh" << std::endl
              << std::endl;
    std::exit( 1 );
}

Variable Documentation

const double HD = 4.5

Definition at line 52 of file deforming.cpp.

std::string INPUT_FILE = "/sph-10-zsquare.vtk"

Definition at line 48 of file deforming.cpp.

Referenced by main().

const double Z = 7.0

Definition at line 50 of file deforming.cpp.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines