[Liblas-commits] hg-main-tree: No longer do assert() when getDimensionIndex retur...

liblas-commits at liblas.org liblas-commits at liblas.org
Fri Apr 1 08:44:01 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/88cd7ccaa6b5
changeset: 487:88cd7ccaa6b5
user:      Howard Butler <hobu.inc at gmail.com>
date:      Fri Apr 01 07:43:35 2011 -0500
description:
No longer do assert() when getDimensionIndex returns a -1. Instead, return the -1, and then have getField return a 0 if it was given a field dimension of -1
Subject: hg-main-tree: BLOB point selection now working

details:   http://hg.libpc.orghg-main-tree/rev/4100e8e5a35f
changeset: 488:4100e8e5a35f
user:      Howard Butler <hobu.inc at gmail.com>
date:      Fri Apr 01 07:43:52 2011 -0500
description:
BLOB point selection now working

diffstat:

 apps/pc2pc.cpp                          |    6 +-
 include/libpc/PointBuffer.hpp           |   17 ++-
 include/libpc/drivers/oci/Iterator.hpp  |    3 +
 include/libpc/drivers/oci/Reader.hpp    |   49 +++++++++
 include/libpc/drivers/oci/oci_wrapper.h |    3 +
 src/Schema.cpp                          |    7 +-
 src/drivers/oci/Iterator.cpp            |   13 ++-
 src/drivers/oci/Reader.cpp              |  158 ++++++++++++++++++++++++++++---
 src/drivers/oci/oci_wrapper.cpp         |   51 ++++++++++
 9 files changed, 277 insertions(+), 30 deletions(-)

diffs (truncated from 562 to 300 lines):

diff -r 712ec8b1bd73 -r 4100e8e5a35f apps/pc2pc.cpp
--- a/apps/pc2pc.cpp	Thu Mar 31 09:33:40 2011 -0500
+++ b/apps/pc2pc.cpp	Fri Apr 01 07:43:52 2011 -0500
@@ -154,8 +154,8 @@
             tree.put("connection", "lidar/lidar at oracle.hobu.biz/crrel");
             tree.put("debug", true);
             tree.put("verbose", true);
-            // tree.put("select_sql", "select * from output");
-            tree.put("select_sql", "select cloud from hobu where id = 5");
+            tree.put("select_sql", "select * from output");
+            // tree.put("select_sql", "select cloud from hobu where id = 5");
 
             libpc::drivers::oci::Reader reader(options);
 
@@ -164,7 +164,7 @@
 
 
             libpc::drivers::liblas::LiblasWriter writer(reader, *ofs);
-            writer.setPointFormat( 3);
+            // writer.setPointFormat( 3);
             writer.write(numPoints);
     #else
             throw configuration_error("libPC not compiled with Oracle support");
diff -r 712ec8b1bd73 -r 4100e8e5a35f include/libpc/PointBuffer.hpp
--- a/include/libpc/PointBuffer.hpp	Thu Mar 31 09:33:40 2011 -0500
+++ b/include/libpc/PointBuffer.hpp	Fri Apr 01 07:43:52 2011 -0500
@@ -99,8 +99,8 @@
     }
 
     // accessors to a particular field of a particular point in this buffer
-    template<class T> T getField(std::size_t pointIndex, std::size_t fieldIndex) const;
-    template<class T> void setField(std::size_t pointIndex, std::size_t fieldIndex, T value);
+    template<class T> T getField(std::size_t pointIndex, boost::int32_t fieldIndex) const;
+    template<class T> void setField(std::size_t pointIndex, boost::int32_t fieldIndex, T value);
 
     // bulk copy all the fields from the given point into this object
     // NOTE: this is only legal if the src and dest schemas are exactly the same
@@ -132,8 +132,12 @@
 
 
 template <class T>
