diff --git a/src/lib/geogram/basic/command_line.cpp b/src/lib/geogram/basic/command_line.cpp index 8737aae7b8e0..3b34ede95d26 100644 --- a/src/lib/geogram/basic/command_line.cpp +++ b/src/lib/geogram/basic/command_line.cpp @@ -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) { diff --git a/src/lib/geogram/delaunay/CDT_2d.cpp b/src/lib/geogram/delaunay/CDT_2d.cpp index 784ac0120043..38c1d7c5d4af 100644 --- a/src/lib/geogram/delaunay/CDT_2d.cpp +++ b/src/lib/geogram/delaunay/CDT_2d.cpp @@ -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 diff --git a/src/lib/geogram/mesh/mesh_CSG.cpp b/src/lib/geogram/mesh/mesh_CSG.cpp index 63ec57bb0c95..76c941dc4341 100644 --- a/src/lib/geogram/mesh/mesh_CSG.cpp +++ b/src/lib/geogram/mesh/mesh_CSG.cpp @@ -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::infinity() ); bbox_.xyz_max[c] = std::nextafter( bbox_.xyz_max[c], std::numeric_limits::infinity() ); + */ } } @@ -556,6 +561,7 @@ namespace GEO { } mesh_repair(*result, mode, STL_epsilon_); } + result->facets.compute_borders(); result->update_bbox(); return result; } @@ -644,6 +650,13 @@ namespace GEO { } CSGMesh_var CSGBuilder::union_instr(const CSGScope& scope) { + + /* + for(index_t i=0; ivertices.dimension() == 2) { - triangulate(mesh, boolean_expr); + triangulate(mesh, boolean_expr, true); // keep borders only } else { MeshSurfaceIntersection I(*mesh); I.set_verbose(verbose_); @@ -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(); @@ -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 vertex_id(mesh->vertices.nb()); for(index_t v: mesh->vertices) { @@ -977,6 +990,12 @@ 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( @@ -984,7 +1003,7 @@ namespace GEO { ); } } - + CDT.classify_triangles(boolean_expr); // Create vertices coming from constraint intersections @@ -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; @@ -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) { diff --git a/src/lib/geogram/mesh/mesh_CSG.h b/src/lib/geogram/mesh/mesh_CSG.h index 70c97ad0c130..cfebad920f50 100644 --- a/src/lib/geogram/mesh/mesh_CSG.h +++ b/src/lib/geogram/mesh/mesh_CSG.h @@ -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, diff --git a/src/lib/geogram/mesh/mesh_surface_intersection.cpp b/src/lib/geogram/mesh/mesh_surface_intersection.cpp index 207771adcc66..9f00fbe4fa8b 100644 --- a/src/lib/geogram/mesh/mesh_surface_intersection.cpp +++ b/src/lib/geogram/mesh/mesh_surface_intersection.cpp @@ -1730,7 +1730,7 @@ namespace GEO { } } - /*****************************************************************************/ + /*************************************************************************/ void MeshSurfaceIntersection::simplify_coplanar_facets() { @@ -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)); diff --git a/src/lib/geogram/mesh/mesh_surface_intersection_internal.cpp b/src/lib/geogram/mesh/mesh_surface_intersection_internal.cpp index ae9b31d32e71..d027cb412f6a 100644 --- a/src/lib/geogram/mesh/mesh_surface_intersection_internal.cpp +++ b/src/lib/geogram/mesh/mesh_surface_intersection_internal.cpp @@ -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; @@ -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); @@ -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; @@ -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);