[Liblas-commits] hg-main-tree: comment out the assertion about making sure we wro...

liblas-commits at liblas.org liblas-commits at liblas.org
Thu Apr 7 14:06:34 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/dc12125afc0f
changeset: 505:dc12125afc0f
user:      Howard Butler <hobu.inc at gmail.com>
date:      Thu Apr 07 13:04:18 2011 -0500
description:
comment out the assertion about making sure we wrote the right number of points.  We don't know that anymore
Subject: hg-main-tree: successfully read 5-fixed-dimension OCI data for the first time

details:   http://hg.libpc.orghg-main-tree/rev/68912ea61235
changeset: 506:68912ea61235
user:      Howard Butler <hobu.inc at gmail.com>
date:      Thu Apr 07 13:06:22 2011 -0500
description:
successfully read 5-fixed-dimension OCI data for the first time

diffstat:

 include/libpc/drivers/oci/Common.hpp   |   13 ++++
 include/libpc/drivers/oci/Iterator.hpp |    2 +-
 src/Writer.cpp                         |    2 +-
 src/drivers/oci/Iterator.cpp           |  104 ++++++++++++++++++++++++++++----
 src/drivers/oci/common.cpp             |    9 +-
 5 files changed, 111 insertions(+), 19 deletions(-)

diffs (250 lines):

diff -r 82cabe497436 -r 68912ea61235 include/libpc/drivers/oci/Common.hpp
--- a/include/libpc/drivers/oci/Common.hpp	Wed Apr 06 21:19:59 2011 -0500
+++ b/include/libpc/drivers/oci/Common.hpp	Thu Apr 07 13:06:22 2011 -0500
@@ -38,6 +38,7 @@
 #include <libpc/libpc.hpp>
 
 #include "oci_wrapper.h"
+#include "Endian.hpp"
 
 #include <boost/shared_ptr.hpp>
 #include <boost/scoped_ptr.hpp>
@@ -66,6 +67,18 @@
 #define compare_no_case(a,b,n)  strncasecmp( (a), (b), (n) )
 #endif
 
+struct FiveDimensionOCI
+{
+    double x;
+    double y;
+    double z;
+    double t;
+    double c;
+    uint32_t blk_id;
+    uint32_t pc_id;
+};
+
+
 enum QueryType
 {
     QUERY_SDO_PC,
diff -r 82cabe497436 -r 68912ea61235 include/libpc/drivers/oci/Iterator.hpp
--- a/include/libpc/drivers/oci/Iterator.hpp	Wed Apr 06 21:19:59 2011 -0500
+++ b/include/libpc/drivers/oci/Iterator.hpp	Thu Apr 07 13:06:22 2011 -0500
@@ -62,7 +62,7 @@
     Statement m_statement;
     bool m_at_end;
     QueryType m_querytype;
-    Block* m_block;
+    boost::scoped_ptr<Block> m_block;
     OCILobLocator* m_locator;
 
     sdo_pc* m_pc;
diff -r 82cabe497436 -r 68912ea61235 src/Writer.cpp
--- a/src/Writer.cpp	Wed Apr 06 21:19:59 2011 -0500
+++ b/src/Writer.cpp	Thu Apr 07 13:06:22 2011 -0500
@@ -143,7 +143,7 @@
 
     writeEnd();
 
-    assert(m_actualNumPointsWritten <= m_targetNumPointsToWrite);
+    // assert(m_actualNumPointsWritten <= m_targetNumPointsToWrite);
 
     return m_actualNumPointsWritten;
 }
diff -r 82cabe497436 -r 68912ea61235 src/drivers/oci/Iterator.cpp
--- a/src/drivers/oci/Iterator.cpp	Wed Apr 06 21:19:59 2011 -0500
+++ b/src/drivers/oci/Iterator.cpp	Thu Apr 07 13:06:22 2011 -0500
@@ -33,6 +33,7 @@
 ****************************************************************************/
 
 #include <libpc/drivers/oci/Iterator.hpp>
+#include <libpc/Utils.hpp>
 
 #include <liblas/factory.hpp>
 
@@ -43,19 +44,20 @@
 
 #include <sstream>
 #include <map>
