[Liblas-devel] Point constructor must take Header, tutorial issue, and odd ePointSize3

Ben Discoe bdiscoe at 510systems.com
Mon Mar 7 13:38:34 EST 2011


There's an issue with the tutorial
(http://liblas.org/tutorial/cpp.html) that i'd like to address.

I based my test code on the section "Writing using liblas::Writer".
Then i tried adding color, by adding two lines:

	header.SetDataFormatId(liblas::ePointFormat2); // Defaults fields, plus Color
	...
	point.SetColor(..);

I thought it would be sufficient - tell the header that we have color,
and set color on each point.  It seemed to work, silently accepted the
calls, but no color was written to the file.  After much debugging
into liblas and learning its internals, i found the problem: the Point
object must take the Header in its constructor, or it will incorrectly
handle values like Color.  The tutorial happens to show a special case
that AFAICT only works in the case of ePointFormat0.

A better thing to show would be:

	boost::shared_ptr<liblas::Header> header(new liblas::Header);
	...
	liblas::Point point(header);

That would save someone else the headache that i went through.

--------------
BTW, the default Point::Point() constructor has a very strange default:
    m_data.resize(ePointSize3);
I don't know the purpose of setting it to ePointSize3, since it fails
to do the right thing for e.g. ePointSize2 (color) since it applies a
Time offset (8 bytes) which makes SetColor silently fail.  Similarly:

    Point::Point(HeaderPtr hdr) : m_header(hdr),
m_default_header(DefaultHeader::get()) {
        m_data.resize(ePointSize3);

I can't guess why it uses ePointSize3 as a default, even when it has a
header whose schema could tell it the correct DataFormatId.

-Ben


More information about the Liblas-devel mailing list