[Liblas-commits] laszip: fix of pointreader and small optimization
of POINT10 com...
liblas-commits at liblas.org
liblas-commits at liblas.org
Thu Dec 23 13:11:29 EST 2010
changeset 113c76a6708b in /Volumes/Data/www/liblas.org/laszip
details: http://hg.liblas.orglaszip?cmd=changeset;node=113c76a6708b
summary: fix of pointreader and small optimization of POINT10 compressor
diffstat:
src/lasreaditemcompressed_v1.cpp | 72 +++++++++++++++++---------------------
src/lasreaditemcompressed_v1.hpp | 7 +--
src/lasreadpoint.cpp | 4 +-
src/laswriteitemcompressed_v1.cpp | 72 +++++++++++++++++---------------------
src/laswriteitemcompressed_v1.hpp | 7 +--
5 files changed, 72 insertions(+), 90 deletions(-)
diffs (296 lines):
diff -r 294dfaf3b0d3 -r 113c76a6708b src/lasreaditemcompressed_v1.cpp
--- a/src/lasreaditemcompressed_v1.cpp Thu Dec 23 06:11:29 2010 -0800
+++ b/src/lasreaditemcompressed_v1.cpp Thu Dec 23 10:11:19 2010 -0800
@@ -78,7 +78,7 @@
this->dec = dec;
/* create models and integer compressors */
- ic_dx = new IntegerCompressor(dec, 32, 2); // 32 bits, 2 contexts
+ ic_dx = new IntegerCompressor(dec, 32); // 32 bits, 1 context
ic_dy = new IntegerCompressor(dec, 32, 33); // 32 bits, 33 contexts
ic_z = new IntegerCompressor(dec, 32, 33); // 32 bits, 33 contexts
m_changed_values = dec->createSymbolModel(64);
@@ -112,10 +112,9 @@
BOOL LASreadItemCompressed_POINT10_v1::init(const U8* item)
{
/* init state */
- last_dir = 0;
- last_x_diff[0][0] = last_x_diff[0][1] = last_x_diff[0][2] = last_x_diff[1][0] = last_x_diff[1][1] = last_x_diff[1][2] = 0;
- last_y_diff[0][0] = last_y_diff[0][1] = last_y_diff[0][2] = last_y_diff[1][0] = last_y_diff[1][1] = last_y_diff[1][2] = 0;
- last_incr[0] = last_incr[1] = 0;
+ 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();
@@ -139,50 +138,50 @@
{
// find median difference for x and y from 3 preceding differences
I32 median_x;
- if (last_x_diff[last_dir][0] < last_x_diff[last_dir][1])
+ if (last_x_diff[0] < last_x_diff[1])
{
- if (last_x_diff[last_dir][1] < last_x_diff[last_dir][2])
- median_x = last_x_diff[last_dir][1];
- else if (last_x_diff[last_dir][0] < last_x_diff[last_dir][2])
- median_x = last_x_diff[last_dir][2];
+ 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[last_dir][0];
+ median_x = last_x_diff[0];
}
else
{
- if (last_x_diff[last_dir][0] < last_x_diff[last_dir][2])
- median_x = last_x_diff[last_dir][0];
- else if (last_x_diff[last_dir][1] < last_x_diff[last_dir][2])
- median_x = last_x_diff[last_dir][2];
+ 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[last_dir][1];
+ median_x = last_x_diff[1];
}
I32 median_y;
- if (last_y_diff[last_dir][0] < last_y_diff[last_dir][1])
+ if (last_y_diff[0] < last_y_diff[1])
{
- if (last_y_diff[last_dir][1] < last_y_diff[last_dir][2])
- median_y = last_y_diff[last_dir][1];
- else if (last_y_diff[last_dir][0] < last_y_diff[last_dir][2])
- median_y = last_y_diff[last_dir][2];
+ 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[last_dir][0];
+ median_y = last_y_diff[0];
}
else
{
- if (last_y_diff[last_dir][0] < last_y_diff[last_dir][2])
- median_y = last_y_diff[last_dir][0];
- else if (last_y_diff[last_dir][1] < last_y_diff[last_dir][2])
- median_y = last_y_diff[last_dir][2];
+ 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[last_dir][1];
+ 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, last_dir);
+ 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();
@@ -233,18 +232,11 @@
}
}
- // only record the difference if the scan direction has not changed
- if (last_dir == ((LASpoint10*)item)->scan_direction_flag)
- {
- last_x_diff[last_dir][last_incr[last_dir]] = x_diff;
- last_y_diff[last_dir][last_incr[last_dir]] = y_diff;
- last_incr[last_dir]++;
- if (last_incr[last_dir] > 2) last_incr[last_dir] = 0;
- }
- else
- {
- last_dir = ((LASpoint10*)item)->scan_direction_flag;
- }
+ // record the difference
+ last_x_diff[last_incr] = x_diff;
+ last_y_diff[last_incr] = y_diff;
+ last_incr++;
+ if (last_incr > 2) last_incr = 0;
// copy the last point
memcpy(last_item, item, 20);
diff -r 294dfaf3b0d3 -r 113c76a6708b src/lasreaditemcompressed_v1.hpp
--- a/src/lasreaditemcompressed_v1.hpp Thu Dec 23 06:11:29 2010 -0800
+++ b/src/lasreaditemcompressed_v1.hpp Thu Dec 23 10:11:19 2010 -0800
@@ -65,10 +65,9 @@
EntropyDecoder* dec;
U8* last_item;
- I32 last_dir;
- I32 last_x_diff[2][3];
- I32 last_y_diff[2][3];
- I32 last_incr[2];
+ I32 last_x_diff[3];
+ I32 last_y_diff[3];
+ I32 last_incr;
IntegerCompressor* ic_dx;
IntegerCompressor* ic_dy;
IntegerCompressor* ic_z;
diff -r 294dfaf3b0d3 -r 113c76a6708b src/lasreadpoint.cpp
--- a/src/lasreadpoint.cpp Thu Dec 23 06:11:29 2010 -0800
+++ b/src/lasreadpoint.cpp Thu Dec 23 10:11:19 2010 -0800
@@ -146,8 +146,8 @@
return FALSE;
break;
case LASitem::WAVEPACKET13:
- if (items[i].version == 0)
- readers_compressed[i] = new LASreadItemCompressed_BYTE_v1(dec, items[i].size);
+ if (items[i].version == 1)
+ readers_compressed[i] = new LASreadItemCompressed_WAVEPACKET13_v1(dec);
else
return FALSE;
break;
diff -r 294dfaf3b0d3 -r 113c76a6708b src/laswriteitemcompressed_v1.cpp
--- a/src/laswriteitemcompressed_v1.cpp Thu Dec 23 06:11:29 2010 -0800
+++ b/src/laswriteitemcompressed_v1.cpp Thu Dec 23 10:11:19 2010 -0800
@@ -78,7 +78,7 @@
this->enc = enc;
/* create models and integer compressors */
- ic_dx = new IntegerCompressor(enc, 32, 2); // 32 bits, 2 contexts
+ ic_dx = new IntegerCompressor(enc, 32); // 32 bits, 1 context
ic_dy = new IntegerCompressor(enc, 32, 33); // 32 bits, 33 contexts
ic_z = new IntegerCompressor(enc, 32, 33); // 32 bits, 33 contexts
m_changed_values = enc->createSymbolModel(64);
@@ -111,10 +111,9 @@
BOOL LASwriteItemCompressed_POINT10_v1::init(const U8* item)
{
/* init state */
- last_dir = 0;
- last_x_diff[0][0] = last_x_diff[0][1] = last_x_diff[0][2] = last_x_diff[1][0] = last_x_diff[1][1] = last_x_diff[1][2] = 0;
- last_y_diff[0][0] = last_y_diff[0][1] = last_y_diff[0][2] = last_y_diff[1][0] = last_y_diff[1][1] = last_y_diff[1][2] = 0;
- last_incr[0] = last_incr[1] = 0;
+ 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->initCompressor();
@@ -138,50 +137,50 @@
{
// find median difference for x and y from 3 preceding differences
I32 median_x;
- if (last_x_diff[last_dir][0] < last_x_diff[last_dir][1])
+ if (last_x_diff[0] < last_x_diff[1])
{
- if (last_x_diff[last_dir][1] < last_x_diff[last_dir][2])
- median_x = last_x_diff[last_dir][1];
- else if (last_x_diff[last_dir][0] < last_x_diff[last_dir][2])
- median_x = last_x_diff[last_dir][2];
+ 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[last_dir][0];
+ median_x = last_x_diff[0];
}
else
{
- if (last_x_diff[last_dir][0] < last_x_diff[last_dir][2])
- median_x = last_x_diff[last_dir][0];
- else if (last_x_diff[last_dir][1] < last_x_diff[last_dir][2])
- median_x = last_x_diff[last_dir][2];
+ 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[last_dir][1];
+ median_x = last_x_diff[1];
}
I32 median_y;
- if (last_y_diff[last_dir][0] < last_y_diff[last_dir][1])
+ if (last_y_diff[0] < last_y_diff[1])
{
- if (last_y_diff[last_dir][1] < last_y_diff[last_dir][2])
- median_y = last_y_diff[last_dir][1];
- else if (last_y_diff[last_dir][0] < last_y_diff[last_dir][2])
- median_y = last_y_diff[last_dir][2];
+ 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[last_dir][0];
+ median_y = last_y_diff[0];
}
else
{
- if (last_y_diff[last_dir][0] < last_y_diff[last_dir][2])
- median_y = last_y_diff[last_dir][0];
- else if (last_y_diff[last_dir][1] < last_y_diff[last_dir][2])
- median_y = last_y_diff[last_dir][2];
+ 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[last_dir][1];
+ median_y = last_y_diff[1];
}
// compress x y z coordinates
I32 x_diff = ((LASpoint10*)item)->x - ((LASpoint10*)last_item)->x;
I32 y_diff = ((LASpoint10*)item)->y - ((LASpoint10*)last_item)->y;
- ic_dx->compress(median_x, x_diff, last_dir);
+ ic_dx->compress(median_x, x_diff);
// we use the number k of bits corrector bits to switch contexts
U32 k_bits = ic_dx->getK();
ic_dy->compress(median_y, y_diff, k_bits);
@@ -234,18 +233,11 @@
ic_point_source_ID->compress(((LASpoint10*)last_item)->point_source_ID, ((LASpoint10*)item)->point_source_ID);
}
- // only record the difference if the scan direction has not changed
- if (last_dir == ((LASpoint10*)item)->scan_direction_flag)
- {
- last_x_diff[last_dir][last_incr[last_dir]] = x_diff;
- last_y_diff[last_dir][last_incr[last_dir]] = y_diff;
- last_incr[last_dir]++;
- if (last_incr[last_dir] > 2) last_incr[last_dir] = 0;
- }
- else
- {
- last_dir = ((LASpoint10*)item)->scan_direction_flag;
- }
+ // record the difference
+ last_x_diff[last_incr] = x_diff;
+ last_y_diff[last_incr] = y_diff;
+ last_incr++;
+ if (last_incr > 2) last_incr = 0;
// copy the last item
memcpy(last_item, item, 20);
diff -r 294dfaf3b0d3 -r 113c76a6708b src/laswriteitemcompressed_v1.hpp
--- a/src/laswriteitemcompressed_v1.hpp Thu Dec 23 06:11:29 2010 -0800
+++ b/src/laswriteitemcompressed_v1.hpp Thu Dec 23 10:11:19 2010 -0800
@@ -65,10 +65,9 @@
EntropyEncoder* enc;
U8* last_item;
- I32 last_dir;
- I32 last_x_diff[2][3];
- I32 last_y_diff[2][3];
- I32 last_incr[2];
+ I32 last_x_diff[3];
+ I32 last_y_diff[3];
+ I32 last_incr;
IntegerCompressor* ic_dx;
IntegerCompressor* ic_dy;
IntegerCompressor* ic_z;
More information about the Liblas-commits
mailing list