Skip to content

Commit

Permalink
temporary fix for CGAL bug CGAL/cgal#2733
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoledoux committed Jan 13, 2018
1 parent 7948f0d commit 1681207
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
6 changes: 2 additions & 4 deletions src/Surface.cpp
Expand Up @@ -298,8 +298,7 @@ bool Surface::triangulate_shell()
for ( ; itp2 != ids2.end(); itp2++)
allpts.push_back(_lsPts[*itp2]);
}
CgalPolyhedron::Plane_3 bestfitplane;
get_best_fitted_plane(allpts, bestfitplane);
CgalPolyhedron::Plane_3 bestfitplane = get_best_fitted_plane(allpts);

// int proj = projection_plane(_lsPts, idsob);
// Vector v0 = bestfitplane.orthogonal_vector();
Expand Down Expand Up @@ -504,8 +503,7 @@ bool Surface::validate_2d_primitives(double tol_planarity_d2p, double tol_planar
}
}
double value;
CgalPolyhedron::Plane_3 bestfitplane;
get_best_fitted_plane(allpts, bestfitplane);
CgalPolyhedron::Plane_3 bestfitplane = get_best_fitted_plane(allpts);
if (false == is_face_planar_distance2plane(allpts, bestfitplane, value, tol_planarity_d2p))
{
std::stringstream msg;
Expand Down
27 changes: 25 additions & 2 deletions src/geomtools.cpp
Expand Up @@ -262,9 +262,32 @@ Nef_polyhedron* get_aabb(Nef_polyhedron* mynef)
}


void get_best_fitted_plane(const std::vector< Point3 > &lsPts, CgalPolyhedron::Plane_3 &plane)
CgalPolyhedron::Plane_3 get_best_fitted_plane(const std::vector< Point3 > &lsPts)
{
linear_least_squares_fitting_3(lsPts.begin(), lsPts.end(), plane, CGAL::Dimension_tag<0>());
CgalPolyhedron::Plane_3 p;
linear_least_squares_fitting_3(lsPts.begin(), lsPts.end(), p, CGAL::Dimension_tag<0>());
K::FT tol = 1e-12;
K::FT a = p.a();
K::FT b = p.b();
K::FT c = p.c();
bool updated = false;
if (abs(p.a()) < tol) {
a = 0;
updated = true;
}
if (abs(p.b()) < tol) {
b = 0;
updated = true;
}
if (abs(p.c()) < tol) {
c = 0;
updated = true;
}
if (updated == false)
return p;
else {
return CgalPolyhedron::Plane_3(a, b, c, p.d());
}
}


Expand Down
3 changes: 2 additions & 1 deletion src/geomtools.h
Expand Up @@ -37,8 +37,9 @@ namespace val3dity
//-- misc
#define PI 3.14159265

CgalPolyhedron::Plane_3 get_best_fitted_plane(const std::vector< Point3 > &lsPts);

bool cmpPoint3(Point3 &p1, Point3 &p2, double tol);
void get_best_fitted_plane(const std::vector< Point3 > &lsPts, CgalPolyhedron::Plane_3 &plane);
void create_cgal_polygon(const std::vector<Point3>& lsPts, const std::vector<int>& ids, const CgalPolyhedron::Plane_3 &plane, Polygon &outpgn);
bool is_face_planar_distance2plane(const std::vector<Point3> &pts, const CgalPolyhedron::Plane_3 &plane, double& value, float tolerance);
bool is_face_planar_normals(const std::vector<int*> &trs, const std::vector<Point3>& lsPts, double& value, float angleTolerance);
Expand Down

0 comments on commit 1681207

Please sign in to comment.