MOAB: Mesh Oriented datABase  (version 5.3.0)
lloyd_smoother_test.cpp
Go to the documentation of this file.
00001 #include "moab/Core.hpp"
00002 #include "moab/LloydSmoother.hpp"
00003 #include "moab/CartVect.hpp"
00004 #include "TestUtil.hpp"
00005 
00006 std::string filename = TestDir + "/surfrandomtris-4part.h5m";
00007 
00008 using namespace moab;
00009 
00010 int main( int argc, char** argv )
00011 {
00012     if( argc > 1 ) filename = std::string( argv[1] );
00013     Core mb;
00014     ErrorCode rval = mb.load_file( filename.c_str() );CHECK_ERR( rval );
00015 
00016     Range elems;
00017     rval = mb.get_entities_by_dimension( 0, 3, elems );CHECK_ERR( rval );
00018     if( elems.empty() )
00019     {
00020         rval = mb.get_entities_by_dimension( 0, 2, elems );CHECK_ERR( rval );
00021     }
00022     if( elems.empty() )
00023     {
00024         std::cout << "Mesh must have faces or regions for this test." << std::endl;CHECK_ERR( MB_FAILURE );
00025     }
00026 
00027     // get the vertex positions and set on an intermediate tag, to test smoothing for
00028     // a tag instead of for coords
00029     Tag ctag;
00030     rval = mb.tag_get_handle( "vcentroid", 3, MB_TYPE_DOUBLE, ctag, MB_TAG_CREAT | MB_TAG_DENSE );CHECK_ERR( rval );
00031     Range verts;
00032     rval = mb.get_entities_by_dimension( 0, 0, verts );CHECK_ERR( rval );
00033     std::vector< double > coords( 3 * verts.size() );
00034     rval = mb.get_coords( verts, &coords[0] );CHECK_ERR( rval );
00035     rval = mb.tag_set_data( ctag, verts, &coords[0] );CHECK_ERR( rval );
00036 
00037     LloydSmoother ll( &mb, NULL, elems, ctag );
00038     ll.report_its( 10 );
00039     rval = ll.perform_smooth();CHECK_ERR( rval );
00040     std::cout << "Mesh smoothed in " << ll.num_its() << " iterations." << std::endl;
00041 
00042     // now, set vertex coords to almost their converged positions, then re-smooth; should take fewer
00043     // iterations
00044     std::vector< double > new_coords( 3 * verts.size() );
00045     rval = mb.tag_get_data( ctag, verts, &new_coords[0] );CHECK_ERR( rval );
00046     unsigned int i;
00047     Range::iterator vit;
00048     for( vit = verts.begin(), i = 0; vit != verts.end(); ++vit, i += 3 )
00049     {
00050         CartVect old_pos( &coords[i] ), new_pos( &new_coords[i] );
00051         CartVect almost_pos = old_pos + .99 * ( new_pos - old_pos );
00052         almost_pos.get( &new_coords[i] );
00053     }
00054     rval = mb.set_coords( verts, &new_coords[0] );CHECK_ERR( rval );
00055 
00056     LloydSmoother ll2( &mb, NULL, elems );
00057     ll2.report_its( 10 );
00058     rval = ll2.perform_smooth();CHECK_ERR( rval );
00059     std::cout << "Mesh smoothed in " << ll2.num_its() << " iterations." << std::endl;
00060 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines