[Liblas-devel] [LAStools] Re: set rgb with laslib

Helimap Postmaster postmaster at helimap.ch
Sat Apr 9 03:09:31 PDT 2016


Waho, thanks for writing down this example!

it is very helpful. I didn't know about the unlink function. Very useful
example on how to 'move' a header.

Much appreciated,

Pol

On Sat, Apr 9, 2016 at 10:41 AM, Martin Isenburg <martin.isenburg at gmail.com>
wrote:

> Hello Pol,
>
> attached is sample code that uses LASlib to read a LAS / LAZ file with
> point type 0, 1, or 4, add RGB colors, and write a LAS / LAZ file with
> point type 2, 3, or 5 respectively. This lasexample_add_rgb.cpp source code
> has also been added as a new permanent example of LASlib use to the
> ./LAStools/LASlib/example folder and can be accessed via github here:
>
> http://github.com/LAStools/LAStools/tree/master/LASlib
>
> Regards,
>
> Martin @rapidlasso
>
> On Fri, Apr 8, 2016 at 1:02 PM, Pol Monsó Purtí <lluna.nova at gmail.com>
> wrote:
>
>> I was wrong.
>>
>> The init is not sufficient because the header itself stores the point
>> data format and size.
>>
>> If I set them in a copy of the header that I then pass to the init, I get
>> a segfault on the first point write, third writer. Probably because the
>> size of the points is in fact incorrect.
>>
>> Anybody willing to weight in?...?
>>
>> On Tue, Apr 5, 2016 at 6:12 PM, Pol Monsó Purtí <lluna.nova at gmail.com>
>> wrote:
>>
>>> Ok, it seems I should create a new point and call to init, as seen on
>>> the *writer only* example.
>>>
>>> In my case, the output point data record format is 3, with a size of 34.
>>>
>>> Therefore:
>>>
>>>
>>>   LASpoint p;
>>>
>>>   laspoint.init(&lasreader->header, PointDataFormatID_2, PointDataFormatSize, 0);
>>>
>>>
>>> with 2 and 34. Is that correct? Do I have to manually change the header to activate have_rgb?
>>>
>>>
>>> Is that the way to do this?
>>>
>>> Do I have to guarantee the existence of the LASpoint memory until the
>>> close or just until the write? (effectively reusing it after each iteration)
>>>
>>> What happens if I call init on the LASpoint* of the reader?
>>>
>>> Cheers,
>>>
>>> Pol
>>>
>>> On Tue, Apr 5, 2016 at 5:27 PM, Pol Monsó Purtí <lluna.nova at gmail.com>
>>> wrote:
>>>
>>>> Ok, it definetly has to do something about the header or the point
>>>> type. If I take in a cloud with rgb I can change it and save it. And it
>>>> does have the RGB12_LE writer in its vector.
>>>>
>>>> Now, how can I tell liblas to add this writer on the writer if it ain't
>>>> there on the reader?
>>>>
>>>> On Tue, Apr 5, 2016 at 5:02 PM, Pol Monsó Purtí <lluna.nova at gmail.com>
>>>> wrote:
>>>>
>>>>> I've debugged the application and the point p has the rgb, but I
>>>>> couldn't find where it is written.
>>>>>
>>>>> It is probably at LASwriteItemRaw_POINT10_LE, which is the writer that
>>>>> gets called from the writers vector. Does LAS 1.0 support color? If not,
>>>>> how do I set the LAS specification?
>>>>>
>>>>> The input cloud is supposed to be las 1.2. I've added the following
>>>>> line after the writing loop and before the close, so that I don't get the
>>>>> npoints mismatch error:
>>>>>
>>>>> laswriter->update_header(&lasreader->header, TRUE);
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Btw, I forget to mention that I'm on windows
>>>>>
>>>>> On Tue, Apr 5, 2016 at 4:53 PM, Pol Monsó Purtí <lluna.nova at gmail.com>
>>>>> wrote:
>>>>>
>>>>>> I want to colorize a colorless las cloud, but I get only 0 as rgb. Is
>>>>>> there a parameter that must be set (e.g. has_rgb)?
>>>>>>
>>>>>> I am currently doing the following:
>>>>>>
>>>>>>     LASreadOpener lasreadopener;
>>>>>>
>>>>>>   lasreadopener.set_file_name(infilename);
>>>>>>
>>>>>>   LASreader* lasreader = lasreadopener.open();
>>>>>>
>>>>>>
>>>>>>   LASwriteOpener laswriteopener;
>>>>>>
>>>>>>   laswriteopener.set_file_name("test.las");
>>>>>>
>>>>>>   LASwriter* laswriter = laswriteopener.open(&lasreader->header);
>>>>>>
>>>>>>
>>>>>> [...]
>>>>>>
>>>>>>
>>>>>>   lasreader->seek(0);
>>>>>>
>>>>>>
>>>>>>   U16 rgb[4];
>>>>>>
>>>>>>   U16 colur = 100;
>>>>>>
>>>>>>
>>>>>>   for(int i = 0; i < npoints; i++)
>>>>>>
>>>>>>   {
>>>>>>
>>>>>>     lasreader->read_point();
>>>>>>
>>>>>>     LASpoint *p = &lasreader->point;
>>>>>>
>>>>>>     rgb[0] = colur;
>>>>>>
>>>>>>     rgb[1] = colur;
>>>>>>
>>>>>>     rgb[2] = colur;
>>>>>>
>>>>>>     rgb[3] = 0;
>>>>>>
>>>>>>     p->set_rgb(rgb);
>>>>>>
>>>>>>     laswriter->write_point(p);
>>>>>>
>>>>>>   }
>>>>>>
>>>>>>
>>>>>>
>>>>>>   I64 total_bytes = laswriter->close();
>>>>>>
>>>>>>   delete laswriter;
>>>>>>
>>>>>>
>>>>>>   lasreader->close();
>>>>>>
>>>>>>   delete lasreader;
>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>> --
>> Download LAStools at
>> http://lastools.org
>> http://rapidlasso.com
>> Be social with LAStools at
>> http://facebook.com/LAStools
>> http://twitter.com/LAStools
>> http://linkedin.com/groups/LAStools-4408378
>> Manage your settings at
>> http://groups.google.com/group/lastools/subscribe
>>
>
>
> _______________________________________________
> Liblas-devel mailing list
> Liblas-devel at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/liblas-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/liblas-devel/attachments/20160409/564547c3/attachment.html>


More information about the Liblas-devel mailing list