[Liblas-commits] hg-main-tree: make the liblas iters have their own ::liblas::rea...

liblas-commits at liblas.org liblas-commits at liblas.org
Thu Mar 24 13:38:41 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/8eae0b9e7501
changeset: 424:8eae0b9e7501
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Thu Mar 24 10:04:29 2011 -0700
description:
make the liblas iters have their own ::liblas::reader objects
Subject: hg-main-tree: refactored read() into the liblasiter base

details:   http://hg.libpc.orghg-main-tree/rev/6a4624826852
changeset: 425:6a4624826852
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Thu Mar 24 10:08:53 2011 -0700
description:
refactored read() into the liblasiter base
Subject: hg-main-tree: good 4-iter test

details:   http://hg.libpc.orghg-main-tree/rev/1848afbdad4d
changeset: 426:1848afbdad4d
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Thu Mar 24 10:38:30 2011 -0700
description:
good 4-iter test

diffstat:

 include/libpc/drivers/liblas/Iterator.hpp |   43 +++-
 include/libpc/drivers/liblas/Reader.hpp   |   16 +-
 src/drivers/liblas/Iterator.cpp           |  271 +++++++++++------------------
 src/drivers/liblas/Reader.cpp             |   52 +++-
 test/unit/LiblasReaderTest.cpp            |  209 +++++++++++++++++++---
 5 files changed, 353 insertions(+), 238 deletions(-)

diffs (truncated from 924 to 300 lines):

diff -r f99d29deba24 -r 1848afbdad4d include/libpc/drivers/liblas/Iterator.hpp
--- a/include/libpc/drivers/liblas/Iterator.hpp	Thu Mar 24 09:12:53 2011 -0700
+++ b/include/libpc/drivers/liblas/Iterator.hpp	Thu Mar 24 10:38:30 2011 -0700
@@ -53,34 +53,53 @@
 class LiblasReader;
 
 
-class SequentialIterator : public libpc::SequentialIterator
+class LiblasIteratorBase
+{
+public:
+    LiblasIteratorBase(const LiblasReader& reader);
+    ~LiblasIteratorBase();
+
+protected:
+    ::liblas::Reader& getExternalReader() const;
+    const LiblasReader& getReader() const;
+    
+    boost::uint32_t readBuffer(PointBuffer& data);
+
+private:
+    const LiblasReader& m_reader;
+    std::string m_filename;
+    std::istream* m_istream;
+    ::liblas::Reader* m_externalReader;
+    
+    LiblasIteratorBase& operator=(const LiblasIteratorBase&); // not implemented
+    LiblasIteratorBase(const LiblasIteratorBase&); // not implemented};
+};
+
+
+class SequentialIterator : public LiblasIteratorBase, public libpc::SequentialIterator
 {
 public:
     SequentialIterator(const LiblasReader& reader);
     ~SequentialIterator();
 
 private:
-    boost::uint64_t skipImpl(boost::uint64_t);
-    boost::uint32_t readImpl(PointBuffer&);
+    boost::uint64_t skipImpl(boost::uint64_t count);
+    boost::uint32_t readImpl(PointBuffer& data);
     bool atEndImpl() const;
-
-    const LiblasReader& m_reader;
-    std::istream* m_istream;
 };
 
-class RandomIterator : public libpc::RandomIterator
+
+class RandomIterator : public LiblasIteratorBase, public libpc::RandomIterator
 {
 public:
     RandomIterator(const LiblasReader& reader);
     ~RandomIterator();
 
 private:
-    boost::uint64_t seekImpl(boost::uint64_t);
-    boost::uint32_t readImpl(PointBuffer&);
+    boost::uint64_t seekImpl(boost::uint64_t pos);
+    boost::uint32_t readImpl(PointBuffer& data);
+};
 
-    const LiblasReader& m_reader;
-    std::istream* m_istream;
-};
 
 } } } // namespaces
 
