[Liblas-commits] hg-main-tree: fix up CacheFilter in light of changes to PointDat...

liblas-commits at liblas.org liblas-commits at liblas.org
Thu Mar 17 09:57:19 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/44eb8b8885ee
changeset: 312:44eb8b8885ee
user:      Howard Butler <hobu.inc at gmail.com>
date:      Thu Mar 17 08:56:45 2011 -0500
description:
fix up CacheFilter in light of changes to PointData wrt capacity vs. count
Subject: hg-main-tree: fix up PointDataTest in light of changes to PointData wrt capacity vs. count

details:   http://hg.libpc.orghg-main-tree/rev/5d0067fe2896
changeset: 313:5d0067fe2896
user:      Howard Butler <hobu.inc at gmail.com>
date:      Thu Mar 17 08:57:04 2011 -0500
description:
fix up PointDataTest in light of changes to PointData wrt capacity vs. count
Subject: hg-main-tree: merge

details:   http://hg.libpc.orghg-main-tree/rev/0ee55bbcac4b
changeset: 314:0ee55bbcac4b
user:      Howard Butler <hobu.inc at gmail.com>
date:      Thu Mar 17 08:57:14 2011 -0500
description:
merge

diffstat:

 include/libpc/Schema.hpp              |  16 +++++++++-
 include/libpc/exceptions.hpp          |  11 ++++++-
 include/libpc/filters/ColorFilter.hpp |   2 +-
 src/filters/CacheFilter.cpp           |   6 +-
 src/filters/ColorFilter.cpp           |  36 +++++++++++++++++++++--
 test/unit/CMakeLists.txt              |   1 +
 test/unit/ColorFilterTest.cpp         |  53 +++++++++++++++++++++++++++++++++++
 test/unit/PointDataTest.cpp           |  15 ++++++---
 test/unit/SchemaTest.cpp              |   8 +++++
 9 files changed, 133 insertions(+), 15 deletions(-)

diffs (285 lines):

diff -r c12273525164 -r 0ee55bbcac4b include/libpc/Schema.hpp
--- a/include/libpc/Schema.hpp	Wed Mar 16 16:55:46 2011 -0400
+++ b/include/libpc/Schema.hpp	Thu Mar 17 08:57:14 2011 -0500
@@ -97,7 +97,21 @@
         return index != -1;
     }
 
