[Liblas-commits] hg: we need to cache size calculations in schemas and not pass s...

liblas-commits at liblas.org liblas-commits at liblas.org
Wed Sep 22 13:28:52 EDT 2010


changeset f9317af500d4 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=f9317af500d4
summary: we need to cache size calculations in schemas and not pass so many copies of them around

diffstat:

 include/liblas/detail/reader/point.hpp |    2 +
 include/liblas/lasheader.hpp           |    2 +-
 include/liblas/lasschema.hpp           |   20 ++-
 src/detail/reader/point.cpp            |    8 +-
 src/lasheader.cpp                      |    2 +-
 src/laspoint.cpp                       |   20 ++-
 src/lasschema.cpp                      |  212 +++++++++++++++-----------------
 7 files changed, 140 insertions(+), 126 deletions(-)

diffs (truncated from 557 to 300 lines):

diff -r 83a3b4024767 -r f9317af500d4 include/liblas/detail/reader/point.hpp
--- a/include/liblas/detail/reader/point.hpp	Tue Sep 21 13:12:19 2010 -0500
+++ b/include/liblas/detail/reader/point.hpp	Wed Sep 22 12:28:42 2010 -0500
@@ -81,6 +81,8 @@
     HeaderPtr m_header;
     liblas::Point m_point;
     std::vector<boost::uint8_t> m_raw_data;
+    bool bColor;
+    bool bTime;
     
     void setup();
     void fill(PointRecord& record);
diff -r 83a3b4024767 -r f9317af500d4 include/liblas/lasheader.hpp
--- a/include/liblas/lasheader.hpp	Tue Sep 21 13:12:19 2010 -0500
+++ b/include/liblas/lasheader.hpp	Wed Sep 22 12:28:42 2010 -0500
@@ -328,7 +328,7 @@
     void SetSRS(SpatialReference& srs);
     
     /// Returns the schema.
-    Schema GetSchema() const;
+    Schema const& GetSchema() const;
 
     /// Sets the schema
     void SetSchema(const Schema& format);
diff -r 83a3b4024767 -r f9317af500d4 include/liblas/lasschema.hpp
--- a/include/liblas/lasschema.hpp	Tue Sep 21 13:12:19 2010 -0500
+++ b/include/liblas/lasschema.hpp	Wed Sep 22 12:28:42 2010 -0500
@@ -58,11 +58,13 @@
 #include <string>
 #include <vector>
 #include <algorithm>
+#include <map>
 
 namespace liblas {  
 
 class Dimension;
 typedef boost::shared_ptr<Dimension> DimensionPtr;
+typedef std::map<std::string, DimensionPtr> DimensionMap;
 
 
 
@@ -79,12 +81,13 @@
     ~Schema() {};
 
     /// Fetch byte size
-    boost::uint32_t GetByteSize() const;
+    std::size_t GetByteSize() const;
 
-    boost::uint32_t GetBitSize() const;
+    std::size_t GetBitSize() const;
+    void CalculateSizes();
 
     /// Get the base size (only accounting for Time, Color, etc )
-    boost::uint32_t GetBaseByteSize() const;
+    std::size_t GetBaseByteSize() const;
 
 
     PointFormatName GetDataFormatId() const { return m_data_format_id; }
@@ -95,11 +98,11 @@
     
     void AddDimension(DimensionPtr dim);
     DimensionPtr GetDimension(std::string const& name) const;
-    DimensionPtr GetDimension(std::size_t index) const;
+    // DimensionPtr GetDimension(std::size_t index) const;
     void RemoveDimension(DimensionPtr dim);
     
     std::vector<std::string> GetDimensionNames() const;
-    std::vector<DimensionPtr> GetDimensions() const { return m_dimensions; }
+    DimensionMap const& GetDimensions() const { return m_dimensions; }
     liblas::property_tree::ptree GetPTree() const;
     
     bool IsCustom() const;
@@ -110,9 +113,12 @@
     boost::uint16_t m_size;
     PointFormatName m_data_format_id;
     boost::uint32_t m_nextpos;
+    std::size_t m_bit_size;
+    std::size_t m_base_bit_size;
+    
 private:
 
-    std::vector<DimensionPtr> m_dimensions;    
+    DimensionMap m_dimensions;
     
     void add_record0_dimensions();
     void add_time();
@@ -120,7 +126,7 @@
     void update_required_dimensions(PointFormatName data_format_id);
     bool IsSchemaVLR(VariableRecord const& vlr);
     liblas::property_tree::ptree LoadPTree(VariableRecord const& v);
-    std::vector<DimensionPtr> LoadDimensions(liblas::property_tree::ptree tree);
+    DimensionMap LoadDimensions(liblas::property_tree::ptree tree);
 
 };
 
