[Liblas-commits] hg-main-tree: file rename for PointData->PointBuffer

liblas-commits at liblas.org liblas-commits at liblas.org
Tue Mar 22 13:59:01 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/d6f663e246cf
changeset: 387:d6f663e246cf
user:      Howard Butler <hobu.inc at gmail.com>
date:      Tue Mar 22 12:58:10 2011 -0500
description:
file rename for PointData->PointBuffer
Subject: hg-main-tree: add a getData method that returns copied raw bytes back to the user they can own

details:   http://hg.libpc.orghg-main-tree/rev/15770dc2c858
changeset: 388:15770dc2c858
user:      Howard Butler <hobu.inc at gmail.com>
date:      Tue Mar 22 12:58:50 2011 -0500
description:
add a getData method that returns copied raw bytes back to the user they can own

diffstat:

 include/libpc/PointBuffer.hpp      |    3 +
 src/PointBuffer.cpp                |    6 +
 test/unit/CMakeLists.txt           |    4 +-
 test/unit/PointBufferCacheTest.cpp |   92 +++++++++++++++++
 test/unit/PointBufferTest.cpp      |  195 +++++++++++++++++++++++++++++++++++++
 test/unit/PointDataCacheTest.cpp   |   92 -----------------
 test/unit/PointDataTest.cpp        |  195 -------------------------------------
 7 files changed, 298 insertions(+), 289 deletions(-)

diffs (truncated from 633 to 300 lines):

diff -r ffb2b588a7cf -r 15770dc2c858 include/libpc/PointBuffer.hpp
--- a/include/libpc/PointBuffer.hpp	Tue Mar 22 12:04:59 2011 -0500
+++ b/include/libpc/PointBuffer.hpp	Tue Mar 22 12:58:50 2011 -0500
@@ -112,6 +112,9 @@
     // access to the raw memory
     boost::uint8_t* getData(std::size_t pointIndex) const;
 
+    // access to the raw memory
+    void getData(boost::uint8_t** data, std::size_t* array_size) const;
+
 private:
 
     SchemaLayout m_schemaLayout;
diff -r ffb2b588a7cf -r 15770dc2c858 src/PointBuffer.cpp
--- a/src/PointBuffer.cpp	Tue Mar 22 12:04:59 2011 -0500
+++ b/src/PointBuffer.cpp	Tue Mar 22 12:58:50 2011 -0500
@@ -115,6 +115,12 @@
     return m_numPoints;
 }
 
