[Liblas-commits] hg: get rid of SizesArray junk

liblas-commits at liblas.org liblas-commits at liblas.org
Sat Oct 9 22:36:40 EDT 2010


changeset 684912262acb in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=684912262acb
summary: get rid of SizesArray junk

diffstat:

 include/liblas/lasdimension.hpp |  46 ++++++++++++++++++++++++++++++--------
 include/liblas/lasschema.hpp    |   6 +----
 src/las_c_api.cpp               |  33 +++++++++++++++++++++++++--
 src/lasdimension.cpp            |  15 +++++++-----
 src/laspoint.cpp                |  10 +++++---
 src/lasschema.cpp               |  49 +++++++++++++++++++---------------------
 6 files changed, 105 insertions(+), 54 deletions(-)

diffs (truncated from 354 to 300 lines):

diff -r 2fe4df7bda66 -r 684912262acb include/liblas/lasdimension.hpp
--- a/include/liblas/lasdimension.hpp	Sat Oct 09 18:17:39 2010 -0500
+++ b/include/liblas/lasdimension.hpp	Sat Oct 09 21:36:25 2010 -0500
@@ -70,22 +70,21 @@
 
 namespace liblas {  
 
-typedef boost::array<std::size_t, 4> SizesArray;
-
 /// Dimension definition
 class Dimension
 {
 public:
-    Dimension(std::string const& name, boost::uint32_t size_in_bits);
+    Dimension(std::string const& name, std::size_t size_in_bits);
     Dimension& operator=(Dimension const& rhs);
     Dimension(Dimension const& other);
         
     virtual ~Dimension() {};
         
-    std::string const& GetName() const { return m_name; }
+    inline std::string const& GetName() const { return m_name; }
     
-    /// bits, logical size of point record
-    std::size_t GetBitSize() const 
+    /// bits, total logical size of point record, including any custom
+    /// dimensions
+    inline std::size_t GetBitSize() const 
     {
         return m_bit_size;
     }
@@ -93,6 +92,34 @@
     /// bytes, physical/serialisation size of record
     std::size_t GetByteSize() const;
 
+    /// The byte location to start reading/writing 
+    /// point data from in a composited schema.  liblas::Schema 
+    /// will set these values for you when liblas::Dimension are 
+    /// added to the liblas::Schema.
+    inline std::size_t GetByteOffset() const 
+    {
+        return m_byte_offset;
+    }
+
+    inline void SetByteOffset(std::size_t v) 
+    {
+        m_byte_offset = v;
+    }
+
+    /// The bit location within the byte to start reading data.  liblas::Schema 
+    /// will set these values for you when liblas::Dimension are 
+    /// added to the liblas::Schema.  This value will be 0 for dimensions 
+    /// that are composed of entire bytes.
+    inline std::size_t GetBitOffset() const 
+    {
+        return m_bit_offset;
+    }
+
+    inline void SetBitOffset(std::size_t v) 
+    {
+        m_bit_offset = v;
+    }
+
     /// Is this dimension required by PointFormatName
     bool IsRequired() const { return m_required; }
     void IsRequired(bool v) { m_required = v; }
@@ -151,12 +178,10 @@
         return m_position > dim.m_position;
     }
     
-    SizesArray const& GetSizes() const { return m_sizes; }
-    void SetSizes(SizesArray const& a) { m_sizes = a; }
 private:
         
     std::string m_name;
-    boost::uint32_t m_bit_size;
+    std::size_t m_bit_size;
     bool m_required;
     bool m_active;
     std::string m_description;
@@ -169,7 +194,8 @@
     double m_scale;
     bool m_precise;
     double m_offset;
-    SizesArray m_sizes;
+    std::size_t m_byte_offset;
+    std::size_t m_bit_offset;
     
   
 };
