24 #include <core/exception.h> 25 #include <fvmodels/scanlines/beams.h> 68 unsigned int start_x,
unsigned int start_y,
69 unsigned int stop_y,
unsigned int offset_y,
70 bool distribute_start_x,
71 float angle_from,
float angle_range,
72 unsigned int num_beams)
75 if ( (stop_y > image_height) || (start_y > image_height) ) {
79 this->start_x = start_x;
80 this->start_y = start_y;
81 this->angle_from = angle_from;
82 this->angle_range = angle_range;
83 this->num_beams = num_beams;
84 this->stop_y = stop_y;
85 this->offset_y = offset_y;
86 this->image_width = image_width;
87 this->image_height = image_height;
88 this->distribute_start_x = distribute_start_x;
115 ScanlineBeams::advance()
118 while ( ! _finished && (first_beam < last_beam) ) {
120 unsigned int x_start = beam_current_pos[next_beam].x;
121 unsigned int y_start = beam_current_pos[next_beam].y;
123 unsigned int x_end = beam_end_pos[next_beam].x;
124 unsigned int y_end = beam_end_pos[next_beam].y;
126 int x, y, dist, xerr, yerr, dx, dy, incx, incy;
129 dx = x_end - x_start;
130 dy = y_end - y_start;
148 dist = (dx > dy) ? dx : dy;
157 unsigned int offset = 0;
158 while ( (x >= 0) && ((
unsigned int )x < image_width) && ((
unsigned int)y > stop_y) &&
159 (offset < offset_y) ) {
175 if ( (y < 0) || (
unsigned int)y <= stop_y ) {
180 first_beam = ++next_beam;
183 if ( (
unsigned int)x > image_width ) {
184 last_beam = next_beam - 1;
185 next_beam = first_beam;
192 beam_current_pos[next_beam] = coord;
194 if ( next_beam < last_beam) {
197 next_beam = first_beam;
216 tmp_coord.
x = coord.
x;
217 tmp_coord.
y = coord.
y;
228 beam_current_pos.clear();
229 if ( distribute_start_x ) {
230 unsigned int offset_start_x = image_width / (num_beams - 1);
231 for (
unsigned int i = 0; i < num_beams; ++i) {
232 coord.
x = i * offset_start_x;
234 beam_current_pos.push_back(coord);
236 coord.
x = beam_current_pos[0].x;
237 coord.
y = beam_current_pos[0].y;
241 beam_current_pos.resize( num_beams, coord );
245 beam_end_pos.clear();
247 float angle_between_beams = angle_range / num_beams;
248 for (
unsigned int i = 0; i < num_beams; ++i) {
249 float diff_y = beam_current_pos[i].y - stop_y;
250 float diff_x = diff_y * tan( angle_from + (
float)i * angle_between_beams );
252 end_point.
y = stop_y;
253 end_point.
x = (int)roundf(diff_x) + start_x;
254 beam_end_pos.push_back(end_point);
257 last_beam = beam_end_pos.size() - 1;
263 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.