Skip to content

Commit c03ed79

Browse files
committed
Updates based on comments from PullRequest in svalinn#660.
1 parent 74b1404 commit c03ed79

6 files changed

Lines changed: 44 additions & 87 deletions

File tree

src/make_watertight/CheckWatertight.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,6 @@ moab::ErrorCode CheckWatertight::check_mesh_for_watertightness(moab::EntityHandl
8181
if (moab::MB_SUCCESS != result) { // failed to get edge data
8282
return result; // failed
8383
}
84-
//10/11/13
85-
//removed as a result of the change from the gen::find_skin function to the moab::Skinner:find_skin function
86-
/*
87-
result = MBI()->delete_entities( edges ); //otherwise delete all edge
88-
89-
if(moab::MB_SUCCESS != result) // failed to delete edge data
90-
{
91-
return result; // failed
92-
}
93-
*/
9484
// loop over each volume meshset
9585
int vol_counter = 0;
9686
for (moab::Range::iterator i = vol_sets.begin(); i != vol_sets.end(); ++i) {
@@ -128,7 +118,6 @@ moab::ErrorCode CheckWatertight::check_mesh_for_watertightness(moab::EntityHandl
128118
}
129119

130120
// save the edges in a vector that is large enough to avoid resizing
131-
// presumably some kind of efficiency thing?? ad ??
132121
std::vector<coords_and_id> the_coords_and_id;
133122
the_coords_and_id.reserve(n_tris);
134123

@@ -224,20 +213,6 @@ moab::ErrorCode CheckWatertight::check_mesh_for_watertightness(moab::EntityHandl
224213
temp.matched = false;
225214
the_coords_and_id.push_back(temp);
226215
}
227-
//10/10/13
228-
// Removed the following to avoid altering the data set at all
229-
// -No need to delete skin_edges with the moab:Skinner find_skin function
230-
// -skin_edges size will be reset to zero upon new moab::Range skin_edges; call
231-
// clean up the edges for the next find_skin call
232-
//result = MBI()->delete_entities( skin_edges );
233-
//if(moab::MB_SUCCESS != result) return result;
234-
235-
//10/10/13
236-
// - No ned to ensure edges aren't in the meshset with moab::Skinner find_skin function
237-
//int n_edges;
238-
//result = MBI()->get_number_entities_by_type(0, moab::MBEDGE, n_edges );
239-
//if(moab::MB_SUCCESS != result) return result;
240-
//if(0 != n_edges) MB_CHK_SET_ERR(moab::MB_MULTIPLE_ENTITIES_FOUND,"n_edges not equal to zero");
241216
}
242217

243218
// sort the edges by the first vert. The first vert has a lower handle than the second.
@@ -271,7 +246,6 @@ moab::ErrorCode CheckWatertight::check_mesh_for_watertightness(moab::EntityHandl
271246
the_coords_and_id[j].vert2 == the_coords_and_id[k].vert2) {
272247
the_coords_and_id[j].matched = true;
273248
the_coords_and_id[k].matched = true;
274-
//std::cout<< "matched by handle" << std::endl;
275249
break;
276250
}
277251
} else {
@@ -292,7 +266,6 @@ moab::ErrorCode CheckWatertight::check_mesh_for_watertightness(moab::EntityHandl
292266
if (d0 < tol * tol && d1 < tol * tol) {
293267
the_coords_and_id[j].matched = true;
294268
the_coords_and_id[k].matched = true;
295-
//std::cout<< "matched by proximity" << std::endl;
296269
break;
297270
}
298271
// Due to the sort, once the x-coords are out of tolerance, a match

src/make_watertight/CheckWatertight.hpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,26 +78,23 @@ inline int compare_by_coords(const void* a, const void* b) {
7878
if (ia->z2 == ib->z2) {
7979
return ia->surf_id - ib->surf_id;
8080
} else {
81-
return (ia->z2 > ib->z2) - (ia->z2 < ib->z2);
81+
return (ia->z2 > ib->z2) ? 1 : -1;
8282
}
8383
} else {
84-
return (ia->y2 > ib->y2) - (ia->y2 < ib->y2);
84+
return (ia->y2 > ib->y2) ? 1 : -1;
8585
}
8686
} else {
87-
return (ia->x2 > ib->x2) - (ia->x2 < ib->x2);
87+
return (ia->x2 > ib->x2) ? 1 : -1;
8888
}
8989
} else {
90-
return (ia->z1 > ib->z1) - (ia->z1 < ib->z1);
90+
return (ia->z1 > ib->z1) ? 1 : -1;
9191
}
9292
} else {
93-
return (ia->y1 > ib->y1) - (ia->y1 < ib->y1);;
93+
return (ia->y1 > ib->y1) ? 1 : -1;
9494
}
9595
} else {
96-
return (ia->x1 > ib->x1) - (ia->x1 < ib->x1);
96+
return (ia->x1 > ib->x1) ? 1 : -1;
9797
}
98-
/* float comparison: returns negative if b > a
99-
and positive if a > b. We multiplied result by 100.0
100-
to preserve decimal fraction */
10198
}
10299

