[Liblas-commits] libpc: lint

liblas-commits at liblas.org liblas-commits at liblas.org
Fri Feb 25 14:30:20 EST 2011


details:   http://hg.liblas.orglibpc/rev/bef489dc0b54
changeset: 96:bef489dc0b54
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Fri Feb 25 11:28:56 2011 -0800
description:
lint
Subject: libpc: liblas reader ocming online; fixed bad by-ref param

details:   http://hg.liblas.orglibpc/rev/97f48e532edf
changeset: 97:97f48e532edf
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Fri Feb 25 11:30:11 2011 -0800
description:
liblas reader ocming online; fixed bad by-ref param

diffstat:

 include/libpc/FauxReader.hpp   |   2 +-
 include/libpc/Filter.hpp       |   2 +-
 include/libpc/LasReader.hpp    |   2 +-
 include/libpc/LiblasReader.hpp |  19 ++++++-
 include/libpc/PointData.hpp    |  17 ++++++-
 include/libpc/Reader.hpp       |   2 +-
 include/libpc/Stage.hpp        |   2 +-
 src/FauxReader.cpp             |   2 +-
 src/Filter.cpp                 |   2 +-
 src/LasReader.cpp              |   2 +-
 src/LiblasReader.cpp           |  58 ++++++++++++++++++++++---
 src/PointData.cpp              |   6 --
 src/Reader.cpp                 |   2 +-
 test/unit/CropFilterTest.cpp   |   2 +-
 test/unit/LiblasReaderTest.cpp |  97 ++++++++++++++++++++++++++++++++++++++++++
 15 files changed, 189 insertions(+), 28 deletions(-)

diffs (truncated from 437 to 300 lines):

diff -r a5450fd240c7 -r 97f48e532edf include/libpc/FauxReader.hpp
--- a/include/libpc/FauxReader.hpp	Thu Feb 24 12:08:59 2011 -0800
+++ b/include/libpc/FauxReader.hpp	Fri Feb 25 11:30:11 2011 -0800
@@ -67,7 +67,7 @@
 
     boost::uint32_t readPoints(PointData& data);
 
-    void seekToPoint(boost::uint64_t&);
+    void seekToPoint(boost::uint64_t);
 
 private:
     Mode m_mode;
diff -r a5450fd240c7 -r 97f48e532edf include/libpc/Filter.hpp
--- a/include/libpc/Filter.hpp	Thu Feb 24 12:08:59 2011 -0800
+++ b/include/libpc/Filter.hpp	Fri Feb 25 11:30:11 2011 -0800
@@ -51,7 +51,7 @@
 
     // advance (or retreat) to the Nth point in the file (absolute, 
     // default behaviour for filters is just to call seek on the previous stage
-    virtual void seekToPoint(boost::uint64_t& pointNum);
+    virtual void seekToPoint(boost::uint64_t pointNum);
 
     // reset the filter
     // default behaviour for filters is just to call reset on the previous stage
diff -r a5450fd240c7 -r 97f48e532edf include/libpc/LasReader.hpp
--- a/include/libpc/LasReader.hpp	Thu Feb 24 12:08:59 2011 -0800
+++ b/include/libpc/LasReader.hpp	Fri Feb 25 11:30:11 2011 -0800
@@ -52,7 +52,7 @@
 
     // default is to reset() and then read N points manually
     // override this if you can
-    virtual void seekToPoint(boost::uint64_t& pointNum);
+    virtual void seekToPoint(boost::uint64_t pointNum);
 
     // default just resets the point index
     virtual void reset();
diff -r a5450fd240c7 -r 97f48e532edf include/libpc/LiblasReader.hpp
--- a/include/libpc/LiblasReader.hpp	Thu Feb 24 12:08:59 2011 -0800
+++ b/include/libpc/LiblasReader.hpp	Fri Feb 25 11:30:11 2011 -0800
@@ -35,11 +35,19 @@
 #ifndef INCLUDED_LIBLASREADER_HPP
 #define INCLUDED_LIBLASREADER_HPP
 
+#include "libpc/Reader.hpp"
+
 #include <iostream>
 
-#include "libpc/Reader.hpp"
 #include "libpc/LiblasHeader.hpp"
 
