From 94e8c084508984c1cf4b96a1ab73ed456d1f58e9 Mon Sep 17 00:00:00 2001 From: Howard Butler Date: Mon, 19 Mar 2018 09:56:32 -0500 Subject: [PATCH] scaffolding for RDB --- plugins/CMakeLists.txt | 5 + plugins/rdb/CMakeLists.txt | 30 ++++++ plugins/rdb/io/RdbPointCloud.cpp | 164 +++++++++++++++++++++++++++++ plugins/rdb/io/RdbPointCloud.hpp | 94 +++++++++++++++++ plugins/rdb/io/RdbReader.cpp | 127 ++++++++++++++++++++++ plugins/rdb/io/RdbReader.hpp | 99 +++++++++++++++++ plugins/rdb/test/Config.hpp.in | 13 +++ plugins/rdb/test/RdbReaderTest.cpp | 107 +++++++++++++++++++ 8 files changed, 639 insertions(+) create mode 100644 plugins/rdb/CMakeLists.txt create mode 100644 plugins/rdb/io/RdbPointCloud.cpp create mode 100644 plugins/rdb/io/RdbPointCloud.hpp create mode 100644 plugins/rdb/io/RdbReader.cpp create mode 100644 plugins/rdb/io/RdbReader.hpp create mode 100644 plugins/rdb/test/Config.hpp.in create mode 100644 plugins/rdb/test/RdbReaderTest.cpp diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 4c6bf38cfc..48944eff28 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -65,10 +65,15 @@ if(BUILD_PLUGIN_OPENSCENEGRAPH) add_subdirectory(openscenegraph) endif() +if(BUILD_PLUGIN_RDBLIB) + add_subdirectory(rdb) +endif(BUILD_PLUGIN_RDBLIB) + if(BUILD_PLUGIN_RIVLIB) add_subdirectory(rxp) endif(BUILD_PLUGIN_RIVLIB) + if(BUILD_PLUGIN_SQLITE) if (NOT PDAL_HAVE_LIBXML2) message(FATAL_ERROR "Can't build sqlite plugin without libxml2") diff --git a/plugins/rdb/CMakeLists.txt b/plugins/rdb/CMakeLists.txt new file mode 100644 index 0000000000..31f45f52ad --- /dev/null +++ b/plugins/rdb/CMakeLists.txt @@ -0,0 +1,30 @@ + +find_package(rdb COMPONENTS REQUIRED) +set_package_properties(rdb PROPERTIES + TYPE REQUIRED + PURPOSE "Read data from Riegl databases" + ) + +PDAL_ADD_PLUGIN(libname reader rdb + FILES + io/RdbPointcloud.cpp + io/RdbReader.cpp + LINK_WITH + ${RDB_LIBRARY}) +target_include_directories(${libname} PUBLIC ${RDB_INCLUDE_DIR}) + +set(RDB_TEST_NAME pdal_io_rxp_reader_test) +option(BUILD_RDBLIB_TESTS "Build rdblib tests" ON) +if (BUILD_RDBLIB_TESTS) + configure_file( + test/Config.hpp.in + "${CMAKE_CURRENT_BINARY_DIR}/test/Config.hpp" + ) + + PDAL_ADD_TEST(${RDB_TEST_NAME} + FILES test/RdbReaderTest.cpp + LINK_WITH ${libname}) + target_include_directories(${RDB_TEST_NAME} PRIVATE + ${PROJECT_BINARY_DIR}/plugins/rdb/test + ${PROJECT_SOURCE_DIR}/plugins/rdb/io) +endif() diff --git a/plugins/rdb/io/RdbPointCloud.cpp b/plugins/rdb/io/RdbPointCloud.cpp new file mode 100644 index 0000000000..a001c390b9 --- /dev/null +++ b/plugins/rdb/io/RdbPointCloud.cpp @@ -0,0 +1,164 @@ +/****************************************************************************** +* Copyright (c) 2015, Peter J. Gadomski (pete.gadomski@gmail.com) +* +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following +* conditions are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided +* with the distribution. +* * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the +* names of its contributors may be used to endorse or promote +* products derived from this software without specific prior +* written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY +* OF SUCH DAMAGE. +* +* +* This software has not been developed by RIEGL, and RIEGL will not provide any +* support for this driver. Please do not contact RIEGL with any questions or +* issues regarding this driver. RIEGL is not responsible for damages or other +* issues that arise from use of this driver. This driver has been tested +* against RiVLib version 1.39 on a Ubuntu 14.04 using gcc43. + ****************************************************************************/ + +#include "RdbPointcloud.hpp" + + +namespace pdal +{ + + +Dimension::Id getTimeDimensionId(bool syncToPps) +{ + return syncToPps ? Dimension::Id::GpsTime : Dimension::Id::InternalTime; +} + + +RdbPointcloud::RdbPointcloud( + const std::string& uri, + bool syncToPps, + bool minimal, + bool reflectanceAsIntensity, + float minReflectance, + float maxReflectance, + PointTableRef table) + : + , m_view(new PointView(table)) + , m_idx(0) + , m_syncToPps(syncToPps) + , m_minimal(minimal) + , m_reflectanceAsIntensity(reflectanceAsIntensity) + , m_minReflectance(minReflectance) + , m_maxReflectance(maxReflectance) + , m_rc(scanlib::basic_rconnection::create(uri)) + , m_dec(m_rc) +{} + + +RdbPointcloud::~RdbPointcloud() +{ + m_rc->close(); +} + + +point_count_t RdbPointcloud::read(PointViewPtr view, point_count_t count) +{ + point_count_t numRead = 0; + + if (m_idx < m_view->size()) + { + numRead += writeSavedPoints(view, count); + if (numRead == count) + return numRead; + } + + for (m_dec.get(m_rdbbuf); !m_dec.eoi(); m_dec.get(m_rdbbuf)) + { + dispatch(m_rdbbuf.begin(), m_rdbbuf.end()); + if (m_view->size() - m_idx + numRead >= count) break; + } + + numRead += writeSavedPoints(view, count - numRead); + + return numRead; +} + + +point_count_t RdbPointcloud::writeSavedPoints(PointViewPtr view, point_count_t count) +{ + point_count_t numRead = 0; + while (m_idx < m_view->size() && numRead < count) + { + view->appendPoint(*m_view, m_idx); + ++m_idx, ++numRead; + } + return numRead; +}; + + +void RdbPointcloud::on_echo_transformed(echo_type echo) +{ + if (!(scanlib::pointcloud::single == echo || scanlib::pointcloud::last == echo)) + { + // Come back later, when we've got all the echos + return; + } + + using namespace Dimension; + + point_count_t idx = m_view->size(); + unsigned int returnNumber = 1; + Id timeId = getTimeDimensionId(m_syncToPps); + for (const auto& t : targets) + { + m_view->setField(Id::X, idx, t.vertex[0]); + m_view->setField(Id::Y, idx, t.vertex[1]); + m_view->setField(Id::Z, idx, t.vertex[2]); + m_view->setField(timeId, idx, t.time); + if (!m_minimal) + { + m_view->setField(Id::Amplitude, idx, t.amplitude); + m_view->setField(Id::Reflectance, idx, t.reflectance); + m_view->setField(Id::ReturnNumber, idx, returnNumber); + m_view->setField(Id::NumberOfReturns, idx, targets.size()); + m_view->setField(Id::EchoRange, idx, t.echo_range); + m_view->setField(Id::Deviation, idx, t.deviation); + m_view->setField(Id::BackgroundRadiation, idx, t.background_radiation); + m_view->setField(Id::IsPpsLocked, idx, t.is_pps_locked); + } + if (m_reflectanceAsIntensity) { + uint16_t intensity; + if (t.reflectance > m_maxReflectance) { + intensity = std::numeric_limits::max(); + } else if (t.reflectance < m_minReflectance) { + intensity = 0; + } else { + intensity = uint16_t(std::roundf(double(std::numeric_limits::max()) * + (t.reflectance - m_minReflectance) / (m_maxReflectance - m_minReflectance))); + } + m_view->setField(Id::Intensity, idx, intensity); + } + ++idx, ++returnNumber; + } +} + + +} diff --git a/plugins/rdb/io/RdbPointCloud.hpp b/plugins/rdb/io/RdbPointCloud.hpp new file mode 100644 index 0000000000..3d079b4259 --- /dev/null +++ b/plugins/rdb/io/RdbPointCloud.hpp @@ -0,0 +1,94 @@ +/****************************************************************************** +* Copyright (c) 2015, Peter J. Gadomski (pete.gadomski@gmail.com) +* +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following +* conditions are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided +* with the distribution. +* * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the +* names of its contributors may be used to endorse or promote +* products derived from this software without specific prior +* written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY +* OF SUCH DAMAGE. +* +* +* This software has not been developed by RIEGL, and RIEGL will not provide any +* support for this driver. Please do not contact RIEGL with any questions or +* issues regarding this driver. RIEGL is not responsible for damages or other +* issues that arise from use of this driver. This driver has been tested +* against RiVLib version 1.39 on a Ubuntu 14.04 using gcc43. + ****************************************************************************/ + +#pragma once + +#include + +#include +#include + +namespace pdal +{ + + +Dimension::Id getTimeDimensionId(bool syncToPps); + + +class PDAL_DLL RdbPointcloud +{ +public: + RdbPointcloud( + const std::string& uri, + bool isSyncToPps, + bool m_minimal, + bool m_reflectanceAsIntensity, + float m_minReflectance, + float m_maxReflectance, + PointTableRef table); + virtual ~RdbPointcloud(); + + point_count_t read(PointViewPtr view, point_count_t count); + + inline bool isSyncToPps() const + { + return m_syncToPps; + } + +protected: + void on_echo_transformed(echo_type echo); + +private: + virtual point_count_t writeSavedPoints(PointViewPtr view, point_count_t count); + + PointViewPtr m_view; + point_count_t m_idx; + bool m_syncToPps; + bool m_minimal; + bool m_reflectanceAsIntensity; + float m_minReflectance; + float m_maxReflectance; +// std::shared_ptr m_rc; + +}; + + +} // namespace pdal diff --git a/plugins/rdb/io/RdbReader.cpp b/plugins/rdb/io/RdbReader.cpp new file mode 100644 index 0000000000..fcbee3528a --- /dev/null +++ b/plugins/rdb/io/RdbReader.cpp @@ -0,0 +1,127 @@ +/****************************************************************************** +* Copyright (c) 2014, Peter J. Gadomski (pete.gadomski@gmail.com) +* +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following +* conditions are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided +* with the distribution. +* * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the +* names of its contributors may be used to endorse or promote +* products derived from this software without specific prior +* written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY +* OF SUCH DAMAGE. +* +* This software has not been developed by RIEGL, and RIEGL will not provide any +* support for this driver. Please do not contact RIEGL with any questions or +* issues regarding this driver. RIEGL is not responsible for damages or other +* issues that arise from use of this driver. This driver has been tested +* against RiVLib version 1.39 on a Ubuntu 14.04 using gcc43. +****************************************************************************/ + +#include "RdbReader.hpp" + +#include + +namespace pdal +{ + +static PluginInfo const s_info +{ + "readers.rdb", + "RXP Reader", + "http://pdal.io/stages/readers.rdb.html" +}; + +CREATE_SHARED_STAGE(RdbReader, s_info) + +std::string RdbReader::getName() const { return s_info.name; } + +Dimension::IdList getRdbDimensions(bool syncToPps, bool minimal, bool reflectanceAsIntensity) +{ + using namespace Dimension; + Dimension::IdList ids; + + ids.push_back(Id::X); + ids.push_back(Id::Y); + ids.push_back(Id::Z); + ids.push_back(getTimeDimensionId(syncToPps)); + if (!minimal) + { + ids.push_back(Id::ReturnNumber); + ids.push_back(Id::NumberOfReturns); + ids.push_back(Id::Amplitude); + ids.push_back(Id::Reflectance); + ids.push_back(Id::EchoRange); + ids.push_back(Id::Deviation); + ids.push_back(Id::BackgroundRadiation); + ids.push_back(Id::IsPpsLocked); + } + if (reflectanceAsIntensity) { + ids.push_back(Id::Intensity); + } + + return ids; +} + + +void RdbReader::addArgs(ProgramArgs& args) +{ + args.add("rdtp", "", m_isRdtp, DEFAULT_IS_RDTP); + args.add("sync_to_pps", "Sync to PPS", m_syncToPps, DEFAULT_SYNC_TO_PPS); + args.add("reflectance_as_intensity", "Reflectance as intensity", m_reflectanceAsIntensity, DEFAULT_REFLECTANCE_AS_INTENSITY); + args.add("min_reflectance", "Minimum reflectance", m_minReflectance, DEFAULT_MIN_REFLECTANCE); + args.add("max_reflectance", "Maximum reflectance", m_maxReflectance, DEFAULT_MAX_REFLECTANCE); +} + +void RdbReader::initialize() +{ + m_uri = m_isRdtp ? "rdtp://" + m_filename : "file:" + m_filename; +} + + +void RdbReader::addDimensions(PointLayoutPtr layout) +{ + layout->registerDims(getRdbDimensions(m_syncToPps, m_minimal, m_reflectanceAsIntensity)); +} + + +void RdbReader::ready(PointTableRef table) +{ + m_pointcloud.reset(new RdbPointcloud(m_uri, m_syncToPps, m_minimal, m_reflectanceAsIntensity, m_minReflectance, m_maxReflectance, table)); +} + + +point_count_t RdbReader::read(PointViewPtr view, point_count_t count) +{ + point_count_t numRead = m_pointcloud->read(view, count); + return numRead; +} + + +void RdbReader::done(PointTableRef table) +{ + m_pointcloud.reset(); +} + + +} // namespace pdal diff --git a/plugins/rdb/io/RdbReader.hpp b/plugins/rdb/io/RdbReader.hpp new file mode 100644 index 0000000000..e13a8253ad --- /dev/null +++ b/plugins/rdb/io/RdbReader.hpp @@ -0,0 +1,99 @@ +/****************************************************************************** +* Copyright (c) 2014, Peter J. Gadomski (pete.gadomski@gmail.com) +* +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following +* conditions are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided +* with the distribution. +* * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the +* names of its contributors may be used to endorse or promote +* products derived from this software without specific prior +* written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY +* OF SUCH DAMAGE. +* +* +* This software has not been developed by RIEGL, and RIEGL will not provide any +* support for this driver. Please do not contact RIEGL with any questions or +* issues regarding this driver. RIEGL is not responsible for damages or other +* issues that arise from use of this driver. This driver has been tested +* against RiVLib version 1.39 on a Ubuntu 14.04 using gcc43. + ****************************************************************************/ + +#pragma once + +#include + +#include +#include +#include +#include "RdbPointcloud.hpp" + +namespace pdal +{ + + +const bool DEFAULT_SYNC_TO_PPS = true; +const bool DEFAULT_IS_RDTP = false; +const bool DEFAULT_MINIMAL = false; +const bool DEFAULT_REFLECTANCE_AS_INTENSITY = true; +const float DEFAULT_MIN_REFLECTANCE = -25.0; +const float DEFAULT_MAX_REFLECTANCE = 5.0; + +std::string extractRivlibURI(const Options& options); +Dimension::IdList getRdbDimensions(bool syncToPps, bool minimal); + +class PDAL_DLL RdbReader : public pdal::Reader +{ +public: + RdbReader() + : pdal::Reader() + , m_syncToPps(DEFAULT_SYNC_TO_PPS) + , m_minimal(false) + , m_reflectanceAsIntensity(DEFAULT_REFLECTANCE_AS_INTENSITY) + , m_minReflectance(DEFAULT_MIN_REFLECTANCE) + , m_maxReflectance(DEFAULT_MAX_REFLECTANCE) + , m_pointcloud() + {} + + std::string getName() const; + +private: + virtual void addArgs(ProgramArgs& args); + virtual void initialize(); + virtual void addDimensions(PointLayoutPtr layout); + virtual void ready(PointTableRef table); + virtual point_count_t read(PointViewPtr view, point_count_t count); + virtual void done(PointTableRef table); + + std::string m_uri; + bool m_syncToPps; + bool m_minimal; + bool m_isRdtp; + bool m_reflectanceAsIntensity; + float m_minReflectance; + float m_maxReflectance; + std::unique_ptr m_pointcloud; +}; + + +} // namespace pdal diff --git a/plugins/rdb/test/Config.hpp.in b/plugins/rdb/test/Config.hpp.in new file mode 100644 index 0000000000..752a990caa --- /dev/null +++ b/plugins/rdb/test/Config.hpp.in @@ -0,0 +1,13 @@ +#pragma once + +namespace pdal +{ + + +inline std::string testDataPath() +{ + return "@CMAKE_SOURCE_DIR@/plugins/rxp/test/data/"; +} + + +} diff --git a/plugins/rdb/test/RdbReaderTest.cpp b/plugins/rdb/test/RdbReaderTest.cpp new file mode 100644 index 0000000000..faea9b7205 --- /dev/null +++ b/plugins/rdb/test/RdbReaderTest.cpp @@ -0,0 +1,107 @@ +/****************************************************************************** +* Copyright (c) 2017, Peter J. Gadomski (pete.gadomski@gmail.com) +* +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following +* conditions are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided +* with the distribution. +* * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the +* names of its contributors may be used to endorse or promote +* products derived from this software without specific prior +* written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +* OF USE, view, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY +* OF SUCH DAMAGE. +****************************************************************************/ + +#include + +#include + +#include +#include +#include + +#include "RdbReader.hpp" +#include "Config.hpp" + +using namespace pdal; + +Options defaultRdbReaderOptions() +{ + Options options; + Option filename("filename", testDataPath() + "130501_232206_cut.rdb"); + options.add(filename); + return options; +} + +template +void checkDimensionClose(const PointViewPtr view, + std::size_t index, + Dimension::Id dim, + T edbected) +{ + T actual = view->getFieldAs(dim, index); + EXPECT_FLOAT_EQ(edbected, actual); +} + +template +void checkDimensionEqual(const PointViewPtr view, + std::size_t index, + Dimension::Id dim, + T edbected) +{ + T actual = view->getFieldAs(dim, index); + EXPECT_EQ(edbected, actual); +} + +void checkPoint(const PointViewPtr view, std::size_t index, + float x, float y, float z, + double time, double echoRange, float amplitude, + float reflectance, float deviation, + bool isPpsLocked, uint8_t returnNumber, + uint8_t numberOfReturns + ) +{ + using namespace Dimension; + checkDimensionClose(view, index, Id::X, x); + checkDimensionClose(view, index, Id::Y, y); + checkDimensionClose(view, index, Id::Z, z); + checkDimensionClose(view, + index, + getTimeDimensionId(isPpsLocked), + time); + checkDimensionClose(view, index, Id::EchoRange, echoRange); + checkDimensionClose(view, index, Id::Amplitude, amplitude); + checkDimensionClose(view, index, Id::Reflectance, reflectance); + checkDimensionClose(view, index, Id::Deviation, deviation); + checkDimensionEqual(view, index, Id::IsPpsLocked, isPpsLocked); + checkDimensionEqual(view, index, Id::ReturnNumber, returnNumber); + checkDimensionEqual(view, index, Id::NumberOfReturns, numberOfReturns); +} + +TEST(RdbReaderTest, testConstructor) +{ + Options options = defaultRdbReaderOptions(); + RdbReader reader; + reader.setOptions(options); + EXPECT_EQ(reader.getName(), "readers.rdb"); +}