forked from KeckCAVES/LidarViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLidarElevationSampler.h
175 lines (159 loc) · 5.27 KB
/
LidarElevationSampler.h
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/***********************************************************************
LidarElevationSampler - Functor class to evaluate the implicit elevation
function of a 2.5D LiDAR point cloud.
Copyright (c) 2009-2010 Oliver Kreylos
This file is part of the LiDAR processing and analysis package.
The LiDAR processing and analysis package is free software; you can
redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
The LiDAR processing and analysis package is distributed in the hope
that it will be useful, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with the LiDAR processing and analysis package; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA
***********************************************************************/
#ifndef LIDARELEVATIONSAMPLER_INCLUDED
#define LIDARELEVATIONSAMPLER_INCLUDED
#include <Math/Math.h>
#include <Math/Constants.h>
#include "LidarTypes.h"
class LidarSeparableElevationSampler // Sampler using a separable Lanczos filter for Cartesian grid generation
{
/* Elements: */
private:
double pos[2]; // Sample point's (x, y) position
double filterSize[2]; // Filter size, or cell size of target grid, in x and y
double numLobes; // Number of lobes in Lanczos reconstruction filter
double accumulator; // Accumulated convolution between point cloud and filter
double weightSum; // Sum of weights for all accumulated points
double absWeightSum; // Sum of absolute weights for all accumulated points
/* Constructors and destructors: */
public:
LidarSeparableElevationSampler(const double sPos[2],const double sFilterSize[2],int sNumLobes) // Creates an empty sampler
:numLobes(double(sNumLobes)),
accumulator(0.0),weightSum(0.0),absWeightSum(0.0)
{
for(int i=0;i<2;++i)
{
pos[i]=sPos[i];
filterSize[i]=sFilterSize[i];
}
}
/* Methods: */
Box getBox(void) const
{
Box result;
for(int i=0;i<2;++i)
{
result.min[i]=pos[i]-filterSize[i]*numLobes;
result.max[i]=pos[i]+filterSize[i]*numLobes;
}
result.min[2]=Box::full.min[2];
result.max[2]=Box::full.max[2];
return result;
}
void operator()(const LidarPoint& p)
{
/* Calculate the Lanczos filter weight for the LiDAR point: */
double weight=1.0;
for(int i=0;i<2;++i)
{
double x=Math::Constants<double>::pi*(double(p[i])-pos[i])/filterSize[i];
if(x!=0.0)
{
weight*=Math::sin(x)/x;
x/=numLobes;
weight*=Math::sin(x)/x;
}
}
/* Accumulate the weighted point: */
accumulator+=double(p[2])*weight;
weightSum+=weight;
absWeightSum+=Math::abs(weight);
}
double getWeightSum(void) const // Returns the sum of point weights
{
return weightSum;
}
double getAbsWeightSum(void) const // Returns the sum of absolute point weights
{
return absWeightSum;
}
double getValue(void) const // Returns the convolution result
{
/* Return the weighted average: */
return accumulator/weightSum;
}
};
class LidarRadialElevationSampler // Sampler using a radial Lanczos filter
{
/* Elements: */
private:
double pos[2]; // Sample point's (x, y) position
double filterRadius; // Filter radius
double numLobes; // Number of lobes in Lanczos reconstruction filter
double maxRadius2; // Squared maximum radius of Lanczos reconstruction filter
double accumulator; // Accumulated convolution between point cloud and filter
double weightSum; // Sum of weights for all accumulated points
double absWeightSum; // Sum of absolute weights for all accumulated points
/* Constructors and destructors: */
public:
LidarRadialElevationSampler(const double sPos[2],double sFilterRadius,int sNumLobes) // Creates an empty sampler
:filterRadius(sFilterRadius),numLobes(double(sNumLobes)),maxRadius2(Math::sqr(filterRadius*numLobes)),
accumulator(0.0),weightSum(0.0),absWeightSum(0.0)
{
for(int i=0;i<2;++i)
pos[i]=sPos[i];
}
/* Methods: */
Box getBox(void) const
{
Box result;
for(int i=0;i<2;++i)
{
result.min[i]=pos[i]-filterRadius*numLobes;
result.max[i]=pos[i]+filterRadius*numLobes;
}
result.min[2]=Box::full.min[2];
result.max[2]=Box::full.max[2];
return result;
}
void operator()(const LidarPoint& p)
{
double r=Math::sqr(double(p[0])-pos[0])+Math::sqr(double(p[1])-pos[1]);
if(r<maxRadius2)
{
/* Calculate the Lanczos filter weight for the LiDAR point: */
r=Math::Constants<double>::pi*Math::sqrt(r)/filterRadius;
double weight=1.0;
if(r!=0.0)
{
weight*=Math::sin(r)/r;
r/=numLobes;
weight*=Math::sin(r)/r;
}
/* Accumulate the weighted point: */
accumulator+=double(p[2])*weight;
weightSum+=weight;
absWeightSum+=Math::abs(weight);
}
}
double getWeightSum(void) const // Returns the sum of point weights
{
return weightSum;
}
double getAbsWeightSum(void) const // Returns the sum of absolute point weights
{
return absWeightSum;
}
double getValue(void) const // Returns the convolution result
{
/* Return the weighted average: */
return accumulator/weightSum;
}
};
#endif