Skip to content

Commit

Permalink
- command_line: fixed log10(0) error in progress logger display
Browse files Browse the repository at this point in the history
- mesh_CSG, surface_intersection: fixed 2D CSG primitives:
    only keep 2D boundary when it is a 2D CSG operation, and
    keep internal triangles when it is an extrusion.
  • Loading branch information
BrunoLevy committed Nov 20, 2023
1 parent 05e17a1 commit 4a18a6e
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/lib/geogram/basic/command_line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@ namespace GEO {
size_t max_L =
sub(ui_terminal_width(), 43 + ui_left_margin + ui_right_margin);

max_L -= size_t(std::log10(double(val)));
max_L -= size_t(std::log10(std::max(double(val),1.0)));
max_L += 2;

if(val > max_L) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/geogram/delaunay/CDT_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
//#define CDT_NAIVE // use naive per-edge method (kept for reference/debugging)

#ifdef GEO_DEBUG
//#define CDT_DEBUG // display *lots* of messages and activates costly checks
#define CDT_DEBUG // display *lots* of messages and activates costly checks
#endif

#ifdef CDT_DEBUG
Expand Down
41 changes: 35 additions & 6 deletions src/lib/geogram/mesh/mesh_CSG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,17 @@ namespace GEO {
}
// Enlarge boxes a bit
for(index_t c=0; c<3; ++c) {
bbox_.xyz_min[c] -= 1e-6;
bbox_.xyz_max[c] += 1e-6;
/*
// nextafter triggers FPEs with denormals
bbox_.xyz_min[c] = std::nextafter(
bbox_.xyz_min[c], -std::numeric_limits<double>::infinity()
);
bbox_.xyz_max[c] = std::nextafter(
bbox_.xyz_max[c], std::numeric_limits<double>::infinity()
);
*/
}
}

Expand Down Expand Up @@ -556,6 +561,7 @@ namespace GEO {
}
mesh_repair(*result, mode, STL_epsilon_);
}
result->facets.compute_borders();
result->update_bbox();
return result;
}
Expand Down Expand Up @@ -644,6 +650,13 @@ namespace GEO {
}

