38 return fmod(fmod(angle, 2.0*M_PI) + 2.0*M_PI, 2.0*M_PI);
60 this->
r = rand() / double(RAND_MAX);
61 this->
g = rand() / double(RAND_MAX);
62 this->
b = rand() / double(RAND_MAX);
78 this->
Lshape = l_shape_tracker_ukf;
79 Lshape.
BoxModel(
cx,
cy,
cvx,
cvy,
th,
psi,
comega,
L1_box,
L2_box,
length_box,
width_box);
98 Lshape.
BoxModel(
cx,
cy,
cvx,
cvy,
th,
psi,
comega,
L1_box,
L2_box,
length_box,
width_box);
127 unsigned int n = new_cluster.size();
128 VectorXd e1(2),e2(2);
130 for (
unsigned int i = 0; i < n; ++i) {
131 X(i,0) = new_cluster[i].first;
132 X(i,1) = new_cluster[i].second;
134 VectorXd C1(n),C2(n);
141 float step = (3.14/2)/d;
143 for (i = 0; i < d; ++i) {
157 ArrayX2d::Index max_index;
158 Q.col(1).maxCoeff(&max_index);
165 double a1,a2,a3,a4,b1,b2,b3,b4,c1,c2,c3,c4;
179 std::vector<Point> corners;
188 unsigned int idx = 0;
191 for (
unsigned int i = 1; i < 4; ++i) {
193 if (distance<min_distance) {
194 min_distance = distance;
201 std::vector<Point> l1l2_list;
203 l1l2_list.push_back(corners[0]);
206 l1l2_list.push_back(corners[idx+1]);
208 l1l2_list.push_back(corners[idx]);
210 l1l2_list.push_back(corners[3]);
213 l1l2_list.push_back(corners[idx-1]);
218 double dx = l1l2_list[1].first - l1l2_list[0].first;
219 double dy = l1l2_list[1].second- l1l2_list[0].second;
221 dx = l1l2_list[1].first - l1l2_list[2].first;
222 dy = l1l2_list[1].second- l1l2_list[2].second;
232 visualization_msgs::Marker bb_msg;
235 bb_msg.ns =
"bounding_boxes";
236 bb_msg.action = visualization_msgs::Marker::ADD;
237 bb_msg.pose.orientation.w = 1.0;
238 bb_msg.type = visualization_msgs::Marker::LINE_STRIP;
239 bb_msg.id = this->
id;
241 bb_msg.scale.x = 0.008;
242 bb_msg.color.g = this->
g;
243 bb_msg.color.b = this->
b;
244 bb_msg.color.r = this->
r;
245 bb_msg.color.a = 1.0;
248 for (
unsigned int i = 0; i < 4; ++i) {
251 bb_msg.points.push_back(p);
255 bb_msg.points.push_back(p);
261 visualization_msgs::Marker bb_msg;
265 bb_msg.ns =
"box_models_kf";
266 bb_msg.action = visualization_msgs::Marker::ADD;
267 bb_msg.pose.orientation.w = 1.0;
268 bb_msg.type = visualization_msgs::Marker::LINE_STRIP;
269 bb_msg.id = this->
id;
270 bb_msg.scale.x = 0.02;
281 bb_msg.points.push_back(p);
284 p.x =
cx + x*cos(
th) - y*sin(
th);
285 p.y =
cy + x*sin(
th) + y*cos(
th);
286 bb_msg.points.push_back(p);
289 p.x =
cx + x*cos(
th) - y*sin(
th);
290 p.y =
cy + x*sin(
th) + y*cos(
th);
291 bb_msg.points.push_back(p);
294 p.x =
cx + x*cos(
th) - y*sin(
th);
295 p.y =
cy + x*sin(
th) + y*cos(
th);
296 bb_msg.points.push_back(p);
299 p.x =
cx + x*cos(
th) - y*sin(
th);
300 p.y =
cy + x*sin(
th) + y*cos(
th);
301 bb_msg.points.push_back(p);
309 visualization_msgs::Marker l1l2_msg;
313 l1l2_msg.ns =
"L-Shapes";
314 l1l2_msg.action = visualization_msgs::Marker::ADD;
315 l1l2_msg.pose.orientation.w = 1.0;
316 l1l2_msg.type = visualization_msgs::Marker::LINE_STRIP;
317 l1l2_msg.id = this->
id;
319 l1l2_msg.scale.x = 0.1;
320 l1l2_msg.color.r = 1;
321 l1l2_msg.color.g = 0;
322 l1l2_msg.scale.x = 0.1;
323 l1l2_msg.color.b = 0;
324 l1l2_msg.color.a = 1.0;
326 double theta_degrees =
thetaL1 * (180.0/3.141592653589793238463);
327 if (theta_degrees > 360){
328 l1l2_msg.color.r = 1.0;
329 l1l2_msg.color.g = 0;
330 l1l2_msg.color.b = 0;
334 for (
unsigned int i = 0; i < 3; ++i) {
336 p.y =
l1l2[i].second;
337 l1l2_msg.points.push_back(p);
349 double determinant = a1*b2 - a2*b1;
350 Point intersection_point;
351 intersection_point.first = (b2*c1 - b1*c2)/determinant;
352 intersection_point.second = (a1*c2 - a2*c1)/determinant;
354 return intersection_point;
359 a = -(C1.maxCoeff()-C1.minCoeff())*(C2.maxCoeff()-C2.minCoeff());
367 double c1_max, c1_min, c2_max, c2_min;
368 c1_max = C1.maxCoeff();
369 c1_min = C1.minCoeff();
370 c2_max = C2.maxCoeff();
371 c2_min = C2.minCoeff();
372 VectorXd C1_max = c1_max - C1.array();
373 VectorXd C1_min = C1.array() - c1_min;
375 if(C1_max.squaredNorm() < C1_min.squaredNorm()){
381 VectorXd C2_max = c2_max - C2.array();
382 VectorXd C2_min = C2.array() - c2_min;
383 if(C2_max.squaredNorm() < C2_min.squaredNorm()){
392 for (
int i = 0; i < D1.size(); ++i) {
393 min = std::min(D1(i),D2(i));
394 d = std::max(min,d0);
402 visualization_msgs::Marker arrow_marker;
403 arrow_marker.type = visualization_msgs::Marker::ARROW;
405 arrow_marker.ns =
"thetaBox";
406 arrow_marker.action = visualization_msgs::Marker::ADD;
407 arrow_marker.color.a = 0.5;
408 arrow_marker.color.g = this->
g;
409 arrow_marker.color.b = this->
b;
410 arrow_marker.color.r = this->
r;
411 arrow_marker.id = this->
id;
412 arrow_marker.pose.position.x =
cx;
413 arrow_marker.pose.position.y =
cy;
414 arrow_marker.pose.position.z = 0;
417 arrow_marker.scale.z = 0.01;
429 visualization_msgs::Marker arrow_marker;
431 arrow_marker.type = visualization_msgs::Marker::ARROW;
433 arrow_marker.ns =
"thetaL1";
434 arrow_marker.action = visualization_msgs::Marker::ADD;
435 arrow_marker.color.a = 1.0;
436 arrow_marker.color.r = 1;
437 arrow_marker.color.g = 0;
438 arrow_marker.color.b = 0;
439 arrow_marker.id = this->
id;
443 arrow_marker.pose.orientation =
tf2::toMsg(quat_theta);
446 arrow_marker.pose.position.z = 0;
447 arrow_marker.scale.x =
L1_box;
449 arrow_marker.scale.y = 0.04;
450 arrow_marker.scale.z = 0.001;
456 visualization_msgs::Marker arrow_marker;
457 arrow_marker.type = visualization_msgs::Marker::ARROW;
460 arrow_marker.ns =
"thetaL2";
461 arrow_marker.action = visualization_msgs::Marker::ADD;
462 arrow_marker.color.a = 1.0;
463 arrow_marker.color.g = 1;
464 arrow_marker.color.g = 0;
465 arrow_marker.color.b = 0;
466 arrow_marker.id = this->
id;
472 arrow_marker.pose.orientation =
tf2::toMsg(quat_theta);
475 arrow_marker.scale.x =
L2_box;
476 arrow_marker.scale.y = 0.04;
477 arrow_marker.scale.z = 0.01;
483 visualization_msgs::Marker arrow_marker;
484 arrow_marker.type = visualization_msgs::Marker::ARROW;
488 arrow_marker.ns =
"velocities";
489 arrow_marker.action = visualization_msgs::Marker::ADD;
490 arrow_marker.color.a = 1.0;
491 arrow_marker.color.g =
g;
492 arrow_marker.color.b =
b;
493 arrow_marker.color.r =
r;
494 arrow_marker.id = this->
id;
495 arrow_marker.scale.x = 0.05;
496 arrow_marker.scale.y = 0.1;
502 arrow_marker.points.push_back(p);
507 arrow_marker.points.push_back(p);
512 visualization_msgs::Marker corner_msg;
513 corner_msg.type = visualization_msgs::Marker::POINTS;
516 corner_msg.ns =
"closest_corner";
517 corner_msg.action = visualization_msgs::Marker::ADD;
518 corner_msg.pose.orientation.w = 1.0;
521 corner_msg.scale.x = 0.08;
522 corner_msg.scale.y = 0.08;
523 corner_msg.color.a = 1.0;
524 corner_msg.color.g = 0.0;
525 corner_msg.color.b = 0.0;
526 corner_msg.color.r = 0.0;
527 corner_msg.id = this->
id;
533 corner_msg.points.push_back(p);
539 visualization_msgs::Marker boxcenter_marker;
540 boxcenter_marker.type = visualization_msgs::Marker::POINTS;
541 boxcenter_marker.header.frame_id =
frame_name;
543 boxcenter_marker.ns =
"bounding_box_center";
544 boxcenter_marker.action = visualization_msgs::Marker::ADD;
545 boxcenter_marker.pose.orientation.w = 1.0;
546 boxcenter_marker.scale.x = 0.1;
547 boxcenter_marker.scale.y = 0.1;
548 boxcenter_marker.color.a = 1.0;
549 boxcenter_marker.color.r = 1;
550 boxcenter_marker.color.g = 1;
551 boxcenter_marker.color.b = 0;
552 boxcenter_marker.id = this->
id;
557 boxcenter_marker.points.push_back(p);
559 return boxcenter_marker;
563 visualization_msgs::Marker cluster_vmsg;
566 cluster_vmsg.ns =
"clusters";
567 cluster_vmsg.action = visualization_msgs::Marker::ADD;
568 cluster_vmsg.pose.orientation.w = 1.0;
569 cluster_vmsg.type = visualization_msgs::Marker::POINTS;
570 cluster_vmsg.scale.x = 0.02;
571 cluster_vmsg.scale.y = 0.02;
572 cluster_vmsg.id = this->
id;
574 cluster_vmsg.color.g = this->
g;
575 cluster_vmsg.color.b = this->
b;
576 cluster_vmsg.color.r = this->
r;
577 cluster_vmsg.color.a = 1.0;
586 cluster_vmsg.points.push_back(p);
595 visualization_msgs::Marker marker;
599 marker.id = this->
id;
600 marker.type = visualization_msgs::Marker::CUBE;
601 marker.action = visualization_msgs::Marker::ADD;
603 marker.pose.position.x =
cx;
604 marker.pose.position.y =
cy;
605 marker.pose.position.z = 0;
612 marker.scale.z = 0.01;
614 marker.color.r = this->
r;
615 marker.color.g = this->
g;
616 marker.color.b = this->
b;
617 marker.color.a = 1.0;
624 visualization_msgs::Marker line_msg;
628 line_msg.ns =
"lines";
629 line_msg.action = visualization_msgs::Marker::ADD;
630 line_msg.pose.orientation.w = 1.0;
631 line_msg.type = visualization_msgs::Marker::LINE_STRIP;
632 line_msg.id = this->
id;
633 line_msg.scale.x = 0.1;
634 line_msg.color.g = this->
g;
635 line_msg.color.b = this->
b;
636 line_msg.color.r = this->
r;
637 line_msg.color.a = 1.0;
644 std::vector<Point> pointListOut;
647 for(
unsigned int k =0 ;k<pointListOut.size();++k){
648 p.x = pointListOut[k].first;
649 p.y = pointListOut[k].second;
652 line_msg.points.push_back(p);
655 if(pointListOut.size()==1){
656 for(
unsigned int k=0; k<pointListOut.size()-1;++k){
657 l =
sqrt(
pow(pointListOut[k+1].first - pointListOut[k].first,2) +
pow(pointListOut[k+1].second - pointListOut[k].second,2));
665 double sum_x = 0, sum_y = 0;
667 for(
unsigned int i = 0; i<c.size(); ++i){
669 sum_x = sum_x + c[i].first;
670 sum_y = sum_y + c[i].second;
681 double dx = lineEnd.first - lineStart.first;
682 double dy = lineEnd.second - lineStart.second;
685 double mag =
pow(
pow(dx,2.0)+
pow(dy,2.0),0.5);
688 dx /= mag; dy /= mag;
691 double pvx = pt.first - lineStart.first;
692 double pvy = pt.second - lineStart.second;
695 double pvdot = dx * pvx + dy * pvy;
698 double dsx = pvdot * dx;
699 double dsy = pvdot * dy;
702 double ax = pvx - dsx;
703 double ay = pvy - dsy;
716 size_t end = pointList.size()-1;
717 for(
size_t i = 1; i < end; i++)
731 std::vector<Point> recResults1;
732 std::vector<Point> recResults2;
733 std::vector<Point> firstLine(pointList.begin(), pointList.begin()+index+1);
734 std::vector<Point> lastLine(pointList.begin()+index, pointList.end());
739 out.assign(recResults1.begin(), recResults1.end()-1);
740 out.insert(out.end(), recResults2.begin(), recResults2.end());
742 throw std::runtime_error(
"Problem assembling output");
748 out.push_back(pointList[0]);
749 out.push_back(pointList[end]);
datmo::Track msg_track_box_kf
visualization_msgs::Marker getArrowVisualisationMessage()
std::vector< Point > corner_list
void setRPY(const tf2Scalar &roll, const tf2Scalar &pitch, const tf2Scalar &yaw)
std::vector< Point > l1l2
visualization_msgs::Marker getClosestCornerPointVisualisationMessage()
static double normalize_angle(double angle)
Point closest_corner_point
void update(const pointList &, const double dt, const tf::Transform &ego_pose)
visualization_msgs::Marker getBoundingBoxVisualisationMessage()
std::pair< double, double > Point
Point lineIntersection(double &, double &, double &, double &, double &, double &)
static double shortest_angular_distance(double from, double to)
void populateTrackingMsgs(const double &dt)
double areaCriterion(const VectorXd &, const VectorXd &)
std::vector< Point > pointList
Cluster(unsigned long int id, const pointList &, const double &, const std::string &, const tf::Transform &ego_pose)
visualization_msgs::Marker getThetaL2VisualisationMessage()
visualization_msgs::Marker getThetaL1VisualisationMessage()
visualization_msgs::Marker getClusterVisualisationMessage()
visualization_msgs::Marker getLineVisualisationMessage()
visualization_msgs::Marker getThetaBoxVisualisationMessage()
double min(double a, double b)
visualization_msgs::Marker getBoxModelKFVisualisationMessage()
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
static double normalize_angle_positive(double angle)
tf2::Quaternion quaternion
visualization_msgs::Marker getBoundingBoxCenterVisualisationMessage()
INLINE Rall1d< T, V, S > pow(const Rall1d< T, V, S > &arg, double m)
void ramerDouglasPeucker(const std::vector< Point > &, double, std::vector< Point > &)
void BoxModel(double &x, double &y, double &vx, double &vy, double &theta, double &psi, double &omega, double &L1, double &L2, double &length, double &width)
std::pair< double, double > mean_values
visualization_msgs::Marker getBoxSolidVisualisationMessage()
double perpendicularDistance(const Point &, const Point &, const Point &)
std::pair< double, double > previous_mean_values
void update(const double &thetaL1, const double &x_corner, const double &y_corner, const double &L1, const double &L2, const double &dt, const int cluster_size)
void rectangleFitting(const pointList &)
INLINE Rall1d< T, V, S > atan2(const Rall1d< T, V, S > &y, const Rall1d< T, V, S > &x)
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
void calcMean(const pointList &)
double closenessCriterion(const VectorXd &, const VectorXd &, const double &)
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
visualization_msgs::Marker getLShapeVisualisationMessage()