+// fwd decls
+namespace liblas
+{
+    class Reader;
+}
+
+
 namespace libpc
 {
 
@@ -47,25 +55,28 @@
 {
 public:
     LiblasReader(std::istream&);
+    ~LiblasReader();
 
     virtual boost::uint32_t readPoints(PointData&);
 
     // default is to reset() and then read N points manually
     // override this if you can
-    virtual void seekToPoint(boost::uint64_t& pointNum);
+    virtual void seekToPoint(boost::uint64_t pointNum);
 
     // default just resets the point index
     virtual void reset();
 
     const LiblasHeader& getLiblasHeader() const;
 
-protected:
+private:
     LiblasHeader& getLiblasHeader();
     void setLiblasHeader(const LiblasHeader&);
 
     std::istream& m_istream;
 
-private:
+    liblas::Reader *m_reader;
+
+
     LiblasReader& operator=(const LiblasReader&); // not implemented
     LiblasReader(const LiblasReader&); // not implemented
 };
diff -r a5450fd240c7 -r 97f48e532edf include/libpc/PointData.hpp
--- a/include/libpc/PointData.hpp	Thu Feb 24 12:08:59 2011 -0800
+++ b/include/libpc/PointData.hpp	Fri Feb 25 11:30:11 2011 -0800
@@ -71,7 +71,16 @@
     boost::uint32_t getNumValidPoints();
 
     // schema (number and kinds of fields) for a point in this buffer
-    const SchemaLayout& getSchemaLayout() const;
+    const SchemaLayout& getSchemaLayout() const
+    {
+        return m_schemaLayout;
+    }
+
+    // convenience function
+    const Schema& getSchema() const
+    {
+        return m_schemaLayout.getSchema();
+    }
 
     // "valid" means the data for the point can be used; if invalid, the point should
     // be ignored or skipped.  (This is done for efficiency; we don't want to have to
@@ -79,6 +88,12 @@
     bool isValid(std::size_t pointIndex) const;
     void setValid(std::size_t pointIndex, bool value=true);
 
+    // convenience function
+    std::size_t getDimensionIndex(Dimension::Field field) const
+    {
+        return getSchema().getDimensionIndex(field);
+    }
+
     // accessors to a particular field of a particular point in this buffer
     template<class T> T getField(std::size_t pointIndex, std::size_t fieldIndex) const;
     template<class T> void setField(std::size_t pointIndex, std::size_t fieldIndex, T value);
diff -r a5450fd240c7 -r 97f48e532edf include/libpc/Reader.hpp
--- a/include/libpc/Reader.hpp	Thu Feb 24 12:08:59 2011 -0800
+++ b/include/libpc/Reader.hpp	Fri Feb 25 11:30:11 2011 -0800
@@ -48,7 +48,7 @@
 
     // default is to reset() and then read N points manually
     // override this if you can
-    virtual void seekToPoint(boost::uint64_t& pointNum);
+    virtual void seekToPoint(boost::uint64_t pointNum);
 
     // default just resets the point index
     virtual void reset();
diff -r a5450fd240c7 -r 97f48e532edf include/libpc/Stage.hpp
--- a/include/libpc/Stage.hpp	Thu Feb 24 12:08:59 2011 -0800
+++ b/include/libpc/Stage.hpp	Fri Feb 25 11:30:11 2011 -0800
@@ -65,7 +65,7 @@
     // advance (or retreat) to the Nth point in the file (absolute, 
     // not relative).  In some cases, this might be a very slow, painful
     // function to call.
-    virtual void seekToPoint(boost::uint64_t& pointNum) = 0;
+    virtual void seekToPoint(boost::uint64_t pointNum) = 0;
 
     // resets the object's state such that it is positioned to the beginning
     // of the file, as if no reads had yet been done
diff -r a5450fd240c7 -r 97f48e532edf src/FauxReader.cpp
--- a/src/FauxReader.cpp	Thu Feb 24 12:08:59 2011 -0800
+++ b/src/FauxReader.cpp	Fri Feb 25 11:30:11 2011 -0800
@@ -128,7 +128,7 @@
 }
 
 
-void FauxReader::seekToPoint(boost::uint64_t& pointNumber)
+void FauxReader::seekToPoint(boost::uint64_t pointNumber)
 {
     m_currentPointIndex = pointNumber;
 }
diff -r a5450fd240c7 -r 97f48e532edf src/Filter.cpp
--- a/src/Filter.cpp	Thu Feb 24 12:08:59 2011 -0800
+++ b/src/Filter.cpp	Fri Feb 25 11:30:11 2011 -0800
@@ -48,7 +48,7 @@
 }
 
 
-void Filter::seekToPoint(boost::uint64_t& pointNum)
+void Filter::seekToPoint(boost::uint64_t pointNum)
 {
     m_prevStage.seekToPoint(pointNum);
 }
