[Liblas-commits] hg-main-tree: provide pessimistic defaults for iter creation

liblas-commits at liblas.org liblas-commits at liblas.org
Thu Mar 24 13:55:04 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/5db06e2fd8bf
changeset: 429:5db06e2fd8bf
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Thu Mar 24 10:54:33 2011 -0700
description:
provide pessimistic defaults for iter creation
Subject: hg-main-tree: merg

details:   http://hg.libpc.orghg-main-tree/rev/ea942f2e7393
changeset: 430:ea942f2e7393
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Thu Mar 24 10:54:51 2011 -0700
description:
merg

diffstat:

 include/libpc/Chipper.hpp         |   21 +++-
 include/libpc/ChipperIterator.hpp |   64 ++++++++++++++
 include/libpc/Stage.hpp           |    8 +-
 src/CMakeLists.txt                |    3 +
 src/Chipper.cpp                   |   61 +++++++++++++
 src/ChipperIterator.cpp           |  116 +++++++++++++++++++++++++
 src/drivers/oci/Writer.cpp        |  173 +++++--------------------------------
 7 files changed, 289 insertions(+), 157 deletions(-)

diffs (truncated from 569 to 300 lines):

diff -r 1848afbdad4d -r ea942f2e7393 include/libpc/Chipper.hpp
--- a/include/libpc/Chipper.hpp	Thu Mar 24 10:38:30 2011 -0700
+++ b/include/libpc/Chipper.hpp	Thu Mar 24 10:54:51 2011 -0700
@@ -2,10 +2,11 @@
 #define LIBLAS_CHIPPER_H
 
 #include <libpc/Stage.hpp>
+#include <libpc/Filter.hpp>
 #include <libpc/Bounds.hpp>
 #include <libpc/export.hpp>
-#include <libpc/Dimension.hpp>
 #include <libpc/Iterator.hpp>
+#include <libpc/FilterIterator.hpp>
 
 #include <boost/scoped_ptr.hpp>
 
@@ -88,6 +89,7 @@
     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 GetBuffer( Stage& stage) const;    
     // double GetXmin() const
     //     { return m_xmin; }
     // double GetYmin() const
@@ -98,12 +100,12 @@
     //     { return m_ymax; }
 };
 
-class LIBPC_DLL Chipper
+class LIBPC_DLL Chipper : public libpc::Filter
 {
 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)
+        libpc::Filter(prevStage), m_stage(prevStage), m_threshold(max_partition_size),
+        m_xvec(DIR_X), m_yvec(DIR_Y), m_spare(DIR_NONE) 
     {}
 
     void Chip();
@@ -112,6 +114,13 @@
     const Block& GetBlock(std::vector<Block>::size_type i)
         { return m_blocks[i]; }
 
+    const std::string& getName() const ;
+
+    bool supportsSequentialIterator() const { return true; }
+    bool supportsRandomIterator() const { return false; }
+    libpc::SequentialIterator* createSequentialIterator() const;
+    libpc::RandomIterator* createRandomIterator() const;
+
 private:
     void Load(RefList& xvec, RefList& yvec, RefList& spare);
     void Partition(boost::uint32_t size);
@@ -124,7 +133,9 @@
         boost::uint32_t pleft, boost::uint32_t pcenter);
     void Emit(RefList& wide, boost::uint32_t widemin, boost::uint32_t widemax,
         RefList& narrow, boost::uint32_t narrowmin, boost::uint32_t narrowmax );
-
+    
+    void ConstructBuffers();
+    
     // Reader *m_reader;
     Stage& m_stage;
     boost::uint32_t m_threshold;
diff -r 1848afbdad4d -r ea942f2e7393 include/libpc/ChipperIterator.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/libpc/ChipperIterator.hpp	Thu Mar 24 10:54:51 2011 -0700
@@ -0,0 +1,64 @@
+/******************************************************************************
+* 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.
+****************************************************************************/
+
+#ifndef INCLUDED_CHIPPERITERATOR_HPP
+#define INCLUDED_CHIPPERITERATOR_HPP
+
+#include <libpc/Filter.hpp>
+#include <libpc/FilterIterator.hpp>
+
+namespace libpc {
+
+class chipper::Chipper;
+    
+namespace filters {
+
+
+class ChipperSequentialIterator : public libpc::FilterSequentialIterator
+{
+public:
+    ChipperSequentialIterator(const chipper::Chipper& chipper);
+
+private:
+    boost::uint64_t skipImpl(boost::uint64_t);
+    boost::uint32_t readImpl(PointBuffer&);
+    bool atEndImpl() const;
+
+    const chipper::Chipper& m_chipper;
+};
+
+
+} } // namespaces
+
+#endif
diff -r 1848afbdad4d -r ea942f2e7393 include/libpc/Stage.hpp
--- a/include/libpc/Stage.hpp	Thu Mar 24 10:38:30 2011 -0700
+++ b/include/libpc/Stage.hpp	Thu Mar 24 10:54:51 2011 -0700
@@ -67,10 +67,10 @@
     const Header& getHeader() const;
     Header& getHeader();
 
