[Liblas-commits] laszip: added functions to query point type and size

liblas-commits at liblas.org liblas-commits at liblas.org
Fri May 6 08:50:59 EDT 2011


details:   http://hg.liblas.orglaszip/rev/f855f27a78eb
changeset: 222:f855f27a78eb
user:      isenburg
date:      Fri May 06 05:52:24 2011 -0700
description:
added functions to query point type and size
Subject: laszip: added functions to query point type and size

details:   http://hg.liblas.orglaszip/rev/3fc5cbb8490e
changeset: 223:3fc5cbb8490e
user:      isenburg
date:      Fri May 06 05:53:12 2011 -0700
description:
added functions to query point type and size

diffstat:

 include/laszip/laszip.hpp |    7 +
 src/laszip.cpp            |  264 +++++++++++++++++++++++++++++++++++++--------
 2 files changed, 221 insertions(+), 50 deletions(-)

diffs (truncated from 341 to 300 lines):

diff -r 9b6736a2d308 -r 3fc5cbb8490e include/laszip/laszip.hpp
--- a/include/laszip/laszip.hpp	Thu May 05 17:05:48 2011 -0700
+++ b/include/laszip/laszip.hpp	Fri May 06 05:53:12 2011 -0700
@@ -71,6 +71,10 @@
   bool supported() const;
 
   const char* get_name() const;
+
+  // back and forth between item array and point type and size
+  bool setup(const unsigned char point_type, const unsigned short point_size, unsigned short* num_items, LASitem** items) const;
+  bool is_standard(const unsigned short num_items, const LASitem* items, unsigned char* point_type=0, unsigned short* record_length=0) const;
 };
 
 class LASZIP_DLL LASzip
@@ -91,6 +95,9 @@
   void set_chunk_size(const unsigned int chunk_size);
   void request_version(const unsigned int requested_version);
 
+  // query point type and size
+  bool is_standard(unsigned char* point_type=0, unsigned short* record_length=0) const;
+
   // stored in LASzip VLR data section
   unsigned short compressor;
   unsigned short coder;
diff -r 9b6736a2d308 -r 3fc5cbb8490e src/laszip.cpp
--- a/src/laszip.cpp	Thu May 05 17:05:48 2011 -0700
+++ b/src/laszip.cpp	Fri May 06 05:53:12 2011 -0700
@@ -185,14 +185,68 @@
 bool LASzip::setup(const U8 point_type, const U16 point_size, const U16 compressor)
 {
   if (compressor > LASZIP_COMPRESSOR_POINTWISE_CHUNKED) return false;
+  this->num_items = 0;
+  if (this->items) delete [] this->items;
+  this->items = 0;
+  if (!LASitem().setup(point_type, point_size, &num_items, &items)) return false;
+  this->compressor = compressor;
+  if (this->compressor == LASZIP_COMPRESSOR_POINTWISE_CHUNKED)
+  {
+    if (chunk_size == 0) chunk_size = LASZIP_CHUNK_SIZE_DEFAULT;
+  }
+  return true;
+}
 
-  // switch over the point types we know
+bool LASzip::setup(const U16 num_items, const LASitem* items, const U16 compressor)
+{
+  U16 i;
+  if (num_items == 0) return false;
+  if (items == 0) return false;
+  if (compressor > LASZIP_COMPRESSOR_POINTWISE_CHUNKED) return false;
+  this->num_items = 0;
+  if (this->items) delete [] this->items;
+  this->items = 0;
+  for (i = 0; i < num_items; i++)
+  {
+    if (!items[i].supported()) return false;
+  }
+  this->num_items = num_items;
+  this->items = new LASitem[num_items];
+  for (i = 0; i < num_items; i++)
+  {
+    this->items[i] = items[i];
+  }
+  this->compressor = compressor;
+  if (this->compressor == LASZIP_COMPRESSOR_POINTWISE_CHUNKED)
+  {
+    if (chunk_size == 0) chunk_size = LASZIP_CHUNK_SIZE_DEFAULT;
+  }
+  return true;
+}
 
