[Liblas-commits] hg: 2 new changesets

liblas-commits at liblas.org liblas-commits at liblas.org
Fri Oct 8 13:36:58 EDT 2010


changeset 1420307ffed0 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=1420307ffed0
summary: parallel implementation of multi_index_container for liblas::Schema complete.  committing here so I have somewhere to roll back to if it goes terribly, terribly wrong

changeset 35180fc82d8b in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=35180fc82d8b
summary: replace usage of liblas::Schema's storage of dimensions from an unordered map to a multi_index

diffstat:

 include/liblas/lasdimension.hpp |   26 +++++
 include/liblas/lasschema.hpp    |   46 ++++++---
 src/lasheader.cpp               |   12 +-
 src/lasschema.cpp               |  174 ++++++++++++++++++++++-----------------
 4 files changed, 162 insertions(+), 96 deletions(-)

diffs (truncated from 486 to 300 lines):

diff -r 9f5bd70a3a6d -r 35180fc82d8b include/liblas/lasdimension.hpp
--- a/include/liblas/lasdimension.hpp	Thu Oct 07 14:27:35 2010 -0500
+++ b/include/liblas/lasdimension.hpp	Fri Oct 08 12:36:47 2010 -0500
@@ -164,6 +164,32 @@
   
 };
 
+struct SetRequired
+{
+  SetRequired(bool req):req_(req){}
+
+  void operator()(Dimension& e)
+  {
+      e.IsRequired(req_);
+  }
+
+private:
+  int req_;
+};
+
+struct SetActive
+{
+  SetActive(bool req):req_(req){}
+
+  void operator()(Dimension& e)
+  {
+      e.IsActive(req_);
+  }
+
+private:
+  int req_;
+};
+
 
 } // namespace liblas
 
diff -r 9f5bd70a3a6d -r 35180fc82d8b include/liblas/lasschema.hpp
--- a/include/liblas/lasschema.hpp	Thu Oct 07 14:27:35 2010 -0500
+++ b/include/liblas/lasschema.hpp	Fri Oct 08 12:36:47 2010 -0500
@@ -60,6 +60,7 @@
 #include <boost/multi_index/ordered_index.hpp>
 #include <boost/multi_index/hashed_index.hpp>
 #include <boost/multi_index/sequenced_index.hpp>
+#include <boost/multi_index/mem_fun.hpp>
 
 
 // std
@@ -72,21 +73,32 @@
 
 namespace liblas {  
 
-typedef boost::unordered_map<std::string, Dimension> DimensionMap;
 typedef std::vector<Dimension> DimensionArray;
 typedef boost::array<std::size_t, 4> SizesArray;
 typedef boost::unordered_map<std::string, SizesArray> SizesMap;
 
-// using namespace boost::multi_index;
-// 
-// typedef multi_index_container<
-//     DimensionPtr,
-//     indexed_by<
-//         hashed_unique<tag<key>,  BOOST_MULTI_INDEX_MEMBER(Data_t,int,key_)>,
-//         sequenced<tag<key_seq> >
-//     >
-// > Map;
+using namespace boost::multi_index;
 
+struct name{};
+struct position{};
+
+
+
+typedef multi_index_container<
+  Dimension,
+  indexed_by<
+    // sort by Dimension::operator<
+    ordered_unique<tag<position>, identity<Dimension> >,
+    
+    // sort by less<string> on GetName
+    hashed_unique<tag<name>, const_mem_fun<Dimension,std::string const&,&Dimension::GetName> >
+    
+
+  >
+> IndexMap;
+
+typedef IndexMap::index<name>::type index_by_name;
+typedef IndexMap::index<position>::type index_by_position;
 
 /// Schema definition
 class Schema
@@ -114,16 +126,18 @@
     void SetDataFormatId(PointFormatName const& value);
     
     void AddDimension(Dimension const& dim);
-    Dimension const& GetDimension(std::string const& name) const;
-    Dimension& GetDimension(std::string const& name);
+    Dimension const& GetDimension(std::string const& n) const;
+    // Dimension& GetDimension(std::string const& n);
     
     // DimensionPtr GetDimension(std::size_t index) const;
     void RemoveDimension(Dimension const& dim);
     
+    void SetDimension(Dimension const& dim);
+    
     std::vector<std::string> GetDimensionNames() const;
-    DimensionMap const& GetDimensions() const { return m_dimensions; }
+    IndexMap const& GetDimensions() const { return m_index; }
     liblas::property_tree::ptree GetPTree() const;
-    SizesArray const& GetSizes(std::string const& name) const;
+    SizesArray const& GetSizes(std::string const& n) const;
     
     boost::uint16_t GetSchemaVersion() const { return m_schemaversion; }
     void SetSchemaVersion(boost::uint16_t v) { m_schemaversion = v; }
@@ -142,7 +156,7 @@
     
 private:
 
-    DimensionMap m_dimensions;
+    IndexMap m_index;
     
     void add_record0_dimensions();
     void add_time();
@@ -150,7 +164,7 @@
     void update_required_dimensions(PointFormatName data_format_id);
     bool IsSchemaVLR(VariableRecord const& vlr);
     liblas::property_tree::ptree LoadPTree(VariableRecord const& v);
-    DimensionMap LoadDimensions(liblas::property_tree::ptree tree);
+    IndexMap LoadDimensions(liblas::property_tree::ptree tree);
 
 };
 
