[Liblas-commits] libpc: get chipper working. bolt on some testing
liblas-commits at liblas.org
liblas-commits at liblas.org
Fri Mar 4 13:27:35 EST 2011
details: http://hg.liblas.orglibpc/rev/bc4b2a24fe12
changeset: 171:bc4b2a24fe12
user: Howard Butler <hobu.inc at gmail.com>
date: Fri Mar 04 12:27:30 2011 -0600
description:
get chipper working. bolt on some testing
diffstat:
src/chipper.cpp | 37 +++++++++++++----
test/unit/CMakeLists.txt | 1 +
test/unit/ChipperTest.cpp | 96 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 124 insertions(+), 10 deletions(-)
diffs (179 lines):
diff -r b90ead329da0 -r bc4b2a24fe12 src/chipper.cpp
--- a/src/chipper.cpp Thu Mar 03 17:39:35 2011 -0800
+++ b/src/chipper.cpp Fri Mar 04 12:27:30 2011 -0600
@@ -109,8 +109,8 @@
yvec.reserve(count);
spare.resize(count);
- boost::uint32_t chunks = count/m_threshold;
- count = 0;
+ // boost::uint32_t chunks = count/m_threshold;
+
const int indexX = schema.getDimensionIndex(Dimension::Field_X);
@@ -124,12 +124,22 @@
double xoffset = dimX.getNumericOffset();
double yoffset = dimY.getNumericOffset();
+
+ std::size_t num_points_loaded = 0;
+ std::size_t num_points_to_load = count;
- for (boost::uint32_t i = 0; i < chunks; i++)
+ boost::uint32_t counter = 0;
+ while (num_points_loaded < num_points_to_load)
{
- PointData buffer(schema, m_threshold);
- m_stage.read(buffer);
-
+ boost::uint64_t num_remaining = num_points_to_load - num_points_loaded;
+ boost::uint32_t num_to_read = static_cast<boost::uint32_t>(std::min<boost::uint64_t>(num_remaining, m_threshold));
+
+ PointData buffer(schema, num_to_read);
+
+ boost::uint32_t num_read = m_stage.read(buffer);
+
+ assert(num_read <= num_to_read);
+
for (boost::uint32_t j = 0; j < m_threshold; j++)
{
// (v * m_header->GetScaleX()) + m_header->GetOffsetX();
@@ -137,15 +147,22 @@
const double y = (buffer.getField<boost::int32_t>(j, indexY) * yscale) + yoffset;
// const double z = (buffer.getField<boost::int32_t>(j, indexZ) * zscale) + zoffset;
ref.m_pos = x;
- ref.m_ptindex = j;
+ ref.m_ptindex = counter;
xvec.push_back(ref);
ref.m_pos = y;
yvec.push_back(ref);
-
+ counter++;
}
-
- }
+
+ num_points_loaded += num_read;
+
+
+ if (m_stage.atEnd())
+ {
+ break;
+ }
+ }
// while (m_reader->ReadNextPoint()) {
// const liblas::Point& pt = m_reader->GetPoint();
diff -r b90ead329da0 -r bc4b2a24fe12 test/unit/CMakeLists.txt
--- a/test/unit/CMakeLists.txt Thu Mar 03 17:39:35 2011 -0800
+++ b/test/unit/CMakeLists.txt Fri Mar 04 12:27:30 2011 -0600
@@ -9,6 +9,7 @@
SET(LIBPC_UNIT_TEST_SRC
BoundsTest.cpp
+ ChipperTest.cpp
ColorTest.cpp
ConfigTest.cpp
CropFilterTest.cpp
diff -r b90ead329da0 -r bc4b2a24fe12 test/unit/ChipperTest.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/unit/ChipperTest.cpp Fri Mar 04 12:27:30 2011 -0600
@@ -0,0 +1,96 @@
+/******************************************************************************
+* 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/chipper.hpp"
+#include "libpc/../../src/drivers/liblas/writer.hpp"
+#include "libpc/../../src/drivers/liblas/reader.hpp"
+
+#include "support.hpp"
+
+using namespace libpc;
+
+BOOST_AUTO_TEST_SUITE(ChipperTest)
+
+BOOST_AUTO_TEST_CASE(test_construction)
+{
+
+ std::istream* ifs = Utils::openFile("../../test/data/1.2-with-color.las");
+ LiblasReader reader(*ifs);
+
+
+ {
+ const boost::uint64_t num_points = reader.getHeader().getNumPoints();
+
+ // need to scope the writer, so that's it dtor can use the stream
+ libpc::chipper::Chipper chipper(reader, 15);
+
+ chipper.Chip();
+ boost::uint32_t num_blocks = chipper.GetBlockCount();
+ BOOST_CHECK(num_points == 1065);
+ BOOST_CHECK(num_blocks==71);
+
+
+ libpc::Bounds<double> const& bounds = chipper.GetBlock(0).GetBounds();
+
+
+ std::vector< Range<double> > ranges = bounds.dimensions();
+
+ libpc::Range<double> x = ranges[0];
+ libpc::Range<double> y = ranges[1];
+
+ BOOST_CHECK(Utils::compare_approx(x.getMinimum(), (double)635674, (double) 1) == true);
+ BOOST_CHECK(Utils::compare_approx(x.getMaximum(), (double)635994, (double) 1) == true);
+ BOOST_CHECK(Utils::compare_approx(y.getMinimum(), (double)848992, (double) 1) == true);
+ BOOST_CHECK(Utils::compare_approx(y.getMaximum(), (double)849427, (double) 1) == true);
+
+ std::vector<boost::uint32_t> ids = chipper.GetBlock(70).GetIDs();
+
+ BOOST_CHECK(ids.size() == 15);
+ BOOST_CHECK(ids[14] == 1050 );
+
+ }
+
+
+ Utils::closeFile(ifs);
+
+
+ return;
+}
+
+
+
+BOOST_AUTO_TEST_SUITE_END()
More information about the Liblas-commits
mailing list