PotreeConverter: repaired bounding boxes rounding problem?

PotreeConverter_2.1_x64_windows doesn’t like the bounding boxes of LAZ files that have been repaired with LAStools-2021-07-20/lasinfo -repair_bb that appear to be due to rounding values…

ERROR(chunker_countsort_laszip.cpp:237): encountered point outside bounding box.
box.min: -10.192, -14.1157, -1.7038
box.max: 17.855499999999999, 13.931799999999999, 26.343699999999998
point: 7.3163, 13.931800000000001, -1.649
file: whatever.laz
PotreeConverter requires a valid bounding box to operate.
Please try to repair the bounding box, e.g. using lasinfo with the -repair_bb argument.

About this issue

Commits related to this issue

Most upvoted comments

For me, the following patch solved the issue:

diff --git a/Converter/src/chunker_countsort_laszip.cpp b/Converter/src/chunker_countsort_laszip.cpp
index 086c00d..bc9a553 100644
--- a/Converter/src/chunker_countsort_laszip.cpp
+++ b/Converter/src/chunker_countsort_laszip.cpp
@@ -6,6 +6,7 @@
 #include <mutex>
 #include <memory>
 #include <atomic>
+#include <cfloat>
 
 #include "chunker_countsort_laszip.h"
 
@@ -234,7 +235,7 @@ namespace chunker_countsort_laszip {
                                        double uz = (double(Z) * posScale.z + posOffset.z - min.z) / size.z;
 
                                        bool inBox = ux >= 0.0 && uy >= 0.0 && uz >= 0.0;
-                                       inBox = inBox && ux <= 1.0 && uy <= 1.0 && uz <= 1.0;
+                                       inBox = inBox && ux <= 1.0 + DBL_EPSILON && uy <= 1.0 + DBL_EPSILON && uz <= 1.0 + DBL_EPSILON;
 
                                        if (!inBox) {
                                                stringstream ss;

@m-schuetz What is the purpose of these added computations in your commit?

https://github.com/potree/PotreeConverter/commit/5307150e84f1335e645e6561bee6c5a2078135bc#diff-1fc6aa609a43bfd39fe0cc841ebc85b43f4c9c2da48d3414d218d06156784114R198-R210

https://github.com/potree/PotreeConverter/blob/5307150e84f1335e645e6561bee6c5a2078135bc/Converter/src/chunker_countsort_laszip.cpp#L199-L210

The expression double(X) * posScale.x + posOffset.x should just be x.

Proof:

  double(X)                                       * posScale.x + posOffset.x
  // subsituting `int32_t X = ...`
= double(int32_t((x - posOffset.x) / posScale.x)) * posScale.x + posOffset.x
  // assuming infinite precision, treating numbers matematically
=               ((x - posOffset.x) / posScale.x)  * posScale.x + posOffset.x
  // simplifying / with *
=                (x - posOffset.x)                             + posOffset.x
  // simplifying - with +
=                 x

So I think the code was better as was before your commit, namely:

double ux = (coordinates[0] - min.x) / size.x;

By going via int32_t X (computing back to integers, just to immediately convert back to float the inverse way), the only thing that seems to be achieved is loss-of-floating-point-precision, and thus the <= comparison errors in this ticket.

Am I missing something?

My understanding is that the main fix to the problem #426 was the addition of (computeScaleOffset()) which “Compute suitable scale and offset based on scale, offset and bounding box of all input files” as #426 suggested.

Why also these forward-and-backward conversions?

I modified the code and is to be found here: https://github.com/ykhedar/PotreeConverter