diff -r a5450fd240c7 -r 97f48e532edf src/LasReader.cpp
--- a/src/LasReader.cpp	Thu Feb 24 12:08:59 2011 -0800
+++ b/src/LasReader.cpp	Fri Feb 25 11:30:11 2011 -0800
@@ -66,7 +66,7 @@
 }
 
 
-void LasReader::seekToPoint(boost::uint64_t& pointNum)
+void LasReader::seekToPoint(boost::uint64_t pointNum)
 {
     reset();
 
diff -r a5450fd240c7 -r 97f48e532edf src/LiblasReader.cpp
--- a/src/LiblasReader.cpp	Thu Feb 24 12:08:59 2011 -0800
+++ b/src/LiblasReader.cpp	Fri Feb 25 11:30:11 2011 -0800
@@ -36,6 +36,7 @@
 #include "libpc/LiblasReader.hpp"
 
 #include <liblas/factory.hpp>
+#include <liblas/bounds.hpp>
 
 #include "libpc/LiblasHeader.hpp"
 
@@ -45,15 +46,34 @@
     : Reader()
     , m_istream(istream)
 {
-    LiblasHeader* liblasHeader = new LiblasHeader;
-    setHeader(liblasHeader);
+    liblas::ReaderFactory f;
+    liblas::Reader rr = f.CreateWithStream(m_istream);
+    m_reader = new liblas::Reader(rr);
+
+    const liblas::Header& extHeader = m_reader->GetHeader();
     
-    liblas::ReaderFactory f;
-    liblas::Reader reader = f.CreateWithStream(m_istream);
+    LiblasHeader* myHeader = new LiblasHeader;
+    setHeader(myHeader);
+
+    myHeader->setNumPoints( extHeader.GetPointRecordsCount() );
+
+    const liblas::Bounds<double>& extBounds = extHeader.GetExtent();
+    const Bounds<double> bounds(extBounds.minx(), extBounds.miny(), extBounds.minz(), extBounds.maxx(), extBounds.maxy(), extBounds.maxz());
+    myHeader->setBounds(bounds);
+
+    Schema& schema = myHeader->getSchema();
+    schema.addDimension(Dimension(Dimension::Field_X, Dimension::Double));
+    schema.addDimension(Dimension(Dimension::Field_Y, Dimension::Double));
+    schema.addDimension(Dimension(Dimension::Field_Z, Dimension::Double));
 
     return;
 }
 
+LiblasReader::~LiblasReader()
+{
+    delete m_reader;
+}
+
 
 const LiblasHeader& LiblasReader::getLiblasHeader() const
 {
@@ -67,20 +87,44 @@
 }
 
 
-void LiblasReader::seekToPoint(boost::uint64_t&)
+void LiblasReader::seekToPoint(boost::uint64_t n)
 {
+    m_reader->Seek(n);
     return;
 }
 
 
 void LiblasReader::reset()
 {
+    m_reader->Reset();
 }
 
 
-boost::uint32_t LiblasReader::readPoints(PointData&)
+boost::uint32_t LiblasReader::readPoints(PointData& pointData)
 {
-    return 0;
+    boost::uint32_t numPoints = pointData.getNumPoints();
+    boost::uint32_t i = 0;
+
+    const std::size_t indexX = pointData.getDimensionIndex(Dimension::Field_X);
+    const std::size_t indexY = pointData.getDimensionIndex(Dimension::Field_Y);
+    const std::size_t indexZ = pointData.getDimensionIndex(Dimension::Field_Z);
+
+    for (i=0; i<numPoints; i++)
+    {
+        bool ok = m_reader->ReadNextPoint();
+        assert(ok);
+        const liblas::Point& pt = m_reader->GetPoint();
+
+        double x = pt.GetX();
+        double y = pt.GetY();
+        double z = pt.GetZ();
+
+        pointData.setField(i, indexX, x);
+        pointData.setField(i, indexY, y);
+        pointData.setField(i, indexZ, z);
+    }
+
+    return numPoints;
 }
 
 } // namespace libpc
diff -r a5450fd240c7 -r 97f48e532edf src/PointData.cpp
--- a/src/PointData.cpp	Thu Feb 24 12:08:59 2011 -0800
+++ b/src/PointData.cpp	Fri Feb 25 11:30:11 2011 -0800
@@ -92,12 +92,6 @@
 }
 
 
-const SchemaLayout& PointData::getSchemaLayout() const
-{
-    return m_schemaLayout;
-}
-
-
 void PointData::copyPointFast(std::size_t destPointIndex, std::size_t srcPointIndex, const PointData& srcPointData)
 {
     assert(getSchemaLayout() == srcPointData.getSchemaLayout());


More information about the Liblas-commits mailing list