MOAB: Mesh Oriented datABase  (version 5.4.1)
lloyd_smoother_test.cpp File Reference
#include "moab/Core.hpp"
#include "moab/LloydSmoother.hpp"
#include "moab/CartVect.hpp"
#include "TestUtil.hpp"
+ Include dependency graph for lloyd_smoother_test.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)

Variables

std::string filename = "unittest/surfrandomtris-4part.h5m"

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 10 of file lloyd_smoother_test.cpp.

References moab::Range::begin(), CHECK_ERR, moab::Range::empty(), moab::Range::end(), ErrorCode, filename, moab::CartVect::get(), moab::Core::get_coords(), moab::Core::get_entities_by_dimension(), moab::Core::load_file(), mb, MB_TAG_CREAT, MB_TAG_DENSE, MB_TYPE_DOUBLE, moab::LloydSmoother::num_its(), moab::LloydSmoother::perform_smooth(), moab::LloydSmoother::report_its(), moab::Core::set_coords(), moab::Range::size(), moab::Core::tag_get_data(), moab::Core::tag_get_handle(), and moab::Core::tag_set_data().

{
    if( argc > 1 ) filename = std::string( argv[1] );
    Core mb;
    ErrorCode rval = mb.load_file( filename.c_str() );CHECK_ERR( rval );

    Range elems;
    rval = mb.get_entities_by_dimension( 0, 3, elems );CHECK_ERR( rval );
    if( elems.empty() )
    {
        rval = mb.get_entities_by_dimension( 0, 2, elems );CHECK_ERR( rval );
    }
    if( elems.empty() )
    {
        std::cout << "Mesh must have faces or regions for this test." << std::endl;CHECK_ERR( MB_FAILURE );
    }

    // get the vertex positions and set on an intermediate tag, to test smoothing for
    // a tag instead of for coords
    Tag ctag;
    rval = mb.tag_get_handle( "vcentroid", 3, MB_TYPE_DOUBLE, ctag, MB_TAG_CREAT | MB_TAG_DENSE );CHECK_ERR( rval );
    Range verts;
    rval = mb.get_entities_by_dimension( 0, 0, verts );CHECK_ERR( rval );
    std::vector< double > coords( 3 * verts.size() );
    rval = mb.get_coords( verts, &coords[0] );CHECK_ERR( rval );
    rval = mb.tag_set_data( ctag, verts, &coords[0] );CHECK_ERR( rval );

    LloydSmoother ll( &mb, NULL, elems, ctag );
    ll.report_its( 10 );
    rval = ll.perform_smooth();CHECK_ERR( rval );
    std::cout << "Mesh smoothed in " << ll.num_its() << " iterations." << std::endl;

    // now, set vertex coords to almost their converged positions, then re-smooth; should take fewer
    // iterations
    std::vector< double > new_coords( 3 * verts.size() );
    rval = mb.tag_get_data( ctag, verts, &new_coords[0] );CHECK_ERR( rval );
    unsigned int i;
    Range::iterator vit;
    for( vit = verts.begin(), i = 0; vit != verts.end(); ++vit, i += 3 )
    {
        CartVect old_pos( &coords[i] ), new_pos( &new_coords[i] );
        CartVect almost_pos = old_pos + .99 * ( new_pos - old_pos );
        almost_pos.get( &new_coords[i] );
    }
    rval = mb.set_coords( verts, &new_coords[0] );CHECK_ERR( rval );

    LloydSmoother ll2( &mb, NULL, elems );
    ll2.report_its( 10 );
    rval = ll2.perform_smooth();CHECK_ERR( rval );
    std::cout << "Mesh smoothed in " << ll2.num_its() << " iterations." << std::endl;
}

Variable Documentation

std::string filename = "unittest/surfrandomtris-4part.h5m"

Definition at line 6 of file lloyd_smoother_test.cpp.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines