[Liblas-commits] hg-main-tree: make the las readers take filenames,
not istreams, ...
liblas-commits at liblas.org
liblas-commits at liblas.org
Wed Mar 23 14:25:24 EDT 2011
details: http://hg.libpc.orghg-main-tree/rev/1f4f08813c49
changeset: 412:1f4f08813c49
user: Michael P. Gerlek <mpg at flaxen.com>
date: Wed Mar 23 11:25:19 2011 -0700
description:
make the las readers take filenames, not istreams, for future parallel I/O
diffstat:
apps/pc2pc.cpp | 8 +++-----
apps/pcinfo.cpp | 12 ++++++------
include/libpc/drivers/las/Iterator.hpp | 2 ++
include/libpc/drivers/las/Reader.hpp | 8 +++++---
include/libpc/drivers/liblas/Iterator.hpp | 2 ++
include/libpc/drivers/liblas/Reader.hpp | 7 +++++--
src/drivers/las/Iterator.cpp | 11 ++++++++++-
src/drivers/las/Reader.cpp | 18 ++++++++++++++----
src/drivers/liblas/Iterator.cpp | 9 +++++++++
src/drivers/liblas/Reader.cpp | 18 +++++++++++++++---
test/unit/ChipperTest.cpp | 10 +---------
test/unit/LiblasReaderTest.cpp | 6 +-----
test/unit/LiblasWriterTest.cpp | 8 ++------
13 files changed, 75 insertions(+), 44 deletions(-)
diffs (truncated from 419 to 300 lines):
diff -r 3dcaaec431bb -r 1f4f08813c49 apps/pc2pc.cpp
--- a/apps/pc2pc.cpp Wed Mar 23 11:03:19 2011 -0700
+++ b/apps/pc2pc.cpp Wed Mar 23 11:25:19 2011 -0700
@@ -102,12 +102,11 @@
return 1;
}
- std::istream* ifs = Utils::openFile(m_inputFile);
std::ostream* ofs = Utils::createFile(m_outputFile);
if (hasOption("native"))
{
- libpc::drivers::las::LasReader reader(*ifs);
+ libpc::drivers::las::LasReader reader(m_inputFile);
const boost::uint64_t numPoints = reader.getHeader().getNumPoints();
@@ -125,7 +124,7 @@
else if (hasOption("oracle"))
{
#ifdef HAVE_ORACLE
- libpc::drivers::liblas::LiblasReader reader(*ifs);
+ libpc::drivers::liblas::LiblasReader reader(m_inputFile);
const boost::uint64_t numPoints = reader.getHeader().getNumPoints();
@@ -155,7 +154,7 @@
}
else
{
- libpc::drivers::liblas::LiblasReader reader(*ifs);
+ libpc::drivers::liblas::LiblasReader reader(m_inputFile);
const boost::uint64_t numPoints = reader.getHeader().getNumPoints();
@@ -171,7 +170,6 @@
}
Utils::closeFile(ofs);
- Utils::closeFile(ifs);
return 0;
}
diff -r 3dcaaec431bb -r 1f4f08813c49 apps/pcinfo.cpp
--- a/apps/pcinfo.cpp Wed Mar 23 11:03:19 2011 -0700
+++ b/apps/pcinfo.cpp Wed Mar 23 11:25:19 2011 -0700
@@ -79,8 +79,6 @@
return 1;
}
- std::istream* ifs = Utils::openFile(m_inputFile);
-
libpc::Stage* reader = NULL;
size_t ext = m_inputFile.find_last_of('.');
if (ext != std::string::npos)
@@ -90,9 +88,13 @@
!m_inputFile.substr(ext).compare("laz"))
{
if (hasOption("native"))
- reader = new libpc::drivers::las::LasReader(*ifs);
+ {
+ reader = new libpc::drivers::las::LasReader(m_inputFile);
+ }
else
- reader = new libpc::drivers::liblas::LiblasReader(*ifs);
+ {
+ reader = new libpc::drivers::liblas::LiblasReader(m_inputFile);
+ }
}
#ifdef HAVE_MRSID
else if (!m_inputFile.substr(ext).compare("sid"))
@@ -111,8 +113,6 @@
boost::uint64_t numPoints = reader->getNumPoints();
delete reader;
- if (ifs)
- Utils::closeFile(ifs);
std::cout << numPoints << " points\n";
diff -r 3dcaaec431bb -r 1f4f08813c49 include/libpc/drivers/las/Iterator.hpp
--- a/include/libpc/drivers/las/Iterator.hpp Wed Mar 23 11:03:19 2011 -0700
+++ b/include/libpc/drivers/las/Iterator.hpp Wed Mar 23 11:25:19 2011 -0700
@@ -49,6 +49,7 @@
{
public:
Iterator(const LasReader& reader);
+ ~Iterator();
private:
boost::uint64_t skipImpl(boost::uint64_t);
@@ -56,6 +57,7 @@
bool atEndImpl() const;
const LasReader& m_reader;
+ std::istream* m_istream;
};
diff -r 3dcaaec431bb -r 1f4f08813c49 include/libpc/drivers/las/Reader.hpp
--- a/include/libpc/drivers/las/Reader.hpp Wed Mar 23 11:03:19 2011 -0700
+++ b/include/libpc/drivers/las/Reader.hpp Wed Mar 23 11:25:19 2011 -0700
@@ -46,10 +46,12 @@
class LIBPC_DLL LasReader : public Stage
{
public:
- LasReader(std::istream&);
+ LasReader(const std::string& filename);
const std::string& getName() const;
+ const std::string& getFileName() const;
+
const LasHeader& getLasHeader() const;
libpc::Iterator* createIterator() const;
@@ -57,13 +59,13 @@
// 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&);
private:
+ const std::string m_filename;
+
LasReader& operator=(const LasReader&); // not implemented
LasReader(const LasReader&); // not implemented
};
diff -r 3dcaaec431bb -r 1f4f08813c49 include/libpc/drivers/liblas/Iterator.hpp
--- a/include/libpc/drivers/liblas/Iterator.hpp Wed Mar 23 11:03:19 2011 -0700
+++ b/include/libpc/drivers/liblas/Iterator.hpp Wed Mar 23 11:25:19 2011 -0700
@@ -57,6 +57,7 @@
{
public:
Iterator(const LiblasReader& reader);
+ ~Iterator();
private:
boost::uint64_t skipImpl(boost::uint64_t);
@@ -64,6 +65,7 @@
bool atEndImpl() const;
const LiblasReader& m_reader;
+ std::istream* m_istream;
};
} } } // namespaces
diff -r 3dcaaec431bb -r 1f4f08813c49 include/libpc/drivers/liblas/Reader.hpp
--- a/include/libpc/drivers/liblas/Reader.hpp Wed Mar 23 11:03:19 2011 -0700
+++ b/include/libpc/drivers/liblas/Reader.hpp Wed Mar 23 11:25:19 2011 -0700
@@ -57,11 +57,13 @@
friend class Iterator;
public:
- LiblasReader(std::istream&);
+ LiblasReader(const std::string& filename);
~LiblasReader();
const std::string& getName() const;
+ const std::string& getFileName() const;
+
const LiblasHeader& getLiblasHeader() const;
boost::int8_t getPointFormatNumber() const;
@@ -74,7 +76,8 @@
void processExternalHeader();
void registerFields();
- std::istream& m_istream;
+ std::string m_filename;
+ std::istream* m_istream;
::liblas::Reader *m_externalReader;
diff -r 3dcaaec431bb -r 1f4f08813c49 src/drivers/las/Iterator.cpp
--- a/src/drivers/las/Iterator.cpp Wed Mar 23 11:03:19 2011 -0700
+++ b/src/drivers/las/Iterator.cpp Wed Mar 23 11:25:19 2011 -0700
@@ -43,7 +43,16 @@
Iterator::Iterator(const LasReader& reader)
: libpc::Iterator(reader)
, m_reader(reader)
+ , m_istream(NULL)
{
+ m_istream = Utils::openFile(m_reader.getFileName());
+ return;
+}
+
+
+Iterator::~Iterator()
+{
+ Utils::closeFile(m_istream);
return;
}
@@ -72,7 +81,7 @@
boost::uint32_t Iterator::readImpl(PointBuffer& data)
{
- return m_reader.processBuffer(data, m_reader.m_istream);
+ return m_reader.processBuffer(data, *m_istream);
}
diff -r 3dcaaec431bb -r 1f4f08813c49 src/drivers/las/Reader.cpp
--- a/src/drivers/las/Reader.cpp Wed Mar 23 11:03:19 2011 -0700
+++ b/src/drivers/las/Reader.cpp Wed Mar 23 11:25:19 2011 -0700
@@ -41,16 +41,20 @@
-LasReader::LasReader(std::istream& istream)
+LasReader::LasReader(const std::string& filename)
: Stage()
- , m_istream(istream)
+ , m_filename(filename)
{
LasHeader* lasHeader = new LasHeader;
setHeader(lasHeader);
- LasHeaderReader lasHeaderReader(*lasHeader, istream);
+ std::istream* str = Utils::openFile(m_filename);
+
+ LasHeaderReader lasHeaderReader(*lasHeader, *str);
lasHeaderReader.read();
+ Utils::closeFile(str);
+
return;
}
@@ -62,6 +66,12 @@
}
+const std::string& LasReader::getFileName() const
+{
+ return m_filename;
+}
+
+
const LasHeader& LasReader::getLasHeader() const
{
return (const LasHeader&)getHeader();
@@ -145,7 +155,7 @@
if (pointFormat == LasHeader::ePointFormat0)
{
- Utils::read_n(buf, m_istream, LasHeader::ePointSize0);
+ Utils::read_n(buf, stream, LasHeader::ePointSize0);
boost::uint8_t* p = buf;
diff -r 3dcaaec431bb -r 1f4f08813c49 src/drivers/liblas/Iterator.cpp
--- a/src/drivers/liblas/Iterator.cpp Wed Mar 23 11:03:19 2011 -0700
+++ b/src/drivers/liblas/Iterator.cpp Wed Mar 23 11:25:19 2011 -0700
@@ -48,7 +48,16 @@
Iterator::Iterator(const LiblasReader& reader)
: libpc::Iterator(reader)
, m_reader(reader)
+ , m_istream(NULL)
{
+ m_istream = Utils::openFile(m_reader.getFileName());
+ return;
+}
+
+
+Iterator::~Iterator()
+{
+ Utils::closeFile(m_istream);
return;
}
diff -r 3dcaaec431bb -r 1f4f08813c49 src/drivers/liblas/Reader.cpp
--- a/src/drivers/liblas/Reader.cpp Wed Mar 23 11:03:19 2011 -0700
+++ b/src/drivers/liblas/Reader.cpp Wed Mar 23 11:25:19 2011 -0700
@@ -44,9 +44,10 @@
namespace libpc { namespace drivers { namespace liblas {
-LiblasReader::LiblasReader(std::istream& istream)
+LiblasReader::LiblasReader(const std::string& filename)
: Stage()
- , m_istream(istream)
+ , m_filename(filename)
+ , m_istream(NULL)
, m_externalReader(NULL)
, m_versionMajor(0)
, m_versionMinor(0)
@@ -62,8 +63,10 @@
, m_hasColorData(false)
, m_hasWaveData(false)
{
+ m_istream = Utils::openFile(m_filename);
+
::liblas::ReaderFactory f;
More information about the Liblas-commits
mailing list