7 : beam_size(beam_size),
8 map_azimuth(beam_size * 2, beam_size * 2),
9 map_range(beam_size * 2, beam_size * 2)
11 for (
unsigned y = 0; y < beam_size * 2; ++y)
12 for (
unsigned x = 0; x < beam_size * 2; ++x)
15 double absx = (double)x - beam_size;
16 double absy = (double)y - beam_size;
40 map_azimuth(y,x)= fmod (450 - atan2( -absy,absx)*M_1_PI*180., 360. );
47 unsigned range_idx = floor(
map_range(y, x));
55 int az_min = floor((az - .45) * beam_count / 360.0);
56 int az_max = ceil((az + .45) * beam_count / 360.0);
65 double d_az = M_1_PI * 180. / (range_idx + 0.5) / 2;
66 int az_min = round((az - d_az) * beam_count / 360.);
67 int az_max = round((az + d_az) * beam_count / 360.);
70 for (
int iaz = az_min; iaz <= az_max; ++iaz)
71 f((
unsigned)((iaz+beam_count) % beam_count), range_idx);
76 IndexMapping::IndexMapping(
unsigned height,
unsigned width)
77 : height(height), width(width),
78 map_azimuth(
Matrix2D<unsigned>::Constant(height, width, missing)),
79 map_range(
Matrix2D<unsigned>::Constant(height, width, missing))
83 FullsizeIndexMapping::FullsizeIndexMapping(
unsigned beam_size)
84 : IndexMapping(beam_size * 2, beam_size * 2)
96 for (
unsigned y = 0; y < height; ++y)
97 for (
unsigned x = 0; x < width; ++x)
101 unsigned maxval_azimuth;
102 unsigned maxval_range;
103 std::function<void(unsigned, unsigned)> f = [&](
unsigned azimuth,
unsigned range) {
104 double sample = scan.
get(azimuth, range);
105 if (first || sample > maxval)
108 maxval_azimuth = azimuth;
109 maxval_range = range;
125 ScaledIndexMapping::ScaledIndexMapping(
const CoordinateMapping& mapping,
unsigned image_side,
unsigned fullsize_pixels_per_scaled_pixel)
126 :
IndexMapping(image_side, image_side), mapping(mapping),
127 fullsize_pixels_per_scaled_pixel(fullsize_pixels_per_scaled_pixel),
128 image_offset(((int)mapping.beam_size * 2 - (int)image_side * (int)fullsize_pixels_per_scaled_pixel) / 2)
130 if ((image_side * fullsize_pixels_per_scaled_pixel) % 2 != 0)
131 throw std::runtime_error(
"the image cannot be properly centered on the full size image");
137 for(
unsigned sy = 0; sy < fullsize_pixels_per_scaled_pixel; ++sy)
138 for(
unsigned sx = 0; sx < fullsize_pixels_per_scaled_pixel; ++sx)
141 int src_x = x * fullsize_pixels_per_scaled_pixel + sx +
image_offset;
142 int src_y = y * fullsize_pixels_per_scaled_pixel + sy +
image_offset;
143 if (src_x < 0 || src_x >= mapping.
beam_size || src_y < 0 || src_y >= mapping.
beam_size)
continue;
147 std::function<void(unsigned, unsigned)> fullsize_sample = [&f](
unsigned azimuth,
unsigned range) {
150 mapping.
sample(beam_count, src_x, src_y, fullsize_sample);
157 for (
unsigned y = 0; y < height; ++y)
158 for (
unsigned x = 0; x < width; ++x)
163 unsigned maxval_range =
missing;
166 for(
unsigned sy = 0; sy < fullsize_pixels_per_scaled_pixel; ++sy)
167 for(
unsigned sx = 0; sx < fullsize_pixels_per_scaled_pixel; ++sx)
170 int src_x = x * fullsize_pixels_per_scaled_pixel + sx +
image_offset;
171 int src_y = y * fullsize_pixels_per_scaled_pixel + sy +
image_offset;
172 if (src_x < 0 || src_x >= mapping.width || src_y < 0 || src_y >= mapping.height)
continue;
173 unsigned range = mapping.
map_range(src_y, src_x);
174 if (range ==
missing)
continue;
179 if (first || sample > maxval)
183 maxval_range = range;
CoordinateMapping(unsigned beam_size)
Build a cartography mapping cartesian coordinates to volume polar indices.
PolarScan - structure to describe a polarScan containing a matrix of data and conversion factors...
unsigned beam_count
Count of beams in this scan.
T get(unsigned az, unsigned beam) const
Get a beam value.
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.
Base for all matrices we use, since we rely on row-major data.
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.
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.