Skip to content

Commit

Permalink
Merge branch 'master' into iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
hobu committed Jan 12, 2012
2 parents d5e0628 + f263b18 commit 8f61bac
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -141,7 +141,7 @@ else()
# Recommended C++ compilation flags
# -Weffc++
set(PDAL_COMMON_CXX_FLAGS
"-pedantic -Wall -Wpointer-arith -Wcast-align -Wcast-qual -Wfloat-equal -Wredundant-decls -Wno-long-long")
"-pedantic -Wall -Wpointer-arith -Wcast-align -Wcast-qual -Wfloat-equal -Wredundant-decls -Wno-long-long -fPIC")

if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)

Expand Down
39 changes: 27 additions & 12 deletions include/pdal/PointBuffer.hpp
Expand Up @@ -38,6 +38,7 @@

#include <boost/scoped_array.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/numeric/conversion/cast.hpp>

#include <pdal/pdal_internal.hpp>
#include <pdal/Bounds.hpp>
Expand Down Expand Up @@ -95,6 +96,7 @@ class PDAL_DLL PointBuffer
template<class T> T getRawField(std::size_t pointIndex, std::size_t pointBytePosition) const;
template<class T> void setField(Dimension const& dim, std::size_t pointIndex, T value);

template<typename Target, typename Source> static Target saturation_cast(Source const& src);
// bulk copy all the fields from the given point into this object
// NOTE: this is only legal if the src and dest schemas are exactly the same
// (later, this will be implemented properly, to handle the general cases slowly and the best case quickly)
Expand Down Expand Up @@ -181,7 +183,20 @@ class PDAL_DLL PointBuffer
schema::size_type m_byteSize;
};

template<typename Target, typename Source>
inline Target PointBuffer::saturation_cast(Source const& src) {

try {
return boost::numeric_cast<Target>(src);
}
catch (boost::numeric::negative_overflow const&) {
return std::numeric_limits<Target>::min();
}
catch (boost::numeric::positive_overflow const&) {
return std::numeric_limits<Target>::max();
}

}

template <class T>
inline void PointBuffer::setField(pdal::Dimension const& dim, std::size_t pointIndex, T value)
Expand Down Expand Up @@ -261,31 +276,31 @@ inline T PointBuffer::getField(pdal::Dimension const& dim, std::size_t pointInde
{
case dimension::SignedByte:
i8 = *(boost::int8_t*)(void*)p;
output = boost::lexical_cast<T>(i8);
output = saturation_cast<T, int8_t>(i8);
break;
case dimension::UnsignedByte:
u8 = *(boost::uint8_t*)(void*)p;
output = boost::lexical_cast<T>(u8);
output = saturation_cast<T, uint8_t>(u8);
break;

case dimension::SignedInteger:
if (dim.getByteSize() == 1 )
{
i8 = *(boost::int8_t*)(void*)p;
output = boost::lexical_cast<T>(i8);
output = saturation_cast<T, int8_t>(i8);
} else if (dim.getByteSize() == 2)
{
i16 = *(boost::int16_t*)(void*)p;
output = boost::lexical_cast<T>(i16);
output = saturation_cast<T, int16_t>(i16);

} else if (dim.getByteSize() == 4)
{
i32 = *(boost::int32_t*)(void*)p;
output = boost::lexical_cast<T>(i32);
output = saturation_cast<T, int32_t>(i32);
} else if (dim.getByteSize() == 8)
{
i64 = *(boost::int64_t*)(void*)p;
output = boost::lexical_cast<T>(i64);
output = saturation_cast<T, int64_t>(i64);
} else
{
throw buffer_error("getField::Unhandled datatype size for SignedInteger");
Expand All @@ -295,20 +310,20 @@ inline T PointBuffer::getField(pdal::Dimension const& dim, std::size_t pointInde
if (dim.getByteSize() == 1 )
{
u8 = *(boost::uint8_t*)(void*)p;
output = boost::lexical_cast<T>(u8);
output = saturation_cast<T, uint8_t>(u8);
} else if (dim.getByteSize() == 2)
{
u16 = *(boost::uint16_t*)(void*)p;
output = boost::lexical_cast<T>(u16);
output = saturation_cast<T, uint16_t>(u16);

} else if (dim.getByteSize() == 4)
{
u32 = *(boost::uint32_t*)(void*)p;
output = boost::lexical_cast<T>(u32);
output = saturation_cast<T, uint32_t>(u32);
} else if (dim.getByteSize() == 8)
{
u64 = *(boost::uint64_t*)(void*)p;
output = boost::lexical_cast<T>(u64);
output = saturation_cast<T, uint64_t>(u64);
} else
{
throw buffer_error("getField::Unhandled datatype size for UnsignedInteger");
Expand All @@ -319,11 +334,11 @@ inline T PointBuffer::getField(pdal::Dimension const& dim, std::size_t pointInde
if (dim.getByteSize() == 4)
{
flt = *(float*)(void*)p;
output = boost::lexical_cast<T>(flt);
output = saturation_cast<T, float>(flt);
} else if (dim.getByteSize() == 8)
{
dbl = *(double*)(void*)p;
output = boost::lexical_cast<T>(dbl);
output = saturation_cast<T, double>(dbl);
} else
{
throw buffer_error("getField::Unhandled datatype size for Float");
Expand Down
Binary file added test/data/qfit/20100515_152839.atm4bT2.qi
Binary file not shown.
12 changes: 12 additions & 0 deletions test/data/qfit/pipeline.xml
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<Pipeline version="1.0">
<Writer type="drivers.las.writer">
<Option name="filename">qfit-foo.las</Option>
<Reader type="drivers.qfit.reader">
<Option name="flip_coordinates">true</Option>
<Option name="scale_z">0.001</Option>
<Option name="spatialreference">EPSG:4919+3855</Option>
<Option name="filename">20100515_152839.atm4bT2.qi</Option>
</Reader>
</Writer>
</Pipeline>
18 changes: 18 additions & 0 deletions test/unit/QFITReaderTest.cpp
Expand Up @@ -39,6 +39,9 @@
#include <pdal/Options.hpp>
#include <pdal/PointBuffer.hpp>
#include <pdal/drivers/qfit/Reader.hpp>
#include <pdal/drivers/pipeline/Reader.hpp>
#include <pdal/PipelineReader.hpp>
#include <pdal/PipelineManager.hpp>
#include "Support.hpp"

#include <iostream>
Expand Down Expand Up @@ -162,6 +165,21 @@ BOOST_AUTO_TEST_CASE(test_14_word)
return;
}

BOOST_AUTO_TEST_CASE(test_pipeline)
{
PipelineManager manager;
PipelineReader reader(manager);


bool isWriter = reader.readPipeline(Support::datapath("qfit/pipeline.xml"));
BOOST_CHECK_EQUAL(isWriter, true);

const boost::uint64_t np = manager.execute();

BOOST_CHECK_EQUAL(np, 3432);

return;
}


BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 8f61bac

Please sign in to comment.