[Liblas-commits] laszip: added asserts

liblas-commits at liblas.org liblas-commits at liblas.org
Mon Jan 31 13:17:48 EST 2011


details:   http://hg.liblas.orglaszip/rev/70c18563cbe5
changeset: 169:70c18563cbe5
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Mon Jan 31 10:17:43 2011 -0800
description:
added asserts

diffstat:

 src/lasreaditemcompressed_v1.cpp  |  1123 +++++++++++++++---------------
 src/laswriteitemcompressed_v1.cpp |  1311 ++++++++++++++++++------------------
 2 files changed, 1222 insertions(+), 1212 deletions(-)

diffs (truncated from 2473 to 300 lines):

diff -r bba0e8b23ab9 -r 70c18563cbe5 src/lasreaditemcompressed_v1.cpp
--- a/src/lasreaditemcompressed_v1.cpp	Mon Jan 31 09:47:13 2011 -0800
+++ b/src/lasreaditemcompressed_v1.cpp	Mon Jan 31 10:17:43 2011 -0800
@@ -7,20 +7,20 @@
   
     see corresponding header file
   
-  PROGRAMMERS:
-
-    martin.isenburg at gmail.com
-
-  COPYRIGHT:
-
-    (c) 2011, Martin Isenburg, LASSO - tools to catch reality
-
-    This is free software; you can redistribute and/or modify it under the
-    terms of the GNU Lesser General Licence as published by the Free Software
-    Foundation. See the COPYING file for more information.
-
-    This software is distributed WITHOUT ANY WARRANTY and without even the
-    implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  PROGRAMMERS:
+
+    martin.isenburg at gmail.com
+
+  COPYRIGHT:
+
+    (c) 2011, Martin Isenburg, LASSO - tools to catch reality
+
+    This is free software; you can redistribute and/or modify it under the
+    terms of the GNU Lesser General Licence as published by the Free Software
+    Foundation. See the COPYING file for more information.
+
+    This software is distributed WITHOUT ANY WARRANTY and without even the
+    implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   
   CHANGE HISTORY:
   
@@ -30,554 +30,559 @@
 */
 
 #include "lasreaditemcompressed_v1.hpp"
-
-#include <assert.h>
-#include <string.h>
-
-/*
-===============================================================================
-                       LASreadItemCompressed_POINT10_v1
-===============================================================================
-*/
-
-struct LASpoint10
-{
-  I32 x;
-  I32 y;
-  I32 z;
-  U16 intensity;
-  U8 return_number : 3;
-  U8 number_of_returns_of_given_pulse : 3;
-  U8 scan_direction_flag : 1;
-  U8 edge_of_flight_line : 1;
-  U8 classification;
-  I8 scan_angle_rank;
-  U8 user_data;
-  U16 point_source_ID;
-};
+
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+/*
+===============================================================================
+                       LASreadItemCompressed_POINT10_v1
+===============================================================================
+*/
+
+struct LASpoint10
+{
+  I32 x;
+  I32 y;
+  I32 z;
+  U16 intensity;
+  U8 return_number : 3;
+  U8 number_of_returns_of_given_pulse : 3;
+  U8 scan_direction_flag : 1;
+  U8 edge_of_flight_line : 1;
+  U8 classification;
+  I8 scan_angle_rank;
+  U8 user_data;
+  U16 point_source_ID;
+};
 
 LASreadItemCompressed_POINT10_v1::LASreadItemCompressed_POINT10_v1(EntropyDecoder* dec)
 {
-  U32 i;
-
-  /* set decoder */
-  assert(dec);
-  this->dec = dec;
-
-  /* create models and integer compressors */
-  ic_dx = new IntegerCompressor(dec, 32);  // 32 bits, 1 context
-	ic_dy = new IntegerCompressor(dec, 32, 20); // 32 bits, 20 contexts
-	ic_z = new IntegerCompressor(dec, 32, 20);  // 32 bits, 20 contexts
-	ic_intensity = new IntegerCompressor(dec, 16);
-	ic_scan_angle_rank = new IntegerCompressor(dec, 8, 2);
-	ic_point_source_ID = new IntegerCompressor(dec, 16);
-	m_changed_values = dec->createSymbolModel(64);
-  for (i = 0; i < 256; i++)
-  {
-    m_bit_byte[i] = 0;
-    m_classification[i] = 0;
-    m_user_data[i] = 0;
-  }
+  U32 i;
+
+  /* set decoder */
+  assert(dec);
+  this->dec = dec;
+
+  /* create models and integer compressors */
+  ic_dx = new IntegerCompressor(dec, 32);  // 32 bits, 1 context
+	ic_dy = new IntegerCompressor(dec, 32, 20); // 32 bits, 20 contexts
+	ic_z = new IntegerCompressor(dec, 32, 20);  // 32 bits, 20 contexts
+	ic_intensity = new IntegerCompressor(dec, 16);
+	ic_scan_angle_rank = new IntegerCompressor(dec, 8, 2);
+	ic_point_source_ID = new IntegerCompressor(dec, 16);
+	m_changed_values = dec->createSymbolModel(64);
+  for (i = 0; i < 256; i++)
+  {
+    m_bit_byte[i] = 0;
+    m_classification[i] = 0;
+    m_user_data[i] = 0;
+  }
 }