diff -r 2fe4df7bda66 -r 684912262acb include/liblas/lasschema.hpp
--- a/include/liblas/lasschema.hpp	Sat Oct 09 18:17:39 2010 -0500
+++ b/include/liblas/lasschema.hpp	Sat Oct 09 21:36:25 2010 -0500
@@ -75,8 +75,6 @@
 namespace liblas {  
 
 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;
 
@@ -132,7 +130,7 @@
     
     void AddDimension(Dimension const& dim);
     Dimension const& GetDimension(std::string const& n) const;
-    // Dimension& GetDimension(std::string const& n);
+    Dimension const& GetDimension(index_by_index::size_type t) const;
     
     // DimensionPtr GetDimension(std::size_t index) const;
     void RemoveDimension(Dimension const& dim);
@@ -142,8 +140,6 @@
     std::vector<std::string> GetDimensionNames() const;
     IndexMap const& GetDimensions() const { return m_index; }
     liblas::property_tree::ptree GetPTree() const;
-    SizesArray const& GetSizes(std::string const& n) const;
-    SizesArray const& GetSizes(std::size_t pos) const;
     
     boost::uint16_t GetSchemaVersion() const { return m_schemaversion; }
     void SetSchemaVersion(boost::uint16_t v) { m_schemaversion = v; }
diff -r 2fe4df7bda66 -r 684912262acb src/las_c_api.cpp
--- a/src/las_c_api.cpp	Sat Oct 09 18:17:39 2010 -0500
+++ b/src/las_c_api.cpp	Sat Oct 09 21:36:25 2010 -0500
@@ -666,7 +666,14 @@
 
     try {
             ((liblas::Point*) hPoint)->SetTime(value);
-    } catch (std::exception const& e)
+    
+    }
+    catch (std::runtime_error const&) 
+    {
+        // drop the value on the floor.  If the point has a schema that 
+        // doesn't have time, the user needs to change the point's header.
+    }
+    catch (std::exception const& e)
     {
         LASError_PushError(LE_Failure, e.what(), "LASPoint_SetTime");
         return LE_Failure;
@@ -680,7 +687,14 @@
     
     VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetTime", 0.0);
     
-    double value = ((liblas::Point*) hPoint)->GetTime();
+    double value = 0.0;
+    try {
+        value = ((liblas::Point*) hPoint)->GetTime();
+        
+    } catch (std::runtime_error const&) 
+    {
+        
+    }
     return value;
 }
 
@@ -1790,7 +1804,14 @@
 LAS_DLL LASColorH LASPoint_GetColor(const LASPointH hPoint) {
     VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetColor", 0);
     
-    liblas::Color color = ((liblas::Point*) hPoint)->GetColor();
+    liblas::Color color;
+    try {
+        color = ((liblas::Point*) hPoint)->GetColor();
+        
+    } catch (std::runtime_error const&) 
+    {
+        
+    }
     return (LASColorH) new liblas::Color(color);
 }
 
@@ -1802,6 +1823,12 @@
     try {
         ((liblas::Point*) hPoint)->SetColor(*((liblas::Color*)hColor));
     }
