[Liblas-commits] hg-main-tree: turn off endianness Dimension setting for now

liblas-commits at liblas.org liblas-commits at liblas.org
Tue Jul 26 13:10:23 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/97158d9d8875
changeset: 936:97158d9d8875
user:      Howard Butler <hobu.inc at gmail.com>
date:      Tue Jul 26 12:10:08 2011 -0500
description:
turn off endianness Dimension setting for now
Subject: hg-main-tree: implement a tuple-map for dimension lookup

details:   http://hg.libpc.orghg-main-tree/rev/50d3de7fe1a0
changeset: 937:50d3de7fe1a0
user:      Howard Butler <hobu.inc at gmail.com>
date:      Tue Jul 26 12:10:18 2011 -0500
description:
implement a tuple-map for dimension lookup

diffstat:

 include/pdal/Schema.hpp        |  10 +++++-
 src/Schema.cpp                 |  67 ++++++++++++++++++++++++++++++++---------
 src/filters/ByteSwapFilter.cpp |  29 +++++++++--------
 3 files changed, 76 insertions(+), 30 deletions(-)

diffs (201 lines):

diff -r 0592edb74697 -r 50d3de7fe1a0 include/pdal/Schema.hpp
--- a/include/pdal/Schema.hpp	Tue Jul 26 11:52:01 2011 -0500
+++ b/include/pdal/Schema.hpp	Tue Jul 26 12:10:18 2011 -0500
@@ -45,6 +45,7 @@
 #include <pdal/pdal.hpp>
 
 #include <vector>
+#include <map>
 
 #include <pdal/Dimension.hpp>
 
@@ -56,10 +57,16 @@
 #include <boost/array.hpp>
 #include <boost/optional.hpp>
 
