[Liblas-commits] hg: ExtraData support complete

liblas-commits at liblas.org liblas-commits at liblas.org
Mon Apr 12 15:02:05 EDT 2010


changeset 4c7a8a986f66 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=4c7a8a986f66
summary: ExtraData support complete

diffstat:

 include/liblas/capi/liblas.h |   3 ++
 include/liblas/lasformat.hpp |   2 +
 python/liblas/core.py        |   4 ++
 python/liblas/format.py      |   8 +++++-
 python/liblas/point.py       |   2 +-
 python/tests/File.txt        |  59 ++++++++++++++++++++++++++++++++++++++++++++
 python/tests/Format.txt      |   5 ++-
 src/detail/reader/point.cpp  |  26 ++++++++++--------
 src/detail/writer/point.cpp  |  30 ++++++++++++++++++++--
 src/las_c_api.cpp            |   9 ++++++
 src/lasformat.cpp            |   5 +++
 11 files changed, 135 insertions(+), 18 deletions(-)

diffs (274 lines):

diff -r 726c6e34ca1c -r 4c7a8a986f66 include/liblas/capi/liblas.h
--- a/include/liblas/capi/liblas.h	Mon Apr 12 08:59:26 2010 -0500
+++ b/include/liblas/capi/liblas.h	Mon Apr 12 13:56:09 2010 -0500
@@ -1179,6 +1179,9 @@
 LAS_DLL LASError LASPointFormat_SetTime( LASPointFormatH hFormat, uint8_t bTime);
 LAS_DLL uint16_t LASPointFormat_GetByteSize( LASPointFormatH hFormat);
 LAS_DLL LASError LASPointFormat_SetByteSize( LASPointFormatH hFormat, uint16_t size);
+LAS_DLL uint16_t LASPointFormat_GetBaseByteSize( LASPointFormatH hFormat);
+LAS_DLL LASError LASPointFormat_SetBaseByteSize( LASPointFormatH hFormat, uint16_t size);
+
 
 LAS_DLL LASPointFormatH LASHeader_GetPointFormat( LASHeaderH hHeader );
 LAS_DLL LASError LASHeader_SetPointFormat( LASHeaderH hHeader, LASPointFormatH hFormat);
diff -r 726c6e34ca1c -r 4c7a8a986f66 include/liblas/lasformat.hpp
--- a/include/liblas/lasformat.hpp	Mon Apr 12 08:59:26 2010 -0500
+++ b/include/liblas/lasformat.hpp	Mon Apr 12 13:56:09 2010 -0500
@@ -76,6 +76,8 @@
     /// Set value of the red image channel 
     void SetByteSize(uint16_t const& value);
 
+    /// Get the base size (only accounting for Time, Color, etc )
+    uint16_t GetBaseByteSize() const;
     
     uint8_t GetVersionMajor() const; 
     void SetVersionMajor(uint8_t const& value);
diff -r 726c6e34ca1c -r 4c7a8a986f66 python/liblas/core.py
--- a/python/liblas/core.py	Mon Apr 12 08:59:26 2010 -0500
+++ b/python/liblas/core.py	Mon Apr 12 13:56:09 2010 -0500
@@ -708,6 +708,10 @@
 las.LASPointFormat_SetByteSize.argtypes = [ctypes.c_void_p, ctypes.c_ushort]
 las.LASPointFormat_SetByteSize.errcheck = check_return
 
+las.LASPointFormat_GetBaseByteSize.restype = ctypes.c_ushort
+las.LASPointFormat_GetBaseByteSize.argtypes = [ctypes.c_void_p]
+las.LASPointFormat_GetBaseByteSize.errcheck = check_value
+
 las.LASPointFormat_HasColor.restype = ctypes.c_uint8
 las.LASPointFormat_HasColor.argtypes = [ctypes.c_void_p]
 las.LASPointFormat_HasColor.errcheck = check_value
diff -r 726c6e34ca1c -r 4c7a8a986f66 python/liblas/format.py
--- a/python/liblas/format.py	Mon Apr 12 08:59:26 2010 -0500
+++ b/python/liblas/format.py	Mon Apr 12 13:56:09 2010 -0500
@@ -109,8 +109,14 @@
         return core.las.LASPointFormat_SetByteSize(self.handle, int(value))
     
     doc = """Size in bytes of the format.  """
-    size = property(get_size, set_size)
+    size = property(get_size, set_size, None, doc)
 