+    catch (std::runtime_error const&) 
+    {
+        // drop the value on the floor.  If the point has a schema that 
+        // doesn't have color, the user needs to change the point's header.
+        
+    }
     catch (std::exception const& e) {
         LASError_PushError(LE_Failure, e.what(), "LASPoint_SetColor");
         return LE_Failure;
diff -r 2fe4df7bda66 -r 684912262acb src/lasdimension.cpp
--- a/src/lasdimension.cpp	Sat Oct 09 18:17:39 2010 -0500
+++ b/src/lasdimension.cpp	Sat Oct 09 21:36:25 2010 -0500
@@ -62,7 +62,7 @@
 
 namespace liblas { 
 
-Dimension::Dimension(std::string const& name, boost::uint32_t size_in_bits) : 
+Dimension::Dimension(std::string const& name, std::size_t size_in_bits) : 
     m_name(name), 
     m_bit_size(size_in_bits),
     m_required(false),
@@ -73,14 +73,15 @@
     m_numeric(false),
     m_signed(false),
     m_integer(false),
-    m_position(0)
+    m_position(0),
+    m_byte_offset(0),
+    m_bit_offset(0)
 {
      if (size_in_bits == 0) {
         std::ostringstream oss;
         oss << "The bit size of the dimension is 0, the dimension is invalid.";
         throw std::runtime_error(oss.str());
-    }
-    m_sizes.assign(0);
+     }
 };
 
 /// copy constructor
@@ -96,7 +97,8 @@
     , m_signed(other.m_signed)
     , m_integer(other.m_integer)
     , m_position(other.m_position)
-    , m_sizes(other.m_sizes)
+    , m_byte_offset(other.m_byte_offset)
+    , m_bit_offset(other.m_bit_offset)
 {
 }
 // 
@@ -116,7 +118,8 @@
         m_signed = rhs.m_signed;
         m_integer = rhs.m_integer;
         m_position = rhs.m_position;
-        m_sizes = rhs.m_sizes;
+        m_byte_offset = rhs.m_byte_offset;
+        m_bit_offset = rhs.m_bit_offset;
     }
     
     return *this;
diff -r 2fe4df7bda66 -r 684912262acb src/laspoint.cpp
--- a/src/laspoint.cpp	Sat Oct 09 18:17:39 2010 -0500
+++ b/src/laspoint.cpp	Sat Oct 09 21:36:25 2010 -0500
@@ -822,13 +822,15 @@
 
 std::vector<boost::uint8_t>::size_type Point::GetDimensionBytePosition(std::size_t dim_pos) const
 {
-    SizesArray s;
+    std::size_t output = 0;
     if (m_header) {
-        s = m_header->GetSchema().GetSizes(dim_pos);
+        Dimension const& d = m_header->GetSchema().GetDimension(dim_pos);
+        output = d.GetByteOffset();
     } else {
-        s = m_default_header.GetSchema().GetSizes(dim_pos);
+        Dimension const& d = m_default_header.GetSchema().GetDimension(dim_pos);
+        output = d.GetByteOffset();
     }   
-    return s[0];
+    return output;
 }
 
 
diff -r 2fe4df7bda66 -r 684912262acb src/lasschema.cpp
--- a/src/lasschema.cpp	Sat Oct 09 18:17:39 2010 -0500
+++ b/src/lasschema.cpp	Sat Oct 09 21:36:25 2010 -0500
@@ -609,13 +609,6 @@
     return false;
 }
 
-SizesArray const& Schema::GetSizes(std::size_t pos) const
-{
-    index_by_index const& idx = m_index.get<index>();
-    Dimension const& dim = idx.at(pos);
-    return dim.GetSizes();
-
-}
 
 void Schema::CalculateSizes() 
 {
@@ -624,8 +617,8 @@
 
     index_by_position& position_index = m_index.get<position>();
     
-    std::size_t index_position = 0;
-    std::size_t bit_position = 0;
+    std::size_t byte_offset = 0;
+    std::size_t bit_offset = 0;
 
     for (index_by_position::iterator i = position_index.begin();
          i != position_index.end(); 
@@ -634,26 +627,21 @@
         Dimension t = (*i);
         m_bit_size += t.GetBitSize(); 
 
-        std::size_t byte_size = 0;
-        bit_position = bit_position + (t.GetBitSize() % 8);
+        bit_offset = bit_offset + (t.GetBitSize() % 8);
 
         // std::cout << "position : " << t->GetPosition() << " index_position: " << index_position;
         // std::cout << " d: " << t->GetName() << " bit_position: " << bit_position<<std::endl;
         // std::cout << "bit_size: " << t->GetBitSize()  << std::endl;
         
-        SizesArray a;
-        a[0] = index_position;


More information about the Liblas-commits mailing list