[Liblas-commits] laszip: new test for variable chunking

liblas-commits at liblas.org liblas-commits at liblas.org
Mon May 16 10:58:57 EDT 2011


details:   http://hg.liblas.orglaszip/rev/941aca17929a
changeset: 236:941aca17929a
user:      isenburg
date:      Mon May 16 08:00:05 2011 -0700
description:
new test for variable chunking
Subject: laszip: compressed chunking information and better GPS time compression

details:   http://hg.liblas.orglaszip/rev/846198906775
changeset: 237:846198906775
user:      isenburg
date:      Mon May 16 08:01:23 2011 -0700
description:
compressed chunking information and better GPS time compression

diffstat:

 src/lasreaditemcompressed_v2.cpp  |   90 +++-
 src/lasreaditemcompressed_v2.hpp  |    7 +-
 src/lasreadpoint.cpp              |   30 +-
 src/laswriteitemcompressed_v2.cpp |  124 ++++--
 src/laswriteitemcompressed_v2.hpp |    7 +-
 src/laswritepoint.cpp             |   22 +-
 tools/laszippertest.cpp           |  673 +++++++++++++++++++++++--------------
 7 files changed, 593 insertions(+), 360 deletions(-)

diffs (truncated from 1344 to 300 lines):

diff -r 484b68b9d852 -r 846198906775 src/lasreaditemcompressed_v2.cpp
--- a/src/lasreaditemcompressed_v2.cpp	Wed May 11 16:38:59 2011 -0700
+++ b/src/lasreaditemcompressed_v2.cpp	Mon May 16 08:01:23 2011 -0700
@@ -240,7 +240,7 @@
 ===============================================================================
 */
 
-#define LASZIP_GPSTIME_MULTI 512
+#define LASZIP_GPSTIME_MULTI 500
 #define LASZIP_GPSTIME_MULTI_1024 (LASZIP_GPSTIME_MULTI + 0)
 #define LASZIP_GPSTIME_MULTI_2048 (LASZIP_GPSTIME_MULTI + 1)
 #define LASZIP_GPSTIME_MULTI_4096 (LASZIP_GPSTIME_MULTI + 2)
@@ -248,11 +248,10 @@
 #define LASZIP_GPSTIME_MULTI_MINUS_5500 (LASZIP_GPSTIME_MULTI + 4)
 #define LASZIP_GPSTIME_MULTI_MINUS_550 (LASZIP_GPSTIME_MULTI + 5)
 #define LASZIP_GPSTIME_MULTI_MINUS_55 (LASZIP_GPSTIME_MULTI + 6)
-#define LASZIP_GPSTIME_MULTI_MINUS_5 (LASZIP_GPSTIME_MULTI + 7)
-#define LASZIP_GPSTIME_MULTI_UNCHANGED (LASZIP_GPSTIME_MULTI + 8)
-#define LASZIP_GPSTIME_MULTI_DOUBLE (LASZIP_GPSTIME_MULTI + 9)
+#define LASZIP_GPSTIME_MULTI_UNCHANGED (LASZIP_GPSTIME_MULTI + 17)
+#define LASZIP_GPSTIME_MULTI_DOUBLE (LASZIP_GPSTIME_MULTI + 18)
 
-#define LASZIP_GPSTIME_MULTI_TOTAL (LASZIP_GPSTIME_MULTI + 10) 
+#define LASZIP_GPSTIME_MULTI_TOTAL (LASZIP_GPSTIME_MULTI + 22) 
 
 LASreadItemCompressed_GPSTIME11_v2::LASreadItemCompressed_GPSTIME11_v2(EntropyDecoder* dec)
 {
@@ -261,7 +260,7 @@
   this->dec = dec;
   /* create entropy models and integer compressors */
   m_gpstime_multi = dec->createSymbolModel(LASZIP_GPSTIME_MULTI_TOTAL);
-  m_gpstime_0diff = dec->createSymbolModel(3);
+  m_gpstime_0diff = dec->createSymbolModel(6);
   ic_gpstime = new IntegerCompressor(dec, 32, 7); // 32 bits, 7 contexts
 }
 