diff -r 9f5bd70a3a6d -r 35180fc82d8b src/lasheader.cpp
--- a/src/lasheader.cpp	Thu Oct 07 14:27:35 2010 -0500
+++ b/src/lasheader.cpp	Fri Oct 08 12:36:47 2010 -0500
@@ -685,21 +685,23 @@
     
     m_schema = format;
     
-    Dimension& x = m_schema.GetDimension("X");
+    Dimension x = m_schema.GetDimension("X");
     x.SetScale(m_scales.x);
     x.IsFinitePrecision(true);
     x.SetOffset(m_offsets.x);
+    m_schema.SetDimension(x);
     
-    Dimension& y = m_schema.GetDimension("Y");
+    Dimension y = m_schema.GetDimension("Y");
     y.SetScale(m_scales.y);
     y.IsFinitePrecision(true);
     y.SetOffset(m_offsets.y);
-
-    Dimension& z = m_schema.GetDimension("Z");
+    m_schema.SetDimension(y);
+    
+    Dimension z = m_schema.GetDimension("Z");
     z.SetScale(m_scales.z);
     z.IsFinitePrecision(true);
     z.SetOffset(m_offsets.z);
-    
+    m_schema.SetDimension(z);
     
 } 
 
diff -r 9f5bd70a3a6d -r 35180fc82d8b src/lasschema.cpp
--- a/src/lasschema.cpp	Thu Oct 07 14:27:35 2010 -0500
+++ b/src/lasschema.cpp	Fri Oct 08 12:36:47 2010 -0500
@@ -225,13 +225,13 @@
     AddDimension(point_source_id);    
     text.str("");
 
-    for (DimensionMap::iterator i = m_dimensions.begin(); i != m_dimensions.end(); ++i)
+    index_by_position& position_index = m_index.get<position>();
+    for (index_by_position::iterator i = position_index.begin(); i!= position_index.end(); ++i)
     {
-        Dimension & t = (*i).second;
-        t.IsRequired(true);
-        t.IsActive(true);
+        position_index.modify(i, SetRequired(true));
+        position_index.modify(i, SetActive(true));
     }
-    
+
 }
 
 void Schema::add_color()
