{
int i = 1;
std::vector<int> matsets;
int neuset_num = -1;
bool write_tag = false, write_whole_mesh = false;
bool print_perf = false;
bool use_vert_elem_adjs = false;
bool merge_vertices = false;
double merge_epsilon = -1;
bool list_skin = false;
bool use_scd = false;
const char* fixed_tag = DEFAULT_FIXED_TAG;
const char *input_file = 0, *output_file = 0;
bool no_more_flags = false;
char* endptr = 0;
long block = 0;
while (i < argc) {
if (!no_more_flags && argv[i][0] == '-') {
const int f = i++;
for (int j = 1; argv[f][j]; ++j) {
switch (argv[f][j]) {
case 'a': use_vert_elem_adjs = true; break;
case 'p': print_perf = true; break;
case 't': write_tag = true; break;
case 'w': write_whole_mesh = true; break;
case 'm': merge_vertices = true; break;
case '-': no_more_flags = true; break;
case 'h': usage( argv[0], true ); break;
case 'l': list_skin = true; break;
case 'S': use_scd = true; break;
case 'b':
if (i == argc || 0 >= (block = strtol(argv[i],&endptr,0)) || *endptr) {
std::cerr << "Expected positive integer following '-b' flag" << std::endl;
usage(argv[0]);
}
matsets.push_back((int)block);
++i;
break;
case 'T':
if (i == argc || argv[i][0] == '-') {
std::cerr << "Expected tag name following '-T' flag" << std::endl;
usage(argv[0]);
}
fixed_tag = argv[i++];
break;
case 'M':
if (i == argc || 0.0 > (merge_epsilon = strtod(argv[i],&endptr)) || *endptr) {
std::cerr << "Expected positive numeric value following '-M' flag" << std::endl;
usage(argv[0]);
}
merge_vertices = true;
++i;
break;
default:
std::cerr << "Unrecognized flag: '" << argv[f][j] << "'" << std::endl;
usage(argv[0]);
break;
}
}
}
else if (input_file && output_file) {
std::cerr << "Extra argument: " << argv[i] << std::endl;
usage(argv[0]);
}
else if (input_file) {
output_file = argv[i++];
}
else {
input_file = argv[i++];
}
}
if (!input_file) {
std::cerr << "No input file specified" << std::endl;
usage(argv[0]);
}
ErrorCode result;
Core mbimpl;
Interface* iface = &mbimpl;
if (print_perf) {
double tmp_time1, tmp_mem1;
get_time_mem(tmp_time1, tmp_mem1);
std::cout << "Before reading: cpu time = " << tmp_time1 << ", memory = "
<< tmp_mem1/1.0e6 << "MB." << std::endl;
}
result = iface->load_mesh( input_file );
if (MB_SUCCESS != result)
{
std::cerr << "Failed to load \"" << input_file << "\"." << std::endl;
return 2;
}
std::cerr << "Read \"" << input_file << "\"" << std::endl;
if (print_perf) {
double tmp_time2, tmp_mem2;
get_time_mem(tmp_time2, tmp_mem2);
std::cout << "After reading: cpu time = " << tmp_time2 << ", memory = "
<< tmp_mem2/1.0e6 << "MB." << std::endl;
}
if (merge_vertices) {
if (merge_epsilon < 0.0) {
if (MB_SUCCESS != min_edge_length( *iface, merge_epsilon )) {
std::cerr << "Error determining minimum edge length" << std::endl;
return 1;
}
merge_epsilon /= MIN_EDGE_LEN_DENOM;
}
if (MB_SUCCESS != merge_duplicate_vertices( *iface, merge_epsilon )) {
std::cerr << "Error merging duplicate vertices" << std::endl;
return 1;
}
}
int dim = 4;
Range entities;
while (entities.empty() && dim > 1)
{
dim--;
result = iface->get_entities_by_dimension( 0, dim, entities );
CHKERROR(result);
}
Range skin_ents;
Tag matset_tag = 0, neuset_tag = 0;
result = iface->tag_get_handle(MATERIAL_SET_TAG_NAME, 1, MB_TYPE_INTEGER, matset_tag);
if (MB_SUCCESS != result) return 1;
result = iface->tag_get_handle(NEUMANN_SET_TAG_NAME, 1, MB_TYPE_INTEGER, neuset_tag);
if (MB_SUCCESS != result) return 1;
if (matsets.empty()) skin_ents = entities;
else {
if (0 == matset_tag) {
std::cerr << "Couldn't find any material sets in this mesh." << std::endl;
return 1;
}
for (std::vector<int>::iterator vit = matsets.begin(); vit != matsets.end(); vit++) {
int this_matset = *vit;
const void *this_matset_ptr = &this_matset;
Range this_range, ent_range;
result = iface->get_entities_by_type_and_tag(0, MBENTITYSET, &matset_tag,
&this_matset_ptr, 1, this_range);
if (MB_SUCCESS != result) {
std::cerr << "Trouble getting material set #" << *vit << std::endl;
return 1;
}
else if (this_range.empty()) {
std::cerr << "Warning: couldn't find material set " << *vit << std::endl;
continue;
}
result = iface->get_entities_by_dimension(*this_range.begin(), dim, ent_range, true);
if (MB_SUCCESS != result) continue;
skin_ents.merge(ent_range);
}
}
if (skin_ents.empty()) {
std::cerr << "No entities for which to compute skin; exiting." << std::endl;
return 1;
}
if (use_vert_elem_adjs) {
Range dum_range;
result = iface->get_adjacencies(&(*skin_ents.begin()), 1, 1, false,
dum_range);
if (MB_SUCCESS != result)
return 1;
}
double tmp_time = 0.0, tmp_mem = 0.0;
if (print_perf) {
get_time_mem(tmp_time, tmp_mem);
std::cout << "Before skinning: cpu time = " << tmp_time << ", memory = "
<< tmp_mem/1.0e6 << "MB." << std::endl;
}
Range forward_lower, reverse_lower;
Skinner tool( iface );
if (use_scd)
result = tool.find_skin( 0, skin_ents, false, forward_lower, NULL, false, true, true);
else
result = tool.find_skin( 0, skin_ents, false, forward_lower, &reverse_lower );
Range boundary;
boundary.merge( forward_lower );
boundary.merge( reverse_lower );
if (MB_SUCCESS != result || boundary.empty())
{
std::cerr << "Mesh skinning failed." << std::endl;
return 3;
}
if (list_skin) {
Range skin_verts;
result = iface->get_adjacencies(boundary, 0, true, skin_verts, Interface::UNION);
std::cout << "Skin has ";
if (skin_ents.num_of_dimension(3))
std::cout << boundary.num_of_dimension(2) << " faces and ";
else if (skin_ents.num_of_dimension(2))
std::cout << boundary.num_of_dimension(1) << " edges and ";
std::cout << skin_verts.size() << " vertices." << std::endl;
}
if (write_tag) {
Tag tag;
int zero = 0;
result = iface->tag_get_handle( fixed_tag, 1, MB_TYPE_INTEGER, tag, MB_TAG_DENSE|MB_TAG_CREAT, &zero );
CHKERROR(result);
std::vector<int> ones;
Range bverts;
result = iface->get_adjacencies(boundary, 0, false, bverts, Interface::UNION);
if (MB_SUCCESS != result) {
std::cerr << "Trouble getting vertices on boundary." << std::endl;
return 1;
}
ones.resize( bverts.size(), 1 );
result = iface->tag_set_data( tag, bverts, &ones[0] );
CHKERROR(result);
}
if (-1 != neuset_num) {
if (0 == neuset_tag) {
result = iface->tag_get_handle( "NEUMANN_SET_TAG_NAME", 1, MB_TYPE_INTEGER,
neuset_tag, MB_TAG_SPARSE|MB_TAG_CREAT );
if (MB_SUCCESS != result || 0 == neuset_tag) return 1;
}
EntityHandle forward_neuset = 0;
result = iface->create_meshset(MESHSET_SET, forward_neuset);
if (MB_SUCCESS != result || 0 == forward_neuset) return 1;
result = iface->tag_set_data(neuset_tag, &forward_neuset, 1, &neuset_num);
if (MB_SUCCESS != result) return 1;
if (!forward_lower.empty()) {
result = iface->add_entities(forward_neuset, forward_lower);
if (MB_SUCCESS != result) return 1;
}
if (!reverse_lower.empty()) {
EntityHandle reverse_neuset = 1;
result = iface->create_meshset(MESHSET_SET, reverse_neuset);
if (MB_SUCCESS != result || 0 == forward_neuset) return 1;
result = iface->add_entities(reverse_neuset, reverse_lower);
if (MB_SUCCESS != result) return 1;
Tag sense_tag;
int dum_sense = 0;
result = iface->tag_get_handle("SENSE", 1, MB_TYPE_INTEGER, sense_tag, MB_TAG_SPARSE|MB_TAG_CREAT, &dum_sense);
if (result != MB_SUCCESS) return 1;
int sense_val = -1;
result = iface->tag_set_data(neuset_tag, &reverse_neuset, 1, &sense_val);
if (MB_SUCCESS != result) return 0;
result = iface->add_entities(forward_neuset, &reverse_neuset, 1);
if (MB_SUCCESS != result) return 0;
}
}
if (NULL != output_file && write_whole_mesh) {
result = iface->write_mesh( output_file);
if (MB_SUCCESS != result)
{
std::cerr << "Failed to write \"" << output_file << "\"." << std::endl;
return 2;
}
std::cerr << "Wrote \"" << output_file << "\"" << std::endl;
}
else if (NULL != output_file) {
EntityHandle skin_set;
result = iface->create_meshset(MESHSET_SET, skin_set);
if (MB_SUCCESS != result) return 1;
result = iface->add_entities(skin_set, forward_lower);
if (MB_SUCCESS != result) return 1;
result = iface->add_entities(skin_set, reverse_lower);
if (MB_SUCCESS != result) return 1;
int dum = 10000;
result = iface->tag_set_data(matset_tag, &skin_set, 1, &dum);
if (MB_SUCCESS != result) return 1;
result = iface->write_mesh( output_file, &skin_set, 1);
if (MB_SUCCESS != result)
{
std::cerr << "Failed to write \"" << output_file << "\"." << std::endl;
return 2;
}
std::cerr << "Wrote \"" << output_file << "\"" << std::endl;
}
if (print_perf) {
double tot_time, tot_mem;
get_time_mem(tot_time, tot_mem);
std::cout << "Total cpu time = " << tot_time << " seconds." << std::endl;
std::cout << "Total skin cpu time = " << tot_time-tmp_time << " seconds." << std::endl;
std::cout << "Total memory = " << tot_mem/1024 << " MB." << std::endl;
std::cout << "Total skin memory = " << (tot_mem-tmp_mem)/1024 << " MB." << std::endl;
std::cout << "Entities: " << std::endl;
iface->list_entities(0, 0);
}
return 0;
}