+void LASzip::set_chunk_size(const U32 chunk_size)
+{
+  this->chunk_size = chunk_size;
+}
+
+void LASzip::request_version(const U32 requested_version)
+{
+  this->requested_version = requested_version;
+}
+
+bool LASzip::is_standard(U8* point_type, U16* record_length) const
+{
+  return LASitem().is_standard(num_items, items, point_type, record_length);
+}
+
+bool LASitem::setup(const U8 point_type, const U16 point_size, U16* num_items, LASitem** items) const
+{
   BOOL have_gps_time = FALSE;
   BOOL have_rgb = FALSE;
   BOOL have_wavepacket = FALSE;
   I32 extra_bytes_number = 0;
 
+  // switch over the point types we know
   switch (point_type)
   {
   case 0:
@@ -230,84 +284,194 @@
 
   // create item description
 
-  if (items) delete [] items;
-  num_items = 1 + !!(have_gps_time) + !!(have_rgb) + !!(have_wavepacket) + !!(extra_bytes_number);
-  items = new LASitem[num_items];
+  (*num_items) = 1 + !!(have_gps_time) + !!(have_rgb) + !!(have_wavepacket) + !!(extra_bytes_number);
+  (*items) = new LASitem[*num_items];
 
   U16 i = 1;
-  items[0].type = LASitem::POINT10;
-  items[0].size = 20;
-  items[0].version = 0;
+  (*items)[0].type = LASitem::POINT10;
+  (*items)[0].size = 20;
+  (*items)[0].version = 0;
   if (have_gps_time)
   {
-    items[i].type = LASitem::GPSTIME11;
-    items[i].size = 8;
-    items[i].version = 0;
+    (*items)[i].type = LASitem::GPSTIME11;
+    (*items)[i].size = 8;
+    (*items)[i].version = 0;
     i++;
   }
   if (have_rgb)
   {
-    items[i].type = LASitem::RGB12;
-    items[i].size = 6;
-    items[i].version = 0;
+    (*items)[i].type = LASitem::RGB12;
+    (*items)[i].size = 6;
+    (*items)[i].version = 0;
     i++;
   }
   if (have_wavepacket)
   {
-    items[i].type = LASitem::WAVEPACKET13;
-    items[i].size = 29;
-    items[i].version = 0;
+    (*items)[i].type = LASitem::WAVEPACKET13;
+    (*items)[i].size = 29;
+    (*items)[i].version = 0;
     i++;
   }
   if (extra_bytes_number)
   {
-    items[i].type = LASitem::BYTE;
-    items[i].size = extra_bytes_number;
-    items[i].version = 0;
+    (*items)[i].type = LASitem::BYTE;
+    (*items)[i].size = extra_bytes_number;
+    (*items)[i].version = 0;
     i++;
   }
-  assert(i == num_items);
-  this->compressor = compressor;
-  if (this->compressor == LASZIP_COMPRESSOR_POINTWISE_CHUNKED)
-  {
-    if (chunk_size == 0) chunk_size = LASZIP_CHUNK_SIZE_DEFAULT;
-  }
+  assert(i == *num_items);
   return true;
 }
 
-bool LASzip::setup(const U16 num_items, const LASitem* items, const U16 compressor)
+bool LASitem::is_standard(const U16 num_items, const LASitem* items, U8* point_type, U16* record_length) const
 {
-  U16 i;
-  if (num_items == 0) return false;
   if (items == 0) return false;
-  if (compressor > LASZIP_COMPRESSOR_POINTWISE_CHUNKED) return false;
-  for (i = 0; i < num_items; i++)
+
+  // this is always true
+  if (point_type) *point_type = 127;
+  if (record_length)
   {
-    if (!items[i].supported()) return false;
+    U16 i;
+    *record_length = 0;
+    for (i = 0; i < num_items; i++)
+    {
+      *record_length += items[i].size;
+    }
   }
-  this->num_items = num_items;
-  if (this->items) delete [] this->items;
-  this->items = new LASitem[num_items];
-  for (i = 0; i < num_items; i++)
+
+  // the minimal number of items is 1
+  if (num_items < 1) return false;
+  // the maximal number of items is 5
+  if (num_items > 5) return false;
+
+  // all standard point types start with POINT10
+  if (!items[0].is_type(LASitem::POINT10)) return false;
+
+  // consider all the other combinations
+  if (num_items == 1)
   {
-    this->items[i] = items[i];
+    if (point_type) *point_type = 0;
+    if (record_length) assert(*record_length == 20);
+    return true;
   }
-  this->compressor = compressor;
-  if (this->compressor == LASZIP_COMPRESSOR_POINTWISE_CHUNKED)
+  else
   {
-    if (chunk_size == 0) chunk_size = LASZIP_CHUNK_SIZE_DEFAULT;
+    if (items[1].is_type(LASitem::GPSTIME11))
+    {
+      if (num_items == 2)
+      {
+        if (point_type) *point_type = 1;
+        if (record_length) assert(*record_length == 28);
+        return true;
+      }
+      else
+      {
+        if (items[2].is_type(LASitem::RGB12))
+        {
+          if (num_items == 3)
+          {
+            if (point_type) *point_type = 3;
+            if (record_length) assert(*record_length == 34);
+            return true;
+          }
+          else
+          {
+            if (items[3].is_type(LASitem::WAVEPACKET13))
+            {
+              if (num_items == 4)
+              {
+                if (point_type) *point_type = 5;
+                if (record_length) assert(*record_length == 63);
+                return true;
+              }
+              else
+              {
+                if (items[4].is_type(LASitem::BYTE))
+                {
+                  if (num_items == 5)
+                  {
+                    if (point_type) *point_type = 5;
+                    if (record_length) assert(*record_length == (63 + items[4].size));
+                    return true;
+                  }
+                }
+              }
+            }
+            else if (items[3].is_type(LASitem::BYTE))
+            {
+              if (num_items == 4)
+              {
+                if (point_type) *point_type = 3;
+                if (record_length) assert(*record_length == (34 + items[3].size));
+                return true;
+              }
+            }
+          }
+        }
+        else if (items[2].is_type(LASitem::WAVEPACKET13))
+        {
+          if (num_items == 3)
+          {
+            if (point_type) *point_type = 4;
+            if (record_length) assert(*record_length == 57);
+            return true;
+          }
+          else 
+          {
+            if (items[3].is_type(LASitem::BYTE))
+            {
+              if (num_items == 4)
+              {
+                if (point_type) *point_type = 4;
+                if (record_length) assert(*record_length == (57 + items[3].size));
+                return true;
+              }
+            }
+          }
+        }
+        else if (items[2].is_type(LASitem::BYTE))
+        {
+          if (num_items == 3)
+          {
+            if (point_type) *point_type = 1;
+            if (record_length) assert(*record_length == (28 + items[2].size));
+            return true;
+          }
+        }
+      }
+    }
+    else if (items[1].is_type(LASitem::RGB12))
+    {
+      if (num_items == 2)
+      {
+        if (point_type) *point_type = 2;


More information about the Liblas-commits mailing list