[Liblas-commits] hg-main-tree: Give PointBuffer a ::setData method
for those wish...
liblas-commits at liblas.org
liblas-commits at liblas.org
Wed Mar 23 15:27:28 EDT 2011
details: http://hg.libpc.orghg-main-tree/rev/9c73f6728d01
changeset: 413:9c73f6728d01
user: Howard Butler <hobu.inc at gmail.com>
date: Wed Mar 23 14:23:24 2011 -0500
description:
Give PointBuffer a ::setData method for those wishing to interact with it at the raw level
Subject: hg-main-tree: add indeterminate_count_error for situations where that's a problem
details: http://hg.libpc.orghg-main-tree/rev/b3f17366512a
changeset: 414:b3f17366512a
user: Howard Butler <hobu.inc at gmail.com>
date: Wed Mar 23 14:26:46 2011 -0500
description:
add indeterminate_count_error for situations where that's a problem
Subject: hg-main-tree: have the chipper carry around its point's data and then provide a GetPointBuffer method for blocks to return it to those who need it
details: http://hg.libpc.orghg-main-tree/rev/0475852dc135
changeset: 415:0475852dc135
user: Howard Butler <hobu.inc at gmail.com>
date: Wed Mar 23 14:27:22 2011 -0500
description:
have the chipper carry around its point's data and then provide a GetPointBuffer method for blocks to return it to those who need it
diffstat:
include/libpc/Chipper.hpp | 7 ++++++-
include/libpc/PointBuffer.hpp | 3 +++
include/libpc/exceptions.hpp | 9 +++++++++
src/Chipper.cpp | 38 +++++++++++++++++++++++++++++++++-----
src/PointBuffer.cpp | 7 ++++++-
test/unit/ChipperTest.cpp | 18 ++++++++++++++++++
6 files changed, 75 insertions(+), 7 deletions(-)
diffs (199 lines):
diff -r 1f4f08813c49 -r 0475852dc135 include/libpc/Chipper.hpp
--- a/include/libpc/Chipper.hpp Wed Mar 23 11:25:19 2011 -0700
+++ b/include/libpc/Chipper.hpp Wed Mar 23 14:27:22 2011 -0500
@@ -5,6 +5,7 @@
#include <libpc/Bounds.hpp>
#include <libpc/export.hpp>
#include <libpc/Dimension.hpp>
+#include <libpc/exceptions.hpp>
#include <vector>
@@ -33,6 +34,7 @@
boost::uint32_t m_ptindex;
boost::uint32_t m_oindex;
boost::uint32_t m_pointSize;
+ boost::uint8_t m_data[40];
bool operator < (const PtRef& pt) const
{ return m_pos < pt.m_pos; }
@@ -94,6 +96,8 @@
std::vector<boost::uint32_t> GetIDs() const;
libpc::Bounds<double> const& GetBounds() const {return m_bounds;}
void SetBounds(libpc::Bounds<double> const& bounds) {m_bounds = bounds;}
+ PointBuffer GetPointBuffer(libpc::SchemaLayout const& layout) const;
+
// double GetXmin() const
// { return m_xmin; }
// double GetYmin() const
@@ -109,7 +113,7 @@
public:
Chipper(Stage& prevStage, boost::uint32_t max_partition_size) :
m_stage(prevStage), m_threshold(max_partition_size),
- m_xvec(DIR_X), m_yvec(DIR_Y), m_spare(DIR_NONE)
+ m_xvec(DIR_X), m_yvec(DIR_Y), m_spare(DIR_NONE), m_cache(0)
{}
void Chip();
@@ -139,6 +143,7 @@
RefList m_xvec;
RefList m_yvec;
RefList m_spare;
+ CacheFilter* m_cache;
Chipper& operator=(const Chipper&); // not implemented
Chipper(const Chipper&); // not implemented
diff -r 1f4f08813c49 -r 0475852dc135 include/libpc/PointBuffer.hpp
--- a/include/libpc/PointBuffer.hpp Wed Mar 23 11:25:19 2011 -0700
+++ b/include/libpc/PointBuffer.hpp Wed Mar 23 14:27:22 2011 -0500
@@ -113,6 +113,9 @@
// access to the raw memory
boost::uint8_t* getData(std::size_t pointIndex) const;
+ // copy in raw data
+ void setData(boost::uint8_t* data, std::size_t pointIndex);
+
// access to the raw memory
void getData(boost::uint8_t** data, std::size_t* array_size) const;
diff -r 1f4f08813c49 -r 0475852dc135 include/libpc/exceptions.hpp
--- a/include/libpc/exceptions.hpp Wed Mar 23 11:25:19 2011 -0700
+++ b/include/libpc/exceptions.hpp Wed Mar 23 14:27:22 2011 -0500
@@ -120,6 +120,15 @@
{}
};
+// use this for situations where indeterminate point counts prevent some
+// operation from happening
+class indeterminate_count_error : public libpc_error
+{
+public:
+ indeterminate_count_error(std::string const& msg)
+ : libpc_error(msg)
+ {}
+};
// use this for code still under development
class not_yet_implemented : public libpc_error
diff -r 1f4f08813c49 -r 0475852dc135 src/Chipper.cpp
--- a/src/Chipper.cpp Wed Mar 23 11:25:19 2011 -0700
+++ b/src/Chipper.cpp Wed Mar 23 14:27:22 2011 -0500
@@ -106,6 +106,23 @@
return ids;
}
+PointBuffer Block::GetPointBuffer(SchemaLayout const& layout) const
+{
+ PointBuffer buffer(layout, m_list_p->size());
+
+ for (boost::uint32_t i = 0; i < m_list_p->size(); ++i)
+ {
+ boost::uint8_t* data = (*m_list_p)[i].m_data;
+ buffer.setData(data, i);
+ }
+
+ return buffer;
+ // for (boost::uint32_t i = m_left; i <= m_right; ++i)
+ // ids.push_back((*m_list_p)[i].m_ptindex);
+ // return ids;
+}
+
+
void Chipper::Chip()
{
Load(m_xvec, m_yvec, m_spare);
@@ -121,17 +138,23 @@
libpc::Header const& header = m_stage.getHeader();
libpc::Schema const& schema = header.getSchema();
-
+ libpc::SchemaLayout const& layout = SchemaLayout(schema);
+
PtRef ref;
boost::uint64_t count = header.getNumPoints();
+
+ if (count == 0)
+ {
+ if (header.getPointCountType() == libpc::PointCount_Unknown)
+ throw libpc::indeterminate_count_error("The chipper requires a complete point count");
+ }
xvec.reserve(count);
yvec.reserve(count);
spare.resize(count);
+
- // boost::uint32_t chunks = count/m_threshold;
-
boost::scoped_ptr<Iterator> iter(m_stage.createIterator());
const int indexX = schema.getDimensionIndex(Dimension::Field_X);
@@ -164,8 +187,13 @@
for (boost::uint32_t j = 0; j < m_threshold; j++)
{
- PointBuffer data(buffer.getSchemaLayout(), 1);
- data.copyPointFast(0, j, buffer);
+ if (layout.getByteSize() > 40) {
+ throw libpc_error("Chipper PtRef size not large enough to hold point data");
+ }
+
+ memcpy (ref.m_data, buffer.getData(j), layout.getByteSize());
+ // PointBuffer data(buffer.getSchemaLayout(), 1);
+ // data.copyPointFast(0, j, buffer);
if (j == num_to_read) break; // we're outta here
diff -r 1f4f08813c49 -r 0475852dc135 src/PointBuffer.cpp
--- a/src/PointBuffer.cpp Wed Mar 23 11:25:19 2011 -0700
+++ b/src/PointBuffer.cpp Wed Mar 23 14:27:22 2011 -0500
@@ -114,6 +114,11 @@
return m_data.get() + m_pointSize * index;
}
+void PointBuffer::setData(boost::uint8_t* data, std::size_t index)
+{
+ memcpy(m_data.get() + m_pointSize * index, data, getSchemaLayout().getByteSize());
+}
+
boost::uint32_t PointBuffer::getNumPoints() const
{
@@ -122,7 +127,7 @@
void PointBuffer::getData(boost::uint8_t** data, std::size_t* array_size) const
{
- *array_size = sizeof(uint8_t) * m_pointSize * m_numPoints;
+ *array_size = getSchemaLayout().getByteSize();
*data = (uint8_t*) malloc (*array_size);
memcpy(*data, m_data.get(), *array_size);
}
diff -r 1f4f08813c49 -r 0475852dc135 test/unit/ChipperTest.cpp
--- a/test/unit/ChipperTest.cpp Wed Mar 23 11:25:19 2011 -0700
+++ b/test/unit/ChipperTest.cpp Wed Mar 23 14:27:22 2011 -0500
@@ -79,6 +79,24 @@
BOOST_CHECK(ids.size() == 15);
BOOST_CHECK(ids[14] == 1050 );
+
+ PointBuffer buffer = chipper.GetBlock(20).GetPointBuffer(libpc::SchemaLayout(reader.getHeader().getSchema()));
+
+ // Check X's of first three points in block 20
+ BOOST_CHECK(buffer.getField<boost::int32_t>(0, 0) == 63567405);
+ BOOST_CHECK(buffer.getField<boost::int32_t>(1, 0) == 63568054);
+ BOOST_CHECK(buffer.getField<boost::int32_t>(2, 0) == 63569865);
+
+ // Check Y's of first three points in block 20
+ BOOST_CHECK(buffer.getField<boost::int32_t>(0, 1) == 84901732);
+ BOOST_CHECK(buffer.getField<boost::int32_t>(1, 1) == 84936266);
+ BOOST_CHECK(buffer.getField<boost::int32_t>(2, 1) == 84941588);
+
+ // Check Z's of first three points in block 20
+ BOOST_CHECK(buffer.getField<boost::int32_t>(0, 2) == 42802);
+ BOOST_CHECK(buffer.getField<boost::int32_t>(1, 2) == 42156);
+ BOOST_CHECK(buffer.getField<boost::int32_t>(2, 2) == 42392);
+
}
return;
More information about the Liblas-commits
mailing list