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 "lidar_segmentation.h"
00034 #include "clustering.h"
00035 #include "groundtruth.h"
00036
00037
00038 int readDataFile( vector<C_DataFromFilePtr>& data_gts , int values_per_scan)
00039 {
00040
00041 string path = ros::package::getPath("roslib");
00042 ifstream source("src/gt_datas/GT_NEW_DIV.txt");
00043
00044 if (!source.is_open())
00045 {
00046 cout << "Couldn't open the GT_NEW file" << endl;
00047 return 1;
00048 }
00049
00050 string line;
00051
00052 while(source.good())
00053 {
00054 getline(source, line);
00055
00056 if(line[0]!='i')
00057 continue;
00058
00059 int it;
00060
00061
00062 sscanf(line.c_str(),"%*c %d",&it);
00063
00064 C_DataFromFilePtr data_gt(new C_DataFromFile);
00065
00066 data_gt->iteration = it;
00067
00068 getline(source ,line);
00069
00070 int c = 0;
00071 double x , y;
00072 int label;
00073
00074 const char*ptr = line.c_str();
00075
00076 while(c < values_per_scan)
00077 {
00078 sscanf(ptr,"%lf", &x);
00079
00080 data_gt->x_valuesf.push_back(x);
00081
00082 c++;
00083
00084 ptr = strstr(ptr, " ");
00085
00086 if(ptr==NULL)
00087 break;
00088
00089 ptr++;
00090 }
00091
00092
00093
00094
00095
00096
00097
00098
00099 getline(source , line);
00100 const char*ptr2 = line.c_str();
00101 c = 0;
00102
00103 while(c < values_per_scan)
00104 {
00105 sscanf(ptr2, "%lf" , &y);
00106
00107 data_gt->y_valuesf.push_back(y);
00108 c++;
00109
00110 ptr2 = strstr(ptr2, " ");
00111
00112 if(ptr2==NULL)
00113 break;
00114
00115 ptr2++;
00116 }
00117
00118
00119
00120
00121
00122
00123
00124
00125 getline(source , line);
00126 const char*ptr3 = line.c_str();
00127 c = 0;
00128
00129 while(c < values_per_scan)
00130 {
00131 sscanf(ptr3, "%d" , &label);
00132
00133 data_gt->labels.push_back(label);
00134 c++;
00135
00136 ptr3 = strstr(ptr3, " ");
00137
00138 if(ptr3==NULL)
00139 break;
00140
00141 ptr3++;
00142 }
00143
00144
00145
00146
00147
00148
00149
00150
00151 data_gts.push_back(data_gt);
00152
00153 }
00154
00155 cout<<"close file"<<endl;
00156 source.close();
00157
00158 return 0;
00159
00160 }
00161
00162
00163 bool comparePoints(PointPtr p1,PointPtr p2)
00164 {
00165 return p1->cluster_id < p2->cluster_id;
00166 }
00167
00168 int convertPointsToCluster(vector<PointPtr>& points, vector<ClusterPtr>& clusters_GT)
00169 {
00170
00171 ClusterPtr cluster_gt(new Cluster);
00172
00173
00174 if( points[0]->label != 0 )
00175 {
00176 PointPtr p(new Point);
00177 p->x = points[0]->x;
00178 p->y = points[0]->y;
00179 p->label = points[0]->label;
00180 p->cluster_id = points[0]->cluster_id;
00181
00182 cluster_gt->support_points.push_back(p);
00183 cluster_gt->centroid = calculateClusterCentroid( cluster_gt->support_points );
00184 cluster_gt->central_point = calculateClusterMedian(cluster_gt->support_points);
00185 cluster_gt->id = p->cluster_id;
00186 }
00187
00188
00189
00190 for(uint idx = 1; idx < points.size(); idx++ )
00191 {
00192 if(points[idx]->cluster_id== 0)
00193 continue;
00194
00195 if( (points[idx]->cluster_id != points[idx-1]->cluster_id))
00196 {
00197
00198 if(cluster_gt->support_points.size()>0)
00199 clusters_GT.push_back(cluster_gt);
00200
00201
00202 cluster_gt.reset(new Cluster);
00203
00204 PointPtr p(new Point);
00205 p->x = points[idx]->x;
00206 p->y = points[idx]->y;
00207 p->label = points[idx]->label;
00208 p->cluster_id = points[idx]->cluster_id;
00209
00210 cluster_gt->support_points.push_back(p);
00211 cluster_gt->centroid = calculateClusterCentroid( cluster_gt->support_points );
00212 cluster_gt->central_point = calculateClusterMedian(cluster_gt->support_points);
00213 cluster_gt->id = p->cluster_id;
00214
00215 }else
00216 {
00217 PointPtr p(new Point);
00218 p->x = points[idx]->x;
00219 p->y = points[idx]->y;
00220 p->label = points[idx]->label;
00221 p->cluster_id = points[idx]->cluster_id;
00222
00223 cluster_gt->support_points.push_back(p);
00224
00225 cluster_gt->centroid = calculateClusterCentroid( cluster_gt->support_points );
00226 cluster_gt->central_point = calculateClusterMedian(cluster_gt->support_points);
00227 cluster_gt->id = p->cluster_id;
00228 }
00229
00230 }
00231
00232 if(cluster_gt->support_points.size()>0)
00233 clusters_GT.push_back(cluster_gt);
00234
00235 cout<< "Clusters GT " << clusters_GT.size() << endl;
00236
00237 return clusters_GT.size();
00238 }