73 for (i = 0; i < 256; i++)
76 m_classification[i] = 0;
88 enc->destroySymbolModel(m_changed_values);
90 enc->destroySymbolModel(m_scan_angle_rank[0]);
91 enc->destroySymbolModel(m_scan_angle_rank[1]);
92 delete ic_point_source_ID;
93 for (i = 0; i < 256; i++)
95 if (m_bit_byte[i]) enc->destroySymbolModel(m_bit_byte[i]);
96 if (m_classification[i]) enc->destroySymbolModel(m_classification[i]);
97 if (m_user_data[i]) enc->destroySymbolModel(m_user_data[i]);
109 for (i=0; i < 16; i++)
111 last_x_diff_median5[i].init();
112 last_y_diff_median5[i].init();
113 last_intensity[i] = 0;
114 last_height[i/2] = 0;
118 enc->initSymbolModel(m_changed_values);
119 ic_intensity->initCompressor();
120 enc->initSymbolModel(m_scan_angle_rank[0]);
121 enc->initSymbolModel(m_scan_angle_rank[1]);
122 ic_point_source_ID->initCompressor();
123 for (i = 0; i < 256; i++)
125 if (m_bit_byte[i]) enc->initSymbolModel(m_bit_byte[i]);
126 if (m_classification[i]) enc->initSymbolModel(m_classification[i]);
127 if (m_user_data[i]) enc->initSymbolModel(m_user_data[i]);
129 ic_dx->initCompressor();
130 ic_dy->initCompressor();
131 ic_z->initCompressor();
134 memcpy(last_item, item, 20);
142 U32 n = ((
LASpoint10*)item)->number_of_returns_of_given_pulse;
149 I32 changed_values = (((last_item[14] != item[14]) << 5) |
150 ((last_intensity[m] != ((
LASpoint10*)item)->intensity) << 4) |
151 ((last_item[15] != item[15]) << 3) |
152 ((last_item[16] != item[16]) << 2) |
153 ((last_item[17] != item[17]) << 1) |
156 enc->encodeSymbol(m_changed_values, changed_values);
159 if (changed_values & 32)
161 if (m_bit_byte[last_item[14]] == 0)
163 m_bit_byte[last_item[14]] = enc->createSymbolModel(256);
164 enc->initSymbolModel(m_bit_byte[last_item[14]]);
166 enc->encodeSymbol(m_bit_byte[last_item[14]], item[14]);
170 if (changed_values & 16)
172 ic_intensity->compress(last_intensity[m], ((
LASpoint10*)item)->
intensity, (m < 3 ? m : 3));
173 last_intensity[m] = ((
LASpoint10*)item)->intensity;
177 if (changed_values & 8)
179 if (m_classification[last_item[15]] == 0)
181 m_classification[last_item[15]] = enc->createSymbolModel(256);
182 enc->initSymbolModel(m_classification[last_item[15]]);
184 enc->encodeSymbol(m_classification[last_item[15]], item[15]);
188 if (changed_values & 4)
194 if (changed_values & 2)
196 if (m_user_data[last_item[17]] == 0)
198 m_user_data[last_item[17]] = enc->createSymbolModel(256);
199 enc->initSymbolModel(m_user_data[last_item[17]]);
201 enc->encodeSymbol(m_user_data[last_item[17]], item[17]);
205 if (changed_values & 1)
211 median = last_x_diff_median5[m].get();
213 ic_dx->compress(median, diff, n==1);
214 last_x_diff_median5[m].add(diff);
217 k_bits = ic_dx->getK();
218 median = last_y_diff_median5[m].get();
220 ic_dy->compress(median, diff, (n==1) + ( k_bits < 20 ?
U32_ZERO_BIT_0(k_bits) : 20 ));
221 last_y_diff_median5[m].add(diff);
224 k_bits = (ic_dx->getK() + ic_dy->getK()) / 2;
229 memcpy(last_item, item, 20);
239 #define LASZIP_GPSTIME_MULTI 500 240 #define LASZIP_GPSTIME_MULTI_MINUS -10 241 #define LASZIP_GPSTIME_MULTI_UNCHANGED (LASZIP_GPSTIME_MULTI - LASZIP_GPSTIME_MULTI_MINUS + 1) 242 #define LASZIP_GPSTIME_MULTI_CODE_FULL (LASZIP_GPSTIME_MULTI - LASZIP_GPSTIME_MULTI_MINUS + 2) 244 #define LASZIP_GPSTIME_MULTI_TOTAL (LASZIP_GPSTIME_MULTI - LASZIP_GPSTIME_MULTI_MINUS + 6) 259 enc->destroySymbolModel(m_gpstime_multi);
260 enc->destroySymbolModel(m_gpstime_0diff);
268 last_gpstime_diff[0] = 0;
269 last_gpstime_diff[1] = 0;
270 last_gpstime_diff[2] = 0;
271 last_gpstime_diff[3] = 0;
272 multi_extreme_counter[0] = 0;
273 multi_extreme_counter[1] = 0;
274 multi_extreme_counter[2] = 0;
275 multi_extreme_counter[3] = 0;
278 enc->initSymbolModel(m_gpstime_multi);
279 enc->initSymbolModel(m_gpstime_0diff);
280 ic_gpstime->initCompressor();
283 last_gpstime[0].u64 = *((
U64*)item);
284 last_gpstime[1].u64 = 0;
285 last_gpstime[2].u64 = 0;
286 last_gpstime[3].u64 = 0;
293 this_gpstime.
i64 = *((
I64*)item);
295 if (last_gpstime_diff[last] == 0)
297 if (this_gpstime.
i64 == last_gpstime[last].i64)
299 enc->encodeSymbol(m_gpstime_0diff, 0);
304 I64 curr_gpstime_diff_64 = this_gpstime.
i64 - last_gpstime[last].i64;
305 I32 curr_gpstime_diff = (
I32)curr_gpstime_diff_64;
306 if (curr_gpstime_diff_64 == (
I64)(curr_gpstime_diff))
308 enc->encodeSymbol(m_gpstime_0diff, 1);
309 ic_gpstime->compress(0, curr_gpstime_diff, 0);
310 last_gpstime_diff[last] = curr_gpstime_diff;
311 multi_extreme_counter[last] = 0;
317 for (i = 1; i < 4; i++)
319 I64 other_gpstime_diff_64 = this_gpstime.
i64 - last_gpstime[(last+i)&3].i64;
320 I32 other_gpstime_diff = (
I32)other_gpstime_diff_64;
321 if (other_gpstime_diff_64 == (
I64)(other_gpstime_diff))
323 enc->encodeSymbol(m_gpstime_0diff, i+2);
329 enc->encodeSymbol(m_gpstime_0diff, 2);
330 ic_gpstime->compress((
I32)(last_gpstime[last].u64 >> 32), (
I32)(this_gpstime.
u64 >> 32), 8);
331 enc->writeInt((
U32)(this_gpstime.
u64));
334 last_gpstime_diff[last] = 0;
335 multi_extreme_counter[last] = 0;
337 last_gpstime[last].i64 = this_gpstime.
i64;
342 if (this_gpstime.
i64 == last_gpstime[last].i64)
350 I64 curr_gpstime_diff_64 = this_gpstime.
i64 - last_gpstime[last].i64;
351 I32 curr_gpstime_diff = (
I32)curr_gpstime_diff_64;
354 if (curr_gpstime_diff_64 == (
I64)(curr_gpstime_diff))
357 F32 multi_f = (
F32)curr_gpstime_diff / (
F32)(last_gpstime_diff[last]);
364 enc->encodeSymbol(m_gpstime_multi, 1);
365 ic_gpstime->compress(last_gpstime_diff[last], curr_gpstime_diff, 1);
366 multi_extreme_counter[last] = 0;
372 enc->encodeSymbol(m_gpstime_multi, multi);
374 ic_gpstime->compress(multi*last_gpstime_diff[last], curr_gpstime_diff, 2);
376 ic_gpstime->compress(multi*last_gpstime_diff[last], curr_gpstime_diff, 3);
382 multi_extreme_counter[last]++;
383 if (multi_extreme_counter[last] > 3)
385 last_gpstime_diff[last] = curr_gpstime_diff;
386 multi_extreme_counter[last] = 0;
395 ic_gpstime->compress(multi*last_gpstime_diff[last], curr_gpstime_diff, 5);
401 multi_extreme_counter[last]++;
402 if (multi_extreme_counter[last] > 3)
404 last_gpstime_diff[last] = curr_gpstime_diff;
405 multi_extreme_counter[last] = 0;
411 enc->encodeSymbol(m_gpstime_multi, 0);
412 ic_gpstime->compress(0, curr_gpstime_diff, 7);
413 multi_extreme_counter[last]++;
414 if (multi_extreme_counter[last] > 3)
416 last_gpstime_diff[last] = curr_gpstime_diff;
417 multi_extreme_counter[last] = 0;
425 for (i = 1; i < 4; i++)
427 I64 other_gpstime_diff_64 = this_gpstime.
i64 - last_gpstime[(last+i)&3].i64;
428 I32 other_gpstime_diff = (
I32)other_gpstime_diff_64;
429 if (other_gpstime_diff_64 == (
I64)(other_gpstime_diff))
439 ic_gpstime->compress((
I32)(last_gpstime[last].u64 >> 32), (
I32)(this_gpstime.
u64 >> 32), 8);
440 enc->writeInt((
U32)(this_gpstime.
u64));
443 last_gpstime_diff[last] = 0;
444 multi_extreme_counter[last] = 0;
446 last_gpstime[last].i64 = this_gpstime.
i64;
476 enc->destroySymbolModel(m_byte_used);
477 enc->destroySymbolModel(m_rgb_diff_0);
478 enc->destroySymbolModel(m_rgb_diff_1);
479 enc->destroySymbolModel(m_rgb_diff_2);
480 enc->destroySymbolModel(m_rgb_diff_3);
481 enc->destroySymbolModel(m_rgb_diff_4);
482 enc->destroySymbolModel(m_rgb_diff_5);
490 enc->initSymbolModel(m_byte_used);
491 enc->initSymbolModel(m_rgb_diff_0);
492 enc->initSymbolModel(m_rgb_diff_1);
493 enc->initSymbolModel(m_rgb_diff_2);
494 enc->initSymbolModel(m_rgb_diff_3);
495 enc->initSymbolModel(m_rgb_diff_4);
496 enc->initSymbolModel(m_rgb_diff_5);
499 memcpy(last_item, item, 6);
508 U32 sym = ((last_item[0]&0x00FF) != (((
U16*)item)[0]&0x00FF)) << 0;
509 sym |= ((last_item[0]&0xFF00) != (((
U16*)item)[0]&0xFF00)) << 1;
510 sym |= ((last_item[1]&0x00FF) != (((
U16*)item)[1]&0x00FF)) << 2;
511 sym |= ((last_item[1]&0xFF00) != (((
U16*)item)[1]&0xFF00)) << 3;
512 sym |= ((last_item[2]&0x00FF) != (((
U16*)item)[2]&0x00FF)) << 4;
513 sym |= ((last_item[2]&0xFF00) != (((
U16*)item)[2]&0xFF00)) << 5;
514 sym |= (((((
U16*)item)[0]&0x00FF) != (((
U16*)item)[1]&0x00FF)) || ((((
U16*)item)[0]&0x00FF) != (((
U16*)item)[2]&0x00FF)) || ((((
U16*)item)[0]&0xFF00) != (((
U16*)item)[1]&0xFF00)) || ((((
U16*)item)[0]&0xFF00) != (((
U16*)item)[2]&0xFF00))) << 6;
515 enc->encodeSymbol(m_byte_used, sym);
518 diff_l = ((int)(((
U16*)item)[0]&255)) - (last_item[0]&255);
519 enc->encodeSymbol(m_rgb_diff_0,
U8_FOLD(diff_l));
523 diff_h = ((int)(((
U16*)item)[0]>>8)) - (last_item[0]>>8);
524 enc->encodeSymbol(m_rgb_diff_1,
U8_FOLD(diff_h));
530 corr = ((int)(((
U16*)item)[1]&255)) -
U8_CLAMP(diff_l + (last_item[1]&255));
531 enc->encodeSymbol(m_rgb_diff_2,
U8_FOLD(corr));
535 diff_l = (diff_l + (((
U16*)item)[1]&255) - (last_item[1]&255)) / 2;
536 corr = ((int)(((
U16*)item)[2]&255)) -
U8_CLAMP(diff_l + (last_item[2]&255));
537 enc->encodeSymbol(m_rgb_diff_4,
U8_FOLD(corr));
541 corr = ((int)(((
U16*)item)[1]>>8)) -
U8_CLAMP(diff_h + (last_item[1]>>8));
542 enc->encodeSymbol(m_rgb_diff_3,
U8_FOLD(corr));
546 diff_h = (diff_h + (((
U16*)item)[1]>>8) - (last_item[1]>>8)) / 2;
547 corr = ((int)(((
U16*)item)[2]>>8)) -
U8_CLAMP(diff_h + (last_item[2]>>8));
548 enc->encodeSymbol(m_rgb_diff_5,
U8_FOLD(corr));
551 memcpy(last_item, item, 6);
573 LASwriteItemCompressed_WAVEPACKET13_v2::LASwriteItemCompressed_WAVEPACKET13_v2(
EntropyEncoder* enc)
591 last_item =
new U8[28];
594 LASwriteItemCompressed_WAVEPACKET13_v2::~LASwriteItemCompressed_WAVEPACKET13_v2()
601 delete ic_offset_diff;
602 delete ic_packet_size;
603 delete ic_return_point;
608 BOOL LASwriteItemCompressed_WAVEPACKET13_v2::init(
const U8* item)
612 sym_last_offset_diff = 0;
620 ic_offset_diff->initCompressor();
621 ic_packet_size->initCompressor();
622 ic_return_point->initCompressor();
623 ic_xyz->initCompressor();
627 memcpy(last_item, item, 28);
631 inline BOOL LASwriteItemCompressed_WAVEPACKET13_v2::write(
const U8* item)
638 I32 curr_diff_32 = (
I32)curr_diff_64;
640 if (curr_diff_64 == (
I64)(curr_diff_32))
642 if (curr_diff_32 == 0)
644 enc->
encodeSymbol(m_offset_diff[sym_last_offset_diff], 0);
645 sym_last_offset_diff = 0;
649 enc->
encodeSymbol(m_offset_diff[sym_last_offset_diff], 1);
650 sym_last_offset_diff = 1;
654 enc->
encodeSymbol(m_offset_diff[sym_last_offset_diff], 2);
655 sym_last_offset_diff = 2;
656 ic_offset_diff->compress(last_diff_32, curr_diff_32);
657 last_diff_32 = curr_diff_32;
662 enc->
encodeSymbol(m_offset_diff[sym_last_offset_diff], 3);
663 sym_last_offset_diff = 3;
671 memcpy(last_item, item, 28);
691 this->number = number;
694 m_byte =
new EntropyModel*[number];
695 for (i = 0; i < number; i++)
701 last_item =
new U8[number];
707 for (i = 0; i < number; i++)
721 for (i = 0; i < number; i++)
727 memcpy(last_item, item, number);
735 for (i = 0; i < number; i++)
737 diff = item[i] - last_item[i];
740 memcpy(last_item, item, number);
#define LASZIP_GPSTIME_MULTI_UNCHANGED
BOOL init(const U8 *item)
virtual void encodeSymbol(EntropyModel *model, U32 sym)=0
~LASwriteItemCompressed_GPSTIME11_v2()
~LASwriteItemCompressed_BYTE_v2()
BOOL write(const U8 *item)
#define LASZIP_GPSTIME_MULTI
BOOL init(const U8 *item)
#define U32_ZERO_BIT_0(n)
~LASwriteItemCompressed_RGB12_v2()
~LASwriteItemCompressed_POINT10_v2()
U8 number_of_returns_of_given_pulse
BOOL init(const U8 *item)
LASwriteItemCompressed_GPSTIME11_v2(EntropyEncoder *enc)
BOOL write(const U8 *item)
virtual void writeInt64(U64 sym)=0
virtual void destroySymbolModel(EntropyModel *model)=0
#define LASZIP_GPSTIME_MULTI_MINUS
BOOL write(const U8 *item)
#define LASZIP_GPSTIME_MULTI_TOTAL
LASwriteItemCompressed_RGB12_v2(EntropyEncoder *enc)
LASwriteItemCompressed_BYTE_v2(EntropyEncoder *enc, U32 number)
BOOL init(const U8 *item)
virtual EntropyModel * createSymbolModel(U32 n)=0
const U8 number_return_map[8][8]
const U8 number_return_level[8][8]
BOOL write(const U8 *item)
#define LASZIP_GPSTIME_MULTI_CODE_FULL
LASwriteItemCompressed_POINT10_v2(EntropyEncoder *enc)
virtual void initSymbolModel(EntropyModel *model, U32 *init=0)=0