26 #include <utils/math/angle.h> 27 #include <fvmodels/shape/line.h> 44 LineShape::LineShape(
unsigned int roi_width,
unsigned int roi_height)
50 max_length = (int)sqrt( roi_width * roi_width + roi_height * roi_height );
51 last_calc_r = last_calc_phi = 0.f;
53 this->roi_width = roi_width;
54 this->roi_height = roi_height;
60 LineShape::~LineShape()
69 LineShape::printToStream(std::ostream &stream)
71 stream <<
"r=" << r <<
" phi=" << phi
72 <<
" count= " << count;
76 LineShape::setMargin(
unsigned int margin)
78 this->margin = margin;
83 LineShape::isClose(
unsigned int in_roi_x,
unsigned int in_roi_y)
104 LineShape::calcPoints()
107 if ((last_calc_r == r) && (last_calc_phi == phi))
return;
114 bool reverse_direction =
false;
119 if ( rad_angle < M_PI/4 ) {
120 x1 = (int)round( r * cos( rad_angle ) );
121 y1 = (int)round( r * sin( rad_angle ) );
123 x2 = (int)round( r / cos( rad_angle ) );
124 }
else if ( rad_angle < M_PI/2 ) {
125 x1 = (int)round( r * cos( rad_angle ) );
126 y1 = (int)round( r * sin( rad_angle ) );
128 y2 = (int)round( r / cos( M_PI/2 - rad_angle ) );
129 }
else if ( rad_angle < 3.0/4.0 * M_PI ) {
130 x1 = (int)round(-r * cos( M_PI - rad_angle ) );
131 y1 = (int)round( r * sin( M_PI - rad_angle ) );
133 y2 = (int)round( r / cos( rad_angle - M_PI/2 ) );
138 reverse_direction =
true;
142 x1 = (int)round(-r * cos( M_PI - rad_angle ) );
143 y1 = (int)round( r * sin( M_PI - rad_angle ) );
145 x2 = (int)round(-r / cos( M_PI - rad_angle ) );
150 reverse_direction =
true;
158 float vx, vy, length;
161 length = sqrt( vx * vx + vy * vy );
168 if ( ! reverse_direction) {
182 }
else if (y2 == 0) {
186 cout <<
"ERROR!" << endl
187 <<
" This case should not have occurred. Please have a look at method" << endl
188 <<
" \"LineShape::calc()\". Treatment of special case is not correct." << endl;
202 LineShape::getPoints(
int *x1,
int *y1,
int *x2,
int *y2)
float deg2rad(float deg)
Convert an angle given in degrees to radians.