Elaboradar 0.1
Caricamento in corso...
Ricerca in corso...
Nessun risultato
cart.h
Vai alla documentazione di questo file.
1
5#ifndef RADARELAB_CART_H
6#define RADARELAB_CART_H
7
8#include <radarelab/matrix.h>
9#include <radarelab/volume.h>
10#include <limits>
11#include <vector>
12
13namespace radarelab {
14
22{
24 const unsigned beam_size;
25
35
45
53
55 void sample(unsigned beam_count, unsigned x, unsigned y, std::function<void(unsigned, unsigned)>& f) const;
56};
57
58
63{
64public:
66 static const unsigned missing = 0xffffffff;
67
68 const unsigned height;
69 const unsigned width;
70
77
78 IndexMapping(unsigned height, unsigned width);
79
81 template<typename SRC, typename DST>
82 void to_cart(const PolarScan<SRC>& src, Matrix2D<DST>& dst) const
83 {
84 // In case dst is not a square with side beam_size*2, center it
85 int dx = ((int)width - dst.cols()) / 2;
86 int dy = ((int)height - dst.rows()) / 2;
87
88 for (unsigned y = 0; y < dst.rows(); ++y)
89 {
90 if (y + dy < 0 || y + dy >= height) continue;
91
92 for (unsigned x = 0; x < dst.cols(); ++x)
93 {
94 if (x + dx < 0 || x + dx >= width) continue;
95
96 auto azimuth = map_azimuth(y + dy, x + dx);
97 auto range = map_range(y + dy, x + dx);
98
99 if (azimuth == missing || range == missing) continue;
100 if (azimuth >= src.beam_count || range >= src.beam_size) continue;
101
102 dst(y, x) = src(azimuth, range);
103 }
104 }
105 }
106
108 template<typename T>
109 void to_cart(const std::function<T(unsigned, unsigned)>& src, Matrix2D<T>& dst) const
110 {
111 // In case dst is not a square with side beam_size*2, center it
112 int dx = ((int)width - dst.cols()) / 2;
113 int dy = ((int)height - dst.rows()) / 2;
114
115 for (unsigned y = 0; y < dst.rows(); ++y)
116 {
117 if (y + dy < 0 || y + dy >= height) continue;
118
119 for (unsigned x = 0; x < dst.cols(); ++x)
120 {
121 if (x + dx < 0 || x + dx >= width) continue;
122
123 auto azimuth = map_azimuth(y + dy, x + dx);
124 auto range = map_range(y + dy, x + dx);
125
126 if (azimuth == missing || range == missing) continue;
127 dst(y, x) = src(azimuth, range);
128 }
129 }
130 }
131};
132
133
138{
139 FullsizeIndexMapping(unsigned beam_size);
140
146 void map_max_sample(const PolarScan<double>& scan);
147
152 void map_max_sample(const PolarScan<double>& scan, const CoordinateMapping& mapping);
153};
154
155
163{
164 const CoordinateMapping& mapping;
165 unsigned fullsize_pixels_per_scaled_pixel;
168
169 ScaledIndexMapping(const CoordinateMapping& mapping, unsigned image_side, unsigned fullsize_pixels_per_scaled_pixel);
170
172 void sample(unsigned beam_count, unsigned x, unsigned y, std::function<void(unsigned, unsigned)>& f);
173
182 void map_max_sample(const PolarScan<double>& scan, const FullsizeIndexMapping& mapping);
183
185 template<typename T>
186 void to_cart_average(const PolarScan<double>& src, std::function<T(const std::vector<double>&)>& convert, Matrix2D<T>& dst) const
187 {
188 // In case dst is not a square with side beam_size*2, center it
189 int dx = ((int)width - dst.cols()) / 2;
190 int dy = ((int)height - dst.rows()) / 2;
191 std::vector<double> samples;
192
193 for (unsigned y = 0; y < dst.rows(); ++y)
194 {
195 if (y + dy < 0 || y + dy >= height) continue;
196
197 for (unsigned x = 0; x < dst.cols(); ++x)
198 {
199 if (x + dx < 0 || x + dx >= width) continue;
200
201 samples.clear();
202 std::function<void(unsigned, unsigned)> compute_average = [&samples, &src](unsigned azimuth, unsigned range) {
203 if (azimuth < 0 || azimuth > src.beam_count) return;
204 if (range < 0 || range > src.beam_size) return;
205 //if(src(azimuth,range) == src.nodata) return
206 samples.push_back(src(azimuth, range));
207 };
208
209 for(unsigned sy = 0; sy < fullsize_pixels_per_scaled_pixel; ++sy)
210 for(unsigned sx = 0; sx < fullsize_pixels_per_scaled_pixel; ++sx)
211 {
212 int src_x = x * fullsize_pixels_per_scaled_pixel + sx + image_offset;
213 int src_y = y * fullsize_pixels_per_scaled_pixel + sy + image_offset;
214 if (src_x < 0 || src_x >= mapping.beam_size * 2 || src_y < 0 || src_y >= mapping.beam_size * 2)
215 continue;
216 mapping.sample(src.beam_count, src_x, src_y, compute_average);
217 }
218
219 if (!samples.empty())
220 dst(y + dy, x + dx) = convert(samples);
221 }
222 }
223 }
224};
225
226}
227
228#endif
void to_cart(const std::function< T(unsigned, unsigned)> &src, Matrix2D< T > &dst) const
Fill the cartesian map dst with the output of the function src(azimuth, range)
Definition: cart.h:109
static const unsigned missing
Missing value in the azimuth and range index mappings.
Definition: cart.h:66
Matrix2D< unsigned > map_range
Range indices to use to lookup a map point in a volume -1 means no mapping.
Definition: cart.h:76
void to_cart(const PolarScan< SRC > &src, Matrix2D< DST > &dst) const
Copy data from the polar scan src to the cartesian map dst.
Definition: cart.h:82
Matrix2D< unsigned > map_azimuth
Azimuth indices to use to lookup a map point in a volume -1 means no mapping.
Definition: cart.h:73
Mapping of cartesian coordinates to specific azimuth and range volume indices.
Definition: cart.h:63
PolarScan - structure to describe a polarScan containing a matrix of data and conversion factors.
Definition: volume.h:113
String functions.
Definition: cart.cpp:4
const unsigned beam_size
Beam size of the volume that we are mapping to cartesian coordinates.
Definition: cart.h:24
Matrix2D< double > map_range
Range indices to use to lookup a map point in a volume.
Definition: cart.h:44
void sample(unsigned beam_count, unsigned x, unsigned y, std::function< void(unsigned, unsigned)> &f) const
Generate all the (azimuth, range) indices corresponding to a map point.
Definition: cart.cpp:44
Matrix2D< double > map_azimuth
Azimuth indices to use to lookup a map point in a volume.
Definition: cart.h:34
Mapping of cartesian coordinates to raw azimuth angles and range distances.
Definition: cart.h:22
void map_max_sample(const PolarScan< double > &scan)
Map cartesian cardinates to polar volume indices.
Definition: cart.cpp:88
Index mapping where the pixel size corresponds to the radar cell size.
Definition: cart.h:138
Base for all matrices we use, since we rely on row-major data.
Definition: matrix.h:37
unsigned beam_size
Number of samples in each beam.
Definition: volume.h:33
unsigned beam_count
Count of beams in this scan.
Definition: volume.h:30
void to_cart_average(const PolarScan< double > &src, std::function< T(const std::vector< double > &)> &convert, Matrix2D< T > &dst) const
Fill the cartesian map dst with the output of the function src(azimuth, range)
Definition: cart.h:186
int image_offset
Image offset in full size pixels.
Definition: cart.h:167
void map_max_sample(const PolarScan< double > &scan, const FullsizeIndexMapping &mapping)
Map cartesian cardinates to polar volume indices.
Definition: cart.cpp:154
void sample(unsigned beam_count, unsigned x, unsigned y, std::function< void(unsigned, unsigned)> &f)
Generate all the (azimuth, range) indices corresponding to a map point.
Definition: cart.cpp:134
Index mapping with arbitrary pixel size.
Definition: cart.h:163
Definisce le principali strutture che contengono i dati.