-    // returns -1 if the index not found
+    bool hasDimension(Dimension::Field field, Dimension::DataType datatype) const
+    {
+        int index = m_indexTable[field];
+        if (index == -1) return false;
+        const Dimension& dim = m_dimensions[index];
+        if (dim.getDataType() != datatype) return false;
+        return true;
+    }
+
+    bool hasDimension(const Dimension& dim) const
+    {
+        return hasDimension(dim.getField(), dim.getDataType());
+    }
+
+    // assumes the index does, in fact, exist
     int getDimensionIndex(Dimension::Field field) const
     {
         int index = m_indexTable[field];
diff -r c12273525164 -r 0ee55bbcac4b include/libpc/exceptions.hpp
--- a/include/libpc/exceptions.hpp	Wed Mar 16 16:55:46 2011 -0400
+++ b/include/libpc/exceptions.hpp	Thu Mar 17 08:57:14 2011 -0500
@@ -73,7 +73,7 @@
     /// Flags are composed with composed with Point::DataMemberFlag.
     /// Testing flags example: bool timeValid = e.who() & Point::eTime;
     unsigned int who() const
-    {
+   {
         return m_who;
     }
 
@@ -101,6 +101,15 @@
     {}
 };
 
+// for when a stage doesn't get the schema it expects
+class impedance_invalid : public libpc_error
+{
+public:
+
+    impedance_invalid(std::string const& msg)
+        : libpc_error(msg)
+    {}
+};
 
 // use this for attempts to use a feature not compiled in, e.g. laszip or gdal
 class configuration_error : public libpc_error
diff -r c12273525164 -r 0ee55bbcac4b include/libpc/filters/ColorFilter.hpp
--- a/include/libpc/filters/ColorFilter.hpp	Wed Mar 16 16:55:46 2011 -0400
+++ b/include/libpc/filters/ColorFilter.hpp	Thu Mar 17 08:57:14 2011 -0500
@@ -53,7 +53,7 @@
 
 private:
     boost::uint32_t readBuffer(PointData&);
-
+    void checkImpedance();
     void getColor(float value, boost::uint8_t& red, boost::uint8_t& green, boost::uint8_t& blue);
 
     ColorFilter& operator=(const ColorFilter&); // not implemented
diff -r c12273525164 -r 0ee55bbcac4b src/filters/CacheFilter.cpp
--- a/src/filters/CacheFilter.cpp	Wed Mar 16 16:55:46 2011 -0400
+++ b/src/filters/CacheFilter.cpp	Thu Mar 17 08:57:14 2011 -0500
@@ -119,14 +119,14 @@
     // for now, we only read from the cache if they are asking for one point
     // (this avoids the problem of an N-point request needing more than one
     // cached block to satisfy it)
-    if (data.getNumPoints() != 1)
+    if (data.getCapacity() != 1)
     {
         const boost::uint32_t numRead = m_prevStage.read(data);
 
         // if they asked for a full block and we got a full block,
         // and the block we got is properly aligned and not already cached,
         // then let's cache it!
-        if (data.getNumPoints() == m_cacheBlockSize && numRead == m_cacheBlockSize && 
+        if (data.getCapacity() == m_cacheBlockSize && numRead == m_cacheBlockSize && 
             (currentPointIndex % m_cacheBlockSize == 0) &&
             m_cache->lookup(currentPointIndex) == NULL)
         {
@@ -137,7 +137,7 @@
 
         incrementCurrentPointIndex(numRead);
 
-        m_numPointsRead += data.getNumPoints();
+        m_numPointsRead += numRead;
         m_numPointsRequested += data.getCapacity();
 
         return numRead;
diff -r c12273525164 -r 0ee55bbcac4b src/filters/ColorFilter.cpp
--- a/src/filters/ColorFilter.cpp	Wed Mar 16 16:55:46 2011 -0400
+++ b/src/filters/ColorFilter.cpp	Thu Mar 17 08:57:14 2011 -0500
@@ -33,6 +33,7 @@
 ****************************************************************************/
 
 #include <cassert>
+#include <libpc/exceptions.hpp>
 #include <libpc/Color.hpp>
 #include <libpc/filters/ColorFilter.hpp>
 
@@ -41,12 +42,39 @@
 ColorFilter::ColorFilter(Stage& prevStage)
     : Filter(prevStage)
 {
+    checkImpedance();
+
+    return;
+}
+
+
+void ColorFilter::checkImpedance()
+{
     Schema& schema = getHeader().getSchema();
 
-    // add the three u8 fields
-    schema.addDimension(Dimension(Dimension::Field_Red, Dimension::Uint8));
-    schema.addDimension(Dimension(Dimension::Field_Green, Dimension::Uint8));
-    schema.addDimension(Dimension(Dimension::Field_Blue, Dimension::Uint8));
+    Dimension dimZ(Dimension::Field_Z, Dimension::Uint8);
+    if (schema.hasDimension(dimZ) == false)
+    {
+        throw impedance_invalid("color filter does not have Z/uint8 field");
+    }
+
+    Dimension dimRed(Dimension::Field_Red, Dimension::Uint8);     
+    Dimension dimGreen(Dimension::Field_Green, Dimension::Uint8);
+    Dimension dimBlue(Dimension::Field_Blue, Dimension::Uint8);
+
+    // are there already u8 fields for color?
+    if (!schema.hasDimension(dimRed))
+    {
+        schema.addDimension(dimRed);
+    }
+    if (!schema.hasDimension(dimGreen))
+    {
+        schema.addDimension(dimGreen);
+    }
+    if (!schema.hasDimension(dimBlue))
+    {
+        schema.addDimension(dimBlue);
+    }
 
     return;
 }
diff -r c12273525164 -r 0ee55bbcac4b test/unit/CMakeLists.txt
--- a/test/unit/CMakeLists.txt	Wed Mar 16 16:55:46 2011 -0400
+++ b/test/unit/CMakeLists.txt	Thu Mar 17 08:57:14 2011 -0500
@@ -13,6 +13,7 @@
 	ChipperTest.cpp
 	ColorTest.cpp
 	ConfigTest.cpp
+	ColorFilterTest.cpp
 	CropFilterTest.cpp
 	DecimationFilterTest.cpp
 	DimensionTest.cpp
diff -r c12273525164 -r 0ee55bbcac4b test/unit/ColorFilterTest.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/unit/ColorFilterTest.cpp	Thu Mar 17 08:57:14 2011 -0500
@@ -0,0 +1,53 @@
+/******************************************************************************
+* 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/drivers/faux/Reader.hpp>
+#include <libpc/drivers/faux/Writer.hpp>
+#include <libpc/filters/ColorFilter.hpp>
+
+using namespace libpc;
+
+BOOST_AUTO_TEST_SUITE(ColorFilter)
+
+BOOST_AUTO_TEST_CASE(test1)
+{
+    // BUG: tbd
+
+    return;
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff -r c12273525164 -r 0ee55bbcac4b test/unit/PointDataTest.cpp
--- a/test/unit/PointDataTest.cpp	Wed Mar 16 16:55:46 2011 -0400
+++ b/test/unit/PointDataTest.cpp	Thu Mar 17 08:57:14 2011 -0500
@@ -53,7 +53,7 @@
 
     PointData data(layout, 10);
 
-    BOOST_CHECK(data.getNumPoints() == 10);
+    BOOST_CHECK(data.getCapacity() == 10);
     BOOST_CHECK(data.getSchemaLayout() == layout);
 
     return;
@@ -78,10 +78,12 @@
     std::size_t offZ = layout.getDimensionLayout(2).getByteOffset();
     BOOST_CHECK(offZ==5);
 
-    PointData* data = new PointData(layout, 17);
+    boost::uint32_t capacity = 17;
+    PointData* data = new PointData(layout, capacity);
 
+    BOOST_CHECK(data->getCapacity() == capacity);
     // write the data into the buffer
-    for (int i=0; i<17; i++)
+    for (int 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;
@@ -90,8 +92,11 @@
       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;
 }
 
@@ -163,7 +168,7 @@
       int ii = 11;
       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);
+      BOOST_CHECK(Utils::compare_approx(z, ii*100.0, (std::numeric_limits<double>::min)()) == true);
     }
 
     delete data;
diff -r c12273525164 -r 0ee55bbcac4b test/unit/SchemaTest.cpp
--- a/test/unit/SchemaTest.cpp	Wed Mar 16 16:55:46 2011 -0400
+++ b/test/unit/SchemaTest.cpp	Thu Mar 17 08:57:14 2011 -0500
@@ -63,6 +63,14 @@
     s4.addDimension(d1);
     BOOST_CHECK(s1!=s4);
     BOOST_CHECK(s4!=s1);
+
+    BOOST_CHECK(s1.hasDimension(Dimension::Field_X));
+    BOOST_CHECK(s1.hasDimension(Dimension::Field_X, Dimension::Uint32));
+    BOOST_CHECK(!s1.hasDimension(Dimension::Field_X, Dimension::Uint16));
+    Dimension dx32(Dimension::Field_X, Dimension::Uint32);
+    Dimension dx16(Dimension::Field_X, Dimension::Uint16);
+    BOOST_CHECK(s1.hasDimension(dx32));
+    BOOST_CHECK(!s1.hasDimension(dx16));
 }
 
 


More information about the Liblas-commits mailing list