@@ -275,8 +274,15 @@
 BOOL LASreadItemCompressed_GPSTIME11_v2::init(const U8* item)
 {
   /* init state */
-  last_gpstime_diff = 0;
-  multi_extreme_counter = 0;
+  last = 0, next = 0;
+  last_gpstime_diff[0] = 0;
+  last_gpstime_diff[1] = 0;
+  last_gpstime_diff[2] = 0;
+  last_gpstime_diff[3] = 0;
+  multi_extreme_counter[0] = 0;
+  multi_extreme_counter[1] = 0;
+  multi_extreme_counter[2] = 0;
+  multi_extreme_counter[3] = 0;
 
   /* init models and integer compressors */
   dec->initSymbolModel(m_gpstime_multi);
@@ -284,24 +290,37 @@
   ic_gpstime->initDecompressor();
 
   /* init last item */
-  last_gpstime.u64 = *((U64*)item);
+  last_gpstime[0].u64 = *((U64*)item);
+  last_gpstime[1].u64 = 0;
+  last_gpstime[2].u64 = 0;
+  last_gpstime[3].u64 = 0;
   return TRUE;
 }
 
 inline BOOL LASreadItemCompressed_GPSTIME11_v2::read(U8* item)
 {
   I32 multi;
-  if (last_gpstime_diff == 0) // if the last integer difference was zero
+  if (last_gpstime_diff[last] == 0) // if the last integer difference was zero
   {
     multi = dec->decodeSymbol(m_gpstime_0diff);
     if (multi == 1) // the difference can be represented with 32 bits
     {
-      last_gpstime_diff = ic_gpstime->decompress(0, 0);
-      last_gpstime.i64 += last_gpstime_diff;      
+      last_gpstime_diff[last] = ic_gpstime->decompress(0, 0);
+      last_gpstime[last].i64 += last_gpstime_diff[last];
+      multi_extreme_counter[last] = 0; 
     }
     else if (multi == 2) // the difference is huge
     {
-      last_gpstime.u64 = dec->readInt64();
+      next = (next+1)&3;
+      last = next;
+      last_gpstime_diff[last] = 0;
+      multi_extreme_counter[last] = 0; 
+      last_gpstime[last].u64 = dec->readInt64();
+    }
+    else if (multi > 2) // we switch to another sequence
+    {
+      last = (last+multi-2)&3;
+      return read(item);
     }
   }
   else
@@ -309,8 +328,8 @@
     multi = dec->decodeSymbol(m_gpstime_multi);
     if (multi == 1)
     {
-      last_gpstime.i64 += ic_gpstime->decompress(last_gpstime_diff, 1);;
-      multi_extreme_counter = 0;
+      last_gpstime[last].i64 += ic_gpstime->decompress(last_gpstime_diff[last], 1);;
+      multi_extreme_counter[last] = 0;
     }
     else if (multi < LASZIP_GPSTIME_MULTI_UNCHANGED)
     {
@@ -318,19 +337,19 @@
       if (multi == 0)
       {
         gpstime_diff = ic_gpstime->decompress(0, 6);
-        multi_extreme_counter++;
-        if (multi_extreme_counter > 3)
+        multi_extreme_counter[last]++;
+        if (multi_extreme_counter[last] > 3)
         {
-          last_gpstime_diff = gpstime_diff;
-          multi_extreme_counter = 0;
+          last_gpstime_diff[last] = gpstime_diff;
+          multi_extreme_counter[last] = 0;
         }
       }
       else if (multi < LASZIP_GPSTIME_MULTI)
       {
         if (multi < 10)
-          gpstime_diff = ic_gpstime->decompress(multi*last_gpstime_diff, 2);
+          gpstime_diff = ic_gpstime->decompress(multi*last_gpstime_diff[last], 2);
         else
-          gpstime_diff = ic_gpstime->decompress(multi*last_gpstime_diff, 3);
+          gpstime_diff = ic_gpstime->decompress(multi*last_gpstime_diff[last], 3);
       }
       else if (multi < LASZIP_GPSTIME_MULTI_MINUS_11000)
       {
@@ -340,12 +359,12 @@
           multi = 2048;
         else
           multi = 4096;
-        gpstime_diff = ic_gpstime->decompress(multi*last_gpstime_diff, 4);
-        multi_extreme_counter++;
-        if (multi_extreme_counter > 3)
+        gpstime_diff = ic_gpstime->decompress(multi*last_gpstime_diff[last], 4);
+        multi_extreme_counter[last]++;
+        if (multi_extreme_counter[last] > 3)
         {
-          last_gpstime_diff = gpstime_diff;
-          multi_extreme_counter = 0;
+          last_gpstime_diff[last] = gpstime_diff;
+          multi_extreme_counter[last] = 0;
         }
       }
       else
@@ -359,17 +378,26 @@
         else if (multi == LASZIP_GPSTIME_MULTI_MINUS_55)
           multi = -55;
         else
-          multi = -5;
-        gpstime_diff = ic_gpstime->decompress(multi*last_gpstime_diff, 5);
+          multi = LASZIP_GPSTIME_MULTI_MINUS_55-multi;
+        gpstime_diff = ic_gpstime->decompress(multi*last_gpstime_diff[last], 5);
       }
-      last_gpstime.i64 += gpstime_diff;
+      last_gpstime[last].i64 += gpstime_diff;
     }
     else if (multi ==  LASZIP_GPSTIME_MULTI_DOUBLE)
     {
-      last_gpstime.u64 = dec->readInt64();
+      next = (next+1)&3;
+      last = next;
+      last_gpstime_diff[last] = 0;
+      multi_extreme_counter[last] = 0; 
+      last_gpstime[last].u64 = dec->readInt64();
+    }
+    else if (multi >=  LASZIP_GPSTIME_MULTI_DOUBLE)
+    {
+      last = (last+multi-LASZIP_GPSTIME_MULTI_DOUBLE)&3;
+      return read(item);
     }
   }