@@ -297,22 +297,22 @@
 {
     DimensionArray user_dims;
 
-    if (!m_dimensions.empty())
+    index_by_position& position_index = m_index.get<position>();
+    if (!position_index.empty())
     {
         // Keep any non-required dimensions the user may have added
         // and add them back to the list of dimensions
-        for (DimensionMap::const_iterator i = m_dimensions.begin(); i != m_dimensions.end(); ++i)
+        for (index_by_position::const_iterator i = position_index.begin(); i != position_index.end(); ++i)
         {
-            if ( i->second.IsRequired() == false)
-                user_dims.push_back(i->second);
+            if ( i->IsRequired() == false)
+                user_dims.push_back(*i);
         }
-    }
-    
+    }    
     // Sort the user dimensions so we preserve the order they were 
     // added in.
     std::sort(user_dims.begin(), user_dims.end(), sort_dimensions);
     
-    m_dimensions.clear();
+    position_index.clear();
     
     // Reset the position counter.  Dimensions will be added in the 
     // order they need to be according to add_record0_dimensions, etc.
@@ -361,7 +361,7 @@
     , m_bit_size(other.m_bit_size)
     , m_base_bit_size(other.m_base_bit_size)
     , m_schemaversion(other.m_schemaversion)
-    , m_dimensions(other.m_dimensions)
+    , m_index(other.m_index)
 {
 }
 // 
@@ -372,7 +372,7 @@
     {
         m_data_format_id = rhs.m_data_format_id;
         m_nextpos = rhs.m_nextpos;
-        m_dimensions = rhs.m_dimensions;
+        m_index = rhs.m_index;
         m_base_bit_size = rhs.m_base_bit_size;
         m_bit_size = rhs.m_bit_size;
         m_schemaversion = rhs.m_schemaversion;
@@ -401,9 +401,9 @@
     return pt;    
 }
 
-DimensionMap Schema::LoadDimensions(liblas::property_tree::ptree tree)
+IndexMap Schema::LoadDimensions(liblas::property_tree::ptree tree)
 {
-    DimensionMap dimensions;
+    IndexMap dimensions;
     
     using liblas::property_tree::ptree;
     ptree::const_iterator i;
@@ -441,9 +441,8 @@
             d.SetMaximum(max);
         }
 
-        dimensions.insert(std::make_pair(name, d));
+        dimensions.insert(d);
 
-        // dimensions[name] = d;
     }
     
     boost::uint32_t pf =tree.get<boost::uint32_t>("LASSchema.formatid");
@@ -460,12 +459,13 @@
     using liblas::property_tree::ptree;
     ptree pt;
     
-    DimensionMap::const_iterator i;
+    index_by_position const& position_index = m_index.get<position>();
+    index_by_position::const_iterator i;
     
-    for(i = m_dimensions.begin(); i != m_dimensions.end(); ++i)
+    for(i = position_index.begin(); i != position_index.end(); ++i)
     {
         ptree dim;
-        Dimension const& t = i->second;
+        Dimension const& t = *i;
         dim.put("name", t.GetName());
         dim.put("description", t.GetDescription());
         dim.put("position", t.GetPosition());
@@ -571,7 +571,7 @@
     
     VariableRecord s = *it;
     liblas::property_tree::ptree pt = LoadPTree(s);
-    m_dimensions = LoadDimensions(pt);
+    m_index = LoadDimensions(pt);
     CalculateSizes();
 
 }
@@ -596,13 +596,14 @@
     // A custom schema has no fields that are required by the PointFormatName
     // This must mean a user has added them themselves.  We only write VLR 
     // schema definitions to files that have custom schemas.
-    DimensionMap::const_iterator i;
+    
+    index_by_position const& position_index = m_index.get<position>();
+    index_by_position::const_iterator i;
     
     // return true; // For now, we'll always say we're  custom
-    for (i = m_dimensions.begin(); i != m_dimensions.end(); ++i)
+    for (i = position_index.begin(); i != position_index.end(); ++i)
     {
-        Dimension const& t = (*i).second;
-        if ( t.IsRequired() == false)
+        if ( i->IsRequired() == false)
             return true;
     }


More information about the Liblas-commits mailing list