-
Notifications
You must be signed in to change notification settings - Fork 26
/
StreamingMedian5.cs
128 lines (124 loc) · 2.26 KB
/
StreamingMedian5.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
//===============================================================================
//
// FILE: streamingmedian5.cs
//
// CONTENTS:
//
// Common defines and functionalities for version 2 of LASitemReadCompressed
// and LASitemwriteCompressed.
//
// PROGRAMMERS:
//
// martin.isenburg@rapidlasso.com - http://rapidlasso.com
//
// COPYRIGHT:
//
// (c) 2005-2012, martin isenburg, rapidlasso - tools to catch reality
// (c) of the C# port 2014 by Shinta <shintadono@googlemail.com>
//
// 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)
//
//===============================================================================
namespace laszip.net
{
struct StreamingMedian5
{
public int values0;
public int values1;
public int values2;
public int values3;
public int values4;
public bool low;
public void init()
{
values0=values1=values2=values3=values4=0;
low=false;
}
public void add(int v)
{
if(!low)
{
if(v<values2)
{
values4=values3;
values3=values2;
if(v<values0)
{
values2=values1;
values1=values0;
values0=v;
}
else if(v<values1)
{
values2=values1;
values1=v;
}
else
{
values2=v;
}
}
else
{
if(v<values3)
{
values4=values3;
values3=v;
}
else
{
values4=v;
}
low=true;
}
}
else
{
if(values2<v)
{
values0=values1;
values1=values2;
if(values4<v)
{
values2=values3;
values3=values4;
values4=v;
}
else if(values3<v)
{
values2=values3;
values3=v;
}
else
{
values2=v;
}
}
else
{
if(values1<v)
{
values0=values1;
values1=v;
}
else
{
values0=v;
}
low=false;
}
}
}
public int get()
{
return values2;
}
}
}