26 std::cerr <<
"Error: " << mbi->
get_error_string( code ) <<
" (" << code <<
")" << std::endl;
29 std::cerr <<
"Error message: " << message << std::endl;
30 std::string fname = file;
31 size_t slash = fname.find_last_of(
'/' );
32 if( slash != fname.npos )
34 fname = fname.substr( slash + 1 );
36 std::cerr <<
"At " << fname <<
" line: " << line << std::endl;
37 std::exit( EXIT_FAILURE );
43 chkerr( &mbi, code, line, file );
61 double& signed_volume )
65 rval =
MBI->get_entities_by_type( surf_set,
MBTRI, tris );
74 rval =
MBI->get_connectivity( *j, conn, len,
true );
77 rval =
MBI->get_coords( conn, 3, coords[0].array() );
82 for(
unsigned int k = 0; k < 3; ++k )
87 coords[1] -= coords[0];
88 coords[2] -= coords[0];
89 signed_volume += ( coords[0] % ( coords[1] * coords[2] ) );
102 const Tag& senseTag )
113 const double min_vol = 0.1;
115 double old_vol = 0, new_vol = 0;
117 bool success =
false;
118 int num_attempts = 100;
120 while( num_attempts-- > 0 )
129 if( std::fabs( old_vol ) >= min_vol && std::fabs( new_vol ) >= min_vol )
136 const int max_random = 10;
137 for(
int i = 0; i < 3; ++i )
139 offset[i] = std::rand() % max_random;
145 std::cerr <<
"Error: could not calculate a surface volume" << std::endl;
151 if( ( old_vol < 0 && new_vol > 0 ) || ( old_vol > 0 && new_vol < 0 ) )
155 rval = mbi->
tag_get_data( senseTag, &old_surf, 1, old_surf_volumes );
158 std::swap( old_surf_volumes[0], old_surf_volumes[1] );
160 rval = mbi->
tag_set_data( senseTag, &old_surf, 1, old_surf_volumes );
164 int num_old_tris, num_new_tris;
171 num_old_tris = old_tris.
size();
183 num_new_tris = new_tris.
size();
189 std::cout << num_old_tris <<
" tris -> " << num_new_tris <<
" tris" << std::endl;
204 const Tag& senseTag )
209 const Tag tags[2] = { dimTag,
idTag };
210 const void* tag_vals[2] = { &two, NULL };
226 Range new_surf_range;
227 tag_vals[1] = &surf_id;
231 if( new_surf_range.
size() != 1 )
233 if( new_surf_range.
size() > 1 )
235 std::cerr <<
"Warning: surface " << surf_id <<
" has more than one representation in new file"
248 std::cout <<
"Surface " << surf_id <<
": " << std::flush;
250 rval =
replace_surface( mbi, old_surf, old_file_set, new_surf, senseTag );
255 std::cout <<
"Replaced " << count <<
" surface" << ( count == 1 ?
"." :
"s." ) << std::endl;
260 int main(
int argc,
char* argv[] )
263 ProgOptions po(
"cgm2moab: a tool for preprocessing CAD and mesh files for analysis" );
266 std::string output_file =
"dagmc_preproc_out.h5m";
270 po.
addOpt< std::string >(
"outmesh,o",
"Specify output file name (default " + output_file +
")", &output_file );
271 po.
addOpt<
void >(
"no-outmesh,",
"Do not write an output mesh" );
272 po.
addOpt< std::string >(
",m",
"Specify alternate input mesh to override surfaces in input_file" );
273 po.
addOpt< std::string >(
"obb-vis,O",
"Specify obb visualization output file (default none)" );
274 po.
addOpt<
int >(
"obb-vis-divs",
"Resolution of obb visualization grid (default 50)", &grid );
275 po.
addOpt<
void >(
"obb-stats,S",
"Print obb statistics. With -v, print verbose statistics." );
276 po.
addOpt< std::vector< int > >(
"vols,V",
277 "Specify a set of volumes (applies to --obb_vis and --obb_stats, default all)" );
282 po.
addOpt<
void >(
"all-warnings",
"Verbose warnings about attributes and curve tolerances" );
283 po.
addOpt<
void >(
"no-attribs",
"Do not actuate CGM attributes" );
284 po.
addOpt<
void >(
"fatal_curves",
"Fatal Error when curves cannot be faceted" );
293 if( po.
numOptSet(
"no-outmesh" ) && !obb_task )
295 po.
error(
"Nothing to do. Please specify an OBB-related option, or remove --no_outmesh." );
300 #define OPTION_APPEND( X ) \
302 if( options.length() ) options += ";"; \
324 static const int tol_prec = 12;
325 if( po.
getOpt(
"ftol", &tol ) )
328 s <<
"FACET_DISTANCE_TOLERANCE=" << std::setprecision( tol_prec ) << tol;
332 if( po.
getOpt(
"ltol", &tol ) )
335 s <<
"MAX_FACET_EDGE_LENGTH=" << std::setprecision( tol_prec ) << tol;
340 if( po.
getOpt(
"atol", &atol ) )
343 s <<
"FACET_NORMAL_TOLERANCE=" << atol;
352 std::cout <<
"Loading file " <<
input_file << std::endl;
353 if( options.length() ) std::cout <<
"Option string: " << options << std::endl;
366 std::cerr <<
"Warning: unhandled option while loading input_file, will proceed anyway" << std::endl;
375 std::vector< std::string > m_list;
378 if( m_list.size() > 0 )
383 std::cerr <<
"Warning: using obb features in conjunction with -m may not work correctly!" << std::endl;
396 for( std::vector< std::string >::iterator i = m_list.begin(); i != m_list.end(); ++i )
398 std::cout <<
"Loading alternate mesh file " << *i << std::endl;
404 ret = mbi.
load_file( ( *i ).c_str(), &alt_file_set );
407 if(
verbose ) std::cout <<
"Merging input surfaces..." << std::flush;
412 if(
verbose ) std::cout <<
"done." << std::endl;
422 std::cout <<
"Writing " << output_file << std::endl;
424 ret = mbi.
write_file( output_file.c_str(), NULL, NULL, &input_file_set, 1 );
434 std::cout <<
"Loading data into GeomTopoTool" << std::endl;