[Liblas-commits] hg-main-tree: now passing useful params to writeBegin/End; fixed...

liblas-commits at liblas.org liblas-commits at liblas.org
Tue Aug 2 20:17:54 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/a6cfc29e0c28
changeset: 999:a6cfc29e0c28
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Tue Aug 02 17:17:46 2011 -0700
description:
now passing useful params to writeBegin/End; fixed main write code to only have one loop now (w00t)

diffstat:

 include/pdal/Writer.hpp                |   14 +--
 include/pdal/drivers/faux/Writer.hpp   |    4 +-
 include/pdal/drivers/las/Writer.hpp    |    9 +--
 include/pdal/drivers/liblas/Writer.hpp |    9 +--
 include/pdal/drivers/oci/Writer.hpp    |    9 +--
 src/Writer.cpp                         |  107 ++++++++++++--------------------
 src/drivers/faux/Writer.cpp            |   12 +-
 src/drivers/las/Writer.cpp             |    6 +-
 src/drivers/liblas/Writer.cpp          |    4 +-
 src/drivers/oci/Writer.cpp             |    4 +-
 10 files changed, 67 insertions(+), 111 deletions(-)

diffs (truncated from 372 to 300 lines):

diff -r 74075102dd6e -r a6cfc29e0c28 include/pdal/Writer.hpp
--- a/include/pdal/Writer.hpp	Tue Aug 02 16:48:13 2011 -0700
+++ b/include/pdal/Writer.hpp	Tue Aug 02 17:17:46 2011 -0700
@@ -70,25 +70,23 @@
     const Stage& getPrevStage() const;
 
 protected:
-    // this is called once before the loop with the writeBuffer calls
-    virtual void writeBegin() = 0;
+    // this is called once before the loop with all the writeBuffer calls
+    virtual void writeBegin(boost::uint64_t targetNumPointsToWrite) = 0;
 
+    // this is called before each writeBuffer call
     virtual void writeBufferBegin(const PointBuffer&) {}
 
     // called repeatedly, until out of data
     virtual boost::uint32_t writeBuffer(const PointBuffer&) = 0;
 
+    // this is called after each writeBuffer call
     virtual void writeBufferEnd(const PointBuffer&) {}
 
-    // called once, after the writeBuffer calls
-    virtual void writeEnd() = 0;
+    // called once, after all the the writeBuffer calls
+    virtual void writeEnd(boost::uint64_t actualNumPointsWritten) = 0;
 
     Stage& getPrevStage();
 
-    // these two are valid for use after writeBegin has been called
-    boost::uint64_t m_actualNumPointsWritten;
-    boost::uint64_t m_targetNumPointsToWrite;
-
 private:
     Stage& m_prevStage;
     boost::uint32_t m_chunkSize;
diff -r 74075102dd6e -r a6cfc29e0c28 include/pdal/drivers/faux/Writer.hpp
--- a/include/pdal/drivers/faux/Writer.hpp	Tue Aug 02 16:48:13 2011 -0700
+++ b/include/pdal/drivers/faux/Writer.hpp	Tue Aug 02 17:17:46 2011 -0700
@@ -80,9 +80,9 @@
     double m_averageY;
     double m_averageZ;
 
-    void writeBegin();
+    void writeBegin(boost::uint64_t targetNumPointsToWrite);
     boost::uint32_t writeBuffer(const PointBuffer&);
-    void writeEnd();
+    void writeEnd(boost::uint64_t actualNumPointsWritten);
 
     Writer& operator=(const Writer&); // not implemented
     Writer(const Writer&); // not implemented
diff -r 74075102dd6e -r a6cfc29e0c28 include/pdal/drivers/las/Writer.hpp
--- a/include/pdal/drivers/las/Writer.hpp	Tue Aug 02 16:48:13 2011 -0700
+++ b/include/pdal/drivers/las/Writer.hpp	Tue Aug 02 17:17:46 2011 -0700
@@ -80,14 +80,9 @@
     void setSpatialReference(const SpatialReference&);
 
 protected:
-    // this is called once before the loop with the writeBuffer calls
-    virtual void writeBegin();
-
-    // called repeatedly, until out of data
+    virtual void writeBegin(boost::uint64_t targetNumPointsToWrite);
     virtual boost::uint32_t writeBuffer(const PointBuffer&);
-
-    // called once, after the writeBuffer calls
-    virtual void writeEnd();
+    virtual void writeEnd(boost::uint64_t actualNumPointsWritten);
 
 private:
     OStreamManager m_streamManager;
