[Liblas-devel] Rounding problem with point coordinates?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[Liblas-devel] Rounding problem with point coordinates?

Peder Axensten
Hi Howard and all,

I think I have spotted a small problem and I would really appreciate your opinion. I've built a set of tools that assumes that the las file header information is correct, e.g. points outside the header bounding box will crash the tool if I'm lucky or craete undetermined data if I'm not.

I noticed that there often are points outside the header's bounding box -- even in files produced by las2las. The points are not far outside, my guess is that the problem stems from rounding errors due to the coordinates' float->integer->float roundtrip. I attach a code snippet that solves the problem for me. If you are interested I can post the code for point_nudge_t too, but it is very straight-forward. (As you can see, I have wrappers around liblas::Reader and liblas::Writer. The reader wrapper is simple, but the writer wrapper handles two subtle problems writing points and also updates the header information automagically.)

Am I principally wrong to depend on the file header information?


las_type::reader_type reader( source_ );
const auto header = get_header( reader );
const auto filter = my_filter();

// There is a rounding problem with the file's bounding box.
/* Even in files generated by liblas::las2las, some points might be slightly outside the file's
        bounding box. This is probably due to rounding errors. The box's extent is based on point
        coordinates *before* converting them to integers (in the las file they are stored as 32 bit
        integers). When reading the same file, converting them back to floating point values will
        more often than not result in coordinate values that might differ up to the value of the
        scaling factor.
        The point_nudge_t::outside function:
        - A point inside the header's bounding box: only returns false.
        - A point outside the bounding box: adds or subtracts the coordinates by the amount of the
          scalu factor to move the point in the direction of the bounding box and returns true if
          and only if it is still outside after moving it.
        When writing the points to a new file, the original file's bounding box is used and points
        that remained outside the box were removed. In this way the new file will have no points
        outside the bounding box. Of course, the same problem would occur again [and again...]
        if we updated the bounding box to the new set of points.
const point_nudge_t nudger( header ); // From las-io-stuff.hpp
las_type::writer_type writer( dest_, header, false ); // Do not update the bounding box!
while( reader ) {
        auto pt = *reader;

        if( !nudger.outside( pt ) && !filter.remove( pt )  )
                writer << pt;

Peder Axensten
Research engineer

Swedish University of Agricultural Sciences
Department of Forest Resource Management
Remote Sensing
SE-901 83 Umeå
Visiting address: Skogsmarksgränd
Phone: +46 90 786 85 00
[hidden email], www.slu.se/srh

The Department of Forest Resource Management is environmentally certified in accordance with ISO 14001.

Liblas-devel mailing list
[hidden email]