[Liblas-devel] libLAS 1.6.1 - Can't read color in Point Format 2
Howard Butler
hobu.inc at gmail.com
Tue Nov 8 16:30:44 EST 2011
On Nov 8, 2011, at 3:15 PM, Ryan W. Frenz wrote:
> It seems I am unable to read RGB color from points in point format 2. Using the code snippets below, I write 10 points to a LAS file, with RGB color, and then read it back. I can read back the coordinates properly but not the color (I get RGB=0,0,0 for all points). Anything jump out that I'm doing wrong? Could someone point me to some sample data in point format 2 that I could use for testing?
>
> Notes:
> - This same code works properly using Point Format 0 and Set/GetIntensity instead of Color.
> - I am performing this test using libLAS 1.6.1 compiled for Windows (same results in 32 and 64 bit).
>
> Thanks in advance,
> Ryan
>
> void write(const std::string& filename) {
> std::ofstream out(filename, std::ios::binary);
> liblas::Header h;
> h.SetDataFormatId(liblas::ePointFormat2);
> h.SetPointRecordsCount(10);
> h.SetPointRecordsByReturnCount(1, 10);
> h.SetScale(0.001, 0.001, 0.001);
> h.SetOffset(0,0,0);
>
> liblas::Writer w(out, h);
> for (double i = 0; i <= 1.0; i+=0.1) {
> liblas::Point p;
> p.SetX(i); p.SetY(i); p.SetZ(i);
> liblas::Color c;
> c.SetRed(static_cast<liblas::Color::value_type>(std::numeric_limits<liblas::Color::value_type>::max() * i));
> c.SetGreen(static_cast<liblas::Color::value_type>(std::numeric_limits<liblas::Color::value_type>::max() * i));
> c.SetBlue(static_cast<liblas::Color::value_type>(std::numeric_limits<liblas::Color::value_type>::max() * i));
> p.SetColor(c);
> w.WritePoint(p);
> }
> out.close();
> }
>
> void read(const std::string& filename) {
> std::ifstream in(filename, std::ios::binary);
> liblas::Reader reader(in);
> int ct = 0;
> while ((ct < 10) && reader.ReadNextPoint()) {
> const liblas::Point& p = reader.GetPoint();
> std::cerr << p.GetX() << ", " << p.GetY() << ", " << p.GetZ() << ", " << p.GetColor().GetRed() << ", " << p.GetColor().GetGreen() << ", " << p.GetColor().GetBlue() << "\n";
> ++ct;
> }
> in.close();
> }
Ryan,
Please pull the latest from github if you can. A number of issues have been fixed, and I think the issue you're running into was http://trac.liblas.org/ticket/224
https://github.com/liblas/liblas
Howard
More information about the Liblas-devel
mailing list