+    def get_base_size(self):
+        return core.las.LASPointFormat_GetBaseByteSize(self.handle)
+    
+    doc = """Base size in bytes of the format.  (only accounting for time, color, etc.)"""
+    base_size = property(get_base_size, None, None, doc)
+    
     def get_color(self):
         return bool(core.las.LASPointFormat_HasColor(self.handle))
     
diff -r 726c6e34ca1c -r 4c7a8a986f66 python/liblas/point.py
--- a/python/liblas/point.py	Mon Apr 12 08:59:26 2010 -0500
+++ b/python/liblas/point.py	Mon Apr 12 13:56:09 2010 -0500
@@ -423,7 +423,7 @@
         for i in range(l.contents.value):
             s[i] = d2.contents[i]
         p_d = ctypes.cast(d, ctypes.POINTER(ctypes.c_char_p))
-        core.las.LASString_Free(p_d)
+   #     core.las.LASString_Free(p_d)
 
         return s
 
diff -r 726c6e34ca1c -r 4c7a8a986f66 python/tests/File.txt
--- a/python/tests/File.txt	Mon Apr 12 08:59:26 2010 -0500
+++ b/python/tests/File.txt	Mon Apr 12 13:56:09 2010 -0500
@@ -250,7 +250,65 @@
   630323.57
   630320.95
   630280.89
+
+
+The following tests writing out point data that are larger in size than 
+the base point format, allowing you to store extra data.  
+
+  >>> f6 = file.File('../test/data/TO_core_last_clip.las')
+  >>> p2 = f6.read(6)
+  >>> p2.x, p2.y, p2.z
+  (630320.95999999996, 4834500.0, 55.009999999999998)
+
+  >>> h6 = f6.header
+  >>> f = h6.format
+  >>> f.time = True
+  >>> f.color = True
+  >>> f.size = 52
+  >>> h6.format = f
+  >>> h6.data_record_length
+  52
+
+
+f.size - f.base_size will be 16 bytes of space (h6.data_record_length - 34 bytes for point format 3)
+
+>>> import ctypes
+ 
+  >>> d = (ctypes.c_ubyte * (f.size - f.base_size))() 
+  >>> d[10]
+  0
+  >>> d[0] = 13
+
+  >>> d2 = (ctypes.c_ubyte * 6)() 
+  >>> d2[0] = 11
     
+  >>> f7 = file.File('junk5.las',mode='w', header=h6)
+  >>> i = 0
+  >>> for p in points:
+  ...     if i == 0:
+  ...         p.data = d
+  ...     if i == 1:
+  ...         p.data = d2
+  ...     i = i + 1
+  ...     f7.write(p)
+  >>> f7.close()
+  >>> del f7
+  
+  >>> f8 = file.File('junk5.las')
+  >>> f8.header.data_record_length
+  52
+
+  >>> p = f8[0].data[0]
+  >>> p
+  13
+  >>> p = f8[0].data[15]
+  >>> p
+  0
+  
+  >>> p = f8[1].data[0]
+  >>> p
+  11
+  
   >>> import os
   >>> os.remove('junk.las')
   >>> os.remove('junk2.las')
@@ -272,3 +330,4 @@
   >>> os.remove('junk.las')
   
 
+
diff -r 726c6e34ca1c -r 4c7a8a986f66 python/tests/Format.txt
--- a/python/tests/Format.txt	Mon Apr 12 08:59:26 2010 -0500
+++ b/python/tests/Format.txt	Mon Apr 12 13:56:09 2010 -0500
@@ -62,4 +62,7 @@
   >>> h.format = f
   
   >>> h.data_record_length
-  40
\ No newline at end of file
+  40
+  
+  >>> f.base_size 
+  20
\ No newline at end of file
diff -r 726c6e34ca1c -r 4c7a8a986f66 src/detail/reader/point.cpp
--- a/src/detail/reader/point.cpp	Mon Apr 12 08:59:26 2010 -0500
+++ b/src/detail/reader/point.cpp	Mon Apr 12 13:56:09 2010 -0500
@@ -140,16 +140,8 @@
         }        
     }
     
