Skip to content

Commit cbb2bef

Browse files
committed
Merge branch 'hotfix/error104'
2 parents 7948f0d + 3b6ed8e commit cbb2bef

File tree

8 files changed

+62
-8
lines changed

8 files changed

+62
-8
lines changed

data/test_metadata.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,6 @@ test_valid:
8888
"composite_solid": Two unit cubes in a CompositeSolid as CityJSON and CityGML
8989
"multi_solid": Two unit cubes in a MultiSolid as CityJSON
9090
"composite_solid_1": "Two unit cubes in a CompositeSolid CityGML, with <CityModel>, <cityObjectMember> part of the 'core' namespace"
91+
"v104_1": the bug raised by the Marcin in Poland about wrong error 104, caused by CGAL and Eigen (Plane_3.to_2d())
92+
"v104_2": like 104_1 but with very large z coords
9193

data/test_valid/v104_1.off

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
OFF
2+
5 1 0
3+
758731.86 379196.97 205.54
4+
758736.08 379207.34 205.54
5+
758743.72 379204.23 205.54
6+
758739.37 379193.92 205.54
7+
758732.25 379196.81 205.54
8+
5 0 1 2 3 4

data/test_valid/v104_2.off

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
OFF
2+
5 1 0
3+
758731.86 379196.97 999205.54
4+
758736.08 379207.34 999205.54
5+
758743.72 379204.23 999205.54
6+
758739.37 379193.92 999205.54
7+
758732.25 379196.81 999205.54
8+
5 0 1 2 3 4

src/Surface.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,7 @@ bool Surface::triangulate_shell()
298298
for ( ; itp2 != ids2.end(); itp2++)
299299
allpts.push_back(_lsPts[*itp2]);
300300
}
301-
CgalPolyhedron::Plane_3 bestfitplane;
302-
get_best_fitted_plane(allpts, bestfitplane);
301+
CgalPolyhedron::Plane_3 bestfitplane = get_best_fitted_plane(allpts);
303302

304303
// int proj = projection_plane(_lsPts, idsob);
305304
// Vector v0 = bestfitplane.orthogonal_vector();
@@ -504,8 +503,7 @@ bool Surface::validate_2d_primitives(double tol_planarity_d2p, double tol_planar
504503
}
505504
}
506505
double value;
507-
CgalPolyhedron::Plane_3 bestfitplane;
508-
get_best_fitted_plane(allpts, bestfitplane);
506+
CgalPolyhedron::Plane_3 bestfitplane = get_best_fitted_plane(allpts);
509507
if (false == is_face_planar_distance2plane(allpts, bestfitplane, value, tol_planarity_d2p))
510508
{
511509
std::stringstream msg;

src/geomtools.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,32 @@ Nef_polyhedron* get_aabb(Nef_polyhedron* mynef)
262262
}
263263

264264

265-
void get_best_fitted_plane(const std::vector< Point3 > &lsPts, CgalPolyhedron::Plane_3 &plane)
265+
CgalPolyhedron::Plane_3 get_best_fitted_plane(const std::vector< Point3 > &lsPts)
266266
{
267-
linear_least_squares_fitting_3(lsPts.begin(), lsPts.end(), plane, CGAL::Dimension_tag<0>());
267+
CgalPolyhedron::Plane_3 p;
268+
linear_least_squares_fitting_3(lsPts.begin(), lsPts.end(), p, CGAL::Dimension_tag<0>());
269+
K::FT tol = 1e-12;
270+
K::FT a = p.a();
271+
K::FT b = p.b();
272+
K::FT c = p.c();
273+
bool updated = false;
274+
if (CGAL::abs(p.a()) < tol) {
275+
a = 0;
276+
updated = true;
277+
}
278+
if (CGAL::abs(p.b()) < tol) {
279+
b = 0;
280+
updated = true;
281+
}
282+
if (CGAL::abs(p.c()) < tol) {
283+
c = 0;
284+
updated = true;
285+
}
286+
if (updated == false)
287+
return p;
288+
else {
289+
return CgalPolyhedron::Plane_3(a, b, c, p.d());
290+
}
268291
}
269292

270293

src/geomtools.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ namespace val3dity
3737
//-- misc
3838
#define PI 3.14159265
3939

40+
CgalPolyhedron::Plane_3 get_best_fitted_plane(const std::vector< Point3 > &lsPts);
41+
4042
bool cmpPoint3(Point3 &p1, Point3 &p2, double tol);
41-
void get_best_fitted_plane(const std::vector< Point3 > &lsPts, CgalPolyhedron::Plane_3 &plane);
4243
void create_cgal_polygon(const std::vector<Point3>& lsPts, const std::vector<int>& ids, const CgalPolyhedron::Plane_3 &plane, Polygon &outpgn);
4344
bool is_face_planar_distance2plane(const std::vector<Point3> &pts, const CgalPolyhedron::Plane_3 &plane, double& value, float tolerance);
4445
bool is_face_planar_normals(const std::vector<int*> &trs, const std::vector<Point3>& lsPts, double& value, float angleTolerance);

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ using namespace std;
4242
using namespace val3dity;
4343
using json = nlohmann::json;
4444

45-
std::string VAL3DITY_VERSION = "2.0.1";
45+
std::string VAL3DITY_VERSION = "2.0.2";
4646

4747

4848
std::string print_summary_validation(std::map<std::string, std::vector<Primitive*>>& dPrimitives, std::map<std::string, COError>& dCOerrors, IOErrors& ioerrs);

tests/test_valid.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ def data_v_405(request, dir_valid):
5050
return(file_path)
5151

5252

53+
@pytest.fixture(scope="module",
54+
params=["v104_1.off",
55+
"v104_2.off"])
56+
def data_v_104(request, dir_valid):
57+
file_path = os.path.abspath(
58+
os.path.join(
59+
dir_valid,
60+
request.param))
61+
return(file_path)
62+
5363

5464
@pytest.fixture(scope="module",
5565
params=["basecube_large_coords.poly"])
@@ -107,6 +117,10 @@ def test_v_405(validate, data_v_405):
107117
error = validate(data_v_405)
108118
assert(error == [])
109119

120+
def test_v_104(validate, data_planar):
121+
error = validate(data_planar)
122+
assert(error == [301])
123+
110124
def test_planar(validate, data_planar):
111125
error = validate(data_planar)
112126
assert(error == [301])

0 commit comments

Comments
 (0)