103100
#endif

src/make_watertight/Cleanup.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ moab::ErrorCode Cleanup::delete_small_edges(const moab::Range& surfaces, const d
115115

116116
// get the skin first, because my find_skin does not check before creating edges.
117117
moab::Range skin_edges;
118-
//result = gen->find_skin( tris, 1, skin_edges, false );
119118
moab::Skinner tool(MBI());
120119
result = tool.find_skin(0, tris, 1, skin_edges, false);
121120
assert(moab::MB_SUCCESS == result);
@@ -152,7 +151,7 @@ moab::ErrorCode Cleanup::delete_small_edges(const moab::Range& surfaces, const d
152151
MBI()->list_entities(duplicate_edges);
153152
assert(1 == duplicate_edges.size());
154153

155-
// if the edge length is less than MERGE_TOL do nothing
154+
// if the edge length is less than FACET_TOL do nothing
156155
if (FACET_TOL < gen->dist_between_verts(endpts[0], endpts[1]))
157156
continue;
158157

@@ -208,11 +207,6 @@ moab::ErrorCode Cleanup::delete_small_edges(const moab::Range& surfaces, const d
208207
}
209208
assert(3 <= adj_edges0.size());
210209
moab::Range adj_skin_edges0 = intersect(adj_edges0, skin_edges);
211-
bool endpt0_is_skin;
212-
if (adj_skin_edges0.empty())
213-
endpt0_is_skin = false;
214-
else
215-
endpt0_is_skin = true;
216210

217211
moab::Range adj_edges1;
218212
result = MBI()->get_adjacencies(&endpts[1], 1, 1, true, adj_edges1);
@@ -225,13 +219,11 @@ moab::ErrorCode Cleanup::delete_small_edges(const moab::Range& surfaces, const d
225219
}
226220
assert(3 <= adj_edges1.size());
227221
moab::Range adj_skin_edges1 = intersect(adj_edges1, skin_edges);
228-
bool endpt1_is_skin;
229-
if (adj_skin_edges1.empty())
230-
endpt1_is_skin = false;
231-
else
232-
endpt1_is_skin = true;
233-
if (endpt0_is_skin && endpt1_is_skin)
234-
continue;
222+
223+
// check to see if the endpoints part of the skin
224+
bool endpt0_is_skin = !adj_skin_edges0.empty();
225+
bool endpt1_is_skin = !adj_skin_edges1.empty();
226+
if (endpt0_is_skin && endpt1_is_skin) { continue; }
235227

236228
// Keep the skin endpt, and delete the other endpt
237229
moab::EntityHandle keep_endpt, delete_endpt;

src/make_watertight/Gen.cpp

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ void Gen::moab_printer(moab::ErrorCode error_code) {
5858
if (error_code == moab::MB_FAILURE) {
5959
std::cerr << "ERROR: moab::MB_FAILURE" << std::endl;
6060
}
61+
else {
62+
std::cerr << "ERROR CODE NOT RECOGNIZED" << std::endl;
63+
}
6164
return;
6265
}
6366

@@ -69,7 +72,7 @@ void Gen::print_vertex_cubit(const moab::EntityHandle vertex) {
6972

7073
moab::ErrorCode result;
7174
double coords[3];
72-
int n_precision = 20;
75+
const int n_precision = 20;
7376
result = MBI()->get_coords(&vertex, 1, coords);
7477
assert(moab::MB_SUCCESS == result);
7578
std::cout << " create vertex "
@@ -214,7 +217,7 @@ void Gen::print_loop(const std::vector<moab::EntityHandle> loop_of_verts) {
214217
/// For efficiency: only get_coords on the reference vertex once
215218
/// if specified, limit search length along curve
216219
moab::ErrorCode Gen::find_closest_vert(const moab::EntityHandle reference_vert,
217-
const std::vector<moab::EntityHandle> arc_of_verts,
220+
const std::vector<moab::EntityHandle>& arc_of_verts,
218221
unsigned& position,
219222
const double dist_limit) {
220223
moab::ErrorCode rval;
@@ -264,7 +267,7 @@ moab::ErrorCode Gen::find_closest_vert(const moab::EntityHandle reference_vert,
264267
// This ensure that both are returned as candidates.
265268
moab::ErrorCode Gen::find_closest_vert(const double tol,
266269
const moab::EntityHandle reference_vert,
267-
const std::vector<moab::EntityHandle> loop_of_verts,
270+
const std::vector<moab::EntityHandle>& loop_of_verts,
268271
std::vector<unsigned>& positions,
269272
std::vector<double>& dists) {
270273

@@ -305,7 +308,7 @@ moab::ErrorCode Gen::merge_vertices(moab::Range verts /* in */, const double tol
305308
const double SQR_TOL = tol * tol;
306309
// Clean up the created tree, and track verts so that if merged away they are
307310
// removed from the tree.
308-
moab::AdaptiveKDTree kdtree(MBI()); //, true, 0, moab::MESHSET_TRACK_OWNER);
311+
moab::AdaptiveKDTree kdtree(MBI());
309312
// initialize the KD Tree
310313
moab::EntityHandle root;
311314
const char settings[] = "MAX_PER_LEAF=6;MAX_DEPTH=50;SPLITS_PER_DIR=1;PLANE_SET=2;MESHSET_FLAGS=0x1;TAG_NAME=0";
@@ -327,8 +330,12 @@ moab::ErrorCode Gen::merge_vertices(moab::Range verts /* in */, const double tol
327330
std::vector<moab::EntityHandle> leaf_verts;
328331
result = MBI()->get_entities_by_type(leaves_out[j], moab::MBVERTEX, leaf_verts);
329332
assert(moab::MB_SUCCESS == result);
330-
if (100 < leaf_verts.size())
333+
334+
// write number of leaf verts to screen if there is an abnormally high number of them
335+
const int large_leaf_limit = 100;
336+
if (leaf_verts.size() > large_leaf_limit)
331337
std::cout << "*i=" << *i << " leaf_verts.size()=" << leaf_verts.size() << std::endl;
338+
332339
for (unsigned int k = 0; k < leaf_verts.size(); k++) {
333340
if (leaf_verts[k] == *i)
334341
continue;
@@ -357,7 +364,7 @@ moab::ErrorCode Gen::merge_vertices(moab::Range verts /* in */, const double tol
357364

358365
moab::ErrorCode Gen::squared_dist_between_verts(const moab::EntityHandle v0,
359366
const moab::EntityHandle v1,
360-
double& d) {
367+
double& squared_dist) {
361368
moab::ErrorCode result;
362369
moab::CartVect coords0, coords1;
363370
result = MBI()->get_coords(&v0, 1, coords0.array());
@@ -373,7 +380,7 @@ moab::ErrorCode Gen::squared_dist_between_verts(const moab::EntityHandle v0,
373380
return result;
374381
}
375382
const moab::CartVect diff = coords0 - coords1;
376-
d = diff.length_squared();
383+
squared_dist = diff.length_squared();
377384
return moab::MB_SUCCESS;
378385
}
379386

@@ -427,15 +434,14 @@ double Gen::length(std::vector<moab::EntityHandle> edges) {
427434
return 0;
428435

429436
moab::ErrorCode result;
430-
std::vector<moab::EntityHandle>::iterator i;
431437
double dist = 0;
432438
moab::EntityType type = MBI()->type_from_handle(edges[0]);
433439

434440
// if vector has both edges and verts, only use edges
435441
// NOTE: The curve sets from ReadCGM do not contain duplicate endpoints for loops!
436442
moab::EntityType end_type = MBI()->type_from_handle(edges.back());
437443
if (type != end_type) {
438-
for (std::vector<moab::EntityHandle>::iterator i = edges.begin(); i != edges.end(); i++) {
444+
for (auto i = edges.begin(); i != edges.end(); i++) {
439445
if (moab::MBVERTEX == MBI()->type_from_handle(*i)) {
440446
i = edges.erase(i) - 1;
441447
}
@@ -447,7 +453,7 @@ double Gen::length(std::vector<moab::EntityHandle> edges) {
447453
if (moab::MBEDGE == type) {
448454
if (edges.empty())
449455
return 0.0;
450-
for (i = edges.begin(); i != edges.end(); i++) {
456+
for (auto i = edges.begin(); i != edges.end(); i++) {
451457
int n_verts;
452458
const moab::EntityHandle* conn;
453459
result = MBI()->get_connectivity(*i, conn, n_verts);
@@ -463,7 +469,7 @@ double Gen::length(std::vector<moab::EntityHandle> edges) {
463469
if (2 > edges.size())
464470
return 0.0;
465471
moab::EntityHandle front_vert = edges.front();
466-
for (i = edges.begin() + 1; i != edges.end(); i++) {
472+
for (auto i = edges.begin() + 1; i != edges.end(); i++) {
467473
dist += dist_between_verts(front_vert, *i);
468474
front_vert = *i;
469475
}
@@ -510,7 +516,6 @@ bool Gen::edges_adjacent(moab::EntityHandle edge0, moab::EntityHandle edge1) {
510516
// get the direction unit vector from one vertex to another vertex
511517
moab::ErrorCode Gen::get_direction(const moab::EntityHandle from_vert, const moab::EntityHandle to_vert,
512518
moab::CartVect& dir) {
513-
// double d[3];
514519
moab::ErrorCode result;
515520
moab::CartVect coords0, coords1;
516521
result = MBI()->get_coords(&from_vert, 1, coords0.array());
@@ -821,11 +826,6 @@ bool Gen::collinear(const moab::EntityHandle a, const moab::EntityHandle b,
821826
return false;
822827
}
823828

824-
// Exclusive or: T iff exactly one argument is true
825-
bool logical_xor(const bool x, const bool y) {
826-
return (x || y) && !(x && y);
827-
}
828-
829829
bool Gen::intersect_prop(const moab::EntityHandle a, const moab::EntityHandle b,
830830
const moab::EntityHandle c, const moab::EntityHandle d,
831831
const moab::CartVect n) {
@@ -835,8 +835,8 @@ bool Gen::intersect_prop(const moab::EntityHandle a, const moab::EntityHandle b,
835835
collinear(c, d, b, n)) {
836836
return false;
837837
} else {
838-
return logical_xor(left(a, b, c, n), left(a, b, d, n)) &&
839-
logical_xor(left(c, d, a, n), left(c, d, b, n));
838+
return (left(a, b, c, n) != left(a, b, d, n)) &&
839+
(left(c, d, a, n) != left(c, d, b, n));
840840
}
841841
}
842842

@@ -1246,18 +1246,11 @@ moab::ErrorCode Gen::dist_between_arcs(bool debug,
12461246
}
12471247
}
12481248

1249-
for (unsigned int i = 0; i < mgd_params.size(); i++) {
1250-
1251-
}
1252-
12531249
// Insert new points to match the other arcs points, by parameter.
12541250
for (unsigned int i = 0; i < 2; i++) {
12551251
for (unsigned int j = 0; j < mgd_params.size(); j++) {
1256-
//std::cout << "params[" << i << "][" << j << "]=" << params[i][j]
1257-
// << " mgd_params[" << j << "]=" << mgd_params[j] << std::endl;
12581252
if (params[i][j] > mgd_params[j]) {
12591253
double ratio = (mgd_params[j] - params[i][j - 1]) / (params[i][j] - params[i][j - 1]);
1260-
//std::cout << "j=" << j << " ratio=" << ratio << std::endl;
12611254
moab::CartVect pt = coords[i][j - 1] + ratio * (coords[i][j] - coords[i][j - 1]);
12621255
coords[i].insert(coords[i].begin() + j, pt);
12631256
params[i].insert(params[i].begin() + j, mgd_params[j]);
@@ -1533,7 +1526,11 @@ moab::ErrorCode Gen::get_signed_volume(const moab::EntityHandle surf_set, double
15331526
return moab::MB_SUCCESS;
15341527
}
15351528

1536-
moab::ErrorCode Gen::measure(const moab::EntityHandle set, const moab::Tag geom_tag, double& size, bool debug, bool verbose) {
1529+
moab::ErrorCode Gen::measure(const moab::EntityHandle set,
1530+
const moab::Tag geom_tag,
1531+
double& measurement,
1532+
bool debug,
1533+
bool verbose) {
15371534
moab::ErrorCode result;
15381535
int dim;
15391536
result = MBI()->tag_get_data(geom_tag, &set, 1, &dim);
@@ -1546,17 +1543,17 @@ moab::ErrorCode Gen::measure(const moab::EntityHandle set, const moab::Tag geom_
15461543
std::vector<moab::EntityHandle> vctr;
15471544
result = get_meshset(set, vctr);
15481545
assert(moab::MB_SUCCESS == result);
1549-
size = length(vctr);
1546+
measurement = length(vctr);
15501547

15511548
} else if (2 == dim) {
15521549
moab::Range tris;
15531550
result = MBI()->get_entities_by_type(set, moab::MBTRI, tris);
15541551
assert(moab::MB_SUCCESS == result);
1555-
size = triangle_area(tris);
1552+
measurement = triangle_area(tris);
15561553

15571554
} else if (3 == dim) {
15581555

1559-
result = measure_volume(set, size, debug, verbose);
1556+
result = measure_volume(set, measurement, debug, verbose);
15601557

15611558
if (moab::MB_SUCCESS != result) {
15621559
std::cout << "result=" << result << " vol_id="
@@ -1758,10 +1755,8 @@ moab::ErrorCode Gen::remove_surf_sense_data(moab::EntityHandle del_surf, bool de
17581755
moab::Range del_surf_curves;
17591756
result = MBI() -> get_child_meshsets(del_surf, del_surf_curves);
17601757
MB_CHK_SET_ERR(result, "could not get the curves of the surface to delete");
1761-
if (debug)
1762-
std::cout << "got the curves" << std::endl;
1763-
17641758
if (debug) {
1759+
std::cout << "got the curves" << std::endl;
17651760
std::cout << "number of curves to the deleted surface = " << del_surf_curves.size() << std::endl;
17661761
for (unsigned int index = 0 ; index < del_surf_curves.size() ; index++) {
17671762
std::cout << "deleted surface's child curve id " << index << " = " << geom_id_by_handle(del_surf_curves[index]) << std::endl;

src/make_watertight/Gen.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ class Gen {
5454
void print_loop(const std::vector<moab::EntityHandle> loop_of_verts);
5555

5656
moab::ErrorCode find_closest_vert(const moab::EntityHandle reference_vert,
57-
const std::vector<moab::EntityHandle> arc_of_verts,
57+
const std::vector<moab::EntityHandle>& arc_of_verts,
5858
unsigned& position,
5959
const double dist_limit);
6060

6161
moab::ErrorCode find_closest_vert(const double tol,
6262
const moab::EntityHandle reference_vert,
63-
const std::vector<moab::EntityHandle> loop_of_verts,
63+
const std::vector<moab::EntityHandle>& loop_of_verts,
6464
std::vector<unsigned>& positions,
6565
std::vector<double>& dists);
6666

src/make_watertight/MakeWatertight.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ moab::ErrorCode MakeWatertight::seal_arc_pair(const bool debug,
724724
std::cout << "skin:" << std::endl;
725725
gen->print_loop(skin);
726726
}
727-
//return moab::MB_FAILURE;
727+
return moab::MB_FAILURE;
728728
}
729729

730730
if (debug) {
@@ -1520,7 +1520,7 @@ moab::ErrorCode MakeWatertight::delete_merged_curves(moab::Range& existing_curve
15201520
result = MBI()->delete_entities(curves_to_delete);
15211521
assert(moab::MB_SUCCESS == result);
15221522
if (result != moab::MB_SUCCESS) {
1523-
std::cout << "Houston, we have a problem" << std::endl;
1523+
std::cout << "Failed to delete curves" << std::endl;
15241524
}
15251525
existing_curve_sets = subtract(existing_curve_sets, curves_to_delete);
15261526
if (debug)

0 commit comments

Comments
 (0)