-
-LASreadItemCompressed_POINT10_v1::~LASreadItemCompressed_POINT10_v1()
-{
-  U32 i;
-
-  delete ic_dx;
-  delete ic_dy;
-  delete ic_z;
-  delete ic_intensity;
-  delete ic_scan_angle_rank;
-  delete ic_point_source_ID;
-  dec->destroySymbolModel(m_changed_values);
-  for (i = 0; i < 256; i++)
-  {
-    if (m_bit_byte[i]) dec->destroySymbolModel(m_bit_byte[i]);
-    if (m_classification[i]) dec->destroySymbolModel(m_classification[i]);
-    if (m_user_data[i]) dec->destroySymbolModel(m_user_data[i]);
-  }
-}
+
+LASreadItemCompressed_POINT10_v1::~LASreadItemCompressed_POINT10_v1()
+{
+  U32 i;
+
+  delete ic_dx;
+  delete ic_dy;
+  delete ic_z;
+  delete ic_intensity;
+  delete ic_scan_angle_rank;
+  delete ic_point_source_ID;
+  dec->destroySymbolModel(m_changed_values);
+  for (i = 0; i < 256; i++)
+  {
+    if (m_bit_byte[i]) dec->destroySymbolModel(m_bit_byte[i]);
+    if (m_classification[i]) dec->destroySymbolModel(m_classification[i]);
+    if (m_user_data[i]) dec->destroySymbolModel(m_user_data[i]);
+  }
+}
 
 BOOL LASreadItemCompressed_POINT10_v1::init(const U8* item)
-{
-  U32 i;
-
-  /* init state */
-	last_x_diff[0] = last_x_diff[1] = last_x_diff[2] = 0;
-	last_y_diff[0] = last_y_diff[1] = last_y_diff[2] = 0;
-  last_incr = 0;
-
-  /* init models and integer compressors */
-  ic_dx->initDecompressor();
-  ic_dy->initDecompressor();
-  ic_z->initDecompressor();
-  ic_intensity->initDecompressor();
-  ic_scan_angle_rank->initDecompressor();
-  ic_point_source_ID->initDecompressor();
-  dec->initSymbolModel(m_changed_values);
-  for (i = 0; i < 256; i++)
-  {
-    if (m_bit_byte[i]) dec->initSymbolModel(m_bit_byte[i]);
-    if (m_classification[i]) dec->initSymbolModel(m_classification[i]);
-    if (m_user_data[i]) dec->initSymbolModel(m_user_data[i]);
-  }
-
-  /* init last item */
-  memcpy(last_item, item, 20);
-
-  return TRUE;
-}
-
-inline BOOL LASreadItemCompressed_POINT10_v1::read(U8* item)
-{
-  // find median difference for x and y from 3 preceding differences
-  I32 median_x;
-  if (last_x_diff[0] < last_x_diff[1])
-  {
-    if (last_x_diff[1] < last_x_diff[2])
-      median_x = last_x_diff[1];
-    else if (last_x_diff[0] < last_x_diff[2])
-      median_x = last_x_diff[2];
-    else
-      median_x = last_x_diff[0];
-  }
-  else
-  {
-    if (last_x_diff[0] < last_x_diff[2])
-      median_x = last_x_diff[0];
-    else if (last_x_diff[1] < last_x_diff[2])
-      median_x = last_x_diff[2];
-    else
-      median_x = last_x_diff[1];
-  }
-
-  I32 median_y;
-  if (last_y_diff[0] < last_y_diff[1])
-  {
-    if (last_y_diff[1] < last_y_diff[2])
-      median_y = last_y_diff[1];
-    else if (last_y_diff[0] < last_y_diff[2])
-      median_y = last_y_diff[2];
-    else
-      median_y = last_y_diff[0];
-  }
-  else
-  {
-    if (last_y_diff[0] < last_y_diff[2])
-      median_y = last_y_diff[0];
-    else if (last_y_diff[1] < last_y_diff[2])
-      median_y = last_y_diff[2];
-    else
-      median_y = last_y_diff[1];
-  }
-
-  // copy point from last point
-  memcpy(item, last_item, 20);
-
-  // decompress x y z coordinates
-  I32 x_diff = ic_dx->decompress(median_x);
-  ((LASpoint10*)item)->x += x_diff;
-  // we use the number k of bits corrector bits to switch contexts
-  U32 k_bits = ic_dx->getK();
-  I32 y_diff = ic_dy->decompress(median_y, (k_bits < 19 ? k_bits : 19));
-  ((LASpoint10*)item)->y += y_diff;
-  k_bits = (k_bits + ic_dy->getK())/2;
-  ((LASpoint10*)item)->z = ic_z->decompress(((LASpoint10*)last_item)->z, (k_bits < 19 ? k_bits : 19));
-
-	// decompress which other values have changed
-	I32 changed_values = dec->decodeSymbol(m_changed_values);
-
-  if (changed_values)
-  {
-		// decompress the intensity if it has changed
-		if (changed_values & 32)
-		{
-			((LASpoint10*)item)->intensity = ic_intensity->decompress(((LASpoint10*)last_item)->intensity);
-		}
-
-		// decompress the edge_of_flight_line, scan_direction_flag, ... if it has changed
-		if (changed_values & 16)
-		{
-      if (m_bit_byte[last_item[14]] == 0)
-      {
-        m_bit_byte[last_item[14]] = dec->createSymbolModel(256);
-        dec->initSymbolModel(m_bit_byte[last_item[14]]);
-      }
-			item[14] = dec->decodeSymbol(m_bit_byte[last_item[14]]);
-		}
-
-		// decompress the classification ... if it has changed
-		if (changed_values & 8)
-		{
-      if (m_classification[last_item[15]] == 0)
-      {
-        m_classification[last_item[15]] = dec->createSymbolModel(256);
-        dec->initSymbolModel(m_classification[last_item[15]]);
-      }
-			item[15] = dec->decodeSymbol(m_classification[last_item[15]]);
-		}
-		
-		// decompress the scan_angle_rank ... if it has changed
-		if (changed_values & 4)
-		{
-			((I8*)item)[16] = ic_scan_angle_rank->decompress(((I8*)last_item)[16], k_bits < 3);


More information about the Liblas-commits mailing list