-inline void PointBuffer::setField(std::size_t pointIndex, std::size_t fieldIndex, T value)
+inline void PointBuffer::setField(std::size_t pointIndex, boost::int32_t fieldIndex, T value)
 {
+    if (fieldIndex == -1)
+    {
+        return; // no-op in the case where fieldIndex is -1 and we don't actually have that field
+    }
     std::size_t offset = (pointIndex * m_pointSize) + m_schemaLayout.getDimensionLayout(fieldIndex).getByteOffset();
     assert(offset + sizeof(T) <= m_pointSize * m_capacity);
     boost::uint8_t* p = m_data.get() + offset;
@@ -143,8 +147,13 @@
 
 
 template <class T>
-inline T PointBuffer::getField(std::size_t pointIndex, std::size_t fieldIndex) const
+inline T PointBuffer::getField(std::size_t pointIndex, boost::int32_t fieldIndex) const
 {
+    if (fieldIndex == -1)
+    {
+        return T(0);
+    }
+        
     std::size_t offset = (pointIndex * m_pointSize) + m_schemaLayout.getDimensionLayout(fieldIndex).getByteOffset();
     assert(offset + sizeof(T) <= m_pointSize * m_capacity);
     boost::uint8_t* p = m_data.get() + offset;
diff -r 712ec8b1bd73 -r 4100e8e5a35f include/libpc/drivers/oci/Iterator.hpp
--- a/include/libpc/drivers/oci/Iterator.hpp	Thu Mar 31 09:33:40 2011 -0500
+++ b/include/libpc/drivers/oci/Iterator.hpp	Fri Apr 01 07:43:52 2011 -0500
@@ -58,11 +58,14 @@
     
     boost::uint32_t readBuffer(PointBuffer& data);
 
+    bool m_at_end;
+
 private:
     const Reader& m_reader;
     
     IteratorBase& operator=(const IteratorBase&); // not implemented
     IteratorBase(const IteratorBase&); // not implemented};
+
 };
 
 
diff -r 712ec8b1bd73 -r 4100e8e5a35f include/libpc/drivers/oci/Reader.hpp
--- a/include/libpc/drivers/oci/Reader.hpp	Thu Mar 31 09:33:40 2011 -0500
+++ b/include/libpc/drivers/oci/Reader.hpp	Fri Apr 01 07:43:52 2011 -0500
@@ -40,10 +40,36 @@
 #include <libpc/Stage.hpp>
 #include <libpc/drivers/oci/Common.hpp>
 
+#include <boost/scoped_ptr.hpp>
+#include <boost/scoped_array.hpp>
 
+#include <vector>
 
 namespace libpc { namespace drivers { namespace oci {
 
+class Block
+{
+    
+public:
+    
+    Block() {};
+    
+    boost::int32_t           obj_id;
+    boost::int32_t           blk_id;
+    sdo_geometry*   blk_extent;
+    sdo_orgscl_type* blk_domain;
+
+    double           pcblk_min_res;
+    double           pcblk_max_res;
+    boost::int32_t           num_points;
+    boost::int32_t           num_unsorted_points;
+    boost::int32_t           pt_sort_dim;
+
+
+private:
+    boost::uint32_t m_capacity;
+};
+
 class LIBPC_DLL Reader : public libpc::Stage
 {
 
@@ -59,10 +85,23 @@
         return false;
     }
 
+    enum QueryType
+    {
+        QUERY_SDO_PC,
+        QUERY_SDO_PC_BLK,
+        QUERY_BLK_TABLE,
+        QUERY_UNKNOWN
+    };
+    
     libpc::SequentialIterator* createSequentialIterator() const;
     Connection getConnection () const { return m_connection;}
     Options& getOptions() const { return m_options; }
     
+    sdo_pc* getPCObject() const { return m_pc; }
+    sdo_pc_blk* getPCBlockObject() const { return m_block_table_type; }
+    
+    Block* getBlock() const { return m_block_table; }
+    bool fetchNext() const;
 private:
 
     Reader& operator=(const Reader&); // not implemented
@@ -72,11 +111,21 @@
     void Debug();
     void registerFields();
     void fetchPCFields();
+    QueryType describeQueryType();
+    void doBlockTableDefine();
 
     Options& m_options;
     Connection m_connection;
     Statement m_statement;
     bool m_verbose;
+    QueryType m_qtype;
+    
+    sdo_pc* m_pc;
+    sdo_pc_blk* m_block_table_type;
+    Block* m_block_table;
+    OCILobLocator* m_locator;
+    std::vector<boost::uint8_t> m_points;
+
 };
 
 }}} // namespace libpc::driver::oci
diff -r 712ec8b1bd73 -r 4100e8e5a35f include/libpc/drivers/oci/oci_wrapper.h
--- a/include/libpc/drivers/oci/oci_wrapper.h	Thu Mar 31 09:33:40 2011 -0500
+++ b/include/libpc/drivers/oci/oci_wrapper.h	Fri Apr 01 07:43:52 2011 -0500
@@ -347,6 +347,8 @@
     void                DestroyType( sdo_geometry** pphData );
     void                CreateType( sdo_pc** pphData );
     void                DestroyType( sdo_pc** pphData );