diff -r 83a3b4024767 -r f9317af500d4 src/detail/reader/point.cpp
--- a/src/detail/reader/point.cpp	Tue Sep 21 13:12:19 2010 -0500
+++ b/src/detail/reader/point.cpp	Wed Sep 22 12:28:42 2010 -0500
@@ -58,6 +58,8 @@
 Point::Point(std::istream& ifs, HeaderPtr header)
     : m_ifs(ifs)
     , m_header(header)
+    , bColor(header->GetSchema().HasColor())
+    , bTime(header->GetSchema().HasTime())
 
 {
     setup();
@@ -127,14 +129,14 @@
     fill(record);
     m_point.SetCoordinates(m_point.GetX(), m_point.GetY(), m_point.GetZ());
 
-    if (m_header->GetSchema().HasTime()) 
+    if (bTime) 
     {
         memcpy(&gpst, &(m_raw_data[i]), sizeof(double));
         
         m_point.SetTime(gpst);
         i += sizeof(double);
         
-        if (m_header->GetSchema().HasColor()) 
+        if (bColor) 
         {
             memcpy(&red, &(m_raw_data[i]), sizeof(uint16_t));
             i += sizeof(uint16_t);
@@ -148,7 +150,7 @@
             
         }
     } else {
-        if (m_header->GetSchema().HasColor()) 
+        if (bColor) 
         {
             memcpy(&red, &(m_raw_data[i]), sizeof(uint16_t));
             i += sizeof(uint16_t);
diff -r 83a3b4024767 -r f9317af500d4 src/lasheader.cpp
--- a/src/lasheader.cpp	Tue Sep 21 13:12:19 2010 -0500
+++ b/src/lasheader.cpp	Wed Sep 22 12:28:42 2010 -0500
@@ -655,7 +655,7 @@
     m_srs = srs;
 }
 
-Schema Header::GetSchema() const
+Schema const& Header::GetSchema() const
 {
     
     return m_schema;
diff -r 83a3b4024767 -r f9317af500d4 src/laspoint.cpp
--- a/src/laspoint.cpp	Tue Sep 21 13:12:19 2010 -0500
+++ b/src/laspoint.cpp	Wed Sep 22 12:28:42 2010 -0500
@@ -520,13 +520,14 @@
 
 boost::any Point::GetValue(DimensionPtr d) const
 {
-    typedef std::vector<DimensionPtr> Dimensions;
+
     boost::any output;
     
     // If we don't have a header for the point, we can't return 
     // anything because we don't have a schema to go along with it.
     // Use the other method Point::GetValue(DimensionPtr d, liblas::Schema const& schema).
     if (m_header.get() == 0) {
+    std::cout << "GetValue: have no header!" << std::endl;
         return output;
     }
     
@@ -541,7 +542,7 @@
         throw std::runtime_error(oss.str());
     }
     
-    Dimensions dimensions = schema.GetDimensions();
+    DimensionMap const& dimensions = schema.GetDimensions();
     
     
     boost::uint32_t wanted_dim_pos = d->GetPosition();
@@ -550,10 +551,21 @@
     boost::uint32_t dim_pos = 0;
     
     std::vector<boost::uint8_t> data;
+
+    DimensionPtr t;
     
-    for (Dimensions::const_iterator i = dimensions.begin(); i != dimensions.end(); ++i)
+    std::vector<DimensionPtr> positions;
+    for (DimensionMap::const_iterator i = dimensions.begin(); i != dimensions.end(); ++i)
     {
-        DimensionPtr t = *i;
+        positions.push_back((*i).second);
+    }
+    
+    std::sort(positions.begin(), positions.end(), sort_dimensions);
+    
+    
+    for (std::vector<DimensionPtr>::const_iterator i = positions.begin(); i != positions.end(); ++i)
+    {
+        DimensionPtr t = (*i);
         
         if (t->GetPosition() != dim_pos) {
             std::ostringstream oss;
diff -r 83a3b4024767 -r f9317af500d4 src/lasschema.cpp
--- a/src/lasschema.cpp	Tue Sep 21 13:12:19 2010 -0500
+++ b/src/lasschema.cpp	Wed Sep 22 12:28:42 2010 -0500
@@ -56,7 +56,9 @@
 Schema::Schema(PointFormatName data_format_id):
     m_size(0),
     m_data_format_id(data_format_id),
-    m_nextpos(0)
+    m_nextpos(0),
+    m_bit_size(0),
+    m_base_bit_size(0)
 {
     update_required_dimensions(data_format_id);
 }
@@ -216,11 +218,11 @@
     AddDimension(point_source_id);    
     text.str("");
 
-    std::vector<DimensionPtr>::iterator i;
+    DimensionMap::iterator i;
 
     for (i = m_dimensions.begin(); i != m_dimensions.end(); ++i)
     {
-        boost::shared_ptr<Dimension> t = *i;
+        boost::shared_ptr<Dimension> t = (*i).second;
         t->IsRequired(true);
         t->IsActive(true);
     }
@@ -288,8 +290,8 @@
 
 void Schema::update_required_dimensions(PointFormatName data_format_id)
 {
-    std::vector<DimensionPtr> user_dims;
-    std::vector<DimensionPtr>::const_iterator i;
+    DimensionMap user_dims;
+    DimensionMap::const_iterator i;
     
     if (m_dimensions.size() > 0)
     {
@@ -297,9 +299,10 @@
         // and add them back to the list of dimensions
         for (i = m_dimensions.begin(); i != m_dimensions.end(); ++i)
         {
-            DimensionPtr t = *i;
+            DimensionPtr t = (*i).second;
+            std::string name = (*i).first;
             if ( t->IsRequired() == false)
-                user_dims.push_back(t);
+                user_dims[name] = t;
         }
     }
     
@@ -332,21 +335,22 @@
     // required by the PointFormatName
     for (i = user_dims.begin(); i != user_dims.end(); ++i)
     {
-        m_dimensions.push_back(*i);
+        m_dimensions[(*i).first] = (*i).second;
     }
 
-    std::sort(m_dimensions.begin(), m_dimensions.end(), sort_dimensions);  
     m_nextpos = 0;
-
+    
+    CalculateSizes();
 }
 /// copy constructor
 Schema::Schema(Schema const& other) :
     m_size(other.m_size),
     m_data_format_id(other.m_data_format_id),
     m_nextpos(other.m_nextpos),
+    m_bit_size(other.m_bit_size),
+    m_base_bit_size(other.m_base_bit_size),
     m_dimensions(other.m_dimensions)
 {
-    std::sort(m_dimensions.begin(), m_dimensions.end(), sort_dimensions);  
 }
 // 
 // // assignment constructor
@@ -358,9 +362,10 @@
         m_data_format_id = rhs.m_data_format_id;
         m_nextpos = rhs.m_nextpos;
         m_dimensions = rhs.m_dimensions;
+        m_base_bit_size = rhs.m_base_bit_size;
+        m_bit_size = rhs.m_bit_size;
     }
     
-    std::sort(m_dimensions.begin(), m_dimensions.end(), sort_dimensions);  
     return *this;
 }
 
@@ -383,9 +388,10 @@
     // liblas::property_tree::write_xml("schema-output.xml", pt);        
     return pt;    
 }
-std::vector<DimensionPtr> Schema::LoadDimensions(liblas::property_tree::ptree tree)
+
+DimensionMap Schema::LoadDimensions(liblas::property_tree::ptree tree)
 {
-    std::vector<DimensionPtr> dimensions;
+    DimensionMap dimensions;
     
     using liblas::property_tree::ptree;


More information about the Liblas-commits mailing list