+#include <algorithm>
 
 
 namespace libpc { namespace drivers { namespace oci {
 
 IteratorBase::IteratorBase(const Reader& reader)
     : m_at_end(false)
-    , m_block(0)
+    , m_block(new Block(reader.getConnection()))
     , m_reader(reader)
 
 {
     // oci::Options& options = m_reader.getOptions();
 
-    m_reader.getConnection()->CreateType(&m_pc);
+    // m_reader.getConnection()->CreateType(&m_pc);
     
     m_statement = Statement(m_reader.getConnection()->CreateStatement(m_reader.getQuery().c_str()));
     
@@ -90,7 +92,86 @@
 
 boost::uint32_t IteratorBase::unpackOracleData(PointBuffer& data)
 {
+    boost::uint32_t capacity = data.getCapacity();
+    boost::uint32_t numPoints = data.getNumPoints();
     
+    boost::uint32_t space = capacity - numPoints;
+    boost::uint32_t point_position = numPoints;
+    
+    if (m_block->num_points < 0)
+    {
+        std::ostringstream oss;
+        oss << "This oracle block has a num_points that is negative (" << m_block->num_points <<")!";
+        throw libpc_error(oss.str());
+    }
+    
+    if (space < static_cast<boost::uint32_t>(m_block->num_points))
+    {
+        std::ostringstream oss;
+        oss << "Not enough space to store this block!  The capacity left in the buffer is ";
+        oss << capacity << ", the Oracle block has " << m_block->num_points << " points ";
+        throw libpc_error(oss.str());
+    }
+
+    std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield);
+    std::cout.precision(2);
+
+    const Schema& schema = data.getSchema();
+    const int indexX = schema.getDimensionIndex(Dimension::Field_X, Dimension::Int32);
+    const int indexY = schema.getDimensionIndex(Dimension::Field_Y, Dimension::Int32);
+    const int indexZ = schema.getDimensionIndex(Dimension::Field_Z, Dimension::Int32);
+    const int indexTime = schema.getDimensionIndex(Dimension::Field_Time, Dimension::Double);
+    const int indexClassification = schema.getDimensionIndex(Dimension::Field_Classification, Dimension::Uint8);
+
+    const Dimension& dimX = schema.getDimension(indexX);
+    const Dimension& dimY = schema.getDimension(indexY);
+    const Dimension& dimZ = schema.getDimension(indexZ);
+    
+    double scalex = dimX.getNumericScale();
+    double scaley = dimY.getNumericScale();
+    double scalez = dimZ.getNumericScale();
+    
+    double offsetx = dimX.getNumericOffset();
+    double offsety = dimY.getNumericOffset();
+    double offsetz = dimZ.getNumericOffset();
+     
+    FiveDimensionOCI* d;
+    for (boost::uint32_t i = 0; i < static_cast<boost::uint32_t>(m_block->num_points); i++)
+    {
+        boost::uint32_t byte_position = i*sizeof(FiveDimensionOCI);
+        
+        d = (FiveDimensionOCI*)(&(*m_block->chunk)[byte_position]);
+        SWAP_BE_TO_LE(d->x);
+        SWAP_BE_TO_LE(d->y);
+        SWAP_BE_TO_LE(d->z);
+        SWAP_BE_TO_LE(d->t);
+        SWAP_BE_TO_LE(d->c);
+        SWAP_BE_TO_LE(d->blk_id);
+        SWAP_BE_TO_LE(d->pc_id);
+        
+        
+        
+        // std::cout << "sizeof(FiveDimensionOCI): " << sizeof(FiveDimensionOCI) <<  " position: " << position << " i: " << i 
+        //           << " x: " << d->x << " y: " << d->y << " z: " << d->z << std::endl;
+
+
+        boost::int32_t x = static_cast<boost::int32_t>(
+                         Utils::sround((d->x - offsetx) / scalex));
+        boost::int32_t y = static_cast<boost::int32_t>(
+                         Utils::sround((d->y - offsety) / scaley));
+        boost::int32_t z = static_cast<boost::int32_t>(
+                         Utils::sround((d->z - offsetz) / scalez));
+        data.setField(point_position, indexX, x);
+        data.setField(point_position, indexY, y);
+        data.setField(point_position, indexZ, z);
+        
+        data.setField(point_position, indexTime, d->t);
+        data.setField(point_position, indexClassification, static_cast<boost::uint8_t>(d->c));
+        
+        point_position++;
+        data.setNumPoints(point_position);
+    
+    }
     return 0;
 }
 
@@ -122,7 +203,7 @@
         bDidRead = true;
         std::cout << "we already had points in our cache, using those" << std::endl;
 
-
+        unpackOracleData(data);
     }
 
 
@@ -146,7 +227,7 @@
             break;
         }
 
-        boost::uint32_t nAmountRead;
+        boost::uint32_t nAmountRead = 0;
     
     
         boost::uint32_t blob_length = m_statement->GetBlobLength(m_locator);
@@ -156,20 +237,18 @@
         {
             m_block->chunk->resize(blob_length);
         }
-        // std::vector<boost::uint8_t> chunk;
-        // if (chunk.size() < blob_length)
-        // {
-        //     chunk.resize(blob_length);
-        // }
+
+
         std::cout << " m_block->chunk->size() : " << m_block->chunk->size()<< std::endl;
         
         bool read_all_data = m_statement->ReadBlob( m_locator,
                                          (void*)(&(*m_block->chunk)[0]),
-                                         m_block->chunk->size(), 
+                                         m_block->chunk->size() , 
                                          &nAmountRead);
         if (!read_all_data) throw libpc_error("Did not read all blob data!");
         std::cout << "nAmountRead: " << nAmountRead << " m_block->chunk->size() : " << m_block->chunk->size()<< std::endl;
-
+        
+        unpackOracleData(data);
         bDidRead = m_statement->Fetch();
         if (!bDidRead)
         {
@@ -338,10 +417,7 @@
     signed short nScale = 0;
     char szTypeName[OWNAME];
     
-    if (!m_block)
-        m_block = new Block(m_reader.getConnection());
 
-    m_block->num_points = 0;
 
 
 
diff -r 82cabe497436 -r 68912ea61235 src/drivers/oci/common.cpp
--- a/src/drivers/oci/common.cpp	Wed Apr 06 21:19:59 2011 -0500
+++ b/src/drivers/oci/common.cpp	Thu Apr 07 13:06:22 2011 -0500
@@ -145,10 +145,13 @@
 
 Block::~Block()
 {
+    m_connection->DestroyType(&blk_domain);
+    m_connection->DestroyType(&blk_extent->sdo_elem_info);
     m_connection->DestroyType(&blk_extent->sdo_ordinates);
-    m_connection->DestroyType(&blk_extent->sdo_elem_info);
-    m_connection->DestroyType(&blk_extent);
-    m_connection->DestroyType(&blk_domain);
+    
+    // FIXME: For some reason having the dtor destroy this
+    // causes a segfault
+    // m_connection->DestroyType(&blk_extent);
 }
 std::string to_upper(const std::string& input)
 {


More information about the Liblas-commits mailing list