diff -r 74075102dd6e -r a6cfc29e0c28 include/pdal/drivers/liblas/Writer.hpp
--- a/include/pdal/drivers/liblas/Writer.hpp	Tue Aug 02 16:48:13 2011 -0700
+++ b/include/pdal/drivers/liblas/Writer.hpp	Tue Aug 02 17:17:46 2011 -0700
@@ -78,14 +78,9 @@
     void setCompressed(bool);
 
 protected:
-    // this is called once before the loop with the writeBuffer calls
-    virtual void writeBegin();
-
-    // called repeatedly, until out of data
+    virtual void writeBegin(boost::uint64_t targetNumPointsToWrite);
     virtual boost::uint32_t writeBuffer(const PointBuffer&);
-
-    // called once, after the writeBuffer calls
-    virtual void writeEnd();
+    virtual void writeEnd(boost::uint64_t actualNumPointsWritten);
 
 private:
     void setupExternalHeader();
diff -r 74075102dd6e -r a6cfc29e0c28 include/pdal/drivers/oci/Writer.hpp
--- a/include/pdal/drivers/oci/Writer.hpp	Tue Aug 02 16:48:13 2011 -0700
+++ b/include/pdal/drivers/oci/Writer.hpp	Tue Aug 02 17:17:46 2011 -0700
@@ -66,14 +66,9 @@
 
 
 protected:
-    // this is called once before the loop with the writeBuffer calls
-    virtual void writeBegin();
-
-    // called repeatedly, until out of data
+    virtual void writeBegin(boost::uint64_t targetNumPointsToWrite);
     virtual boost::uint32_t writeBuffer(const PointBuffer&);
-
-    // called once, after the writeBuffer calls
-    virtual void writeEnd();
+    virtual void writeEnd(boost::uint64_t actualNumPointsWritten);
 
 private:
 
diff -r 74075102dd6e -r a6cfc29e0c28 src/Writer.cpp
--- a/src/Writer.cpp	Tue Aug 02 16:48:13 2011 -0700
+++ b/src/Writer.cpp	Tue Aug 02 17:17:46 2011 -0700
@@ -53,11 +53,8 @@
 
 Writer::Writer(Stage& prevStage, const Options& options)
     : StageBase(options)
-    , m_actualNumPointsWritten(0)
-    , m_targetNumPointsToWrite(0)
     , m_prevStage(prevStage)
     , m_chunkSize(s_defaultChunkSize)
-
 {
     return;
 }
@@ -104,63 +101,32 @@
         throw pdal_error("stage not initialized");
     }
 
-    m_targetNumPointsToWrite = targetNumPointsToWrite;
-    m_actualNumPointsWritten = 0;
+    boost::uint64_t actualNumPointsWritten = 0;
          
     boost::scoped_ptr<StageSequentialIterator> iter(m_prevStage.createSequentialIterator());
     
     if (!iter) throw pdal_error("Unable to obtain iterator from previous stage!");
 
-    writeBegin();
+    writeBegin(targetNumPointsToWrite);
 
     iter->readBegin();
 