+    void                CreateType( sdo_orgscl_type** pphData );
+    void                DestroyType( sdo_orgscl_type** pphData );
     void                CreateType( OCIArray** phData , OCIType* type);
     void                DestroyType( OCIArray** phData );
     OCIType*            DescribeType( const char *pszTypeName );
@@ -434,6 +436,7 @@
     void                Define( sdo_georaster** pphData );
     void                Define( sdo_geometry** pphData );
     void                Define( sdo_pc** pphData );
+    void                Define( sdo_orgscl_type** pphData );
     void                Define( sdo_pc_blk** pphData );
     void                Define( OCILobLocator** pphLocator, long nIterations );
     void                DefineClob( OCILobLocator** pphLocator, long nIterations );
diff -r 712ec8b1bd73 -r 4100e8e5a35f src/Schema.cpp
--- a/src/Schema.cpp	Thu Mar 31 09:33:40 2011 -0500
+++ b/src/Schema.cpp	Fri Apr 01 07:43:52 2011 -0500
@@ -163,15 +163,16 @@
 {
     const int index = m_indexTable[field];
     
-    assert(index != -1);
+    // assert(index != -1);
     if (index == -1)
     {
-        throw libpc_error("Requested dimension field not present");
+        return -1;
+        // throw libpc_error("Requested dimension field not present");
     }
     
     const Dimension& dim = m_dimensions[index];
     
-    assert(dim.getDataType() == datatype);
+    // assert(dim.getDataType() == datatype);
     if (dim.getDataType() != datatype)
     {
         throw libpc_error("Requested dimension field present, but with different datatype");
diff -r 712ec8b1bd73 -r 4100e8e5a35f src/drivers/oci/Iterator.cpp
--- a/src/drivers/oci/Iterator.cpp	Thu Mar 31 09:33:40 2011 -0500
+++ b/src/drivers/oci/Iterator.cpp	Fri Apr 01 07:43:52 2011 -0500
@@ -44,7 +44,8 @@
 namespace libpc { namespace drivers { namespace oci {
 
 IteratorBase::IteratorBase(const Reader& reader)
-    : m_reader(reader)
+    : m_at_end(false)
+    , m_reader(reader)
 {
     oci::Options& options = m_reader.getOptions();
     
@@ -68,7 +69,15 @@
 {
     boost::uint32_t numPoints = data.getCapacity();
     
+    bool read = m_reader.fetchNext();
+    Block* block = m_reader.getBlock();
     
+    if (!read)
+    {
+        m_at_end = true;
+        return 0;
+    }
+        std::cout << "fetched" << std::endl;
     // boost::uint32_t i = 0;
     // 
     // const Schema& schema = data.getSchema();
@@ -213,7 +222,7 @@
 
 bool SequentialIterator::atEndImpl() const
 {
-    return true; 
+    return m_at_end; 
     // return getIndex() >= getStage().getNumPoints();
 }
 
diff -r 712ec8b1bd73 -r 4100e8e5a35f src/drivers/oci/Reader.cpp
--- a/src/drivers/oci/Reader.cpp	Thu Mar 31 09:33:40 2011 -0500
+++ b/src/drivers/oci/Reader.cpp	Fri Apr 01 07:43:52 2011 -0500
@@ -48,6 +48,7 @@
     : libpc::Stage()
     , m_options(options)
     , m_verbose(false)
+    , m_qtype(QUERY_UNKNOWN)
 {
 
     Debug();
@@ -55,7 +56,6 @@
     m_connection = Connect(m_options);
 
     
-    
     std::string sql = options.GetPTree().get<std::string>("select_sql");
     
     if (sql.size() == 0 )
@@ -67,32 +67,138 @@
     
     m_statement->Execute(0);
 
-    fetchPCFields();
+    m_qtype = describeQueryType();
     
     // int foo;
     // int block_id;
     // 
     // m_statement->Define(&foo);
     // m_statement->Define(&block_id);
-    
-    sdo_pc_blk* block;
-    sdo_pc* pc;
 
-    m_connection->CreateType(&pc);
-
-
-    m_statement->Define(&pc);
+    m_connection->CreateType(&m_pc);
     
 
-    while(m_statement->Fetch() )
+    if (m_qtype == QUERY_SDO_PC)
     {
-        std::cout << " Block: " << m_statement->GetInteger(&(pc->pc_id)) << std::endl;
+        m_statement->Define(&m_pc);
+        // Unpack SDO_PC object to get at block 
+        // table, select that stuff, and unpack the blocks


More information about the Liblas-commits mailing list