26 #include <fvmodels/shape/line.h> 27 #include <utils/math/angle.h> 31 namespace firevision {
41 LineShape::LineShape(
unsigned int roi_width,
unsigned int roi_height)
47 max_length = (int)sqrt(roi_width * roi_width + roi_height * roi_height);
48 last_calc_r = last_calc_phi = 0.f;
50 this->roi_width = roi_width;
51 this->roi_height = roi_height;
55 LineShape::~LineShape()
63 LineShape::printToStream(std::ostream &stream)
65 stream <<
"r=" << r <<
" phi=" << phi <<
" count= " << count;
69 LineShape::setMargin(
unsigned int margin)
71 this->margin = margin;
75 LineShape::isClose(
unsigned int in_roi_x,
unsigned int in_roi_y)
96 LineShape::calcPoints()
98 if ((last_calc_r == r) && (last_calc_phi == phi))
106 bool reverse_direction =
false;
111 if (rad_angle < M_PI / 4) {
112 x1 = (int)round(r * cos(rad_angle));
113 y1 = (int)round(r * sin(rad_angle));
115 x2 = (int)round(r / cos(rad_angle));
116 }
else if (rad_angle < M_PI / 2) {
117 x1 = (int)round(r * cos(rad_angle));
118 y1 = (int)round(r * sin(rad_angle));
120 y2 = (int)round(r / cos(M_PI / 2 - rad_angle));
121 }
else if (rad_angle < 3.0 / 4.0 * M_PI) {
122 x1 = (int)round(-r * cos(M_PI - rad_angle));
123 y1 = (int)round(r * sin(M_PI - rad_angle));
125 y2 = (int)round(r / cos(rad_angle - M_PI / 2));
130 reverse_direction =
true;
134 x1 = (int)round(-r * cos(M_PI - rad_angle));
135 y1 = (int)round(r * sin(M_PI - rad_angle));
137 x2 = (int)round(-r / cos(M_PI - rad_angle));
142 reverse_direction =
true;
146 if (!(x1 == x2 && y1 == y2)) {
149 float vx, vy, length;
152 length = sqrt(vx * vx + vy * vy);
159 if (!reverse_direction) {
173 }
else if (y2 == 0) {
177 cout <<
"ERROR!" << endl
178 <<
" This case should not have occurred. Please have a look at method" << endl
179 <<
" \"LineShape::calc()\". Treatment of special case is not correct." << endl;
192 LineShape::getPoints(
int *x1,
int *y1,
int *x2,
int *y2)
float deg2rad(float deg)
Convert an angle given in degrees to radians.