-    virtual bool supportsSequentialIterator() const = 0;
-    virtual bool supportsRandomIterator() const = 0;
-    virtual SequentialIterator* createSequentialIterator() const = 0;
-    virtual RandomIterator* createRandomIterator() const = 0;
+    virtual bool supportsSequentialIterator() const { return false; }
+    virtual bool supportsRandomIterator() const { return false; }
+    virtual SequentialIterator* createSequentialIterator() const { return NULL; }
+    virtual RandomIterator* createRandomIterator() const  { return NULL; }
 
 protected:
     void setHeader(Header*); // stage takes ownership
diff -r 1848afbdad4d -r ea942f2e7393 src/CMakeLists.txt
--- a/src/CMakeLists.txt	Thu Mar 24 10:38:30 2011 -0700
+++ b/src/CMakeLists.txt	Thu Mar 24 10:54:51 2011 -0700
@@ -39,6 +39,8 @@
   ${LIBPC_HEADERS_DIR}/types.hpp
   ${LIBPC_HEADERS_DIR}/Bounds.hpp
   ${LIBPC_HEADERS_DIR}/Color.hpp
+  ${LIBPC_HEADERS_DIR}/Chipper.hpp
+  ${LIBPC_HEADERS_DIR}/ChipperIterator.hpp
   ${LIBPC_HEADERS_DIR}/Dimension.hpp
   ${LIBPC_HEADERS_DIR}/DimensionLayout.hpp
   ${LIBPC_HEADERS_DIR}/Filter.hpp
@@ -62,6 +64,7 @@
 set(LIBPC_BASE_CPP
   Bounds.cpp
   Chipper.cpp
+  ChipperIterator.cpp
   Color.cpp
   Dimension.cpp
   DimensionLayout.cpp
diff -r 1848afbdad4d -r ea942f2e7393 src/Chipper.cpp
--- a/src/Chipper.cpp	Thu Mar 24 10:38:30 2011 -0700
+++ b/src/Chipper.cpp	Thu Mar 24 10:54:51 2011 -0700
@@ -40,6 +40,8 @@
 
 #include <libpc/chipper.hpp>
 #include <libpc/Utils.hpp>
+#include <libpc/ChipperIterator.hpp>
+#include <libpc/exceptions.hpp>
 // boost
 #include <boost/cstdint.hpp>
 // std
@@ -88,6 +90,46 @@
     return ids;
 }
 
+PointBuffer Block::GetBuffer( Stage& stage) const
+{
+
+    libpc::Header const& header = stage.getHeader();
+    libpc::Schema const& schema = header.getSchema();
+        
+    boost::int32_t size = m_right - m_left + 1;
+    if (size < 0)
+        throw libpc_error("m_right - m_left + 1 was less than 0 in Block::GetBuffer()!");
+        
+    PointBuffer buffer(schema, size);
+
+    if (!stage.supportsRandomIterator())
+        throw libpc_error("Chipper GetBuffer is unable to read data source randomly!");
+            
+    boost::scoped_ptr<RandomIterator> iter(stage.createRandomIterator());
+
+    std::vector<boost::uint32_t> ids = GetIDs();
+    libpc::PointBuffer one_point(schema, 1);
+
+    std::vector<boost::uint32_t>::const_iterator it;
+    boost::uint32_t count = 0;
+    for (it = ids.begin(); it != ids.end(); it++)
+    {
+        iter->seek(*it);
+        iter->read(one_point);
+        // m_stage.seekToPoint(*it);
+        
+        // FIXME: Use a user bounds here instead of reading everything  
+        // m_stage.read(buffer);
+        
+        buffer.copyPointsFast(static_cast<std::size_t>(count), static_cast<std::size_t>(0), one_point, 1); 
+        // 
+        // // put single point onto our block
+        count++;
+    }
+    
+    return buffer;
+}
+
 void Chipper::Chip()
 {
     Load(m_xvec, m_yvec, m_spare);
@@ -95,6 +137,25 @@
     DecideSplit(m_xvec, m_yvec, m_spare, 0, m_partitions.size() - 1);
 }
 
+const std::string& Chipper::getName() const
+{
+    static std::string name("Chipper");
+    return name;
+}
+
+libpc::SequentialIterator* Chipper::createSequentialIterator() const
+{
+    return new filters::ChipperSequentialIterator(*this);
+}
+
+
+libpc::RandomIterator* Chipper::createRandomIterator() const
+{
+    return 0;
+}
+
+
+
 void Chipper::Load(RefList& xvec, RefList& yvec, RefList& spare )
 {
     PtRef ref;
diff -r 1848afbdad4d -r ea942f2e7393 src/ChipperIterator.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ChipperIterator.cpp	Thu Mar 24 10:54:51 2011 -0700
@@ -0,0 +1,116 @@
+/******************************************************************************
+* 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 <libpc/Chipper.hpp>
+#include <libpc/ChipperIterator.hpp>
+
+#include <libpc/exceptions.hpp>
+
+namespace libpc { namespace filters {


More information about the Liblas-commits mailing list