[Liblas-commits] hg-main-tree: refactor for const-correctness and to unfriend the...

liblas-commits at liblas.org liblas-commits at liblas.org
Wed Mar 23 14:03:27 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/3dcaaec431bb
changeset: 411:3dcaaec431bb
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Wed Mar 23 11:03:19 2011 -0700
description:
refactor for const-correctness and to unfriend the Iter

diffstat:

 include/libpc/drivers/las/Reader.hpp |   11 +-
 src/drivers/las/Iterator.cpp         |  164 +----------------------------------
 src/drivers/las/Reader.cpp           |  165 ++++++++++++++++++++++++++++++++++-
 3 files changed, 171 insertions(+), 169 deletions(-)

diffs (truncated from 388 to 300 lines):

diff -r 55dde853abae -r 3dcaaec431bb include/libpc/drivers/las/Reader.hpp
--- a/include/libpc/drivers/las/Reader.hpp	Wed Mar 23 10:54:26 2011 -0700
+++ b/include/libpc/drivers/las/Reader.hpp	Wed Mar 23 11:03:19 2011 -0700
@@ -43,12 +43,8 @@
 
 namespace libpc { namespace drivers { namespace las {
 
-class Iterator;
-
 class LIBPC_DLL LasReader : public Stage
 {
-    friend class Iterator;
-
 public:
     LasReader(std::istream&);
 
@@ -58,12 +54,15 @@
 
     libpc::Iterator* createIterator() const;
 
+    // this is called by the stage's iterator
+    boost::uint32_t processBuffer(PointBuffer& PointBuffer, std::istream& stream) const;
+
+    std::istream& m_istream; // BUG BUG BUG
+
 protected:
     LasHeader& getLasHeader();
     void setLasHeader(const LasHeader&);
 
-    std::istream& m_istream;
-
 private:
     LasReader& operator=(const LasReader&); // not implemented
     LasReader(const LasReader&); // not implemented
diff -r 55dde853abae -r 3dcaaec431bb src/drivers/las/Iterator.cpp
--- a/src/drivers/las/Iterator.cpp	Wed Mar 23 10:54:26 2011 -0700
+++ b/src/drivers/las/Iterator.cpp	Wed Mar 23 11:03:19 2011 -0700
@@ -70,169 +70,9 @@
 }
 
 
-boost::uint32_t Iterator::readImpl(PointBuffer& PointBuffer)
+boost::uint32_t Iterator::readImpl(PointBuffer& data)
 {
-    LasReader& reader = const_cast<LasReader&>(m_reader);       // BUG BUG BUG
-
-    boost::uint32_t numPoints = PointBuffer.getCapacity();
-
-    const LasHeader& lasHeader = reader.getLasHeader();
-    const SchemaLayout& schemaLayout = PointBuffer.getSchemaLayout();
-    const Schema& schema = schemaLayout.getSchema();
-    LasHeader::PointFormatId pointFormat = lasHeader.getDataFormatId();
-
-    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_Time) : 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++)
-    {
-        boost::uint8_t buf[34];
-
-        if (pointFormat == LasHeader::ePointFormat0)
-        {
-            Utils::read_n(buf, reader.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;
-
-            PointBuffer.setField<boost::uint32_t>(pointIndex, fieldIndexX, x);
-            PointBuffer.setField<boost::uint32_t>(pointIndex, fieldIndexY, y);
-            PointBuffer.setField<boost::uint32_t>(pointIndex, fieldIndexZ, z);
-            PointBuffer.setField<boost::uint16_t>(pointIndex, fieldIndexIntensity, intensity);
-            PointBuffer.setField<boost::uint8_t>(pointIndex, fieldIndexReturnNum, returnNum);
-            PointBuffer.setField<boost::uint8_t>(pointIndex, fieldIndexNumReturns, numReturns);
-            PointBuffer.setField<boost::uint8_t>(pointIndex, fieldIndexScanDir, scanDirFlag);
-            PointBuffer.setField<boost::uint8_t>(pointIndex, fieldIndexFlight, flight);
-            PointBuffer.setField<boost::uint8_t>(pointIndex, fieldIndexClassification, classification);
-            PointBuffer.setField<boost::int8_t>(pointIndex, fieldIndexScanAngle, scanAngleRank);
-            PointBuffer.setField<boost::uint8_t>(pointIndex, fieldIndexUserData, user);
-            PointBuffer.setField<boost::uint16_t>(pointIndex, fieldIndexPointSource, pointSourceId);
-
-        }
-        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)
-        {
-            Utils::read_n(buf, reader.m_istream, LasHeader::ePointSize3);
-
-            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 double time = Utils::read_field<double>(p);
-            const boost::uint16_t red = Utils::read_field<boost::uint16_t>(p);
-            const boost::uint16_t green = Utils::read_field<boost::uint16_t>(p);
-            const boost::uint16_t blue = 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;
-
-            PointBuffer.setField<boost::uint32_t>(pointIndex, fieldIndexX, x);
-            PointBuffer.setField<boost::uint32_t>(pointIndex, fieldIndexY, y);
-            PointBuffer.setField<boost::uint32_t>(pointIndex, fieldIndexZ, z);
-            PointBuffer.setField<boost::uint16_t>(pointIndex, fieldIndexIntensity, intensity);
-            PointBuffer.setField<boost::uint8_t>(pointIndex, fieldIndexReturnNum, returnNum);
-            PointBuffer.setField<boost::uint8_t>(pointIndex, fieldIndexNumReturns, numReturns);
-            PointBuffer.setField<boost::uint8_t>(pointIndex, fieldIndexScanDir, scanDirFlag);
-            PointBuffer.setField<boost::uint8_t>(pointIndex, fieldIndexFlight, flight);
-            PointBuffer.setField<boost::uint8_t>(pointIndex, fieldIndexClassification, classification);
-            PointBuffer.setField<boost::int8_t>(pointIndex, fieldIndexScanAngle, scanAngleRank);
-            PointBuffer.setField<boost::uint8_t>(pointIndex, fieldIndexUserData, user);
-            PointBuffer.setField<boost::uint16_t>(pointIndex, fieldIndexPointSource, pointSourceId);
-            PointBuffer.setField<double>(pointIndex, fieldIndexTime, time);
-            PointBuffer.setField<boost::uint16_t>(pointIndex, fieldIndexRed, red);
-            PointBuffer.setField<boost::uint16_t>(pointIndex, fieldIndexGreen, green);
-            PointBuffer.setField<boost::uint16_t>(pointIndex, fieldIndexBlue, blue);
-            
-        }
-        
-        else
-        {
-            throw;
-        }
-        PointBuffer.setNumPoints(pointIndex+1);
-        
-    }
-
-    return numPoints;
+    return m_reader.processBuffer(data, m_reader.m_istream);
 }
 
 
diff -r 55dde853abae -r 3dcaaec431bb src/drivers/las/Reader.cpp
--- a/src/drivers/las/Reader.cpp	Wed Mar 23 10:54:26 2011 -0700
+++ b/src/drivers/las/Reader.cpp	Wed Mar 23 11:03:19 2011 -0700
@@ -74,11 +74,174 @@
 }
 
 
-
 libpc::Iterator* LasReader::createIterator() const
 {
     return new Iterator(*this);
 }
 
 
+boost::uint32_t LasReader::processBuffer(PointBuffer& data, std::istream& stream) const
+{
+    boost::uint32_t numPoints = data.getCapacity();
+
+    const LasHeader& lasHeader = getLasHeader();
+    const SchemaLayout& schemaLayout = data.getSchemaLayout();
+    const Schema& schema = schemaLayout.getSchema();
+    LasHeader::PointFormatId pointFormat = lasHeader.getDataFormatId();
+
+    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_Time) : 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++)
+    {
+        boost::uint8_t buf[34];
+
+        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);


More information about the Liblas-commits mailing list