24 #include <core/exception.h>
25 #include <fvmodels/scanlines/beams.h>
31 namespace firevision {
65 unsigned int image_height,
69 unsigned int offset_y,
70 bool distribute_start_x,
73 unsigned int num_beams)
77 if ((stop_y > image_height) || (start_y > image_height)) {
81 this->start_x = start_x;
82 this->start_y = start_y;
83 this->angle_from = angle_from;
84 this->angle_range = angle_range;
85 this->num_beams = num_beams;
86 this->stop_y = stop_y;
87 this->offset_y = offset_y;
88 this->image_width = image_width;
89 this->image_height = image_height;
90 this->distribute_start_x = distribute_start_x;
114 ScanlineBeams::advance()
116 while (!_finished && (first_beam < last_beam)) {
117 unsigned int x_start = beam_current_pos[next_beam].x;
118 unsigned int y_start = beam_current_pos[next_beam].y;
120 unsigned int x_end = beam_end_pos[next_beam].x;
121 unsigned int y_end = beam_end_pos[next_beam].y;
123 int x, y, dist, xerr, yerr, dx, dy, incx, incy;
126 dx = x_end - x_start;
127 dy = y_end - y_start;
145 dist = (dx > dy) ? dx : dy;
154 unsigned int offset = 0;
155 while ((x >= 0) && ((
unsigned int)x < image_width) && ((
unsigned int)y > stop_y)
156 && (offset < offset_y)) {
172 if ((y < 0) || (
unsigned int)y <= stop_y) {
177 first_beam = ++next_beam;
180 if ((
unsigned int)x > image_width) {
181 last_beam = next_beam - 1;
182 next_beam = first_beam;
189 beam_current_pos[next_beam] = coord;
191 if (next_beam < last_beam) {
194 next_beam = first_beam;
210 tmp_coord.
x = coord.
x;
211 tmp_coord.
y = coord.
y;
221 beam_current_pos.clear();
222 if (distribute_start_x) {
223 unsigned int offset_start_x = image_width / (num_beams - 1);
224 for (
unsigned int i = 0; i < num_beams; ++i) {
225 coord.
x = i * offset_start_x;
227 beam_current_pos.push_back(coord);
229 coord.
x = beam_current_pos[0].x;
230 coord.
y = beam_current_pos[0].y;
234 beam_current_pos.resize(num_beams, coord);
237 beam_end_pos.clear();
239 float angle_between_beams = angle_range / num_beams;
240 for (
unsigned int i = 0; i < num_beams; ++i) {
241 float diff_y = beam_current_pos[i].y - stop_y;
242 float diff_x = diff_y * tan(angle_from + (
float)i * angle_between_beams);
244 end_point.
y = stop_y;
245 end_point.
x = (int)roundf(diff_x) + start_x;
246 beam_end_pos.push_back(end_point);
249 last_beam = beam_end_pos.size() - 1;
255 return "ScanlineModel::Beams";