5 #ifndef RADARELAB_CART_H
6 #define RADARELAB_CART_H
55 void sample(
unsigned beam_count,
unsigned x,
unsigned y, std::function<
void(
unsigned,
unsigned)>& f)
const;
66 static const unsigned missing = 0xffffffff;
68 const unsigned height;
81 template<
typename SRC,
typename DST>
85 int dx = ((int)width - dst.cols()) / 2;
86 int dy = ((int)height - dst.rows()) / 2;
88 for (
unsigned y = 0; y < dst.rows(); ++y)
90 if (y + dy < 0 || y + dy >= height)
continue;
92 for (
unsigned x = 0; x < dst.cols(); ++x)
94 if (x + dx < 0 || x + dx >= width)
continue;
102 dst(y, x) = src(azimuth, range);
112 int dx = ((int)width - dst.cols()) / 2;
113 int dy = ((int)height - dst.rows()) / 2;
115 for (
unsigned y = 0; y < dst.rows(); ++y)
117 if (y + dy < 0 || y + dy >= height)
continue;
119 for (
unsigned x = 0; x < dst.cols(); ++x)
121 if (x + dx < 0 || x + dx >= width)
continue;
127 dst(y, x) = src(azimuth, range);
165 unsigned fullsize_pixels_per_scaled_pixel;
172 void sample(
unsigned beam_count,
unsigned x,
unsigned y, std::function<
void(
unsigned,
unsigned)>& f);
189 int dx = ((int)width - dst.cols()) / 2;
190 int dy = ((int)height - dst.rows()) / 2;
191 std::vector<double> samples;
193 for (
unsigned y = 0; y < dst.rows(); ++y)
195 if (y + dy < 0 || y + dy >= height)
continue;
197 for (
unsigned x = 0; x < dst.cols(); ++x)
199 if (x + dx < 0 || x + dx >= width)
continue;
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 samples.push_back(src(azimuth, range));
208 for(
unsigned sy = 0; sy < fullsize_pixels_per_scaled_pixel; ++sy)
209 for(
unsigned sx = 0; sx < fullsize_pixels_per_scaled_pixel; ++sx)
211 int src_x = x * fullsize_pixels_per_scaled_pixel + sx +
image_offset;
212 int src_y = y * fullsize_pixels_per_scaled_pixel + sy +
image_offset;
213 if (src_x < 0 || src_x >= mapping.
beam_size * 2 || src_y < 0 || src_y >= mapping.
beam_size * 2)
218 if (!samples.empty())
219 dst(y + dy, x + dx) = convert(samples);
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)
CoordinateMapping(unsigned beam_size)
Build a cartography mapping cartesian coordinates to volume polar indices.
Definisce le principali strutture che contengono i dati.
PolarScan - structure to describe a polarScan containing a matrix of data and conversion factors...
unsigned beam_count
Count of beams in this scan.
const unsigned beam_size
Beam size of the volume that we are mapping to cartesian coordinates.
int image_offset
Image offset in full size pixels.
void to_cart(const PolarScan< SRC > &src, Matrix2D< DST > &dst) const
Copy data from the polar scan src to the cartesian map dst.
unsigned beam_size
Number of samples in each beam.
Matrix2D< unsigned > map_range
Range indices to use to lookup a map point in a volume -1 means no mapping.
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.
static const unsigned missing
Missing value in the azimuth and range index mappings.
Mapping of cartesian coordinates to raw azimuth angles and range distances.
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.
Matrix2D< double > map_range
Range indices to use to lookup a map point in a volume.
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)
Index mapping with arbitrary pixel size.
Index mapping where the pixel size corresponds to the radar cell size.
void map_max_sample(const PolarScan< double > &scan)
Map cartesian cardinates to polar volume indices.
Mapping of cartesian coordinates to specific azimuth and range volume indices.
Matrix2D< unsigned > map_azimuth
Azimuth indices to use to lookup a map point in a volume -1 means no mapping.
Matrix2D< double > map_azimuth
Azimuth indices to use to lookup a map point in a volume.
void map_max_sample(const PolarScan< double > &scan, const FullsizeIndexMapping &mapping)
Map cartesian cardinates to polar volume indices.