-
Notifications
You must be signed in to change notification settings - Fork 27
/
LASreadItemCompressed_GPSTIME11_v1.cs
145 lines (132 loc) · 3.77 KB
/
LASreadItemCompressed_GPSTIME11_v1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//===============================================================================
//
// FILE: lasreaditemcompressed_gpstime11_v1.cs
//
// CONTENTS:
//
// Implementation of LASreadItemCompressed for GPSTime11 items (version 1).
//
// PROGRAMMERS:
//
// [email protected] - http://rapidlasso.com
//
// COPYRIGHT:
//
// (c) 2005-2012, martin isenburg, rapidlasso - tools to catch reality
// (c) of the C# port 2014 by Shinta <[email protected]>
//
// 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: omitted for easier Copy&Paste (pls see the original)
//
//===============================================================================
using System.Diagnostics;
namespace laszip.net
{
class LASreadItemCompressed_GPSTIME11_v1 : LASreadItemCompressed
{
const int LASZIP_GPSTIME_MULTIMAX=512;
public LASreadItemCompressed_GPSTIME11_v1(ArithmeticDecoder dec)
{
// set decoder
Debug.Assert(dec!=null);
this.dec=dec;
// create entropy models and integer compressors
m_gpstime_multi=dec.createSymbolModel(LASZIP_GPSTIME_MULTIMAX);
m_gpstime_0diff=dec.createSymbolModel(3);
ic_gpstime=new IntegerCompressor(dec, 32, 6); // 32 bits, 6 contexts
}
public override bool init(laszip_point item)
{
// init state
last_gpstime_diff=0;
multi_extreme_counter=0;
// init models and integer compressors
dec.initSymbolModel(m_gpstime_multi);
dec.initSymbolModel(m_gpstime_0diff);
ic_gpstime.initDecompressor();
// init last item
last_gpstime.f64=item.gps_time;
return true;
}
public override void read(laszip_point item)
{
if(last_gpstime_diff==0) // if the last integer difference was zero
{
int multi=(int)dec.decodeSymbol(m_gpstime_0diff);
if(multi==1) // the difference can be represented with 32 bits
{
last_gpstime_diff=ic_gpstime.decompress(0, 0);
last_gpstime.i64+=last_gpstime_diff;
}
else if(multi==2) // the difference is huge
{
last_gpstime.u64=dec.readInt64();
}
}
else
{
int multi=(int)dec.decodeSymbol(m_gpstime_multi);
if(multi<LASZIP_GPSTIME_MULTIMAX-2)
{
int gpstime_diff;
if(multi==1)
{
gpstime_diff=ic_gpstime.decompress(last_gpstime_diff, 1);
last_gpstime_diff=gpstime_diff;
multi_extreme_counter=0;
}
else if(multi==0)
{
gpstime_diff=ic_gpstime.decompress(last_gpstime_diff/4, 2);
multi_extreme_counter++;
if(multi_extreme_counter>3)
{
last_gpstime_diff=gpstime_diff;
multi_extreme_counter=0;
}
}
else if(multi<10)
{
gpstime_diff=ic_gpstime.decompress(multi*last_gpstime_diff, 3);
}
else if(multi<50)
{
gpstime_diff=ic_gpstime.decompress(multi*last_gpstime_diff, 4);
}
else
{
gpstime_diff=ic_gpstime.decompress(multi*last_gpstime_diff, 5);
if(multi==LASZIP_GPSTIME_MULTIMAX-3)
{
multi_extreme_counter++;
if(multi_extreme_counter>3)
{
last_gpstime_diff=gpstime_diff;
multi_extreme_counter=0;
}
}
}
last_gpstime.i64+=gpstime_diff;
}
else if(multi<LASZIP_GPSTIME_MULTIMAX-1)
{
last_gpstime.u64=dec.readInt64();
}
}
item.gps_time=last_gpstime.f64;
}
ArithmeticDecoder dec;
U64I64F64 last_gpstime;
ArithmeticModel m_gpstime_multi;
ArithmeticModel m_gpstime_0diff;
IntegerCompressor ic_gpstime;
int multi_extreme_counter;
int last_gpstime_diff;
}
}