-    if (m_targetNumPointsToWrite == 0)
+    PointBuffer buffer(m_prevStage.getSchema(), m_chunkSize);
+
+    //
+    // The user has requested a specific number of points: proceed a 
+    // chunk at a time until we reach that number.  (If that number 
+    // is 0, we proceed until no more points can be read.)
+    //
+    while (true)
     {
-        //
-        // user has requested 0 points, which means "as many as is available":
-        // proceed a chunk at a time until we reach the end
-        //
-        PointBuffer buffer(m_prevStage.getSchema(), m_chunkSize);
+        // have we hit the end already?
+        if (iter->atEnd()) break;
 
-        while (true)
+        // rebuild our PointBuffer, if it needs to hold less than the default max chunk size
+        if (targetNumPointsToWrite != 0)
         {
-            // have we done enough yet?
-            if (iter->atEnd()) break;
-
-            // read...
-            iter->readBufferBegin(buffer);
-            const boost::uint32_t numPointsReadThisChunk = iter->readBuffer(buffer);
-            iter->readBufferEnd(buffer);
-
-            // have we reached the end yet?
-            if (numPointsReadThisChunk == 0) break;
-        
-            // write...
-            writeBufferBegin(buffer);
-            const boost::uint32_t numPointsWrittenThisChunk = writeBuffer(buffer);
-            writeBufferEnd(buffer);
-
-            // update count
-            m_actualNumPointsWritten += numPointsWrittenThisChunk;
-
-            // reset the buffer, so we can use it again
-            buffer.setNumPoints(0);
-        }
-    }
-    else 
-    {
-        //
-        // user has requested a specific number of points:
-        // proceed a chunk at a time until we reach that number
-        //
-        PointBuffer buffer(m_prevStage.getSchema(), m_chunkSize);
-        while (true)
-        {
-            // have we done enough yet?
-            if (iter->atEnd()) break;
-
-            const boost::uint64_t numRemainingPointsToRead = m_targetNumPointsToWrite - m_actualNumPointsWritten;
+            const boost::uint64_t numRemainingPointsToRead = targetNumPointsToWrite - actualNumPointsWritten;
         
             const boost::uint64_t numPointsToReadThisChunk64 = std::min<boost::uint64_t>(numRemainingPointsToRead, m_chunkSize);
             // this case is safe because m_chunkSize is a uint32
@@ -171,38 +137,45 @@
             {
                 buffer = PointBuffer(m_prevStage.getSchema(), numPointsToReadThisChunk);
             }
+        }
 
-            // read...
-            iter->readBufferBegin(buffer);
-            const boost::uint32_t numPointsReadThisChunk = iter->readBuffer(buffer);
-            iter->readBufferEnd(buffer);
+        // read...
+        iter->readBufferBegin(buffer);
+        const boost::uint32_t numPointsReadThisChunk = iter->readBuffer(buffer);
+        iter->readBufferEnd(buffer);
 
-            assert(numPointsReadThisChunk <= numPointsToReadThisChunk);
+        assert(numPointsReadThisChunk == buffer.getNumPoints());
+        assert(numPointsReadThisChunk <= buffer.getCapacity());
 
-            // have we reached the end yet?
-            if (numPointsReadThisChunk == 0) break;
+        // have we reached the end yet?
+        if (numPointsReadThisChunk == 0) break;
 
-            // write...
-            writeBufferBegin(buffer);
-            const boost::uint32_t numPointsWrittenThisChunk = writeBuffer(buffer);
-            assert(numPointsWrittenThisChunk == numPointsReadThisChunk);
-            writeBufferEnd(buffer);
+        // write...
+        writeBufferBegin(buffer);
+        const boost::uint32_t numPointsWrittenThisChunk = writeBuffer(buffer);
+        assert(numPointsWrittenThisChunk == numPointsReadThisChunk);
+        writeBufferEnd(buffer);
 
-            // update count
-            m_actualNumPointsWritten += numPointsWrittenThisChunk;
+        // update count
+        actualNumPointsWritten += numPointsWrittenThisChunk;
 
+        if (targetNumPointsToWrite != 0)
+        {
             // have we done enough yet?
-            if (m_actualNumPointsWritten >= m_targetNumPointsToWrite) break;
+            if (actualNumPointsWritten >= targetNumPointsToWrite) break;
         }
+
+        // reset the buffer, so we can use it again
+        buffer.setNumPoints(0);
     }
 
     iter->readEnd();
 
-    writeEnd();
+    writeEnd(actualNumPointsWritten);
 
-    // assert(m_actualNumPointsWritten <= m_targetNumPointsToWrite);
+    assert((targetNumPointsToWrite == 0) || (actualNumPointsWritten <= targetNumPointsToWrite));
 
-    return m_actualNumPointsWritten;
+    return actualNumPointsWritten;
 }
 
 
diff -r 74075102dd6e -r a6cfc29e0c28 src/drivers/faux/Writer.cpp
--- a/src/drivers/faux/Writer.cpp	Tue Aug 02 16:48:13 2011 -0700
+++ b/src/drivers/faux/Writer.cpp	Tue Aug 02 17:17:46 2011 -0700
@@ -64,7 +64,7 @@
 
 
 
-void Writer::writeBegin()
+void Writer::writeBegin(boost::uint64_t /*targetNumPointsToWrite*/)
 {
     m_minimumX = m_minimumY = m_minimumZ = std::numeric_limits<double>::max();
     m_maximumX = m_maximumY = m_maximumZ = std::numeric_limits<double>::min();
@@ -74,14 +74,14 @@
 }
 
 
-void Writer::writeEnd()
+void Writer::writeEnd(boost::uint64_t actualNumPointsWritten)
 {
-    m_averageX /= (double)m_actualNumPointsWritten;
-    m_averageY /= (double)m_actualNumPointsWritten;
-    m_averageZ /= (double)m_actualNumPointsWritten;
+    m_averageX /= (double)actualNumPointsWritten;
+    m_averageY /= (double)actualNumPointsWritten;
+    m_averageZ /= (double)actualNumPointsWritten;
 
     //cout << "FauxWriter::writeEnd()" << endl;
-    //cout << "  wrote " << m_actualNumPointsWritten << " points" << endl;
+    //cout << "  wrote " << actualNumPointsWritten << " points" << endl;
 
     //cout << "  min X: " << m_minimumX << endl;
     //cout << "  min Y: " << m_minimumY << endl;


More information about the Liblas-commits mailing list