-    if (bytesread != m_format.GetByteSize()) {
-        std::ostringstream msg; 
-        msg <<  "The number of bytes that were read ("<< bytesread <<") does not " 
-                "match the number of bytes the point's format "
-                "says it should have (" << 
-                m_format.GetByteSize() << ")";
-        throw std::runtime_error(msg.str());
-        
-    }
-    if (m_format.GetByteSize() != m_header.GetDataRecordLength())
+
+    if (m_format.GetBaseByteSize() != m_format.GetByteSize())
     {
         std::size_t bytesleft = m_header.GetDataRecordLength() - bytesread;
 
@@ -160,8 +152,18 @@
         
         m_point.SetExtraData(data); 
         
-        // off_type const pos(static_cast<off_type>(m_header.GetDataRecordLength() - bytesread));
-        // m_ifs.seekg(pos, std::ios::cur);
+        bytesread = bytesread + bytesleft;
+
+    }
+    
+    if (bytesread != m_format.GetByteSize()) {
+        std::ostringstream msg; 
+        msg <<  "The number of bytes that were read ("<< bytesread <<") does not " 
+                "match the number of bytes the point's format "
+                "says it should have (" << 
+                m_format.GetByteSize() << ")";
+        throw std::runtime_error(msg.str());
+        
     }
 }
 
diff -r 726c6e34ca1c -r 4c7a8a986f66 src/detail/writer/point.cpp
--- a/src/detail/writer/point.cpp	Mon Apr 12 08:59:26 2010 -0500
+++ b/src/detail/writer/point.cpp	Mon Apr 12 13:56:09 2010 -0500
@@ -145,10 +145,34 @@
 
     // write in our extra data that the user set on the 
     // point up to the header's specified DataRecordLength
-    if (m_format.GetByteSize() != m_header.GetDataRecordLength()) {
+    if (m_format.GetByteSize() != m_format.GetBaseByteSize()) {
         std::vector<uint8_t> const& data = point.GetExtraData();
-        std::streamsize const size = static_cast<std::streamsize>(m_header.GetDataRecordLength() - data.size());
-        detail::write_n(GetStream(), data.front(), size);
+
+        uint16_t size = m_format.GetByteSize() - m_format.GetBaseByteSize();
+        
+        if (data.size()  == 0) {
+            char* blanks = new char[size];
+            for (int i=0; i < size; ++i) {
+                blanks[i] = '\0';
+            }
+            detail::write_n(GetStream(), blanks, static_cast<std::streamsize>(size));
+            delete [] blanks; 
+        } else if (data.size() != size){ 
+            int16_t difference = size - data.size();
+            if (difference < 0) {
+                throw std::runtime_error("Format's base size is larger than it's size.  This should not happen!");
+            }
+            char* blanks = new char[difference];
+            for (int i=0; i < size; ++i) {
+                blanks[i] = '\0';
+            }
+            detail::write_n(GetStream(), data.front(), data.size());
+            detail::write_n(GetStream(), blanks, static_cast<std::streamsize>(difference));
+            delete [] blanks;
+
+        } else {
+            detail::write_n(GetStream(), data.front(), static_cast<std::streamsize>(size));
+        }
     }
 }
 
diff -r 726c6e34ca1c -r 4c7a8a986f66 src/las_c_api.cpp
--- a/src/las_c_api.cpp	Mon Apr 12 08:59:26 2010 -0500
+++ b/src/las_c_api.cpp	Mon Apr 12 13:56:09 2010 -0500
@@ -2201,6 +2201,15 @@
 
 }
 
+LAS_DLL liblas::uint16_t LASPointFormat_GetBaseByteSize( LASPointFormatH hFormat)
+{
+    VALIDATE_LAS_POINTER1(hFormat, "LASPointFormat_GetBaseByteSize", 0);
+    
+    liblas::PointFormat* format = ((liblas::PointFormat*) hFormat);
+    return format->GetBaseByteSize();    
+}
+
+
 LAS_DLL void LASPointFormat_Destroy(LASPointFormatH hFormat) {
     VALIDATE_LAS_POINTER0(hFormat, "LASPointFormat_Destroy");
     delete (liblas::PointFormat*) hFormat;
diff -r 726c6e34ca1c -r 4c7a8a986f66 src/lasformat.cpp
--- a/src/lasformat.cpp	Mon Apr 12 08:59:26 2010 -0500
+++ b/src/lasformat.cpp	Mon Apr 12 13:56:09 2010 -0500
@@ -212,4 +212,9 @@
     updatesize();
 }
 
+uint16_t PointFormat::GetBaseByteSize() const
+{
+    return m_base_size;
+}
+
 } // namespace liblas


More information about the Liblas-commits mailing list