+#include <boost/tuple/tuple.hpp>
+#include <boost/tuple/tuple_comparison.hpp>
+
+
 
 namespace pdal
 {
 
+typedef boost::tuple<Dimension::Field, Dimension::DataType> tpl_t;
+
 /// Schema definition
 class PDAL_DLL Schema
 {
@@ -85,7 +92,7 @@
     const Dimension& getDimension(std::size_t index) const;
     Dimension& getDimension(std::size_t index);
     const Dimensions& getDimensions() const;
-    Dimensions& getDimensions();
+    // Dimensions& getDimensions();
 
     // returns the index of the field
     //
@@ -109,6 +116,7 @@
 private:
     std::vector<Dimension> m_dimensions;
 
+    std::map<tpl_t, std::size_t> m_dimensions_map;
     // this is a mapping from field name to index position in the
     // m_dimensions array (or -1 if field not present)
     // int m_indexTable[Dimension::Field_LAST];
diff -r 0592edb74697 -r 50d3de7fe1a0 src/Schema.cpp
--- a/src/Schema.cpp	Tue Jul 26 11:52:01 2011 -0500
+++ b/src/Schema.cpp	Tue Jul 26 12:10:18 2011 -0500
@@ -62,6 +62,7 @@
 /// copy constructor
 Schema::Schema(Schema const& other) 
     : m_dimensions(other.m_dimensions)
+    , m_dimensions_map(other.m_dimensions_map)
 {
 
 }
@@ -73,6 +74,7 @@
     if (&rhs != this)
     {
         m_dimensions = rhs.m_dimensions;
+        m_dimensions_map = rhs.m_dimensions_map;
     }
 
     return *this;
@@ -81,7 +83,8 @@
 
 bool Schema::operator==(const Schema& other) const
 {
-    if (m_dimensions == other.m_dimensions)
+    if (m_dimensions == other.m_dimensions &&
+        m_dimensions_map == other.m_dimensions_map)
     {
         return true;
     }
@@ -125,6 +128,8 @@
 void Schema::addDimension(Dimension const& dim)
 {
     m_dimensions.push_back(dim);
+    std::pair<tpl_t, std::size_t> p(tpl_t(dim.getField(),dim.getDataType() ), m_dimensions.size()-1);
+    m_dimensions_map.insert(p);
     return;
 }
 
@@ -133,6 +138,19 @@
 {
     m_dimensions.erase( std::remove( m_dimensions.begin(), m_dimensions.end(), dim), 
                         m_dimensions.end());
+    
+    m_dimensions_map.clear();
+    DimensionsCIter it = m_dimensions.begin();
+    int i(0);
+    while (it != m_dimensions.end())
+    {
+        std::pair<tpl_t, std::size_t> p(tpl_t(it->getField(),it->getDataType() ), i);
+
+        m_dimensions_map.insert(p);
+        ++it;
+        ++i;
+    }
+    
     return;
 }
 
@@ -154,25 +172,44 @@
     return m_dimensions;
 }
 
-Schema::Dimensions& Schema::getDimensions()
-{
-    return m_dimensions;
-}
+// Schema::Dimensions& Schema::getDimensions()
+// {
+//     return m_dimensions;
+// }
 
 
 int Schema::getDimensionIndex(Dimension::Field field, Dimension::DataType datatype) const
 {
-    DimensionsCIter it = m_dimensions.begin();
-    int i = 0;
-    while (it != m_dimensions.end())
-    {
-        if (field == it->getField() && datatype == it->getDataType())
-            return i;
-        ++it;
-        ++i;
-    }
 
-    return -1;
+    tpl_t t(field,datatype);
+    
+    std::map<tpl_t, std::size_t>::const_iterator i = m_dimensions_map.find(t);
+    
+    int m = 0;
+    
+    if (i == m_dimensions_map.end()) m = -1;
+    else
+        m = i->second;
+    
+    
+
+    // DimensionsCIter it = m_dimensions.begin();
+    // int j = 0;
+    // while (it != m_dimensions.end())
+    // {
+    //     if (field == it->getField() && datatype == it->getDataType())
+    //     {
+    //         break;
+    //     }
+    //     ++it;
+    //     ++j;
+    // }
+    
+    // if (j == m_dimensions.size()) j = -1;
+    
+    // std::cout << "i->second: " << m << " j: " << j << " map size: "<< m_dimensions_map.size() << " vec size: " << m_dimensions.size() << std::endl;
+    return m;
+
 }
 
 
diff -r 0592edb74697 -r 50d3de7fe1a0 src/filters/ByteSwapFilter.cpp
--- a/src/filters/ByteSwapFilter.cpp	Tue Jul 26 11:52:01 2011 -0500
+++ b/src/filters/ByteSwapFilter.cpp	Tue Jul 26 12:10:18 2011 -0500
@@ -66,20 +66,21 @@
 
     Schema& schema = this->getSchemaRef();
 
-    std::vector<Dimension>& dimensions = schema.getDimensions();
-    for (std::vector<Dimension>::iterator i = dimensions.begin(); i != dimensions.end(); ++i)
-    {
-        pdal::EndianType t = i->getEndianness();
-        if (t == Endian_Little)
-        {
-            i->setEndianness(Endian_Big);
-        } else if (t == Endian_Big)
-        {
-            i->setEndianness(Endian_Little);
-        } else {
-            throw pdal_error("ByteSwapFilter can only swap big/little endian dimensions");
-        }
-    }    
+    // FIXME:  this doesn't work anymore
+    // std::vector<Dimension>& dimensions = schema.getDimensions();
+    // for (std::vector<Dimension>::iterator i = dimensions.begin(); i != dimensions.end(); ++i)
+    // {
+    //     pdal::EndianType t = i->getEndianness();
+    //     if (t == Endian_Little)
+    //     {
+    //         i->setEndianness(Endian_Big);
+    //     } else if (t == Endian_Big)
+    //     {
+    //         i->setEndianness(Endian_Little);
+    //     } else {
+    //         throw pdal_error("ByteSwapFilter can only swap big/little endian dimensions");
+    //     }
+    // }    
         
     return;
 }


More information about the Liblas-commits mailing list