[Liblas-commits] r1206 - trunk/apps

liblas-commits at liblas.org liblas-commits at liblas.org
Mon Apr 13 22:41:47 EDT 2009


Author: hobu
Date: Mon Apr 13 22:41:46 2009
New Revision: 1206
URL: http://liblas.org/changeset/1206

Log:
more updates.  messy, but mostly working

Modified:
   trunk/apps/ts2las.cpp
   trunk/apps/ts2las.hpp

Modified: trunk/apps/ts2las.cpp
==============================================================================
--- trunk/apps/ts2las.cpp	(original)
+++ trunk/apps/ts2las.cpp	Mon Apr 13 22:41:46 2009
@@ -72,11 +72,13 @@
     } 
     header.SetVersionMinor(2);
     header.SetDataFormatId(format);
-    header.SetPointRecordsCount(hdr->PntCnt);
+    // header.SetPointRecordsCount(hdr->PntCnt);
     header.SetOffset(hdr->OrgX, hdr->OrgY, hdr->OrgZ);
     std::cout << "offset x: " << header.GetOffsetX() << " offset y: " << header.GetOffsetY()  << " offset z: " <<header.GetOffsetZ() << std::endl;
     std::cout << "units: " << hdr->Units << std::endl;
     std::cout << "format: " << format << std::endl;