diff -r f99d29deba24 -r 1848afbdad4d include/libpc/drivers/liblas/Reader.hpp
--- a/include/libpc/drivers/liblas/Reader.hpp	Thu Mar 24 09:12:53 2011 -0700
+++ b/include/libpc/drivers/liblas/Reader.hpp	Thu Mar 24 10:38:30 2011 -0700
@@ -50,14 +50,9 @@
 
 namespace libpc { namespace drivers { namespace liblas {
 
-class SequentialIterator;
-class RandomIterator;
 
 class LIBPC_DLL LiblasReader : public Stage
 {
-    friend class SequentialIterator;
-    friend class RandomIterator;
-
 public:
     LiblasReader(const std::string& filename);
     ~LiblasReader();
@@ -69,6 +64,10 @@
     const LiblasHeader& getLiblasHeader() const;
 
     boost::int8_t getPointFormatNumber() const;
+    
+    bool hasTimeData() const;
+    bool hasColorData() const;
+    bool hasWaveData() const;
 
     bool supportsSequentialIterator() const { return true; }
     bool supportsRandomIterator() const { return true; }
@@ -78,13 +77,10 @@
 private:
     LiblasHeader& getLiblasHeader();
     void setLiblasHeader(const LiblasHeader&);
-    void processExternalHeader();
-    void registerFields();
+    void processExternalHeader(::liblas::Reader& externalReader);
+    void registerFields(::liblas::Reader& externalReader);
 
     std::string m_filename;
-    std::istream* m_istream;
-
-    ::liblas::Reader *m_externalReader;
 
     // LAS header properties of interest to us
     boost::uint8_t m_versionMajor;
diff -r f99d29deba24 -r 1848afbdad4d src/drivers/liblas/Iterator.cpp
--- a/src/drivers/liblas/Iterator.cpp	Thu Mar 24 09:12:53 2011 -0700
+++ b/src/drivers/liblas/Iterator.cpp	Thu Mar 24 10:38:30 2011 -0700
@@ -45,52 +45,54 @@
 namespace libpc { namespace drivers { namespace liblas {
 
 
-SequentialIterator::SequentialIterator(const LiblasReader& reader)
-    : libpc::SequentialIterator(reader)
-    , m_reader(reader)
+//---------------------------------------------------------------------------
+//
+// LiblasIteratorBase
+//
+//---------------------------------------------------------------------------
+
+
+LiblasIteratorBase::LiblasIteratorBase(const LiblasReader& reader)
+    : m_reader(reader)
+    , m_filename(reader.getFileName())
     , m_istream(NULL)
+    , m_externalReader(NULL)
 {
-    m_istream = Utils::openFile(m_reader.getFileName());
-    m_reader.m_externalReader->Reset();
+    m_istream = Utils::openFile(m_filename);
+
+    ::liblas::ReaderFactory f;
+    ::liblas::Reader extReader = f.CreateWithStream(*m_istream);
+    m_externalReader = new ::liblas::Reader(extReader);
+
     return;
 }
 
 
-SequentialIterator::~SequentialIterator()
+LiblasIteratorBase::~LiblasIteratorBase()
 {
+    delete m_externalReader;
     Utils::closeFile(m_istream);
-    return;
 }
 
 
-boost::uint64_t SequentialIterator::skipImpl(boost::uint64_t count)
+::liblas::Reader& LiblasIteratorBase::getExternalReader() const
 {
-    LiblasReader& reader = const_cast<LiblasReader&>(m_reader); // BUG BUG BUG
-
-    boost::uint64_t newPos = getIndex() + count;
-
-    size_t newPosX = (size_t)newPos;
-    reader.m_externalReader->Seek(newPosX);
-
-    return count;
+    return *m_externalReader;
 }
 
 
-
-bool SequentialIterator::atEndImpl() const
+const LiblasReader& LiblasIteratorBase::getReader() const
 {
-    return getIndex() >= getStage().getNumPoints();
+    return m_reader;
 }
 
 
-boost::uint32_t SequentialIterator::readImpl(PointBuffer& PointBuffer)
+boost::uint32_t LiblasIteratorBase::readBuffer(PointBuffer& data)
 {
-    LiblasReader& reader = const_cast<LiblasReader&>(m_reader);     // BUG BUG BUG
-
-    boost::uint32_t numPoints = PointBuffer.getCapacity();
+    boost::uint32_t numPoints = data.getCapacity();
     boost::uint32_t i = 0;
 
-    const Schema& schema = PointBuffer.getSchema();
+    const Schema& schema = data.getSchema();
 
     const int indexX = schema.getDimensionIndex(Dimension::Field_X);
     const int indexY = schema.getDimensionIndex(Dimension::Field_Y);
@@ -106,11 +108,11 @@
     const int indexUserData = schema.getDimensionIndex(Dimension::Field_UserData);
     const int indexPointSourceId = schema.getDimensionIndex(Dimension::Field_PointSourceId);
     
-    const int indexTime = (reader.m_hasTimeData ? schema.getDimensionIndex(Dimension::Field_Time) : 0);
+    const int indexTime = (getReader().hasTimeData() ? schema.getDimensionIndex(Dimension::Field_Time) : 0);
 
-    const int indexRed = (reader.m_hasColorData ? schema.getDimensionIndex(Dimension::Field_Red) : 0);
-    const int indexGreen = (reader.m_hasColorData ? schema.getDimensionIndex(Dimension::Field_Green) : 0);
-    const int indexBlue = (reader.m_hasColorData ? schema.getDimensionIndex(Dimension::Field_Blue) : 0);
+    const int indexRed = (getReader().hasColorData() ? schema.getDimensionIndex(Dimension::Field_Red) : 0);
+    const int indexGreen = (getReader().hasColorData() ? schema.getDimensionIndex(Dimension::Field_Green) : 0);
+    const int indexBlue = (getReader().hasColorData() ? schema.getDimensionIndex(Dimension::Field_Blue) : 0);
 
     //const int indexWavePacketDescriptorIndex = (m_hasWaveData ? schema.getDimensionIndex(Dimension::Field_WavePacketDescriptorIndex) : 0);
     //const int indexWaveformDataOffset = (m_hasWaveData ? schema.getDimensionIndex(Dimension::Field_WaveformDataOffset) : 0);
@@ -121,13 +123,13 @@
 
     for (i=0; i<numPoints; i++)
     {
-        bool ok = reader.m_externalReader->ReadNextPoint();
+        bool ok = getExternalReader().ReadNextPoint();
         if (!ok)
         {
             throw libpc_error("liblas reader failed to retrieve point");
         }
 
-        const ::liblas::Point& pt = reader.m_externalReader->GetPoint();
+        const ::liblas::Point& pt = getExternalReader().GetPoint();
 
         const boost::int32_t x = pt.GetRawX();
         const boost::int32_t y = pt.GetRawY();
@@ -143,41 +145,41 @@
         const boost::uint8_t userData = pt.GetUserData();
         const boost::uint16_t pointSourceId = pt.GetPointSourceID();
         
-        PointBuffer.setField(i, indexX, x);
-        PointBuffer.setField(i, indexY, y);
-        PointBuffer.setField(i, indexZ, z);
+        data.setField(i, indexX, x);
+        data.setField(i, indexY, y);
+        data.setField(i, indexZ, z);
 
-        PointBuffer.setField(i, indexIntensity, intensity);
-        PointBuffer.setField(i, indexReturnNumber, returnNumber);
-        PointBuffer.setField(i, indexNumberOfReturns, numberOfReturns);
-        PointBuffer.setField(i, indexScanDirectionFlag, scanDirFlag);
-        PointBuffer.setField(i, indexEdgeOfFlightLine, edgeOfFlightLine);
-        PointBuffer.setField(i, indexClassification, classification);
-        PointBuffer.setField(i, indexScanAngleRank, scanAngleRank);
-        PointBuffer.setField(i, indexUserData, userData);
-        PointBuffer.setField(i, indexPointSourceId, pointSourceId);
+        data.setField(i, indexIntensity, intensity);
+        data.setField(i, indexReturnNumber, returnNumber);
+        data.setField(i, indexNumberOfReturns, numberOfReturns);
+        data.setField(i, indexScanDirectionFlag, scanDirFlag);
+        data.setField(i, indexEdgeOfFlightLine, edgeOfFlightLine);
+        data.setField(i, indexClassification, classification);
+        data.setField(i, indexScanAngleRank, scanAngleRank);
+        data.setField(i, indexUserData, userData);
+        data.setField(i, indexPointSourceId, pointSourceId);
 
-        if (reader.m_hasTimeData)
+        if (getReader().hasTimeData())
         {
             const double time = pt.GetTime();
             
-            PointBuffer.setField(i, indexTime, time);
+            data.setField(i, indexTime, time);
         }
 
-        if (reader.m_hasColorData)
+        if (getReader().hasColorData())
         {
             const ::liblas::Color color = pt.GetColor();
             const boost::uint16_t red = color.GetRed();
             const boost::uint16_t green = color.GetGreen();
             const boost::uint16_t blue = color.GetBlue();
 
-            PointBuffer.setField(i, indexRed, red);
-            PointBuffer.setField(i, indexGreen, green);
-            PointBuffer.setField(i, indexBlue, blue);
+            data.setField(i, indexRed, red);
+            data.setField(i, indexGreen, green);
+            data.setField(i, indexBlue, blue);
         }
         
-        PointBuffer.setNumPoints(i+1);
-        if (reader.m_hasWaveData)
+        data.setNumPoints(i+1);
+        if (getReader().hasWaveData())
         {
             throw not_yet_implemented("Waveform data (types 4 and 5) not supported");
         }
@@ -188,139 +190,82 @@
 }
 
 
+//---------------------------------------------------------------------------
+//
+// SequentialIterator
+//
+//---------------------------------------------------------------------------
 


More information about the Liblas-commits mailing list