MOAB: Mesh Oriented datABase  (version 5.5.0)
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 = TestDir + "unittest/surfrandomtris-4part.h5m"
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 10 of file lloyd_smoother_test.cpp.

11 {
12  if( argc > 1 ) filename = std::string( argv[1] );
13  Core mb;
14  ErrorCode rval = mb.load_file( filename.c_str() );CHECK_ERR( rval );
15 
16  Range elems;
17  rval = mb.get_entities_by_dimension( 0, 3, elems );CHECK_ERR( rval );
18  if( elems.empty() )
19  {
20  rval = mb.get_entities_by_dimension( 0, 2, elems );CHECK_ERR( rval );
21  }
22  if( elems.empty() )
23  {
24  std::cout << "Mesh must have faces or regions for this test." << std::endl;CHECK_ERR( MB_FAILURE );
25  }
26 
27  // get the vertex positions and set on an intermediate tag, to test smoothing for
28  // a tag instead of for coords
29  Tag ctag;
30  rval = mb.tag_get_handle( "vcentroid", 3, MB_TYPE_DOUBLE, ctag, MB_TAG_CREAT | MB_TAG_DENSE );CHECK_ERR( rval );
31  Range verts;
32  rval = mb.get_entities_by_dimension( 0, 0, verts );CHECK_ERR( rval );
33  std::vector< double > coords( 3 * verts.size() );
34  rval = mb.get_coords( verts, &coords[0] );CHECK_ERR( rval );
35  rval = mb.tag_set_data( ctag, verts, &coords[0] );CHECK_ERR( rval );
36 
37  LloydSmoother ll( &mb, NULL, elems, ctag );
38  ll.report_its( 10 );
39  rval = ll.perform_smooth();CHECK_ERR( rval );
40  std::cout << "Mesh smoothed in " << ll.num_its() << " iterations." << std::endl;
41 
42  // now, set vertex coords to almost their converged positions, then re-smooth; should take fewer
43  // iterations
44  std::vector< double > new_coords( 3 * verts.size() );
45  rval = mb.tag_get_data( ctag, verts, &new_coords[0] );CHECK_ERR( rval );
46  unsigned int i;
47  Range::iterator vit;
48  for( vit = verts.begin(), i = 0; vit != verts.end(); ++vit, i += 3 )
49  {
50  CartVect old_pos( &coords[i] ), new_pos( &new_coords[i] );
51  CartVect almost_pos = old_pos + .99 * ( new_pos - old_pos );
52  almost_pos.get( &new_coords[i] );
53  }
54  rval = mb.set_coords( verts, &new_coords[0] );CHECK_ERR( rval );
55 
56  LloydSmoother ll2( &mb, NULL, elems );
57  ll2.report_its( 10 );
58  rval = ll2.perform_smooth();CHECK_ERR( rval );
59  std::cout << "Mesh smoothed in " << ll2.num_its() << " iterations." << std::endl;
60 }

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().

Variable Documentation

◆ filename

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

Definition at line 6 of file lloyd_smoother_test.cpp.

Referenced by main().