[Liblas-commits] libpc: more coding

liblas-commits at liblas.org liblas-commits at liblas.org
Tue Mar 1 19:22:14 EST 2011


details:   http://hg.liblas.orglibpc/rev/40b899f547f6
changeset: 152:40b899f547f6
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Tue Mar 01 16:10:45 2011 -0800
description:
more coding
Subject: libpc: added -native

details:   http://hg.liblas.orglibpc/rev/a29f4d126312
changeset: 153:a29f4d126312
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Tue Mar 01 16:21:54 2011 -0800
description:
added -native

diffstat:

 apps/pc2pc.cpp    |   30 ++++++++++++---
 src/LasReader.cpp |  101 ++++++++++++++++++++++++++++++++++++++++++++---------
 src/LasWriter.cpp |  102 +++++++++++++++++++++++++++++++++++++++++++----------
 3 files changed, 191 insertions(+), 42 deletions(-)

diffs (truncated from 340 to 300 lines):

diff -r 54c7bc3e6e05 -r a29f4d126312 apps/pc2pc.cpp
--- a/apps/pc2pc.cpp	Tue Mar 01 15:33:58 2011 -0800
+++ b/apps/pc2pc.cpp	Tue Mar 01 16:21:54 2011 -0800
@@ -23,9 +23,9 @@
 //#include "libpc/MosaicFilter.hpp"
 //#include "libpc/FauxReader.hpp"
 //#include "libpc/FauxWriter.hpp"
-//#include "libpc/LasReader.hpp"
+#include "libpc/LasReader.hpp"
 //#include "libpc/LasHeader.hpp"
-//#include "libpc/LasWriter.hpp"
+#include "libpc/LasWriter.hpp"
 
 #include "libpc/../../src/drivers/liblas/writer.hpp"
 #include "libpc/../../src/drivers/liblas/reader.hpp"
@@ -83,6 +83,7 @@
     file_options->add_options()
         ("input,i", po::value<std::string>(&m_inputFile), "input file name")
         ("output,o", po::value<std::string>(&m_outputFile), "output file name")
+        ("native", "use native LAS classes (not liblas)")
         ;
 
     addOptionSet(file_options);
@@ -97,13 +98,30 @@
     }
 
     std::istream* ifs = Utils::openFile(m_inputFile);