-  *((I64*)item) = last_gpstime.i64;
+  *((I64*)item) = last_gpstime[last].i64;
   return TRUE;
 }
 
diff -r 484b68b9d852 -r 846198906775 src/lasreaditemcompressed_v2.hpp
--- a/src/lasreaditemcompressed_v2.hpp	Wed May 11 16:38:59 2011 -0700
+++ b/src/lasreaditemcompressed_v2.hpp	Mon May 16 08:01:23 2011 -0700
@@ -81,13 +81,14 @@
 
 private:
   EntropyDecoder* dec;
-  U64I64F64 last_gpstime;
+  U32 last, next;
+  U64I64F64 last_gpstime[4];
+  I32 last_gpstime_diff[4];
+  I32 multi_extreme_counter[4];
 
   EntropyModel* m_gpstime_multi;
   EntropyModel* m_gpstime_0diff;
   IntegerCompressor* ic_gpstime;
-  I32 multi_extreme_counter;
-  I32 last_gpstime_diff;
 };
 
 class LASreadItemCompressed_RGB12_v2 : public LASreadItemCompressed
diff -r 484b68b9d852 -r 846198906775 src/lasreadpoint.cpp
--- a/src/lasreadpoint.cpp	Wed May 11 16:38:59 2011 -0700
+++ b/src/lasreadpoint.cpp	Mon May 16 08:01:23 2011 -0700
@@ -210,7 +210,7 @@
   if (!instream) return FALSE;
   this->instream = instream;
 
-  // if chunking is enabled
+  // on very first init with chunking enabled
   if (number_chunks == U32_MAX)
   {
     if (!read_chunk_table())
@@ -218,6 +218,7 @@
       return FALSE;
     }
     current_chunk = 0;
+    if (chunk_totals) chunk_size = chunk_totals[1];
   }
 
   point_start = instream->position();
@@ -374,6 +375,11 @@
   {
     return false;
   }
