lasreaditemcompressed_v1.cpp
Go to the documentation of this file.
1 /*
2 ===============================================================================
3 
4  FILE: lasreaditemcompressed_v1.cpp
5 
6  CONTENTS:
7 
8  see corresponding header file
9 
10  PROGRAMMERS:
11 
12  martin.isenburg@gmail.com
13 
14  COPYRIGHT:
15 
16  (c) 2011, Martin Isenburg, LASSO - tools to catch reality
17 
18  This is free software; you can redistribute and/or modify it under the
19  terms of the GNU Lesser General Licence as published by the Free Software
20  Foundation. See the COPYING file for more information.
21 
22  This software is distributed WITHOUT ANY WARRANTY and without even the
23  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 
25  CHANGE HISTORY:
26 
27  see corresponding header file
28 
29 ===============================================================================
30 */
31 
33 
34 #include <assert.h>
35 #include <string.h>
36 
37 /*
38 ===============================================================================
39  LASreadItemCompressed_POINT10_v1
40 ===============================================================================
41 */
42 
43 struct LASpoint10
44 {
45  I32 x;
46  I32 y;
47  I32 z;
57 };
58 
60 {
61  U32 i;
62 
63  /* set decoder */
64  assert(dec);
65  this->dec = dec;
66 
67  /* create models and integer compressors */
68  ic_dx = new IntegerCompressor(dec, 32); // 32 bits, 1 context
69  ic_dy = new IntegerCompressor(dec, 32, 20); // 32 bits, 20 contexts
70  ic_z = new IntegerCompressor(dec, 32, 20); // 32 bits, 20 contexts
71  ic_intensity = new IntegerCompressor(dec, 16);
72  ic_scan_angle_rank = new IntegerCompressor(dec, 8, 2);
73  ic_point_source_ID = new IntegerCompressor(dec, 16);
74  m_changed_values = dec->createSymbolModel(64);
75  for (i = 0; i < 256; i++)
76  {
77  m_bit_byte[i] = 0;
78  m_classification[i] = 0;
79  m_user_data[i] = 0;
80  }
81 }
82 
84 {
85  U32 i;
86 
87  delete ic_dx;
88  delete ic_dy;
89  delete ic_z;
90  delete ic_intensity;
91  delete ic_scan_angle_rank;
92  delete ic_point_source_ID;
93  dec->destroySymbolModel(m_changed_values);
94  for (i = 0; i < 256; i++)
95  {
96  if (m_bit_byte[i]) dec->destroySymbolModel(m_bit_byte[i]);
97  if (m_classification[i]) dec->destroySymbolModel(m_classification[i]);
98  if (m_user_data[i]) dec->destroySymbolModel(m_user_data[i]);
99  }
100 }
101 
103 {
104  U32 i;
105 
106  /* init state */
107  last_x_diff[0] = last_x_diff[1] = last_x_diff[2] = 0;
108  last_y_diff[0] = last_y_diff[1] = last_y_diff[2] = 0;
109  last_incr = 0;
110 
111  /* init models and integer compressors */
112  ic_dx->initDecompressor();
113  ic_dy->initDecompressor();
114  ic_z->initDecompressor();
115  ic_intensity->initDecompressor();
116  ic_scan_angle_rank->initDecompressor();
117  ic_point_source_ID->initDecompressor();
118  dec->initSymbolModel(m_changed_values);
119  for (i = 0; i < 256; i++)
120  {
121  if (m_bit_byte[i]) dec->initSymbolModel(m_bit_byte[i]);
122  if (m_classification[i]) dec->initSymbolModel(m_classification[i]);
123  if (m_user_data[i]) dec->initSymbolModel(m_user_data[i]);
124  }
125 
126  /* init last item */
127  memcpy(last_item, item, 20);
128 
129  return TRUE;
130 }
131 
133 {
134  // find median difference for x and y from 3 preceding differences
135  I32 median_x;
136  if (last_x_diff[0] < last_x_diff[1])
137  {
138  if (last_x_diff[1] < last_x_diff[2])
139  median_x = last_x_diff[1];
140  else if (last_x_diff[0] < last_x_diff[2])
141  median_x = last_x_diff[2];
142  else
143  median_x = last_x_diff[0];
144  }
145  else
146  {
147  if (last_x_diff[0] < last_x_diff[2])
148  median_x = last_x_diff[0];
149  else if (last_x_diff[1] < last_x_diff[2])
150  median_x = last_x_diff[2];
151  else
152  median_x = last_x_diff[1];
153  }
154 
155  I32 median_y;
156  if (last_y_diff[0] < last_y_diff[1])
157  {
158  if (last_y_diff[1] < last_y_diff[2])
159  median_y = last_y_diff[1];
160  else if (last_y_diff[0] < last_y_diff[2])
161  median_y = last_y_diff[2];
162  else
163  median_y = last_y_diff[0];
164  }
165  else
166  {
167  if (last_y_diff[0] < last_y_diff[2])
168  median_y = last_y_diff[0];
169  else if (last_y_diff[1] < last_y_diff[2])
170  median_y = last_y_diff[2];
171  else
172  median_y = last_y_diff[1];
173  }
174 
175  // decompress x y z coordinates
176  I32 x_diff = ic_dx->decompress(median_x);
177  ((LASpoint10*)last_item)->x += x_diff;
178  // we use the number k of bits corrector bits to switch contexts
179  U32 k_bits = ic_dx->getK();
180  I32 y_diff = ic_dy->decompress(median_y, (k_bits < 19 ? k_bits : 19));
181  ((LASpoint10*)last_item)->y += y_diff;
182  k_bits = (k_bits + ic_dy->getK())/2;
183  ((LASpoint10*)last_item)->z = ic_z->decompress(((LASpoint10*)last_item)->z, (k_bits < 19 ? k_bits : 19));
184 
185  // decompress which other values have changed
186  I32 changed_values = dec->decodeSymbol(m_changed_values);
187 
188  if (changed_values)
189  {
190  // decompress the intensity if it has changed
191  if (changed_values & 32)
192  {
193  ((LASpoint10*)last_item)->intensity = (U16)ic_intensity->decompress(((LASpoint10*)last_item)->intensity);
194  }
195 
196  // decompress the edge_of_flight_line, scan_direction_flag, ... if it has changed
197  if (changed_values & 16)
198  {
199  if (m_bit_byte[last_item[14]] == 0)
200  {
201  m_bit_byte[last_item[14]] = dec->createSymbolModel(256);
202  dec->initSymbolModel(m_bit_byte[last_item[14]]);
203  }
204  last_item[14] = (U8)dec->decodeSymbol(m_bit_byte[last_item[14]]);
205  }
206 
207  // decompress the classification ... if it has changed
208  if (changed_values & 8)
209  {
210  if (m_classification[last_item[15]] == 0)
211  {
212  m_classification[last_item[15]] = dec->createSymbolModel(256);
213  dec->initSymbolModel(m_classification[last_item[15]]);
214  }
215  last_item[15] = (U8)dec->decodeSymbol(m_classification[last_item[15]]);
216  }
217 
218  // decompress the scan_angle_rank ... if it has changed
219  if (changed_values & 4)
220  {
221  last_item[16] = (U8)ic_scan_angle_rank->decompress(last_item[16], k_bits < 3);
222  }
223 
224  // decompress the user_data ... if it has changed
225  if (changed_values & 2)
226  {
227  if (m_user_data[last_item[17]] == 0)
228  {
229  m_user_data[last_item[17]] = dec->createSymbolModel(256);
230  dec->initSymbolModel(m_user_data[last_item[17]]);
231  }
232  last_item[17] = (U8)dec->decodeSymbol(m_user_data[last_item[17]]);
233  }
234 
235  // decompress the point_source_ID ... if it has changed
236  if (changed_values & 1)
237  {
238  ((LASpoint10*)last_item)->point_source_ID = (U16)ic_point_source_ID->decompress(((LASpoint10*)last_item)->point_source_ID);
239  }
240  }
241 
242  // record the difference
243  last_x_diff[last_incr] = x_diff;
244  last_y_diff[last_incr] = y_diff;
245  last_incr++;
246  if (last_incr > 2) last_incr = 0;
247 
248  // copy the last point
249  memcpy(item, last_item, 20);
250 }
251 
252 /*
253 ===============================================================================
254  LASreadItemCompressed_GPSTIME11_v1
255 ===============================================================================
256 */
257 
258 #define LASZIP_GPSTIME_MULTIMAX 512
259 
261 {
262  /* set decoder */
263  assert(dec);
264  this->dec = dec;
265  /* create entropy models and integer compressors */
266  m_gpstime_multi = dec->createSymbolModel(LASZIP_GPSTIME_MULTIMAX);
267  m_gpstime_0diff = dec->createSymbolModel(3);
268  ic_gpstime = new IntegerCompressor(dec, 32, 6); // 32 bits, 6 contexts
269 }
270 
272 {
273  dec->destroySymbolModel(m_gpstime_multi);
274  dec->destroySymbolModel(m_gpstime_0diff);
275  delete ic_gpstime;
276 }
277 
279 {
280  /* init state */
281  last_gpstime_diff = 0;
282  multi_extreme_counter = 0;
283 
284  /* init models and integer compressors */
285  dec->initSymbolModel(m_gpstime_multi);
286  dec->initSymbolModel(m_gpstime_0diff);
287  ic_gpstime->initDecompressor();
288 
289  /* init last item */
290  last_gpstime.u64 = *((U64*)item);
291  return TRUE;
292 }
293 
295 {
296  I32 multi;
297  if (last_gpstime_diff == 0) // if the last integer difference was zero
298  {
299  multi = dec->decodeSymbol(m_gpstime_0diff);
300  if (multi == 1) // the difference can be represented with 32 bits
301  {
302  last_gpstime_diff = ic_gpstime->decompress(0, 0);
303  last_gpstime.i64 += last_gpstime_diff;
304  }
305  else if (multi == 2) // the difference is huge
306  {
307  last_gpstime.u64 = dec->readInt64();
308  }
309  }
310  else
311  {
312  multi = dec->decodeSymbol(m_gpstime_multi);
313 
314  if (multi < LASZIP_GPSTIME_MULTIMAX-2)
315  {
316  I32 gpstime_diff;
317  if (multi == 1)
318  {
319  gpstime_diff = ic_gpstime->decompress(last_gpstime_diff, 1);
320  last_gpstime_diff = gpstime_diff;
321  multi_extreme_counter = 0;
322  }
323  else if (multi == 0)
324  {
325  gpstime_diff = ic_gpstime->decompress(last_gpstime_diff/4, 2);
326  multi_extreme_counter++;
327  if (multi_extreme_counter > 3)
328  {
329  last_gpstime_diff = gpstime_diff;
330  multi_extreme_counter = 0;
331  }
332  }
333  else if (multi < 10)
334  {
335  gpstime_diff = ic_gpstime->decompress(multi*last_gpstime_diff, 3);
336  }
337  else if (multi < 50)
338  {
339  gpstime_diff = ic_gpstime->decompress(multi*last_gpstime_diff, 4);
340  }
341  else
342  {
343  gpstime_diff = ic_gpstime->decompress(multi*last_gpstime_diff, 5);
344  if (multi == LASZIP_GPSTIME_MULTIMAX-3)
345  {
346  multi_extreme_counter++;
347  if (multi_extreme_counter > 3)
348  {
349  last_gpstime_diff = gpstime_diff;
350  multi_extreme_counter = 0;
351  }
352  }
353  }
354  last_gpstime.i64 += gpstime_diff;
355  }
356  else if (multi < LASZIP_GPSTIME_MULTIMAX-1)
357  {
358  last_gpstime.u64 = dec->readInt64();
359  }
360  }
361  *((I64*)item) = last_gpstime.i64;
362 }
363 
364 /*
365 ===============================================================================
366  LASreadItemCompressed_RGB12_v1
367 ===============================================================================
368 */
369 
371 {
372  /* set decoder */
373  assert(dec);
374  this->dec = dec;
375 
376  /* create models and integer compressors */
377  m_byte_used = dec->createSymbolModel(64);
378  ic_rgb = new IntegerCompressor(dec, 8, 6);
379 
380  /* create last item */
381  last_item = new U8[6];
382 }
383 
385 {
386  dec->destroySymbolModel(m_byte_used);
387  delete ic_rgb;
388  delete [] last_item;
389 }
390 
392 {
393  /* init state */
394 
395  /* init models and integer compressors */
396  dec->initSymbolModel(m_byte_used);
397  ic_rgb->initDecompressor();
398 
399  /* init last item */
400  memcpy(last_item, item, 6);
401  return TRUE;
402 }
403 
405 {
406  U32 sym = dec->decodeSymbol(m_byte_used);
407  if (sym & (1 << 0)) ((U16*)item)[0] = (U16)ic_rgb->decompress(((U16*)last_item)[0]&255, 0);
408  else ((U16*)item)[0] = (U16)(((U16*)last_item)[0]&0xFF);
409  if (sym & (1 << 1)) ((U16*)item)[0] |= (((U16)ic_rgb->decompress(((U16*)last_item)[0]>>8, 1)) << 8);
410  else ((U16*)item)[0] |= (((U16*)last_item)[0]&0xFF00);
411  if (sym & (1 << 2)) ((U16*)item)[1] = (U16)ic_rgb->decompress(((U16*)last_item)[1]&255, 2);
412  else ((U16*)item)[1] = (U16)(((U16*)last_item)[1]&0xFF);
413  if (sym & (1 << 3)) ((U16*)item)[1] |= (((U16)ic_rgb->decompress(((U16*)last_item)[1]>>8, 3)) << 8);
414  else ((U16*)item)[1] |= (((U16*)last_item)[1]&0xFF00);
415  if (sym & (1 << 4)) ((U16*)item)[2] = (U16)ic_rgb->decompress(((U16*)last_item)[2]&255, 4);
416  else ((U16*)item)[2] = (U16)(((U16*)last_item)[2]&0xFF);
417  if (sym & (1 << 5)) ((U16*)item)[2] |= (((U16)ic_rgb->decompress(((U16*)last_item)[2]>>8, 5)) << 8);
418  else ((U16*)item)[2] |= (((U16*)last_item)[2]&0xFF00);
419  memcpy(last_item, item, 6);
420 }
421 
422 /*
423 ===============================================================================
424  LASreadItemCompressed_WAVEPACKET13_v1
425 ===============================================================================
426 */
427 
429 {
436 };
437 
439 {
440  /* set decoder */
441  assert(dec);
442  this->dec = dec;
443 
444  /* create models and integer compressors */
445  m_packet_index = dec->createSymbolModel(256);
446  m_offset_diff[0] = dec->createSymbolModel(4);
447  m_offset_diff[1] = dec->createSymbolModel(4);
448  m_offset_diff[2] = dec->createSymbolModel(4);
449  m_offset_diff[3] = dec->createSymbolModel(4);
450  ic_offset_diff = new IntegerCompressor(dec, 32);
451  ic_packet_size = new IntegerCompressor(dec, 32);
452  ic_return_point = new IntegerCompressor(dec, 32);
453  ic_xyz = new IntegerCompressor(dec, 32, 3);
454 
455  /* create last item */
456  last_item = new U8[28];
457 }
458 
460 {
461  dec->destroySymbolModel(m_packet_index);
462  dec->destroyBitModel(m_offset_diff[0]);
463  dec->destroyBitModel(m_offset_diff[1]);
464  dec->destroyBitModel(m_offset_diff[2]);
465  dec->destroyBitModel(m_offset_diff[3]);
466  delete ic_offset_diff;
467  delete ic_packet_size;
468  delete ic_return_point;
469  delete ic_xyz;
470  delete [] last_item;
471 }
472 
474 {
475  /* init state */
476  last_diff_32 = 0;
477  sym_last_offset_diff = 0;
478 
479  /* init models and integer compressors */
480  dec->initSymbolModel(m_packet_index);
481  dec->initSymbolModel(m_offset_diff[0]);
482  dec->initSymbolModel(m_offset_diff[1]);
483  dec->initSymbolModel(m_offset_diff[2]);
484  dec->initSymbolModel(m_offset_diff[3]);
485  ic_offset_diff->initDecompressor();
486  ic_packet_size->initDecompressor();
487  ic_return_point->initDecompressor();
488  ic_xyz->initDecompressor();
489 
490  /* init last item */
491  item++;
492  memcpy(last_item, item, 28);
493  return TRUE;
494 }
495 
497 {
498  item[0] = (U8)(dec->decodeSymbol(m_packet_index));
499  item++;
500 
501  sym_last_offset_diff = dec->decodeSymbol(m_offset_diff[sym_last_offset_diff]);
502 
503  if (sym_last_offset_diff == 0)
504  {
505  ((LASwavepacket13*)item)->offset = ((LASwavepacket13*)last_item)->offset;
506  }
507  else if (sym_last_offset_diff == 1)
508  {
509  ((LASwavepacket13*)item)->offset = ((LASwavepacket13*)last_item)->offset + ((LASwavepacket13*)last_item)->packet_size;
510  }
511  else if (sym_last_offset_diff == 2)
512  {
513  last_diff_32 = ic_offset_diff->decompress(last_diff_32);
514  ((LASwavepacket13*)item)->offset = ((LASwavepacket13*)last_item)->offset + last_diff_32;
515  }
516  else
517  {
518  ((LASwavepacket13*)item)->offset = dec->readInt64();
519  }
520  ((LASwavepacket13*)item)->packet_size = ic_packet_size->decompress(((LASwavepacket13*)last_item)->packet_size);
521  ((LASwavepacket13*)item)->return_point.i32 = ic_return_point->decompress(((LASwavepacket13*)last_item)->return_point.i32);
522  ((LASwavepacket13*)item)->x.i32 = ic_xyz->decompress(((LASwavepacket13*)last_item)->x.i32, 0);
523  ((LASwavepacket13*)item)->y.i32 = ic_xyz->decompress(((LASwavepacket13*)last_item)->y.i32, 1);
524  ((LASwavepacket13*)item)->z.i32 = ic_xyz->decompress(((LASwavepacket13*)last_item)->z.i32, 2);
525  memcpy(last_item, item, 28);
526 }
527 
528 /*
529 ===============================================================================
530  LASreadItemCompressed_BYTE_v1
531 ===============================================================================
532 */
533 
535 {
536  /* set decoder */
537  assert(dec);
538  this->dec = dec;
539  assert(number);
540  this->number = number;
541 
542  /* create models and integer compressors */
543  ic_byte = new IntegerCompressor(dec, 8, number);
544 
545  /* create last item */
546  last_item = new U8[number];
547 }
548 
550 {
551  delete ic_byte;
552  delete [] last_item;
553 }
554 
556 {
557  /* init state */
558 
559  /* init models and integer compressors */
560  ic_byte->initDecompressor();
561 
562  /* init last item */
563  memcpy(last_item, item, number);
564  return TRUE;
565 }
566 
568 {
569  U32 i;
570  for (i = 0; i < number; i++)
571  {
572  item[i] = (U8)(ic_byte->decompress(last_item[i], i));
573  }
574  memcpy(last_item, item, number);
575 }
int BOOL
Definition: mydefs.hpp:57
LASreadItemCompressed_RGB12_v1(EntropyDecoder *dec)
LASreadItemCompressed_BYTE_v1(EntropyDecoder *dec, U32 number)
unsigned int U32
Definition: mydefs.hpp:39
unsigned short U16
Definition: mydefs.hpp:40
long long I64
Definition: mydefs.hpp:48
unsigned char U8
Definition: mydefs.hpp:41
char I8
Definition: mydefs.hpp:37
virtual EntropyModel * createSymbolModel(U32 n)=0
int I32
Definition: mydefs.hpp:35
#define LASZIP_GPSTIME_MULTIMAX
#define TRUE
Definition: mydefs.hpp:137
unsigned long long U64
Definition: mydefs.hpp:47
LASreadItemCompressed_POINT10_v1(EntropyDecoder *dec)


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Mon Feb 28 2022 22:46:07