Skip to content

Commit

Permalink
scaffolding for RDB
Browse files Browse the repository at this point in the history
  • Loading branch information
hobu committed Mar 19, 2018
1 parent c65f1b9 commit 94e8c08
Show file tree
Hide file tree
Showing 8 changed files with 639 additions and 0 deletions.
5 changes: 5 additions & 0 deletions plugins/CMakeLists.txt
Expand Up @@ -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")
Expand Down
30 changes: 30 additions & 0 deletions 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()
164 changes: 164 additions & 0 deletions 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<uint16_t>::max();
} else if (t.reflectance < m_minReflectance) {
intensity = 0;
} else {
intensity = uint16_t(std::roundf(double(std::numeric_limits<uint16_t>::max()) *
(t.reflectance - m_minReflectance) / (m_maxReflectance - m_minReflectance)));
}
m_view->setField(Id::Intensity, idx, intensity);
}
++idx, ++returnNumber;
}
}


}
94 changes: 94 additions & 0 deletions 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 <riegl/scanlib.hpp>

#include <pdal/PointTable.hpp>
#include <pdal/PointView.hpp>

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<scanlib::basic_rconnection> m_rc;

};


} // namespace pdal

0 comments on commit 94e8c08

Please sign in to comment.