+    double scale = 1.0/hdr->Units;
+    header.SetScale(scale, scale, scale);
     return header;
 }
 bool ReadHeader(ScanHdr* hdr, std::istream* istrm) {
@@ -107,48 +109,101 @@
 {
     while (true) {
         
-        if (hdr->HdrVersion == 20020715) {
+
 ///std::cout << "We have header version" << std::endl;
             ScanPnt* point = new ScanPnt;
+            ScanRow* row = new ScanRow;
             try
             {
-                std::cout << "stream position is: " << strm->tellg() << std::endl;
-
-                detail::read_n(*point, *strm, sizeof(ScanPnt));
+                // std::cout << "stream position is: " << strm->tellg() << std::endl;
+                if (hdr->HdrVersion == 20020715) {
+                    detail::read_n(*point, *strm, sizeof(ScanPnt));
+                } else{
+                    detail::read_n(*row, *strm, sizeof(ScanRow));
+                    point->Pnt.x = row->x;
+                    point->Pnt.y = row->y;
+                    point->Pnt.z = row->z;
+                    point->Code = row->Code;
+                    point->Line = row->Line;
+                    point->Intensity = row->EchoInt & 0x3FFF;
+                    point->Echo = (row->EchoInt >> 14);
+                }
                 LASPoint p;
                 p.SetCoordinates(writer->GetHeader(),point->Pnt.x,point->Pnt.y,point->Pnt.z);
-                std::cout << "x: " << point->Pnt.x << " y: "<< point->Pnt.y << " z: " <<point->Pnt.z<< std::endl;
-                std::cout << "x: " << p.GetX() << " y: "<< p.GetY() << " z: " <<p.GetZ()<< std::endl;
-
-                std::cout << "Code: " << point->Code << " Intensity: "<< point->Intensity << std::endl;
+                // std::cout << "x: " << point->Pnt.x << " y: "<< point->Pnt.y << " z: " <<point->Pnt.z<< std::endl;
+                // std::cout << "x: " << p.GetX() << " y: "<< p.GetY() << " z: " <<p.GetZ()<< std::endl;
+                // std::cout << "Code: " << point->Code << " Intensity: "<< point->Intensity << std::endl;
                 p.SetClassification(point->Code);
                 p.SetIntensity(point->Intensity);
-                writer->WritePoint(p);
-                std::cout << "stream position is: " << strm->tellg() << std::endl;
-
-                exit(-1);
-               // std::cout << "Wrote point"<< std::endl;
+                if (hdr->Time) {
+                    liblas::uint32_t t = 0xFFFFFFFF;
+                    detail::read_n(t, *strm, sizeof(t));
+
+                    // Time stamps are assumed to be GPS week seconds. The 
+                    // storage format is a 32 bit unsigned integer where 
+                    // each integer step is 0.0002 seconds.
+
+                    p.SetTime(t*0.0002);
+                }
+                if (hdr->Color) {
+                    liblas::uint8_t r, g, b, a = 0;
+                    LASColor color;
+                    detail::read_n(r, *strm, sizeof(r));
+                    detail::read_n(b, *strm, sizeof(b));
+                    detail::read_n(g, *strm, sizeof(g));
+                    
+                    // TS .bin says to read 4 bytes here for some reason.  Maybe 
+                    // this is an alpha value or something
+                    detail::read_n(a, *strm, sizeof(a));
+                    
+                    color.SetGreen(g);
+                    color.SetBlue(b);
+                    color.SetRed(r);
+                    p.SetColor(color);
+                }
+                
+                // Set return number
+                /* 
+                    TerraScan uses two bits for storing echo information. The possible values are: 
+                    0 Only echo 
+                    1 First of many echo 
+                    2 Intermediate echo 
+                    3 Last of many echo
+                */
+                if (point->Echo == 0) { 
+                    p.SetNumberOfReturns(1);
+                    p.SetReturnNumber(1);
+                } else if (point->Echo == 1) {
+                    p.SetReturnNumber(1);
+                } else if (point->Echo == 3) {
+                    p.SetReturnNumber(5);
+                    p.SetNumberOfReturns(5);
+                } else {
+                    // I don't know what the hell to do here without cumulating
+                    // through all of the points.  Why wouldn't you store the return 
+                    // number?!
+                    p.SetReturnNumber(3);
+                }
+                try {
+                    writer->WritePoint(p);
+                } catch (std::exception const& e) 
+                {
+                    std::cout << "Point writing failed!" << std::endl; 
+                }
                 
             }
             catch (std::out_of_range const& e) // we reached the end of the file
             {
                 std::cout << "catching out of range error!" ;
-                break;
+                return true;
+                // break;
             }
             catch (std::exception const& e) // we reached the end of the file
             {
                 std::cout << e.what() << std::endl;
                 break;
             }   
-        }
-        
-        // Reader::FillPoint(record, point);
-        // point.SetCoordinates(header, point.GetX(), point.GetY(), point.GetZ());
-        //     
-        // if (header.GetDataFormatId() == LASHeader::ePointFormat1) {
-        //     detail::read_n(t, m_ifs, sizeof(double));
-        //     point.SetTime(t);
-        // }
+
     }
     return true;    
 
@@ -225,9 +280,12 @@
     LASHeader header = CreateHeader(hdr);
     LASWriter* writer = new LASWriter(*ostrm, header);
     
-     success = WritePoints(writer, istrm, hdr);
+    success = WritePoints(writer, istrm, hdr);
+    delete writer;
+    delete ostrm;
+    delete istrm;
     
-    std::cout << "Point Count: " << hdr->PntCnt <<std::endl;
+    std::cout << "Point Count: " << header.GetPointRecordsCount() <<std::endl;
     std::cout << "success: " << success << std::endl;
     return rc;
 }
\ No newline at end of file

Modified: trunk/apps/ts2las.hpp
==============================================================================
--- trunk/apps/ts2las.hpp	(original)
+++ trunk/apps/ts2las.hpp	Mon Apr 13 22:41:46 2009
@@ -146,13 +146,9 @@
     if (!src)
         throw std::runtime_error("detail::liblas::read_n<ScanPnt> input stream is not readable");
 
-    std::cout << "ScanPnt stream position is: " << src.tellg() << std::endl;
     src.read(detail::as_buffer(dest), num);
-    std::cout << "ScanPnt stream position is: " << src.tellg() << std::endl;
-
     detail::check_stream_state(src);
 
-
     // Fix little-endian
     LIBLAS_SWAP_BYTES(dest.Pnt.x);
     LIBLAS_SWAP_BYTES(dest.Pnt.y);
@@ -164,8 +160,6 @@
     LIBLAS_SWAP_BYTES(dest.Line);
     LIBLAS_SWAP_BYTES(dest.Intensity);
 
-    std::cout << "x: " << dest.Pnt.x << " y: " << dest.Pnt.y << " z: " << dest.Pnt.z <<std::endl; 
-
 }
 
 template <>
@@ -175,11 +169,7 @@
     if (!src)
         throw std::runtime_error("detail::liblas::read_n<ScanHdr> input stream is not readable");
 
-    std::cout << "ScanHdr stream position is: " << src.tellg() << std::endl;
-
     src.read(detail::as_buffer(dest), num);
-
-    std::cout << "ScanHdr stream position is: " << src.tellg() << std::endl;
     detail::check_stream_state(src);
 
     // Fix little-endian


More information about the Liblas-commits mailing list