00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00033 #include <mtt/mht.h>
00034
00035 using namespace std;
00036
00038 long Hypothesis::_euid=0;
00039 long Target::_euid=0;
00040 long Target::_ntotal=0;
00041
00043 GVGraph*graph_context;
00044
00046 string tracking_frame;
00047
00049 Mht mht;
00050 hypothesisTreePtr htreePtr;
00051
00052 Publisher markers_publisher;
00053
00054 string fileName;
00055
00056 double euclideanDistance(PointPtr& p1,PointPtr& p2)
00057 {
00058 return sqrt( pow(p1->x-p2->x,2) + pow(p1->y-p2->y,2));
00059 }
00060
00061 void pointCloud2ToUnorganizedVector(const sensor_msgs::PointCloud2& cloud,vector<PointPtr>& data)
00062 {
00063 pcl::PointCloud<pcl::PointXYZ> PclCloud;
00064 pcl::fromROSMsg(cloud,PclCloud);
00065
00066
00067 for(uint i=0;i<PclCloud.points.size();i++)
00068 {
00069 PointPtr pt(new Point);
00070
00071 pt->x=PclCloud.points[i].x;
00072 pt->y=PclCloud.points[i].y;
00073 pt->r=sqrt(pow(pt->x,2)+pow(pt->y,2));
00074 pt->t=atan2(pt->y,pt->x);
00075 pt->n=i++;
00076
00077 data.push_back(pt);
00078 }
00079 }
00080
00081 void pointCloud2ToVector(const sensor_msgs::PointCloud2& cloud,vector<PointPtr>& data)
00082 {
00083 pcl::PointCloud<pcl::PointXYZ> PclCloud;
00084
00085 pcl::fromROSMsg(cloud,PclCloud);
00086
00087 double theta;
00088 map<double,pair<uint,double> > grid;
00089 map<double,pair<uint,double> >::iterator it;
00090
00091 double spacing = 0.5*M_PI/180.;
00092
00093 double rightBorder;
00094 double leftBorder;
00095
00096 double r;
00097
00098
00099 for(uint i=0;i<PclCloud.points.size();i++)
00100 {
00101 theta=atan2(PclCloud.points[i].y,PclCloud.points[i].x);
00102 r=sqrt(pow(PclCloud.points[i].x,2)+pow(PclCloud.points[i].y,2));
00103
00104
00105 rightBorder = spacing * ceil(theta/spacing);
00106 leftBorder = rightBorder - spacing;
00107
00108 if(fabs(rightBorder-theta)<fabs(leftBorder-theta))
00109 theta=rightBorder;
00110 else
00111 theta=leftBorder;
00112
00113 if(grid.find(theta)!=grid.end())
00114 {
00115 if(grid[theta].second>r)
00116 {
00117 grid[theta].first=i;
00118 grid[theta].second=r;
00119 }
00120 }else
00121 {
00122 grid[theta].first=i;
00123 grid[theta].second=r;
00124 }
00125 }
00126
00127 uint i=0;
00128 for(it=grid.begin();it!=grid.end();it++)
00129 {
00130 PointPtr pt(new Point);
00131
00132 pt->x=PclCloud.points[(*it).second.first].x;
00133 pt->y=PclCloud.points[(*it).second.first].y;
00134 pt->r=sqrt(pow(pt->x,2)+pow(pt->y,2));
00135 pt->t=atan2(pt->y,pt->x);
00136 pt->n=i++;
00137
00138 data.push_back(pt);
00139 }
00140 }
00141
00142 void recursiveAssociation(vector<PointPtr>& data,vector<pair<MeasurementPtr,bool> >& point_association,double clustering_distance, uint p)
00143 {
00144
00145
00146 MeasurementPtr null_ptr;
00147
00148 for(uint l=0;l<data.size();l++)
00149 {
00150
00151 if(point_association[l].second==false)
00152 {
00153 double dist = euclideanDistance(data[p],data[l]);
00154
00155
00156 if(dist<clustering_distance)
00157 {
00158
00159 point_association[l].first = point_association[p].first;
00160 point_association[l].second=true;
00161
00162
00163
00164
00165 point_association[p].first->points.push_back(data[l]);
00166
00167 recursiveAssociation(data,point_association,clustering_distance,l);
00168 }
00169 }
00170 }
00171 }
00172
00173 void createObjects(vector<PointPtr>& data,vector<MeasurementPtr>& measurements,double clustering_distance)
00174 {
00175 static long id=0;
00176
00177
00178 vector<pair<MeasurementPtr,bool> > point_association;
00179 point_association.resize(data.size(),make_pair(MeasurementPtr(),false));
00180
00181
00182 for(uint p=0;p<data.size();p++)
00183 {
00184
00185 if(point_association[p].second==false)
00186 {
00187
00188 MeasurementPtr new_measurement(new Measurement);
00189
00190
00191 new_measurement->id=id++;
00192
00193
00194 new_measurement->points.push_back(data[p]);
00195
00196
00197 point_association[p].first=new_measurement;
00198 point_association[p].second=true;
00199
00200 measurements.push_back(new_measurement);
00201 }
00202
00203
00204 recursiveAssociation(data,point_association,clustering_distance,p);
00205 }
00206
00207 for(uint m=0;m<measurements.size();m++)
00208 measurements[m]->calculateCentroid();
00209 }
00210
00211 void dataHandler(const sensor_msgs::PointCloud2& msg)
00212 {
00213
00214 visualization_msgs::MarkerArray targets_markers;
00215 visualization_msgs::MarkerArray clusters_markers;
00216
00217 vector<PointPtr> raw_points;
00218 vector<PointPtr>::iterator raw_it;
00219
00220 vector<MeasurementPtr> clusters;
00221 vector<MeasurementPtr>::iterator clusters_it;
00222
00223 static visualization_msgs::MarkerArray markersMsg;
00224 static visualization_msgs::MarkerArray markersTreeMsg;
00225
00226 tracking_frame=msg.header.frame_id;
00227
00228
00229 pointCloud2ToUnorganizedVector(msg,raw_points);
00230
00231
00232
00233 createObjects(raw_points,clusters,1.5);
00234
00235
00236 pthread_mutex_lock(&(htreePtr->_draw_mutex));
00237
00238
00239 mht.iterate(clusters);
00240
00241
00242 pthread_mutex_unlock(&(htreePtr->_draw_mutex));
00243
00244
00245 vector<TargetPtr> targets = mht.getTargets();
00246
00247
00248 targets_markers.markers = createTargetMarkers(targets);
00249
00250
00251 clusters_markers.markers = createClustersMarkers(clusters);
00252
00253 markers_publisher.publish(targets_markers);
00254 markers_publisher.publish(clusters_markers);
00255
00256 return;
00257 }
00258
00259 void dataHandlerFromFile_points(vector<PointPtr>& raw_points)
00260 {
00261
00262 visualization_msgs::MarkerArray targets_markers;
00263 visualization_msgs::MarkerArray clusters_markers;
00264
00265 vector<PointPtr>::iterator raw_it;
00266
00267 vector<MeasurementPtr> clusters;
00268 vector<MeasurementPtr>::iterator clusters_it;
00269
00270 static visualization_msgs::MarkerArray markersMsg;
00271 static visualization_msgs::MarkerArray markersTreeMsg;
00272
00273
00274 tracking_frame="/atc/vehicle/center_bumper";
00275
00276
00277
00278
00279
00280
00281 createObjects(raw_points,clusters,1.0);
00282
00283
00284 pthread_mutex_lock(&(htreePtr->_draw_mutex));
00285
00286
00287 mht.iterate(clusters);
00288
00289
00290 pthread_mutex_unlock(&(htreePtr->_draw_mutex));
00291
00292
00293 vector<TargetPtr> targets = mht.getTargets();
00294
00295
00296 targets_markers.markers = createTargetMarkers(targets);
00297
00298
00299 clusters_markers.markers = createClustersMarkers(clusters);
00300
00301 markers_publisher.publish(targets_markers);
00302 markers_publisher.publish(clusters_markers);
00303
00304 return;
00305 }
00306
00307 void dataHandlerFromFile_clusters(vector<MeasurementPtr>& clusters)
00308 {
00309
00310 visualization_msgs::MarkerArray targets_markers;
00311 visualization_msgs::MarkerArray clusters_markers;
00312
00313 vector<MeasurementPtr>::iterator clusters_it;
00314
00315 static visualization_msgs::MarkerArray markersMsg;
00316 static visualization_msgs::MarkerArray markersTreeMsg;
00317
00318
00319 tracking_frame="/atc/vehicle/center_bumper";
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329 pthread_mutex_lock(&(htreePtr->_draw_mutex));
00330
00331
00332 mht.iterate(clusters);
00333
00334
00335 pthread_mutex_unlock(&(htreePtr->_draw_mutex));
00336
00337
00338 vector<TargetPtr> targets = mht.getTargets();
00339
00340
00341 targets_markers.markers = createTargetMarkers(targets);
00342
00343
00344 clusters_markers.markers = createClustersMarkers(clusters);
00345
00346 markers_publisher.publish(targets_markers);
00347 markers_publisher.publish(clusters_markers);
00348
00349 for(uint i=0;i<clusters.size();i++)
00350 clusters[i]->assigned_clusters.clear();
00351
00352 return;
00353 }
00354
00355 void Markers::update(visualization_msgs::Marker& marker)
00356 {
00357 for(uint i=0;i<markers.size();++i)
00358 if(markers[i].ns==marker.ns && markers[i].id==marker.id)
00359 {
00360 markers.erase(markers.begin()+i);
00361 break;
00362 }
00363
00364 markers.push_back(marker);
00365 }
00366
00367 void Markers::decrement(void)
00368 {
00369 for(uint i=0;i<markers.size();++i)
00370 {
00371 switch(markers[i].action)
00372 {
00373 case visualization_msgs::Marker::ADD:
00374 markers[i].action = visualization_msgs::Marker::DELETE;
00375 break;
00376 case visualization_msgs::Marker::DELETE:
00377 markers[i].action = -1;
00378 break;
00379 }
00380 }
00381 }
00382
00383 void Markers::clean(void)
00384 {
00385 vector<visualization_msgs::Marker> new_markers;
00386
00387 for(uint i=0;i<markers.size();++i)
00388 if(markers[i].action!=-1)
00389 new_markers.push_back(markers[i]);
00390
00391 markers=new_markers;
00392 }
00393
00394 vector<visualization_msgs::Marker> Markers::getOutgoingMarkers(void)
00395 {
00396 vector<visualization_msgs::Marker> m_out(markers);
00397 return markers;
00398 }
00399
00400 geometry_msgs::Point makePoint(double x,double y, double z)
00401 {
00402 geometry_msgs::Point p;
00403 p.x=x;
00404 p.y=y;
00405 p.z=z;
00406 return p;
00407 }
00408
00409 visualization_msgs::Marker makeEllipse(Vector2d mean, Matrix2d covariance, double threshold,string ns, std_msgs::ColorRGBA color, int id,geometry_msgs::Point position)
00410 {
00411
00412 static visualization_msgs::Marker ellipse;
00413 static bool init = true;
00414
00415
00416
00417
00418 if(init)
00419 {
00420 ellipse.header.frame_id = tracking_frame;
00421 ellipse.header.stamp = ros::Time::now();
00422
00423 ellipse.action = visualization_msgs::Marker::ADD;
00424 ellipse.type = visualization_msgs::Marker::LINE_STRIP;
00425
00426 ellipse.scale.x = 0.5;
00427 ellipse.scale.y = 0.5;
00428 ellipse.scale.z = 0.5;
00429
00430 init = false;
00431 }
00432
00433 ellipse.ns = ns;
00434
00435
00436
00437 ellipse.color=color;
00438 ellipse.id=id;
00439
00440 ellipse.points.clear();
00441
00442 assert(is_finite(covariance));
00443 assert(is_finite(mean));
00444
00445 MatrixXd data = ellipseParametric(covariance,mean,threshold);
00446
00447 for(uint c=0;c<data.cols();c++)
00448 {
00449 geometry_msgs::Point p;
00450
00451 p.x = data(0,c);
00452 p.y = data(1,c);
00453 p.z = position.z;
00454
00455 ellipse.points.push_back(p);
00456 }
00457
00458
00459
00460 return ellipse;
00461 }
00462
00463 template <class T>
00464 visualization_msgs::Marker makeTrail(vector<T>& past_states,string ns, std_msgs::ColorRGBA color, int id,geometry_msgs::Point position)
00465 {
00466
00467 static visualization_msgs::Marker trail;
00468 static bool init = true;
00469
00470 if(init)
00471 {
00472 trail.header.frame_id = tracking_frame;
00473 trail.header.stamp = ros::Time::now();
00474
00475 trail.action = visualization_msgs::Marker::ADD;
00476 trail.type = visualization_msgs::Marker::LINE_STRIP;
00477
00478 trail.scale.x = 0.1;
00479 trail.scale.y = 0.1;
00480 trail.scale.z = 0.1;
00481
00482 init = false;
00483 }
00484
00485 trail.ns = ns;
00486
00487 trail.color=color;
00488 trail.id=id;
00489
00490 trail.points.clear();
00491
00492 for(uint i=0;i<past_states.size();i++)
00493 {
00494 geometry_msgs::Point p;
00495
00496 p.x=past_states[i][0];
00497 p.y=past_states[i][1];
00498 p.z = position.z;
00499
00500 trail.points.push_back(p);
00501 }
00502
00503
00504
00505 return trail;
00506 }
00507 vector<visualization_msgs::Marker> createTargetMarkers(vector<TargetPtr>& targets)
00508 {
00509
00510 static Markers marker_list;
00511
00512
00513 marker_list.decrement();
00514
00515
00516 class_colormap colormap("hsv",10, 1, false);
00517
00518 visualization_msgs::Marker marker_ids;
00519 visualization_msgs::Marker marker_centers;
00520 visualization_msgs::Marker marker_velocity;
00521 visualization_msgs::Marker marker_association;
00522
00523 marker_ids.header.frame_id = tracking_frame;
00524 marker_ids.header.stamp = ros::Time::now();
00525
00526 marker_centers.header.frame_id = tracking_frame;
00527 marker_centers.header.stamp = marker_ids.header.stamp;
00528
00529 marker_velocity.header.frame_id = tracking_frame;
00530 marker_velocity.header.stamp = marker_ids.header.stamp;
00531
00532 marker_association.header.frame_id = tracking_frame;
00533 marker_association.header.stamp = marker_ids.header.stamp;
00534
00535 marker_ids.ns = "ids";
00536 marker_ids.action = visualization_msgs::Marker::ADD;
00537
00538 marker_centers.ns = "target_centers";
00539 marker_centers.action = visualization_msgs::Marker::ADD;
00540
00541 marker_velocity.ns = "velocity";
00542 marker_velocity.action = visualization_msgs::Marker::ADD;
00543
00544 marker_association.ns = "associations";
00545 marker_association.action = visualization_msgs::Marker::ADD;
00546
00547 marker_ids.type = visualization_msgs::Marker::TEXT_VIEW_FACING;
00548 marker_centers.type = visualization_msgs::Marker::POINTS;
00549 marker_velocity.type = visualization_msgs::Marker::ARROW;
00550 marker_association.type = visualization_msgs::Marker::LINE_LIST;
00551
00552 marker_ids.scale.x = 2.5;
00553 marker_ids.scale.y = 2.5;
00554 marker_ids.scale.z = 2.5;
00555
00556 marker_centers.scale.x = 1.4;
00557 marker_centers.scale.y = 1.4;
00558 marker_centers.scale.z = 1.4;
00559
00560 marker_velocity.scale.x = 0.4;
00561 marker_velocity.scale.y = 0.5;
00562 marker_velocity.scale.z = 0.8;
00563
00564 marker_association.scale.x = 0.8;
00565
00566 marker_centers.color.r = 0;
00567 marker_centers.color.g = 0;
00568 marker_centers.color.b = 0;
00569 marker_centers.color.a = 1;
00570
00571 marker_ids.color.r=0;
00572 marker_ids.color.g=0;
00573 marker_ids.color.b=0;
00574 marker_ids.color.a=1;
00575
00576 marker_association.color.r = 0;
00577 marker_association.color.g = 0;
00578 marker_association.color.b = 0;
00579 marker_association.color.a = 1;
00580
00581 marker_centers.points.resize(targets.size());
00582 marker_centers.colors.resize(targets.size());
00583
00584 marker_centers.id = 0;
00585
00586 double velocity_scale=0.5;
00587
00588 cout<<"number of targets: "<<targets.size()<<endl;
00589
00590
00591 for(uint i=0;i<targets.size();i++)
00592 {
00593
00594
00595
00596 Color color(colormap.color(targets[i]->_exuid));
00597
00598 if(targets[i]->_missed_associations>0)
00599 color.changeColorBrightness(0.9);
00600
00601
00602
00603 double velocity = targets[i]->_x(2);
00604
00605 marker_centers.colors[i] = colormap.color(targets[i]->_id);
00606
00607 marker_centers.points[i].x = targets[i]->_x(0);
00608 marker_centers.points[i].y = targets[i]->_x(1);
00609 marker_centers.points[i].z = 0.0;
00610
00611 marker_ids.pose.position.x = targets[i]->_x(0);
00612 marker_ids.pose.position.y = targets[i]->_x(1);
00613 marker_ids.pose.position.z = 1.0;
00614
00615
00616 boost::format fm("%ld (%ld)");
00617 fm % targets[i]->_exuid % targets[i]->_cluster;
00618
00619 marker_ids.text = fm.str();
00620
00621
00622 marker_ids.id = targets[i]->_id;
00623
00624 marker_list.update(marker_ids);
00625
00626
00627
00628 if(velocity>0.1)
00629 {
00630 marker_velocity.points.clear();
00631 marker_velocity.points.resize(2);
00632
00633 marker_velocity.color = colormap.color(targets[i]->_id);
00634
00635 marker_velocity.points[0].x = targets[i]->_x(0);
00636 marker_velocity.points[0].y = targets[i]->_x(1);
00637 marker_velocity.points[0].z = 0.0;
00638
00639
00640
00641
00642 marker_velocity.points[1].x = targets[i]->_x(0) + targets[i]->_x(2)*cos(targets[i]->_x(3))*velocity_scale;
00643 marker_velocity.points[1].y = targets[i]->_x(1) + targets[i]->_x(2)*sin(targets[i]->_x(3))*velocity_scale;
00644
00645 marker_velocity.points[1].z = 0.0;
00646
00647 marker_velocity.id=targets[i]->_id;
00648
00649 marker_list.update(marker_velocity);
00650 }
00651
00652
00653
00654
00655 visualization_msgs::Marker ellipse = makeEllipse(targets[i]->_xp.head(2),targets[i]->_P.topLeftCorner(2,2),mht.getMaxGating(),"search areas",color,targets[i]->_id,makePoint(0,0,0));
00656
00657
00658
00659 marker_list.update(ellipse);
00660
00661
00662 visualization_msgs::Marker ellipse_hypothesis = makeEllipse(targets[i]->_xp.head(2),targets[i]->_P.topLeftCorner(2,2),mht.getMaxGating(),"hypothesis cluster",makeColor(targets[i]->_cluster),targets[i]->_id,makePoint(0,0,-0.15));
00663
00664
00665
00666 marker_list.update(ellipse_hypothesis);
00667
00668
00669
00670 visualization_msgs::Marker trail = makeTrail(targets[i]->_past_states,"trail",makeColor(targets[i]->_id),targets[i]->_id,makePoint(0,0,-0.15));
00671
00672 marker_list.update(trail);
00673
00674
00675 geometry_msgs::Point start;
00676 geometry_msgs::Point end;
00677
00678 start.x = targets[i]->_x(0);
00679 start.y = targets[i]->_x(1);
00680 start.z = 0;
00681
00682 end.x = targets[i]->_z(0);
00683 end.y = targets[i]->_z(1);
00684 end.z = 0;
00685
00686
00687
00688 marker_association.points.push_back(start);
00689 marker_association.points.push_back(end);
00690
00691 marker_association.colors.push_back(colormap.color(targets[i]->_exuid));
00692 marker_association.colors.push_back(colormap.color(targets[i]->_exuid));
00693 }
00694
00695
00696
00697 marker_list.update(marker_centers);
00698 marker_list.update(marker_association);
00699
00700
00701 marker_list.clean();
00702
00703
00704
00705
00706 return marker_list.getOutgoingMarkers();
00707 }
00708
00709 std_msgs::ColorRGBA makeColor(double r,double g, double b, double a)
00710 {
00711 std_msgs::ColorRGBA color;
00712
00713 color.r=r;
00714 color.g=g;
00715 color.b=b;
00716 color.a=a;
00717
00718 return color;
00719 }
00720
00721 std_msgs::ColorRGBA makeColor(int id)
00722 {
00723 static class_colormap colormap("hsv",10, 1, false);
00724 return colormap.color(id);
00725 }
00726
00727 vector<visualization_msgs::Marker> createClustersMarkers(vector<MeasurementPtr>& clusters)
00728 {
00729 static Markers marker_list;
00730
00731
00732 marker_list.decrement();
00733
00734
00735 class_colormap colormap("hsv",10, 1, false);
00736
00737 visualization_msgs::Marker points;
00738 visualization_msgs::Marker spheres;
00739
00740 points.header.frame_id = tracking_frame;
00741 points.header.stamp = ros::Time::now();
00742
00743 spheres.header.frame_id = tracking_frame;
00744 spheres.header.stamp = ros::Time::now();
00745
00746 points.ns = "clusters";
00747 points.action = visualization_msgs::Marker::ADD;
00748 points.id=0;
00749
00750 spheres.ns = "clusters_centers";
00751 spheres.action = visualization_msgs::Marker::ADD;
00752
00753 points.type = visualization_msgs::Marker::POINTS;
00754 spheres.type = visualization_msgs::Marker::SPHERE;
00755
00756 points.color.a = 1;
00757
00758
00759
00760
00761
00762 points.scale.x = 0.15;
00763 points.scale.y = 0.15;
00764 points.scale.z = 0.15;
00765
00766 spheres.scale.x = 0.1;
00767 spheres.scale.y = 0.1;
00768 spheres.scale.z = 0.1;
00769
00770 spheres.pose.orientation.x = 0.0;
00771 spheres.pose.orientation.y = 0.0;
00772 spheres.pose.orientation.z = 0.0;
00773 spheres.pose.orientation.w = 1.0;
00774
00775 for(uint i=0;i<clusters.size();++i)
00776 {
00777 for(uint f=0;f<clusters[i]->points.size();++f)
00778 {
00779 geometry_msgs::Point p;
00780
00781 p.x = clusters[i]->points[f]->x;
00782 p.y = clusters[i]->points[f]->y;
00783 p.z = 0.0;
00784
00785 points.points.push_back(p);
00786 points.colors.push_back(colormap.color(i));
00787 }
00788
00789 spheres.pose.position.x=clusters[i]->centroid.x;
00790 spheres.pose.position.y=clusters[i]->centroid.y;
00791
00792 spheres.id=i;
00793
00794 spheres.color = colormap.color(i);
00795
00796 marker_list.update(spheres);
00797 }
00798
00799 marker_list.update(points);
00800
00801
00802 marker_list.clean();
00803
00804
00805 return marker_list.getOutgoingMarkers();
00806 }
00807
00808 void* graphicalThread(void*data)
00809 {
00810 graph_context=new GVGraph("graph");
00811
00812 gvconfig_plugin_install_from_library(graph_context->getGVCcontext(), NULL, &gvplugin_xgtk_LTX_library);
00813
00814 graph_context->applyLayout();
00815 graph_context->startRender();
00816
00817 delete graph_context;
00818
00819 return NULL;
00820 }
00821
00822 int main(int argc,char**argv)
00823 {
00825 pthread_t graph_thread;
00826
00827
00828 init(argc,argv,"mht");
00829
00830 NodeHandle nh("~");
00831
00832 markers_publisher = nh.advertise<visualization_msgs::MarkerArray>("/targets", 1000);
00833
00834 htreePtr = mht.getHypothesisTree();
00835
00836
00837 fileName = argv[1];
00838
00839 fileName += ".txt";
00840
00841
00842 for(uint kk=3;kk<4;kk++)
00843 {
00844 mht._k=kk;
00845 mht._j=4;
00846
00847 mht._aux1 = "/home/atlas/Dropbox/taem/matlab/trials/roundabout/report_rb_";
00848
00849 mht._aux1+=lexical_cast<string>(mht._k);
00850 mht._aux1+=lexical_cast<string>(mht._j);
00851 mht._aux1+="_";
00852
00853 cout<<"Reading data from file: "<<fileName<<endl;
00854
00855 string report = mht.getReportName("");
00856 cout<<"report name: "<<report<<endl;
00857
00858 if(remove(report.c_str()) != 0 )
00859 perror( "Error deleting file" );
00860
00861 report = mht.getReportName("_dist");
00862
00863 if(remove(report.c_str()) != 0 )
00864 perror( "Error deleting file" );
00865
00866 report = mht.getReportName("_total");
00867
00868 if(remove(report.c_str()) != 0 )
00869 perror( "Error deleting file" );
00870
00871 ifstream file (fileName.c_str());
00872 if(!file.is_open())
00873 {
00874 cout<<"error opening file: "<<fileName<<endl;
00875 return 1;
00876 }
00877
00878 string line;
00879
00880
00881 while(file.good() && ros::ok())
00882 {
00883 getline(file,line);
00884
00885
00886
00887 if(line[0]!='%')
00888 continue;
00889
00890 int it;
00891
00892 getline(file,line);
00893 sscanf(line.c_str(),"%*c %d",&it);
00894
00895 cout<<"iteration: "<<it<<endl;
00896
00897 vector<MeasurementPtr> measurements;
00898
00899 do
00900 {
00901
00902 double x,y,r;
00903
00904 MeasurementPtr measurement(new Measurement);
00905
00906 getline(file,line);
00907
00908 if(line[0]=='-')
00909 break;
00910
00911 sscanf(line.c_str(),"%ld %lf %lf %lf",&measurement->id,&x,&y,&r);
00912
00913 measurement->state[0]=x;
00914 measurement->state[1]=y;
00915 measurement->state[2]=r;
00916
00917
00918
00919
00920 measurements.push_back(measurement);
00921
00922 cout<<"target: "<<measurement->id<<" x: "<<x<<" y: "<<y<<" r: "<<r<< endl;
00923
00924 }while(line[0] != '-');
00925
00926 cout<<"measurements size: "<<measurements.size()<<endl;
00927
00928
00929
00930 dataHandlerFromFile_clusters(measurements);
00931
00932
00933
00934 boost::this_thread::sleep(boost::posix_time::milliseconds(50));
00935
00936
00937 }
00938
00939 cout<<"close file"<<endl;
00940 file.close();
00941
00942 }
00943
00944 pthread_cancel(graph_thread);
00945
00946 cout<<"return"<<endl;
00947 return 0;
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120 }