From 2c581e5b628483272d43e4de5b0c1f0b73f846ad Mon Sep 17 00:00:00 2001 From: Andrew Bell Date: Thu, 29 Mar 2018 09:00:02 -0400 Subject: [PATCH] Fix the streaming interface by making the stream-based execute function virtual. (#1876) --- io/BpfReader.cpp | 5 ++++- pdal/Stage.hpp | 6 ++++++ pdal/Streamable.cpp | 3 ++- pdal/Streamable.hpp | 2 +- plugins/nitf/io/NitfWriter.cpp | 5 +---- test/unit/filters/CropFilterTest.cpp | 2 +- test/unit/io/BPFTest.cpp | 14 +++++++------- test/unit/io/PlyReaderTest.cpp | 2 +- 8 files changed, 23 insertions(+), 16 deletions(-) diff --git a/io/BpfReader.cpp b/io/BpfReader.cpp index ad8ef18bca..f582173262 100644 --- a/io/BpfReader.cpp +++ b/io/BpfReader.cpp @@ -308,6 +308,9 @@ void BpfReader::done(PointTableRef) bool BpfReader::processOne(PointRef& point) { + if (eof() || m_index >= m_count) + return false; + switch (m_header.m_pointFormat) { case BpfFormat::PointMajor: @@ -320,7 +323,7 @@ bool BpfReader::processOne(PointRef& point) readByteMajor(point); break; } - return !eof() && (m_index < m_count); + return true; } diff --git a/pdal/Stage.hpp b/pdal/Stage.hpp index 52c25a3407..a929cf89a5 100644 --- a/pdal/Stage.hpp +++ b/pdal/Stage.hpp @@ -123,6 +123,12 @@ class PDAL_DLL Stage */ PointViewSet execute(PointTableRef table); + virtual void execute(StreamPointTable& table) + { + throw pdal_error("Attempting to use stream mode with a non-streamable " + "stage."); + } + /** Determine if a pipeline with this stage as a sink is streamable. diff --git a/pdal/Streamable.cpp b/pdal/Streamable.cpp index ea1de85c2c..a0d2e83ede 100644 --- a/pdal/Streamable.cpp +++ b/pdal/Streamable.cpp @@ -98,7 +98,8 @@ void Streamable::execute(StreamPointTable& table) }; if (!pipelineStreamable()) - return; + throwError("Attempting to use stream mode with a stage that doesn't " + "support streaming."); SpatialReference srs; std::list lists; diff --git a/pdal/Streamable.hpp b/pdal/Streamable.hpp index 2d1e1d211a..9c159bb204 100644 --- a/pdal/Streamable.hpp +++ b/pdal/Streamable.hpp @@ -61,7 +61,7 @@ class PDAL_DLL Streamable : public virtual Stage the same \ref table used in the \ref prepare function. */ - void execute(StreamPointTable& table); + virtual void execute(StreamPointTable& table); using Stage::execute; /** diff --git a/plugins/nitf/io/NitfWriter.cpp b/plugins/nitf/io/NitfWriter.cpp index b29a7792ac..5f3069200e 100644 --- a/plugins/nitf/io/NitfWriter.cpp +++ b/plugins/nitf/io/NitfWriter.cpp @@ -102,9 +102,6 @@ void NitfWriter::addArgs(ProgramArgs& args) void NitfWriter::writeView(const PointViewPtr view) { - //ABELL - Think we can just get this from the LAS file header - // when we're done. - view->calculateBounds(m_bounds); LasWriter::writeView(view); } @@ -131,7 +128,7 @@ void NitfWriter::doneFile() buf->sgetn(bytes.data(), size); m_oss.clear(); m_nitf.wrapData(bytes.data(), size); - m_nitf.setBounds(reprojectBoxToDD(m_srs, m_bounds)); + m_nitf.setBounds(reprojectBoxToDD(m_srs, m_lasHeader.getBounds())); try { diff --git a/test/unit/filters/CropFilterTest.cpp b/test/unit/filters/CropFilterTest.cpp index b6f0780da0..70c1b2e17d 100644 --- a/test/unit/filters/CropFilterTest.cpp +++ b/test/unit/filters/CropFilterTest.cpp @@ -267,7 +267,7 @@ TEST(CropFilterTest, stream) table.layout()->registerDim(Id::Y); table.layout()->registerDim(Id::Z); - class StreamReader : public Reader + class StreamReader : public Reader, public Streamable { public: std::string getName() const diff --git a/test/unit/io/BPFTest.cpp b/test/unit/io/BPFTest.cpp index af47d07006..2ae0fea615 100644 --- a/test/unit/io/BPFTest.cpp +++ b/test/unit/io/BPFTest.cpp @@ -117,13 +117,13 @@ void test_file_type_view(const std::string& filename) PtData pts[3] = { {494915.25f, 4878096.5f, 128.220001f}, {494917.062f, 4878124.5f, 128.539993f}, - {494920.781f, 4877914.5f, 127.43f} }; + {494920.781f, 4877914.5f, 127.42999f} }; - for (int i = 503; i < 3; ++i) + for (int i = 0; i < 3; ++i) { - float x = view->getFieldAs(Dimension::Id::X, i); - float y = view->getFieldAs(Dimension::Id::Y, i); - float z = view->getFieldAs(Dimension::Id::Z, i); + float x = view->getFieldAs(Dimension::Id::X, 503 + i); + float y = view->getFieldAs(Dimension::Id::Y, 503 + i); + float z = view->getFieldAs(Dimension::Id::Z, 503 + i); EXPECT_FLOAT_EQ(x, pts[i].x); EXPECT_FLOAT_EQ(y, pts[i].y); @@ -133,7 +133,7 @@ void test_file_type_view(const std::string& filename) void test_file_type_stream(const std::string& filename) { - class Checker : public Filter + class Checker : public Filter, public Streamable { public: Checker() : m_cnt(0) @@ -157,7 +157,7 @@ void test_file_type_stream(const std::string& filename) PtData pts503[3] = { {494915.25f, 4878096.5f, 128.220001f}, {494917.062f, 4878124.5f, 128.539993f}, - {494920.781f, 4877914.5f, 127.43f} }; + {494920.781f, 4877914.5f, 127.42999f} }; PtData d; diff --git a/test/unit/io/PlyReaderTest.cpp b/test/unit/io/PlyReaderTest.cpp index 2cbd667fe3..f3e4659f00 100644 --- a/test/unit/io/PlyReaderTest.cpp +++ b/test/unit/io/PlyReaderTest.cpp @@ -132,7 +132,7 @@ TEST(PlyReader, ReadBinary) TEST(PlyReader, ReadBinaryStream) { - class Checker : public Filter + class Checker : public Filter, public Streamable { public: std::string getName() const