-    LiblasReader reader(*ifs);
+    std::ostream* ofs = Utils::createFile(m_outputFile);
+
+    if (hasOption("native"))
+    {
+        LasReader reader(*ifs);
     
-    std::ostream* ofs = Utils::createFile(m_outputFile);
-    {
         const boost::uint64_t numPoints = reader.getHeader().getNumPoints();
 
-        // need to scope the writer, so that's it dtor can use the stream
+        LasWriter writer(reader, *ofs);
+
+        //BUG: handle laz writer.setCompressed(false);
+
+        //writer.setPointFormat( reader.getPointFormatNumber() );
+
+        size_t np = (size_t)numPoints;
+        assert(numPoints == np); // BUG
+        writer.write(np);
+    }
+    else
+    {
+        LiblasReader reader(*ifs);
+    
+        const boost::uint64_t numPoints = reader.getHeader().getNumPoints();
+
         LiblasWriter writer(reader, *ofs);
 
         //BUG: handle laz writer.setCompressed(false);
diff -r 54c7bc3e6e05 -r a29f4d126312 src/LasReader.cpp
--- a/src/LasReader.cpp	Tue Mar 01 15:33:58 2011 -0800
+++ b/src/LasReader.cpp	Tue Mar 01 16:21:54 2011 -0800
@@ -34,6 +34,7 @@
 
 #include "libpc/LasReader.hpp"
 #include "libpc/LasHeaderReader.hpp"
+#include "libpc/exceptions.hpp"
 
 namespace libpc
 {
@@ -49,7 +50,6 @@
     LasHeaderReader lasHeaderReader(*lasHeader, istream);
     lasHeaderReader.read();
 
-
     return;
 }
 
@@ -103,22 +103,55 @@
     const Schema& schema = schemaLayout.getSchema();
     LasHeader::PointFormatId pointFormat = lasHeader.getDataFormatId();
 
-    const std::size_t fieldIndexX = schema.getDimensionIndex(Dimension::Field_X);
-    const std::size_t fieldIndexY = schema.getDimensionIndex(Dimension::Field_Y);
-    const std::size_t fieldIndexZ = schema.getDimensionIndex(Dimension::Field_Z);
-    const std::size_t fieldIndexIntensity = schema.getDimensionIndex(Dimension::Field_Intensity);
-    const std::size_t fieldIndexReturnNum = schema.getDimensionIndex(Dimension::Field_ReturnNumber);
-    const std::size_t fieldIndexNumReturns = schema.getDimensionIndex(Dimension::Field_NumberOfReturns);
-    const std::size_t fieldIndexScanDir = schema.getDimensionIndex(Dimension::Field_ScanDirectionFlag);
-    const std::size_t fieldIndexFlight = schema.getDimensionIndex(Dimension::Field_EdgeOfFlightLine);
-    const std::size_t fieldIndexClassification = schema.getDimensionIndex(Dimension::Field_Classification);
-    const std::size_t fieldIndexScanAngle = schema.getDimensionIndex(Dimension::Field_ScanAngleRank);
-    const std::size_t fieldIndexUserData = schema.getDimensionIndex(Dimension::Field_UserData);
-    const std::size_t fieldIndexPointSource = schema.getDimensionIndex(Dimension::Field_PointSourceId);
-    const std::size_t fieldIndexTime = schema.getDimensionIndex(Dimension::Field_GpsTime);
-    const std::size_t fieldIndexRed = schema.getDimensionIndex(Dimension::Field_Red);
-    const std::size_t fieldIndexGreen = schema.getDimensionIndex(Dimension::Field_Green);
-    const std::size_t fieldIndexBlue = schema.getDimensionIndex(Dimension::Field_Blue);
+    bool hasTimeData = false;
+    bool hasColorData = false;
+    bool hasWaveData = false;
+    switch (pointFormat)
+    {
+    case LasHeader::ePointFormat0:
+        break;
+    case LasHeader::ePointFormat1:
+        hasTimeData = true;
+        break;
+    case LasHeader::ePointFormat2:
+        hasColorData = true;
+        break;
+    case LasHeader::ePointFormat3:
+        hasTimeData = true;
+        hasColorData = true;
+        break;
+    case LasHeader::ePointFormat4:
+        hasTimeData = true;
+        hasWaveData = true;
+        break;
+    case LasHeader::ePointFormat5:
+        hasColorData = true;
+        hasTimeData = true;
+        hasWaveData = true;
+        break;
+    case LasHeader::ePointFormatUnknown:
+        throw not_yet_implemented("Unknown point format encountered");
+    }
+
+    const int fieldIndexX = schema.getDimensionIndex(Dimension::Field_X);
+    const int fieldIndexY = schema.getDimensionIndex(Dimension::Field_Y);
+    const int fieldIndexZ = schema.getDimensionIndex(Dimension::Field_Z);
+    
+    const int fieldIndexIntensity = schema.getDimensionIndex(Dimension::Field_Intensity);
+    const int fieldIndexReturnNum = schema.getDimensionIndex(Dimension::Field_ReturnNumber);
+    const int fieldIndexNumReturns = schema.getDimensionIndex(Dimension::Field_NumberOfReturns);
+    const int fieldIndexScanDir = schema.getDimensionIndex(Dimension::Field_ScanDirectionFlag);
+    const int fieldIndexFlight = schema.getDimensionIndex(Dimension::Field_EdgeOfFlightLine);
+    const int fieldIndexClassification = schema.getDimensionIndex(Dimension::Field_Classification);
+    const int fieldIndexScanAngle = schema.getDimensionIndex(Dimension::Field_ScanAngleRank);
+    const int fieldIndexUserData = schema.getDimensionIndex(Dimension::Field_UserData);
+    const int fieldIndexPointSource = schema.getDimensionIndex(Dimension::Field_PointSourceId);
+
+    const int fieldIndexTime = (hasTimeData ? schema.getDimensionIndex(Dimension::Field_GpsTime) : 0);
+
+    const int fieldIndexRed = (hasColorData ? schema.getDimensionIndex(Dimension::Field_Red) : 0);
+    const int fieldIndexGreen = (hasColorData ? schema.getDimensionIndex(Dimension::Field_Green) : 0);
+    const int fieldIndexBlue = (hasColorData ? schema.getDimensionIndex(Dimension::Field_Blue) : 0);
 
     for (boost::uint32_t pointIndex=0; pointIndex<numPoints; pointIndex++)
     {
@@ -127,13 +160,47 @@
         if (pointFormat == LasHeader::ePointFormat0)
         {
             Utils::read_n(buf, m_istream, LasHeader::ePointSize0);
+
+            boost::uint8_t* p = buf;
+
+            const boost::uint32_t x = Utils::read_field<boost::uint32_t>(p);
+            const boost::uint32_t y = Utils::read_field<boost::uint32_t>(p);
+            const boost::uint32_t z = Utils::read_field<boost::uint32_t>(p);
+            const boost::uint16_t intensity = Utils::read_field<boost::uint16_t>(p);
+            const boost::uint8_t flags = Utils::read_field<boost::uint8_t>(p);
+            const boost::uint8_t classification = Utils::read_field<boost::uint8_t>(p);
+            const boost::int8_t scanAngleRank = Utils::read_field<boost::int8_t>(p);
+            const boost::uint8_t user = Utils::read_field<boost::uint8_t>(p);
+            const boost::uint16_t pointSourceId = Utils::read_field<boost::uint16_t>(p);
+
+            const boost::uint8_t returnNum = flags & 0x03;
+            const boost::uint8_t numReturns = (flags >> 3) & 0x03;
+            const boost::uint8_t scanDirFlag = (flags >> 6) & 0x01;
+            const boost::uint8_t flight = (flags >> 7) & 0x01;
+
+            pointData.setField<boost::uint32_t>(pointIndex, fieldIndexX, x);
+            pointData.setField<boost::uint32_t>(pointIndex, fieldIndexY, y);
+            pointData.setField<boost::uint32_t>(pointIndex, fieldIndexZ, z);
+            pointData.setField<boost::uint16_t>(pointIndex, fieldIndexIntensity, intensity);
+            pointData.setField<boost::uint8_t>(pointIndex, fieldIndexReturnNum, returnNum);
+            pointData.setField<boost::uint8_t>(pointIndex, fieldIndexNumReturns, numReturns);
+            pointData.setField<boost::uint8_t>(pointIndex, fieldIndexScanDir, scanDirFlag);
+            pointData.setField<boost::uint8_t>(pointIndex, fieldIndexFlight, flight);
+            pointData.setField<boost::uint8_t>(pointIndex, fieldIndexClassification, classification);
+            pointData.setField<boost::int8_t>(pointIndex, fieldIndexScanAngle, scanAngleRank);
+            pointData.setField<boost::uint8_t>(pointIndex, fieldIndexUserData, user);
+            pointData.setField<boost::uint16_t>(pointIndex, fieldIndexPointSource, pointSourceId);
+
+            pointData.setValid(pointIndex);
         }
         else if (pointFormat == LasHeader::ePointFormat1)
         {
+            throw;
             Utils::read_n(buf, m_istream, LasHeader::ePointSize1);
         }
         else if (pointFormat == LasHeader::ePointFormat2)
         {
+            throw;
             Utils::read_n(buf, m_istream, LasHeader::ePointSize2);
         }
         else if (pointFormat == LasHeader::ePointFormat3)
diff -r 54c7bc3e6e05 -r a29f4d126312 src/LasWriter.cpp
--- a/src/LasWriter.cpp	Tue Mar 01 15:33:58 2011 -0800
+++ b/src/LasWriter.cpp	Tue Mar 01 16:21:54 2011 -0800
@@ -36,6 +36,7 @@
 
 #include "libpc/LasWriter.hpp"
 #include "libpc/LasHeaderWriter.hpp"
+#include "libpc/exceptions.hpp"
 
 namespace libpc
 {
@@ -94,41 +95,105 @@
     const Schema& schema = schemaLayout.getSchema();
     LasHeader::PointFormatId pointFormat = lasHeader.getDataFormatId();
 
-    const std::size_t fieldIndexX = schema.getDimensionIndex(Dimension::Field_X);
-    const std::size_t fieldIndexY = schema.getDimensionIndex(Dimension::Field_Y);
-    const std::size_t fieldIndexZ = schema.getDimensionIndex(Dimension::Field_Z);
-    const std::size_t fieldIndexIntensity = schema.getDimensionIndex(Dimension::Field_Intensity);
-    const std::size_t fieldIndexReturnNum = schema.getDimensionIndex(Dimension::Field_ReturnNumber);
-    const std::size_t fieldIndexNumReturns = schema.getDimensionIndex(Dimension::Field_NumberOfReturns);
-    const std::size_t fieldIndexScanDir = schema.getDimensionIndex(Dimension::Field_ScanDirectionFlag);
-    const std::size_t fieldIndexFlight = schema.getDimensionIndex(Dimension::Field_EdgeOfFlightLine);
-    const std::size_t fieldIndexClassification = schema.getDimensionIndex(Dimension::Field_Classification);
-    const std::size_t fieldIndexScanAngle = schema.getDimensionIndex(Dimension::Field_ScanAngleRank);
-    const std::size_t fieldIndexUserData = schema.getDimensionIndex(Dimension::Field_UserData);
-    const std::size_t fieldIndexPointSource = schema.getDimensionIndex(Dimension::Field_PointSourceId);
-    const std::size_t fieldIndexTime = schema.getDimensionIndex(Dimension::Field_GpsTime);
-    const std::size_t fieldIndexRed = schema.getDimensionIndex(Dimension::Field_Red);
-    const std::size_t fieldIndexGreen = schema.getDimensionIndex(Dimension::Field_Green);
-    const std::size_t fieldIndexBlue = schema.getDimensionIndex(Dimension::Field_Blue);
+    bool hasTimeData = false;
+    bool hasColorData = false;
+    bool hasWaveData = false;
+    switch (pointFormat)
+    {
+    case LasHeader::ePointFormat0:
+        break;
+    case LasHeader::ePointFormat1:
+        hasTimeData = true;
+        break;
+    case LasHeader::ePointFormat2:
+        hasColorData = true;
+        break;
+    case LasHeader::ePointFormat3:
+        hasTimeData = true;
+        hasColorData = true;
+        break;
+    case LasHeader::ePointFormat4:
+        hasTimeData = true;
+        hasWaveData = true;
+        break;
+    case LasHeader::ePointFormat5:
+        hasColorData = true;
+        hasTimeData = true;
+        hasWaveData = true;
+        break;
+    case LasHeader::ePointFormatUnknown:
+        throw not_yet_implemented("Unknown point format encountered");
+    }
+
+    const int fieldIndexX = schema.getDimensionIndex(Dimension::Field_X);
+    const int fieldIndexY = schema.getDimensionIndex(Dimension::Field_Y);
+    const int fieldIndexZ = schema.getDimensionIndex(Dimension::Field_Z);
+    
+    const int fieldIndexIntensity = schema.getDimensionIndex(Dimension::Field_Intensity);
+    const int fieldIndexReturnNum = schema.getDimensionIndex(Dimension::Field_ReturnNumber);
+    const int fieldIndexNumReturns = schema.getDimensionIndex(Dimension::Field_NumberOfReturns);
+    const int fieldIndexScanDir = schema.getDimensionIndex(Dimension::Field_ScanDirectionFlag);
+    const int fieldIndexFlight = schema.getDimensionIndex(Dimension::Field_EdgeOfFlightLine);
+    const int fieldIndexClassification = schema.getDimensionIndex(Dimension::Field_Classification);
+    const int fieldIndexScanAngle = schema.getDimensionIndex(Dimension::Field_ScanAngleRank);
+    const int fieldIndexUserData = schema.getDimensionIndex(Dimension::Field_UserData);
+    const int fieldIndexPointSource = schema.getDimensionIndex(Dimension::Field_PointSourceId);
+    
+    const int fieldIndexTime = (hasTimeData ? schema.getDimensionIndex(Dimension::Field_GpsTime) : 0);
+    
+    const int fieldIndexRed = (hasColorData ? schema.getDimensionIndex(Dimension::Field_Red) : 0);
+    const int fieldIndexGreen = (hasColorData ? schema.getDimensionIndex(Dimension::Field_Green) : 0);
+    const int fieldIndexBlue = (hasColorData ? schema.getDimensionIndex(Dimension::Field_Blue) : 0);
 
     boost::uint32_t numValidPoints = 0;
 
+    boost::uint8_t buf[1024]; // BUG: fixed size
+
     for (boost::uint32_t pointIndex=0; pointIndex<pointData.getNumPoints(); pointIndex++)
     {
         if (pointData.isValid(pointIndex) == false) continue;
 
-        boost::uint8_t buf[100]; // BUG: fixed size
-
         if (pointFormat == LasHeader::ePointFormat0)
         {
+            boost::uint8_t* p = buf;
+
+            const boost::uint32_t x = pointData.getField<boost::uint32_t>(pointIndex, fieldIndexX);
+            const boost::uint32_t y = pointData.getField<boost::uint32_t>(pointIndex, fieldIndexY);
+            const boost::uint32_t z = pointData.getField<boost::uint32_t>(pointIndex, fieldIndexZ);
+            const boost::uint16_t intensity = pointData.getField<boost::uint16_t>(pointIndex, fieldIndexIntensity);
+            
+            const boost::uint8_t returnNum = pointData.getField<boost::uint8_t>(pointIndex, fieldIndexReturnNum);
+            const boost::uint8_t numReturns = pointData.getField<boost::uint8_t>(pointIndex, fieldIndexNumReturns);
+            const boost::uint8_t scanDirFlag = pointData.getField<boost::uint8_t>(pointIndex, fieldIndexScanDir);


More information about the Liblas-commits mailing list