+void PointBuffer::getData(boost::uint8_t** data, std::size_t* array_size) const
+{
+    *array_size = sizeof(uint8_t) * m_pointSize * m_numPoints;
+    *data = (uint8_t*) malloc (*array_size);
+    memcpy(*data, m_data.get(), *array_size);
+}
 
 void PointBuffer::copyPointFast(std::size_t destPointIndex, std::size_t srcPointIndex, const PointBuffer& srcPointBuffer)
 {
diff -r ffb2b588a7cf -r 15770dc2c858 test/unit/CMakeLists.txt
--- a/test/unit/CMakeLists.txt	Tue Mar 22 12:04:59 2011 -0500
+++ b/test/unit/CMakeLists.txt	Tue Mar 22 12:58:50 2011 -0500
@@ -23,8 +23,8 @@
 	LiblasReaderTest.cpp
 	LiblasWriterTest.cpp
 	MosaicFilterTest.cpp
-	PointDataCacheTest.cpp
-	PointDataTest.cpp
+	PointBufferCacheTest.cpp
+	PointBufferTest.cpp
 	RangeTest.cpp
 	SchemaLayoutTest.cpp
 	SchemaTest.cpp
diff -r ffb2b588a7cf -r 15770dc2c858 test/unit/PointBufferCacheTest.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/unit/PointBufferCacheTest.cpp	Tue Mar 22 12:58:50 2011 -0500
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2010, Tim Day <timday at timday.com>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+// This code is from http://www.bottlenose.demon.co.uk/article/lru.htm.  It is
+// under a Internet Systems Consortium (ISC) license (an OSI-approved BSD-alike license).
+
+#include <boost/test/unit_test.hpp>
+
+#include <libpc/PointBuffer.hpp>
+#include <libpc/PointBufferCache.hpp>
+
+using namespace libpc;
+
+
+BOOST_AUTO_TEST_SUITE(PointBufferCacheTest)
+
+BOOST_AUTO_TEST_CASE(test1)
+{
+    Schema schema;
+    Dimension d1(Dimension::Field_X, Dimension::Uint32);
+    schema.addDimension(d1);
+    SchemaLayout layout(schema);
+
+    PointBuffer* item0 = new PointBuffer(layout, 10);
+    PointBuffer* item1 = new PointBuffer(layout, 10);
+    PointBuffer* item2 = new PointBuffer(layout, 10);
+    //PointBuffer* item3 = new PointBuffer(layout, 10);
+    PointBuffer* item4 = new PointBuffer(layout, 10);
+    //PointBuffer* item5 = new PointBuffer(layout, 10);
+
+    // write the data into the buffer
+    for (int i=0; i<10; i++)
+    {
+      item0->setField(i, 0, i);
+      item1->setField(i, 0, i+10);
+      item2->setField(i, 0, i+20);
+      //item3->setField(i, 0, i+30);
+      item4->setField(i, 0, i+40);
+      //item5->setField(i, 0, i+50);
+    }
+
+    PointBufferCache lru(2);
+
+    lru.insert(0, item0);         // insert miss
+    lru.insert(10, item1);        // insert miss
+    lru.insert(20, item2);        // insert miss
+
+    BOOST_CHECK(lru.lookup(0) == NULL);      // lookup miss
+    BOOST_CHECK(lru.lookup(10) == item1);    // lookup hit
+    BOOST_CHECK(lru.lookup(20) == item2);    // lookup hit
+     
+    { 
+        std::vector<boost::uint64_t> actual; 
+        lru.get_keys(std::back_inserter(actual)); 
+        BOOST_CHECK(actual.size() == 2); 
+        BOOST_CHECK(actual[0] == 20);
+        BOOST_CHECK(actual[1] == 10);
+    }
+
+    lru.insert(40,item4);        // insert miss
+     
+    BOOST_CHECK(lru.lookup(0) == NULL);    // lookup miss
+    BOOST_CHECK(lru.lookup(10) == NULL);   // lookup miss
+    BOOST_CHECK(lru.lookup(20) == item2);  // lookup hit
+    BOOST_CHECK(lru.lookup(40) == item4);  // lookup hit
+    BOOST_CHECK(lru.lookup(40) == item4);  // lookup hit
+
+    boost::uint64_t lookupHits, lookupMisses, insertHits, insertMisses;
+    lru.getCacheStats(lookupMisses, lookupHits, insertMisses, insertHits);
+    BOOST_CHECK(lookupMisses == 3);
+    BOOST_CHECK(lookupHits == 5);
+    BOOST_CHECK(insertMisses == 4);
+    BOOST_CHECK(insertHits == 0);
+
+    return;
+}
+
+
+BOOST_AUTO_TEST_SUITE_END()
diff -r ffb2b588a7cf -r 15770dc2c858 test/unit/PointBufferTest.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/unit/PointBufferTest.cpp	Tue Mar 22 12:58:50 2011 -0500
@@ -0,0 +1,195 @@
+/******************************************************************************
+* Copyright (c) 2011, Michael P. Gerlek (mpg at flaxen.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.
+****************************************************************************/
+
+#include <boost/test/unit_test.hpp>
+#include <boost/cstdint.hpp>
+
+#include <libpc/PointBuffer.hpp>
+#include <libpc/Utils.hpp>
+
+using namespace libpc;
+
+BOOST_AUTO_TEST_SUITE(PointBufferTest)
+
+BOOST_AUTO_TEST_CASE(test_ctor)
+{
+    Dimension d1(Dimension::Field_X, Dimension::Uint32);
+    Dimension d2(Dimension::Field_Y, Dimension::Uint32);
+    Schema schema;
+    schema.addDimension(d1);
+    schema.addDimension(d2);
+    SchemaLayout layout(schema);
+
+    PointBuffer data(layout, 10);
+
+    BOOST_CHECK(data.getCapacity() == 10);
+    BOOST_CHECK(data.getSchemaLayout() == layout);
+
+    return;
+}
+
+
+PointBuffer* makeTestBuffer()
+{
+    Dimension d1(Dimension::Field_X, Dimension::Uint8);
+    Dimension d2(Dimension::Field_Y, Dimension::Int32);
+    Dimension d3(Dimension::Field_Z, Dimension::Double);
+    Schema schema;
+    schema.addDimension(d1);
+    schema.addDimension(d2);
+    schema.addDimension(d3);
+    SchemaLayout layout(schema);
+
+    std::size_t offX = layout.getDimensionLayout(0).getByteOffset();
+    BOOST_CHECK(offX==0);
+    std::size_t offY = layout.getDimensionLayout(1).getByteOffset();
+    BOOST_CHECK(offY==1);
+    std::size_t offZ = layout.getDimensionLayout(2).getByteOffset();
+    BOOST_CHECK(offZ==5);
+
+    boost::uint32_t capacity = 17;
+    PointBuffer* data = new PointBuffer(layout, capacity);
+
+    BOOST_CHECK(data->getCapacity() == capacity);
+    // write the data into the buffer
+    for (boost::uint32_t i=0; i<data->getCapacity(); i++)
+    {
+      const boost::uint8_t x = static_cast<boost::uint8_t>(i)+1;
+      const boost::int32_t y = i*10;
+      const double z = i * 100;
+
+      data->setField(i, 0, x);
+      data->setField(i, 1, y);
+      data->setField(i, 2, z);
+      data->setNumPoints(i+1);
+
+    }
+    BOOST_CHECK(data->getCapacity() ==17);
+    BOOST_CHECK(data->getNumPoints() ==17);
+    return data;
+}
+
+
+static void verifyTestBuffer(const PointBuffer& data)
+{
+    // read the data back out
+    for (int i=0; i<17; i++)
+    {
+      const boost::uint8_t x = data.getField<boost::uint8_t>(i, 0);
+      const boost::int32_t y = data.getField<boost::int32_t>(i, 1);
+      const double z = data.getField<double>(i, 2);
+
+      BOOST_CHECK(x == i+1);
+      BOOST_CHECK(y == i*10);
+
+      BOOST_CHECK(Utils::compare_approx(z, static_cast<double>(i)*100.0, (std::numeric_limits<double>::min)()) == true);
+
+    }
+}
+
+BOOST_AUTO_TEST_CASE(test_get_set)
+{
+    PointBuffer* data = makeTestBuffer();
+    verifyTestBuffer(*data);
+    delete data;
+}
+
+
+BOOST_AUTO_TEST_CASE(test_copy)
+{
+    PointBuffer* data = makeTestBuffer();
+   
+    PointBuffer d2(data->getSchemaLayout(), 19);
+
+    d2.copyPointFast(0, 10, *data);
+    d2.copyPointFast(18, 11, *data);
+    d2.copyPointsFast(1, 0, *data, 17);
+
+    // read the data back out
+    {
+      const boost::uint8_t x = d2.getField<boost::uint8_t>(0, 0);
+      const boost::int32_t y = d2.getField<boost::int32_t>(0, 1);
+      const double z = d2.getField<double>(0, 2);
+
+      int ii = 10;
+
+
+      BOOST_CHECK(x == ii+1);
+      BOOST_CHECK(y == ii*10);
+      BOOST_CHECK(Utils::compare_approx(z, ii*100.0, (std::numeric_limits<double>::min)()) == true);
+    }
+    for (int i=1; i<18; i++)
+    {
+      const boost::uint8_t x = d2.getField<boost::uint8_t>(i, 0);
+      const boost::int32_t y = d2.getField<boost::int32_t>(i, 1);
+      const double z = d2.getField<double>(i, 2);
+


More information about the Liblas-commits mailing list