CSGMesh_var CSGBuilder::union_instr(const CSGScope& scope) {

/*
for(index_t i=0; i<scope.size(); ++i) {
mesh_save(*scope[i], String::format("scope_%05d.geogram",int(i)));
}
*/

if(scope.size() == 1) {
return scope[0];
}
Expand Down Expand Up @@ -920,7 +933,7 @@ namespace GEO {

void CSGBuilder::do_CSG(CSGMesh_var mesh, const std::string& boolean_expr) {
if(mesh->vertices.dimension() == 2) {
triangulate(mesh, boolean_expr);
triangulate(mesh, boolean_expr, true); // keep borders only
} else {
MeshSurfaceIntersection I(*mesh);
I.set_verbose(verbose_);
Expand All @@ -931,9 +944,9 @@ namespace GEO {
}

void CSGBuilder::triangulate(
CSGMesh_var mesh, const std::string& boolean_expr
CSGMesh_var mesh, const std::string& boolean_expr,
bool keep_borders_only
) {

mesh->facets.clear();
mesh->vertices.remove_isolated();

Expand Down Expand Up @@ -962,7 +975,7 @@ namespace GEO {
umax+=d;
vmax+=d;
CDT.create_enclosing_rectangle(umin, vmin, umax, vmax);

// In case there are duplicated vertices, keep track of indexing
vector<index_t> vertex_id(mesh->vertices.nb());
for(index_t v: mesh->vertices) {
Expand All @@ -977,14 +990,20 @@ namespace GEO {
// Insert constraint
{
for(index_t e: mesh->edges) {

//HERE
//static int nnn = 0;
//CDT.save(String::format("triangulation_%05d.geogram",nnn));
//++nnn;

index_t v1 = mesh->edges.vertex(e,0);
index_t v2 = mesh->edges.vertex(e,1);
CDT.insert_constraint(
vertex_id[v1], vertex_id[v2], e_operand_bit[e]
);
}
}

CDT.classify_triangles(boolean_expr);

// Create vertices coming from constraint intersections
Expand All @@ -1007,6 +1026,10 @@ namespace GEO {

mesh->facets.connect();
mesh->facets.compute_borders();
if(keep_borders_only) {
mesh->facets.clear();
}
mesh->vertices.remove_isolated();

for(index_t e: mesh->edges) {
e_operand_bit[e] = 1;
Expand Down Expand Up @@ -1261,7 +1284,13 @@ namespace GEO {
}
for(index_t lv1=0; lv1 < P.size(); ++lv1) {
index_t lv2 = (lv1+1)%P.size();
M->edges.create_edge(index_t(P[lv1]), index_t(P[lv2]));
index_t v1 = index_t(P[lv1]);
index_t v2 = index_t(P[lv2]);
// some files do [0,1,2], some others [0,1,2,0], so we need
// to test here for null edges.
if(v1 != v2) {
M->edges.create_edge(v1,v2);
}
}
}
} else if(paths.type == Value::NONE) {
Expand Down
4 changes: 3 additions & 1 deletion src/lib/geogram/mesh/mesh_CSG.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,9 @@ namespace GEO {
* \param[in,out] mesh the input is a set of vertices and edges. The output
* has a set of triangles inside.
*/
void triangulate(CSGMesh_var mesh, const std::string& boolean_expr);
void triangulate(
CSGMesh_var mesh, const std::string& boolean_expr, bool keep_border_only=false
);

/**
* \brief For the file formats that are not supported by geogram,
Expand Down
10 changes: 6 additions & 4 deletions src/lib/geogram/mesh/mesh_surface_intersection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1730,7 +1730,7 @@ namespace GEO {
}
}

/*****************************************************************************/
/*************************************************************************/


void MeshSurfaceIntersection::simplify_coplanar_facets() {
Expand Down Expand Up @@ -1771,9 +1771,11 @@ namespace GEO {
index_t v1 = coplanar.CDT.vertex_id(coplanar.CDT.Tv(t,0));
index_t v2 = coplanar.CDT.vertex_id(coplanar.CDT.Tv(t,1));
index_t v3 = coplanar.CDT.vertex_id(coplanar.CDT.Tv(t,2));
// If one of these assertions fails, it means that v1,v2 or v3
// was one of the four vertices of the external quad. It means
// that there was a inside/outside classification error.
// If one of these assertions fails,
// it means that v1,v2 or v3 was one of the four
// vertices of the external quad.
// It means that there was probably an
// inside/outside classification error.
geo_assert(v1 != index_t(-1));
geo_assert(v2 != index_t(-1));
geo_assert(v3 != index_t(-1));
Expand Down
15 changes: 14 additions & 1 deletion src/lib/geogram/mesh/mesh_surface_intersection_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,9 @@ namespace GEO {
if(point_.size() > nv()) {
point_.pop_back();
id_.pop_back();
#ifndef INTERSECTIONS_USE_EXACT_NT
length_.pop_back();
#endif
}
debug_check_consistency();
return v;
Expand Down Expand Up @@ -759,6 +762,14 @@ namespace GEO {
}

Sign ExactCDT2d::orient2d(index_t i, index_t j, index_t k) const {

/*
return PCK::orient_2d(
point_[i],
point_[j],
point_[k]
);
*/

trindex K(i, j, k);

Expand Down Expand Up @@ -826,7 +837,8 @@ namespace GEO {
);

point_.push_back(mix(t, point_[i], point_[j]));

Numeric::optimize_number_representation(*point_.rbegin());

id_.push_back(index_t(-1));
index_t x = point_.size()-1;

Expand Down Expand Up @@ -1059,6 +1071,7 @@ namespace GEO {

if(f2 == index_t(-1)) {
std::cerr << "INTERNAL BORDER" << std::endl;
geo_assert_not_reached;
}

index_t v1 = mesh_.facets.vertex(f1,le);
Expand Down

0 comments on commit 4a18a6e

Please sign in to comment.