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;
112 ScanlineBeams::advance()
114 while (!_finished && (first_beam < last_beam)) {
115 unsigned int x_start = beam_current_pos[next_beam].x;
116 unsigned int y_start = beam_current_pos[next_beam].y;
118 unsigned int x_end = beam_end_pos[next_beam].x;
119 unsigned int y_end = beam_end_pos[next_beam].y;
121 int x, y, dist, xerr, yerr, dx, dy, incx, incy;
124 dx = x_end - x_start;
125 dy = y_end - y_start;
143 dist = (dx > dy) ? dx : dy;
152 unsigned int offset = 0;
153 while ((x >= 0) && ((
unsigned int)x < image_width) && ((
unsigned int)y > stop_y)
154 && (offset < offset_y)) {
170 if ((y < 0) || (
unsigned int)y <= stop_y) {
175 first_beam = ++next_beam;
178 if ((
unsigned int)x > image_width) {
179 last_beam = next_beam - 1;
180 next_beam = first_beam;
187 beam_current_pos[next_beam] = coord;
189 if (next_beam < last_beam) {
192 next_beam = first_beam;
208 tmp_coord.
x = coord.
x;
209 tmp_coord.
y = coord.
y;
219 beam_current_pos.clear();
220 if (distribute_start_x) {
221 unsigned int offset_start_x = image_width / (num_beams - 1);
222 for (
unsigned int i = 0; i < num_beams; ++i) {
223 coord.
x = i * offset_start_x;
225 beam_current_pos.push_back(coord);
227 coord.
x = beam_current_pos[0].x;
228 coord.
y = beam_current_pos[0].y;
232 beam_current_pos.resize(num_beams, coord);
235 beam_end_pos.clear();
237 float angle_between_beams = angle_range / num_beams;
238 for (
unsigned int i = 0; i < num_beams; ++i) {
239 float diff_y = beam_current_pos[i].y - stop_y;
240 float diff_x = diff_y * tan(angle_from + (
float)i * angle_between_beams);
242 end_point.
y = stop_y;
243 end_point.
x = (int)roundf(diff_x) + start_x;
244 beam_end_pos.push_back(end_point);
247 last_beam = beam_end_pos.size() - 1;
253 return "ScanlineModel::Beams";
bool finished()
Check if all desired points have been processed.
ScanlineBeams(unsigned int image_width, unsigned int image_height, unsigned int start_x, unsigned int start_y, unsigned int stop_y, unsigned int offset_y, bool distribute_start_x, float angle_from, float angle_range, unsigned int num_beams)
Construtor.
fawkes::upoint_t operator*()
Get the current coordinate.
unsigned int y
y coordinate
unsigned int x
x coordinate
const char * get_name()
Get name of scanline model.
unsigned int get_margin()
Get margin around points.
Base class for exceptions in Fawkes.
fawkes::upoint_t * operator++()
Postfix ++ operator.
Point with cartesian coordinates as unsigned integers.
fawkes::upoint_t * operator->()
Get pointer to current point.