+  U32 version;
+  if (!instream->get32bitsLE((U8*)&version) || version != 0)
+  {
+    return FALSE;
+  }
   if (!instream->get32bitsLE((U8*)&number_chunks))
   {
     return FALSE;
@@ -391,20 +397,18 @@
   if (chunk_size == U32_MAX) chunk_totals[0] = 0;
   chunk_starts[0] = chunks_start;
   U32 i;
+  dec->init(instream);
+  IntegerCompressor ic(dec, 32, 2);
+  ic.initDecompressor();
   for (i = 1; i <= number_chunks; i++)
   {
-    if (chunk_size == U32_MAX)
-    {
-      if (!instream->get32bitsLE((U8*)&chunk_totals[i]))
-      {
-        return FALSE;
-      }
-      chunk_totals[i] += chunk_totals[i-1];
-    }
-    if (!instream->get32bitsLE((U8*)&chunk_starts[i]))
-    {
-      return FALSE;
-    }
+    if (chunk_size == U32_MAX) chunk_totals[i] = ic.decompress((i>1 ? chunk_totals[i-1] : 0), 0);
+    chunk_starts[i] = ic.decompress((i>1 ? chunk_starts[i-1] : 0), 1);
+  }
+  dec->done();
+  for (i = 1; i <= number_chunks; i++)
+  {
+    if (chunk_size == U32_MAX) chunk_totals[i] += chunk_totals[i-1];
     chunk_starts[i] += chunk_starts[i-1];
   }
   instream->seek(chunks_start);
diff -r 484b68b9d852 -r 846198906775 src/laswriteitemcompressed_v2.cpp
--- a/src/laswriteitemcompressed_v2.cpp	Wed May 11 16:38:59 2011 -0700
+++ b/src/laswriteitemcompressed_v2.cpp	Mon May 16 08:01:23 2011 -0700
@@ -236,7 +236,7 @@
 ===============================================================================
 */
 
-#define LASZIP_GPSTIME_MULTI 512
+#define LASZIP_GPSTIME_MULTI 500
 #define LASZIP_GPSTIME_MULTI_1024 (LASZIP_GPSTIME_MULTI + 0)
 #define LASZIP_GPSTIME_MULTI_2048 (LASZIP_GPSTIME_MULTI + 1)
 #define LASZIP_GPSTIME_MULTI_4096 (LASZIP_GPSTIME_MULTI + 2)
@@ -244,11 +244,10 @@
 #define LASZIP_GPSTIME_MULTI_MINUS_5500 (LASZIP_GPSTIME_MULTI + 4)
 #define LASZIP_GPSTIME_MULTI_MINUS_550 (LASZIP_GPSTIME_MULTI + 5)
 #define LASZIP_GPSTIME_MULTI_MINUS_55 (LASZIP_GPSTIME_MULTI + 6)
-#define LASZIP_GPSTIME_MULTI_MINUS_5 (LASZIP_GPSTIME_MULTI + 7)
-#define LASZIP_GPSTIME_MULTI_UNCHANGED (LASZIP_GPSTIME_MULTI + 8)
-#define LASZIP_GPSTIME_MULTI_DOUBLE (LASZIP_GPSTIME_MULTI + 9)
+#define LASZIP_GPSTIME_MULTI_UNCHANGED (LASZIP_GPSTIME_MULTI + 17)
+#define LASZIP_GPSTIME_MULTI_DOUBLE (LASZIP_GPSTIME_MULTI + 18)
 
-#define LASZIP_GPSTIME_MULTI_TOTAL (LASZIP_GPSTIME_MULTI + 10) 
+#define LASZIP_GPSTIME_MULTI_TOTAL (LASZIP_GPSTIME_MULTI + 22) 
 
 LASwriteItemCompressed_GPSTIME11_v2::LASwriteItemCompressed_GPSTIME11_v2(EntropyEncoder* enc)
 {
@@ -257,7 +256,7 @@
   this->enc = enc;
   /* create entropy models and integer compressors */
   m_gpstime_multi = enc->createSymbolModel(LASZIP_GPSTIME_MULTI_TOTAL);
-  m_gpstime_0diff = enc->createSymbolModel(3);


More information about the Liblas-commits mailing list