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
00027 #include <navigability_map/navigability_map.h>
00028
00037 using namespace std;
00038 using namespace cv;
00039
00040 void Navigability_Map::Filter_PointCloud(pcl::PointCloud<pcl::PointXYZ>::Ptr &cloud_in,pcl::PointCloud<pcl::PointXYZ>::Ptr &pc_filter)
00041 {
00042 pcl::PassThrough<pcl::PointXYZ> pass;
00043
00044 pass.setInputCloud (cloud_in);
00045 pass.setFilterFieldName ("x");
00046 pass.setFilterLimits (Xmin_filter, Xmax_filter);
00047 pass.filter (*pc_filter);
00048
00049 pass.setInputCloud (pc_filter);
00050 pass.setFilterFieldName ("y");
00051 pass.setFilterLimits (Ymin_filter, Ymax_filter);
00052 pass.filter (*pc_filter);
00053
00054 pass.setInputCloud (pc_filter);
00055 pass.setFilterFieldName ("z");
00056 pass.setFilterLimits (Zmin_filter, Zmax_filter);
00057 pass.filter (*pc_filter);
00058
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 }
00089
00090 void Navigability_Map::Normal_Estimation(pcl::PointCloud<pcl::PointXYZ>::Ptr &cloud)
00091 {
00092 normals.reset(new pcl::PointCloud<pcl::Normal>);
00093
00094 pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> n;
00095 pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ>);
00096 tree->setInputCloud (cloud);
00097
00098 n.useSensorOriginAsViewPoint();
00099 n.setViewPoint (0.8, 0, 4);
00100 n.setInputCloud (cloud);
00101 n.setSearchMethod (tree);
00102
00103
00104 if (Use_Radius_Search)
00105 n.setRadiusSearch(Radius_neighbors);
00106 else
00107 n.setKSearch (K_neighbors);
00108
00109 n.compute (*normals);
00110
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 }
00127
00128 void Navigability_Map::setGrid_parameter(double max_Xval,double max_Yval)
00129 {
00130
00131
00132
00133
00134 total_row=(int)roundl((max_Xval/Sx)+0.5);
00135
00136
00137
00138
00139 int auxCenterCol=(int)roundl((max_Yval/Sy)+0.5);
00140 int center_col;
00141 if (auxCenterCol % 2)
00142 center_col=auxCenterCol;
00143 else
00144 center_col=auxCenterCol+1;
00145
00146
00147
00148
00149 total_col=center_col*2+1;
00150
00151
00152
00153
00154 CARaxis_col=center_col;
00155 }
00156
00157 void Navigability_Map::inicialize_grid(void)
00158 {
00159
00160 grid.resize(total_row,total_col);
00161 grid_nodePtr node_data;
00162
00163 for(uint row=0;row<grid.rows();row++)
00164 {
00165 for(uint col=0;col<grid.cols();col++)
00166 {
00167 node_data.reset(new grid_node);
00168 grid(row,col)=node_data;
00169 }
00170 }
00171 }
00172
00173
00174 void Navigability_Map::setGrid_data(pcl::PointCloud<pcl::PointXYZ>& cloud)
00175 {
00176 int row_pos;
00177 int col_pos;
00178 for (size_t i = 0; i < cloud.points.size (); ++i)
00179 {
00180
00181 if (cloud.points[i].x<3.8 && (cloud.points[i].y<1.4 && cloud.points[i].y>-1.4))
00182 continue;
00183
00184
00185
00186 row_pos=(int)(cloud.points[i].x/Sx);
00187
00188 if (cloud.points[i].y>0)
00189 col_pos=CARaxis_col+(int)((cloud.points[i].y/Sy)+0.5);
00190 else
00191 col_pos=CARaxis_col+(int)((cloud.points[i].y/Sy)-0.5);
00192
00193
00194 grid_nodePtr node_data= grid(row_pos,col_pos);
00195
00196
00197
00198
00199
00200
00201 node_data->Matrix_Points.conservativeResize(node_data->Matrix_Points.rows()+1,3);
00202
00203
00204
00205
00206 node_data->Matrix_Points(node_data->Matrix_Points.rows()-1,0)=(double)cloud.points[i].x;
00207 node_data->Matrix_Points(node_data->Matrix_Points.rows()-1,1)=(double)cloud.points[i].y;
00208 node_data->Matrix_Points(node_data->Matrix_Points.rows()-1,2)=(double)cloud.points[i].z;
00209
00210
00211 if (!isnan(normals->points[i].normal[0]) && !isnan(normals->points[i].normal[1]) && !isnan(normals->points[i].normal[2]))
00212 {
00213 node_data->Angles.conservativeResize(node_data->Angles.rows()+1,3);
00214
00215 node_data->Angles(node_data->Angles.rows()-1,0)=acos((double)normals->points[i].normal[0]);
00216 node_data->Angles(node_data->Angles.rows()-1,1)=acos((double)normals->points[i].normal[1]);
00217 node_data->Angles(node_data->Angles.rows()-1,2)=acos((double)normals->points[i].normal[2]);
00218
00219 node_data->has_normal=true;
00220 }
00221
00222
00223 node_data->num_points=node_data->Matrix_Points.rows();
00224
00225 }
00226 }
00227
00228 void Navigability_Map::calcGrid_data(void)
00229 {
00230 grid_nodePtr node_data;
00231
00232 for(uint row=0;row<grid.rows();row++)
00233 {
00234 for(uint col=0;col<grid.cols();col++)
00235 {
00236 node_data=grid(row,col);
00237
00238 double med_z=0;
00239 double standard_deviance_z=0;
00240
00241
00242 double standard_deviance_anglex=0;
00243 double standard_deviance_angley=0;
00244 double standard_deviance_anglez=0;
00245 double med_angle_X=0;
00246 double med_angle_Y=0;
00247 double med_angle_Z=0;
00248
00249 if (node_data->num_points>0)
00250 {
00251
00252 for (uint i=0; i<node_data->Matrix_Points.rows(); i++)
00253 med_z+=node_data->Matrix_Points(i,2);
00254
00255
00256 med_z/=node_data->num_points;
00257
00258
00259 node_data->Zmed=med_z;
00260
00261
00262 if (node_data->num_points>1)
00263 {
00264 for (uint i=0; i<node_data->Matrix_Points.rows(); i++)
00265 standard_deviance_z+=pow(node_data->Matrix_Points(i,2)-med_z,2);
00266
00267 standard_deviance_z=sqrt(standard_deviance_z/(node_data->num_points-1));
00268
00269
00270 node_data->Standard_Deviation_Z=standard_deviance_z;
00271
00272 }
00273
00274
00275
00276 if (node_data->num_points>1)
00277 node_data->Z_confidence=1-(node_data->Standard_Deviation_Z/Standard_Deviation_max);
00278 else
00279 node_data->Z_confidence=default_confidence;
00280
00281 if (node_data->Z_confidence<0)
00282 node_data->Z_confidence=0;
00283
00284
00285
00286
00287 if (node_data->has_normal)
00288 {
00289
00290 for (uint i=0; i<node_data->Angles.rows(); i++)
00291 {
00292 med_angle_X+=node_data->Angles(i,0);
00293 med_angle_Y+=node_data->Angles(i,1);
00294 med_angle_Z+=node_data->Angles(i,2);
00295
00296 }
00297
00298 med_angle_X/=node_data->Angles.rows();
00299 med_angle_Y/=node_data->Angles.rows();
00300 med_angle_Z/=node_data->Angles.rows();
00301
00302
00303 node_data->med_angle_X=med_angle_X;
00304 node_data->med_angle_Y=med_angle_Y;
00305 node_data->med_angle_Z=med_angle_Z;
00306
00307
00308 if (node_data->num_points>1)
00309 {
00310 for (uint i=0; i<node_data->Angles.rows(); i++)
00311 {
00312 standard_deviance_anglex+=pow(node_data->Angles(i,0)-med_angle_X,2);
00313 standard_deviance_angley+=pow(node_data->Angles(i,1)-med_angle_Y,2);
00314 standard_deviance_anglez+=pow(node_data->Angles(i,2)-med_angle_Z,2);
00315
00316 }
00317
00318 standard_deviance_anglex=sqrt(standard_deviance_anglex/(node_data->Angles.rows()-1));
00319 standard_deviance_angley=sqrt(standard_deviance_angley/(node_data->Angles.rows()-1));
00320 standard_deviance_anglez=sqrt(standard_deviance_anglez/(node_data->Angles.rows()-1));
00321
00322
00323
00324 double Angle_confidence_x=1-(standard_deviance_anglex/Standard_Deviation_anglex_max_confidence);
00325 double Angle_confidence_y=1-(standard_deviance_angley/Standard_Deviation_angley_max_confidence);
00326 double Angle_confidence_z=1-(standard_deviance_anglez/Standard_Deviation_anglez_max_confidence);
00327
00328 if (Angle_confidence_x<0)
00329 node_data->angle_confidence_x=0;
00330 else
00331 node_data->angle_confidence_x=Angle_confidence_x;
00332 if (Angle_confidence_y<0)
00333 node_data->angle_confidence_y=0;
00334 else
00335 node_data->angle_confidence_y=Angle_confidence_y;
00336 if (Angle_confidence_z<0)
00337 node_data->angle_confidence_z=0;
00338 else
00339 node_data->angle_confidence_z=Angle_confidence_z;
00340
00341 }
00342 else
00343 {
00344 node_data->angle_confidence_x=default_confidence;
00345 node_data->angle_confidence_y=default_confidence;
00346 node_data->angle_confidence_z=default_confidence;
00347
00348 }
00349
00350
00351 }
00352
00353 }
00354
00355 }
00356 }
00357 }
00358
00359
00360 void Navigability_Map::fill_data_cells(void)
00361 {
00362 std::vector<grid_nodePtr> vector_node;
00363 grid_nodePtr node_data;
00364 grid_nodePtr aux_data;
00365 int empty_neighbours=0;
00366 int number_neighbours=0;
00367
00368 std::vector<double> Zval_neighbours;
00369 std::vector<double> angle_x_neighbours;
00370 std::vector<double> angle_y_neighbours;
00371 std::vector<double> angle_z_neighbours;
00372
00373 std::vector<double> Zconfidence_neighbours;
00374 std::vector<double> angle_x_confidence_neighbours;
00375 std::vector<double> angle_y_confidence_neighbours;
00376 std::vector<double> angle_z_confidence_neighbours;
00377
00378 for(uint row=0;row<grid.rows();row++)
00379 {
00380 for(uint col=0;col<grid.cols();col++)
00381 {
00382 Zval_neighbours.erase(Zval_neighbours.begin(), Zval_neighbours.end());
00383 Zconfidence_neighbours.erase(Zconfidence_neighbours.begin(), Zconfidence_neighbours.end());
00384
00385 angle_x_neighbours.erase(angle_x_neighbours.begin(), angle_x_neighbours.end());
00386 angle_y_neighbours.erase(angle_y_neighbours.begin(), angle_y_neighbours.end());
00387 angle_z_neighbours.erase(angle_z_neighbours.begin(), angle_z_neighbours.end());
00388
00389 angle_x_confidence_neighbours.erase(angle_x_confidence_neighbours.begin(), angle_x_confidence_neighbours.end());
00390 angle_y_confidence_neighbours.erase(angle_y_confidence_neighbours.begin(), angle_y_confidence_neighbours.end());
00391 angle_z_confidence_neighbours.erase(angle_z_confidence_neighbours.begin(), angle_z_confidence_neighbours.end());
00392
00393 empty_neighbours=0;
00394 number_neighbours=0;
00395
00396
00397 double med_angle_X=0;
00398 double med_angle_Y=0;
00399 double med_angle_Z=0;
00400 double angle_x_confidence=0;
00401 double angle_y_confidence=0;
00402 double angle_z_confidence=0;
00403 int number_normal_neighbours=0;
00404
00405 bool neighbours_has_normal=false;
00406
00407 node_data=grid(row,col);
00408
00409
00410
00411
00412
00413
00414 if (node_data->num_points==0)
00415 {
00416 vector_node=cell_neighbours(row,col,empty_neighbours,number_neighbours);
00417
00418 if (!empty_neighbours && number_neighbours>3)
00419 {
00420
00421 for (uint i=0; i<8; i++)
00422 {
00423 aux_data=vector_node[i];
00424
00425
00426
00427
00428
00429 if (aux_data->has_normal && !aux_data->interpolate_normal_data)
00430 {
00431 neighbours_has_normal=true;
00432
00433
00434 med_angle_X+=aux_data->med_angle_X;
00435 med_angle_Y+=aux_data->med_angle_Y;
00436 med_angle_Z+=aux_data->med_angle_Z;
00437
00438
00439 angle_x_neighbours.push_back(aux_data->med_angle_X);
00440 angle_y_neighbours.push_back(aux_data->med_angle_Y);
00441 angle_z_neighbours.push_back(aux_data->med_angle_Z);
00442
00443
00444 angle_x_confidence+=aux_data->angle_confidence_x;
00445 angle_y_confidence+=aux_data->angle_confidence_y;
00446 angle_z_confidence+=aux_data->angle_confidence_z;
00447
00448 angle_x_confidence_neighbours.push_back(aux_data->angle_confidence_x);
00449 angle_y_confidence_neighbours.push_back(aux_data->angle_confidence_y);
00450 angle_z_confidence_neighbours.push_back(aux_data->angle_confidence_z);
00451
00452 number_normal_neighbours++;
00453 }
00454
00455
00456
00457
00458
00459
00460 if (aux_data->num_points>0)
00461 {
00462 Zval_neighbours.push_back(aux_data->Zmed);
00463 Zconfidence_neighbours.push_back(aux_data->Z_confidence);
00464 }
00465
00466 }
00467
00468
00469
00470
00471
00472
00473 std::sort (Zval_neighbours.begin(), Zval_neighbours.end());
00474 std::sort (Zconfidence_neighbours.begin(), Zconfidence_neighbours.end());
00475
00476 double Zmediana=0;
00477 double Zmediana_confidence=0;
00478 if (Zval_neighbours.size() % 2)
00479 {
00480 Zmediana=Zval_neighbours.at(((Zval_neighbours.size()+1)/2)-1);
00481 Zmediana_confidence=Zconfidence_neighbours.at(((Zconfidence_neighbours.size()+1)/2)-1);
00482 }
00483 else
00484 {
00485 int pos_vect1=((Zval_neighbours.size()+1)/2)-1;
00486 int pos_vect2=(Zval_neighbours.size()+1)/2;
00487
00488 Zmediana=(Zval_neighbours.at(pos_vect1)+Zval_neighbours.at(pos_vect2))/2;
00489 Zmediana_confidence=(Zconfidence_neighbours.at(pos_vect1)+Zconfidence_neighbours.at(pos_vect2))/2;
00490 }
00491
00492
00493 node_data->Zmed=Zmediana;
00494 node_data->Z_confidence=Zmediana_confidence;
00495 node_data->interpolate_z_data=true;
00496
00497
00498
00499
00500
00501
00502 if (neighbours_has_normal && number_normal_neighbours>1)
00503 {
00504 std::sort (angle_x_neighbours.begin(), angle_x_neighbours.end());
00505 std::sort (angle_y_neighbours.begin(), angle_y_neighbours.end());
00506 std::sort (angle_z_neighbours.begin(), angle_z_neighbours.end());
00507
00508 std::sort (angle_x_confidence_neighbours.begin(), angle_x_confidence_neighbours.end());
00509 std::sort (angle_y_confidence_neighbours.begin(), angle_y_confidence_neighbours.end());
00510 std::sort (angle_z_confidence_neighbours.begin(), angle_z_confidence_neighbours.end());
00511
00512 double xmediana=0;
00513 double ymediana=0;
00514 double zmediana=0;
00515 double x_confidence_mediana=0;
00516 double y_confidence_mediana=0;
00517 double z_confidence_mediana=0;
00518 if (angle_x_neighbours.size() % 2)
00519 {
00520 xmediana=angle_x_neighbours.at(((angle_x_neighbours.size()+1)/2)-1);
00521 ymediana=angle_y_neighbours.at(((angle_y_neighbours.size()+1)/2)-1);
00522 zmediana=angle_z_neighbours.at(((angle_z_neighbours.size()+1)/2)-1);
00523
00524 x_confidence_mediana=angle_x_confidence_neighbours.at(((angle_x_confidence_neighbours.size()+1)/2)-1);
00525 y_confidence_mediana=angle_y_confidence_neighbours.at(((angle_y_confidence_neighbours.size()+1)/2)-1);
00526 z_confidence_mediana=angle_z_confidence_neighbours.at(((angle_z_confidence_neighbours.size()+1)/2)-1);
00527
00528 }
00529 else
00530 {
00531 int pos_vect1=((angle_x_neighbours.size()+1)/2)-1;
00532 int pos_vect2=(angle_x_neighbours.size()+1)/2;
00533
00534 xmediana=(angle_x_neighbours.at(pos_vect1)+angle_x_neighbours.at(pos_vect2))/2;
00535 ymediana=(angle_y_neighbours.at(pos_vect1)+angle_y_neighbours.at(pos_vect2))/2;
00536 zmediana=(angle_z_neighbours.at(pos_vect1)+angle_z_neighbours.at(pos_vect2))/2;
00537
00538 x_confidence_mediana=(angle_x_confidence_neighbours.at(pos_vect1)+angle_x_confidence_neighbours.at(pos_vect2))/2;
00539 y_confidence_mediana=(angle_y_confidence_neighbours.at(pos_vect1)+angle_y_confidence_neighbours.at(pos_vect2))/2;
00540 z_confidence_mediana=(angle_z_confidence_neighbours.at(pos_vect1)+angle_z_confidence_neighbours.at(pos_vect2))/2;
00541
00542 }
00543
00544 node_data->med_angle_X=xmediana;
00545 node_data->med_angle_Y=ymediana;
00546 node_data->med_angle_Z=zmediana;
00547
00548 node_data->angle_confidence_x=x_confidence_mediana;
00549 node_data->angle_confidence_y=y_confidence_mediana;
00550 node_data->angle_confidence_z=z_confidence_mediana;
00551
00552 node_data->has_normal=true;
00553 node_data->interpolate_normal_data=true;
00554
00555
00556 }
00557 else
00558 {
00559 node_data->has_normal=true;
00560 node_data->interpolate_normal_data=true;
00561
00562 node_data->med_angle_X=med_angle_X/number_normal_neighbours;
00563 node_data->med_angle_Y=med_angle_Y/number_normal_neighbours;
00564 node_data->med_angle_Z=med_angle_Z/number_normal_neighbours;
00565
00566 node_data->angle_confidence_x=angle_x_confidence/number_normal_neighbours;
00567 node_data->angle_confidence_y=angle_y_confidence/number_normal_neighbours;
00568 node_data->angle_confidence_z=angle_z_confidence/number_normal_neighbours;
00569 }
00570
00571 }
00572
00573 }
00574
00575
00576
00577
00578
00579
00580 if (!node_data->has_normal && node_data->num_points>0)
00581 {
00582 vector_node=cell_neighbours(row,col,empty_neighbours,number_neighbours);
00583
00584 if (!empty_neighbours && number_neighbours>2)
00585 {
00586
00587 for (uint i=0; i<8; i++)
00588 {
00589 aux_data=vector_node[i];
00590
00591
00592
00593
00594
00595 if (aux_data->has_normal && !aux_data->interpolate_normal_data)
00596 {
00597
00598 med_angle_X+=aux_data->med_angle_X;
00599 med_angle_Y+=aux_data->med_angle_Y;
00600 med_angle_Z+=aux_data->med_angle_Z;
00601
00602
00603 angle_x_neighbours.push_back(aux_data->med_angle_X);
00604 angle_y_neighbours.push_back(aux_data->med_angle_Y);
00605 angle_z_neighbours.push_back(aux_data->med_angle_Z);
00606
00607
00608 angle_x_confidence+=aux_data->angle_confidence_x;
00609 angle_y_confidence+=aux_data->angle_confidence_y;
00610 angle_z_confidence+=aux_data->angle_confidence_z;
00611
00612 angle_x_confidence_neighbours.push_back(aux_data->angle_confidence_x);
00613 angle_y_confidence_neighbours.push_back(aux_data->angle_confidence_y);
00614 angle_z_confidence_neighbours.push_back(aux_data->angle_confidence_z);
00615
00616 number_normal_neighbours++;
00617 }
00618 }
00619
00620
00621
00622
00623
00624 if (neighbours_has_normal && number_normal_neighbours>1)
00625 {
00626 node_data->interpolate_normal_data=true;
00627 node_data->has_normal=true;
00628
00629
00630 std::sort (angle_x_neighbours.begin(), angle_x_neighbours.end());
00631 std::sort (angle_y_neighbours.begin(), angle_y_neighbours.end());
00632 std::sort (angle_z_neighbours.begin(), angle_z_neighbours.end());
00633
00634 std::sort (angle_x_confidence_neighbours.begin(), angle_x_confidence_neighbours.end());
00635 std::sort (angle_y_confidence_neighbours.begin(), angle_y_confidence_neighbours.end());
00636 std::sort (angle_z_confidence_neighbours.begin(), angle_z_confidence_neighbours.end());
00637
00638 double xmediana=0;
00639 double ymediana=0;
00640 double zmediana=0;
00641 double x_confidence_mediana=0;
00642 double y_confidence_mediana=0;
00643 double z_confidence_mediana=0;
00644 if (angle_x_neighbours.size() % 2)
00645 {
00646 xmediana=angle_x_neighbours.at(((angle_x_neighbours.size()+1)/2)-1);
00647 ymediana=angle_y_neighbours.at(((angle_y_neighbours.size()+1)/2)-1);
00648 zmediana=angle_z_neighbours.at(((angle_z_neighbours.size()+1)/2)-1);
00649
00650
00651 x_confidence_mediana=angle_x_confidence_neighbours.at(((angle_x_confidence_neighbours.size()+1)/2)-1);
00652 y_confidence_mediana=angle_y_confidence_neighbours.at(((angle_y_confidence_neighbours.size()+1)/2)-1);
00653 z_confidence_mediana=angle_z_confidence_neighbours.at(((angle_z_confidence_neighbours.size()+1)/2)-1);
00654 }
00655 else
00656 {
00657 int pos_vect1=((angle_x_neighbours.size()+1)/2)-1;
00658 int pos_vect2=(angle_x_neighbours.size()+1)/2;
00659
00660 xmediana=(angle_x_neighbours.at(pos_vect1)+angle_x_neighbours.at(pos_vect2))/2;
00661 ymediana=(angle_y_neighbours.at(pos_vect1)+angle_y_neighbours.at(pos_vect2))/2;
00662 zmediana=(angle_z_neighbours.at(pos_vect1)+angle_z_neighbours.at(pos_vect2))/2;
00663
00664
00665 x_confidence_mediana=(angle_x_confidence_neighbours.at(pos_vect1)+angle_x_confidence_neighbours.at(pos_vect2))/2;
00666 y_confidence_mediana=(angle_y_confidence_neighbours.at(pos_vect1)+angle_y_confidence_neighbours.at(pos_vect2))/2;
00667 z_confidence_mediana=(angle_z_confidence_neighbours.at(pos_vect1)+angle_z_confidence_neighbours.at(pos_vect2))/2;
00668
00669
00670 }
00671
00672
00673 node_data->med_angle_X=xmediana;
00674 node_data->med_angle_Y=ymediana;
00675 node_data->med_angle_Z=zmediana;
00676
00677
00678 node_data->angle_confidence_x=x_confidence_mediana;
00679 node_data->angle_confidence_y=y_confidence_mediana;
00680 node_data->angle_confidence_z=z_confidence_mediana;
00681
00682
00683 }
00684 else
00685 {
00686 node_data->has_normal=true;
00687 node_data->interpolate_normal_data=true;
00688
00689 node_data->med_angle_X=med_angle_X/number_normal_neighbours;
00690 node_data->med_angle_Y=med_angle_Y/number_normal_neighbours;
00691 node_data->med_angle_Z=med_angle_Z/number_normal_neighbours;
00692
00693 node_data->angle_confidence_x=angle_x_confidence/number_normal_neighbours;
00694 node_data->angle_confidence_y=angle_y_confidence/number_normal_neighbours;
00695 node_data->angle_confidence_z=angle_z_confidence/number_normal_neighbours;
00696 }
00697
00698 }
00699
00700 }
00701
00702 }
00703 }
00704 }
00705
00706
00707 void Navigability_Map::set_Cells_accessibility(void)
00708 {
00709 std::vector<grid_nodePtr> vector_node;
00710 grid_nodePtr node_data;
00711 grid_nodePtr aux_data;
00712 int empty_neighbours=0;
00713 int number_neighbours=0;
00714
00715 double z_accessibility=0;
00716
00717 double angleX_accessibility=0;
00718 double angleY_accessibility=0;
00719 double angleZ_accessibility=0;
00720
00721
00722 for(uint row=0;row<grid.rows();row++)
00723 {
00724 for(uint col=0;col<grid.cols();col++)
00725 {
00726 node_data=grid(row,col);
00727
00728 double neighbours_full_data=0;
00729 double z_difference_med_confidence=0;
00730 double angleX_difference_med_confidence=0;
00731 double angleY_difference_med_confidence=0;
00732 double angleZ_difference_med_confidence=0;
00733
00734
00735
00736
00737
00738
00739 if ((node_data->num_points>0 && node_data->has_normal) || (node_data->interpolate_z_data && node_data->interpolate_normal_data) || (node_data->num_points>0 && node_data->interpolate_normal_data))
00740 {
00741 vector_node=cell_neighbours(row,col,empty_neighbours,number_neighbours);
00742
00743 for (uint i=0; i<8; i++)
00744 {
00745 aux_data=vector_node[i];
00746
00747
00748 node_data->z_difference_neighbours.push_back(abs(aux_data->Zmed-node_data->Zmed));
00749
00750 node_data->z_confidence_neighbours.push_back(sqrt(aux_data->Z_confidence*node_data->Z_confidence));
00751
00752
00753 node_data->angleX_difference_neighbours.push_back(abs(aux_data->med_angle_X-node_data->med_angle_X));
00754 node_data->angleY_difference_neighbours.push_back(abs(aux_data->med_angle_Y-node_data->med_angle_Y));
00755 node_data->angleZ_difference_neighbours.push_back(abs(aux_data->med_angle_Z-node_data->med_angle_Z));
00756
00757 node_data->angleX_confidence_neighbours.push_back(sqrt(aux_data->angle_confidence_x*node_data->angle_confidence_x));
00758 node_data->angleY_confidence_neighbours.push_back(sqrt(aux_data->angle_confidence_y*node_data->angle_confidence_y));
00759 node_data->angleZ_confidence_neighbours.push_back(sqrt(aux_data->angle_confidence_z*node_data->angle_confidence_z));
00760
00761
00762 if ((aux_data->num_points>0 && aux_data->has_normal) || (aux_data->interpolate_z_data && aux_data->interpolate_normal_data) || (aux_data->num_points>0 && aux_data->interpolate_normal_data))
00763 node_data->has_fulldata_direction.push_back(true);
00764 else
00765 node_data->has_fulldata_direction.push_back(false);
00766 }
00767
00768 double z_difference_med_confidence_aux=0;
00769 double angleX_difference_med_confidence_aux=0;
00770 double angleY_difference_med_confidence_aux=0;
00771 double angleZ_difference_med_confidence_aux=0;
00772
00773 for (uint i=0; i<8; i++)
00774 {
00775 if (node_data->has_fulldata_direction[i])
00776 {
00777
00778
00779 z_difference_med_confidence_aux=node_data->z_difference_neighbours[i]/node_data->z_confidence_neighbours[i];
00780 if (z_difference_med_confidence_aux>fator_confidence_neighbour_limit*Zmax_heigh_difference)
00781 z_difference_med_confidence+=fator_confidence_neighbour_limit*Zmax_heigh_difference;
00782 else
00783 z_difference_med_confidence+=z_difference_med_confidence_aux;
00784
00785
00786 angleX_difference_med_confidence_aux=node_data->angleX_difference_neighbours[i]/node_data->angleX_confidence_neighbours[i];
00787 if (angleX_difference_med_confidence_aux>fator_confidence_neighbour_limit*angleX_max_difference)
00788 angleX_difference_med_confidence+=fator_confidence_neighbour_limit*angleX_max_difference;
00789 else
00790 angleX_difference_med_confidence+=angleX_difference_med_confidence_aux;
00791
00792 angleY_difference_med_confidence_aux=node_data->angleY_difference_neighbours[i]/node_data->angleY_confidence_neighbours[i];
00793 if (angleY_difference_med_confidence_aux>fator_confidence_neighbour_limit*angleY_max_difference)
00794 angleY_difference_med_confidence+=fator_confidence_neighbour_limit*angleY_max_difference;
00795 else
00796 angleY_difference_med_confidence+=angleY_difference_med_confidence_aux;
00797
00798 angleZ_difference_med_confidence_aux=node_data->angleZ_difference_neighbours[i]/node_data->angleZ_confidence_neighbours[i];
00799 if (angleZ_difference_med_confidence_aux>fator_confidence_neighbour_limit*angleZ_max_difference)
00800 angleZ_difference_med_confidence+=fator_confidence_neighbour_limit*angleZ_max_difference;
00801 else
00802 angleZ_difference_med_confidence+=angleZ_difference_med_confidence_aux;
00803
00804
00805 neighbours_full_data++;
00806 }
00807
00808 }
00809
00810
00811
00812
00813
00814
00815
00816
00817 if (neighbours_full_data>0)
00818 {
00819 z_difference_med_confidence/=neighbours_full_data;
00820 z_accessibility=1-(abs(z_difference_med_confidence)/Zmax_heigh_difference);
00821 if (z_accessibility>=0)
00822 node_data->z_accessibility=z_accessibility;
00823 else
00824 node_data->z_accessibility=0;
00825
00826
00827
00828
00829
00830
00831 angleX_difference_med_confidence/=neighbours_full_data;
00832 angleX_accessibility=1-(abs(angleX_difference_med_confidence)/angleX_max_difference);
00833
00834 if (angleX_accessibility>=0)
00835 node_data->angleX_accessibility=angleX_accessibility;
00836 else
00837 node_data->angleX_accessibility=0;
00838
00839 angleY_difference_med_confidence/=neighbours_full_data;
00840 angleY_accessibility=1-(abs(angleY_difference_med_confidence)/angleY_max_difference);
00841
00842 if (angleY_accessibility>=0)
00843 node_data->angleY_accessibility=angleY_accessibility;
00844 else
00845 node_data->angleY_accessibility=0;
00846
00847 angleZ_difference_med_confidence/=neighbours_full_data;
00848 angleZ_accessibility=1-(abs(angleZ_difference_med_confidence)/angleZ_max_difference);
00849
00850 if (angleZ_accessibility>=0)
00851 node_data->angleZ_accessibility=angleZ_accessibility;
00852 else
00853 node_data->angleZ_accessibility=0;
00854 }
00855
00856
00857
00858
00859
00860
00861 node_data->total_accessibility=node_data->z_accessibility*node_data->angleX_accessibility*node_data->angleY_accessibility*node_data->angleZ_accessibility;
00862
00863 }
00864
00865
00866 }
00867
00868 }
00869
00870 }
00871
00872
00873 std::vector<grid_nodePtr> Navigability_Map::cell_neighbours(int row_pos, int col_pos, int &empty_neighbours, int &number_neighbours)
00874 {
00875 std::vector<grid_nodePtr> vector_node;
00876 grid_nodePtr node_data;
00877
00878 bool empty_cell=true;
00879 int counter=0;
00880
00881
00882 int N_pos=row_pos+1;
00883 int S_pos=row_pos-1;
00884 int E_pos=col_pos+1;
00885 int W_pos=col_pos-1;
00886
00887 int max_row_pos=grid.rows()-1;
00888 int max_col_pos=grid.cols()-1;
00889
00890
00891
00892 if (N_pos>max_row_pos)
00893 node_data.reset(new grid_node);
00894 else
00895 node_data=grid(N_pos,col_pos);
00896
00897 if (node_data->num_points>0 && node_data->has_normal && !node_data->interpolate_z_data && !node_data->interpolate_normal_data)
00898 {
00899 empty_cell=false;
00900 counter++;
00901 }
00902
00903 vector_node.push_back(node_data);
00904
00905
00906
00907 if (N_pos>max_row_pos || E_pos>max_col_pos)
00908 node_data.reset(new grid_node);
00909 else
00910 node_data=grid(N_pos,E_pos);
00911
00912 if (node_data->num_points>0 && node_data->has_normal && !node_data->interpolate_z_data && !node_data->interpolate_normal_data)
00913 {
00914 empty_cell=false;
00915 counter++;
00916 }
00917
00918 vector_node.push_back(node_data);
00919
00920
00921
00922 if (E_pos>max_col_pos)
00923 node_data.reset(new grid_node);
00924 else
00925 node_data=grid(row_pos,E_pos);
00926
00927 if (node_data->num_points>0 && node_data->has_normal && !node_data->interpolate_z_data && !node_data->interpolate_normal_data)
00928 {
00929 empty_cell=false;
00930 counter++;
00931 }
00932
00933 vector_node.push_back(node_data);
00934
00935
00936
00937 if (S_pos<0 || E_pos>max_col_pos)
00938 node_data.reset(new grid_node);
00939 else
00940 node_data=grid(S_pos,E_pos);
00941
00942 if (node_data->num_points>0 && node_data->has_normal && !node_data->interpolate_z_data && !node_data->interpolate_normal_data)
00943 {
00944 empty_cell=false;
00945 counter++;
00946 }
00947
00948 vector_node.push_back(node_data);
00949
00950
00951
00952 if (S_pos<0)
00953 node_data.reset(new grid_node);
00954 else
00955 node_data=grid(S_pos,col_pos);
00956
00957 if (node_data->num_points>0 && node_data->has_normal && !node_data->interpolate_z_data && !node_data->interpolate_normal_data)
00958 {
00959 empty_cell=false;
00960 counter++;
00961 }
00962
00963 vector_node.push_back(node_data);
00964
00965
00966
00967 if (S_pos<0 || W_pos<0)
00968 node_data.reset(new grid_node);
00969 else
00970 node_data=grid(S_pos,W_pos);
00971
00972 if (node_data->num_points>0 && node_data->has_normal && !node_data->interpolate_z_data && !node_data->interpolate_normal_data)
00973 {
00974 empty_cell=false;
00975 counter++;
00976 }
00977
00978 vector_node.push_back(node_data);
00979
00980
00981
00982 if (W_pos<0)
00983 node_data.reset(new grid_node);
00984 else
00985 node_data=grid(row_pos,W_pos);
00986
00987 if (node_data->num_points>0 && node_data->has_normal && !node_data->interpolate_z_data && !node_data->interpolate_normal_data)
00988 {
00989 empty_cell=false;
00990 counter++;
00991 }
00992
00993 vector_node.push_back(node_data);
00994
00995
00996
00997 if (N_pos>max_row_pos || W_pos<0)
00998 node_data.reset(new grid_node);
00999 else
01000 node_data=grid(N_pos,W_pos);
01001
01002 if (node_data->num_points>0 && node_data->has_normal && !node_data->interpolate_z_data && !node_data->interpolate_normal_data)
01003 {
01004 empty_cell=false;
01005 counter++;
01006 }
01007
01008 vector_node.push_back(node_data);
01009
01010
01011
01012 if (empty_cell)
01013 empty_neighbours=1;
01014
01015 number_neighbours=counter;
01016
01017 return vector_node;
01018
01019 }
01020
01021
01022 void Navigability_Map::polygon_groundtruth(void)
01023 {
01024 geometry_msgs::Point p;
01025
01026
01027
01028
01029
01030
01031
01032 p.x=4.4;
01033 p.y=-2.3;
01034 p.z=1.2;
01035 polygon_points.push_back(p);
01036 xy_polygon.push_back(Point2f(p.x,p.y));
01037
01038 p.x=4.4;
01039 p.y=3.5;
01040 p.z=1.2;
01041 polygon_points.push_back(p);
01042 xy_polygon.push_back(Point2f(p.x,p.y));
01043
01044
01045 p.x=7;
01046 p.y=7.6;
01047 p.z=1.2;
01048 polygon_points.push_back(p);
01049 xy_polygon.push_back(Point2f(p.x,p.y));
01050
01051 p.x=19;
01052 p.y=7.8;
01053 p.z=1.2;
01054 polygon_points.push_back(p);
01055 xy_polygon.push_back(Point2f(p.x,p.y));
01056
01057 p.x=19;
01058 p.y=-1.5;
01059 p.z=1.2;
01060 polygon_points.push_back(p);
01061 xy_polygon.push_back(Point2f(p.x,p.y));
01062
01063
01064 p.x=13.5;
01065 p.y=-1.5;
01066 p.z=1.2;
01067 polygon_points.push_back(p);
01068 xy_polygon.push_back(Point2f(p.x,p.y));
01069
01070
01071 p.x=13.5;
01072 p.y=-5.3;
01073 p.z=1.2;
01074 polygon_points.push_back(p);
01075 xy_polygon.push_back(Point2f(p.x,p.y));
01076
01077
01078 p.x=8;
01079 p.y=-3;
01080 p.z=1.2;
01081 polygon_points.push_back(p);
01082 xy_polygon.push_back(Point2f(p.x,p.y));
01083
01084
01085 p.x=8.55;
01086 p.y=-1.4;
01087 p.z=1.2;
01088 polygon_points.push_back(p);
01089 xy_polygon.push_back(Point2f(p.x,p.y));
01090
01091 p.x=8.55;
01092 p.y=-0.25;
01093 p.z=1.2;
01094 polygon_points.push_back(p);
01095 xy_polygon.push_back(Point2f(p.x,p.y));
01096
01097 p.x=7.4;
01098 p.y=-0.25;
01099 p.z=1.2;
01100 polygon_points.push_back(p);
01101 xy_polygon.push_back(Point2f(p.x,p.y));
01102
01103 p.x=7.4;
01104 p.y=-1.4;
01105 p.z=1.2;
01106 polygon_points.push_back(p);
01107 xy_polygon.push_back(Point2f(p.x,p.y));
01108
01109 p.x=8.5;
01110 p.y=-1.4;
01111 p.z=1.2;
01112 polygon_points.push_back(p);
01113 xy_polygon.push_back(Point2f(p.x,p.y));
01114
01115 p.x=8.05;
01116 p.y=-2.7;
01117 p.z=1.2;
01118 polygon_points.push_back(p);
01119 xy_polygon.push_back(Point2f(p.x,p.y));
01120
01121 p.x=4.4;
01122 p.y=-2.3;
01123 p.z=1.2;
01124 polygon_points.push_back(p);
01125 xy_polygon.push_back(Point2f(p.x,p.y));
01126
01127
01128
01129 p.x=7.8;
01130 p.y=-1.35;
01131 p.z=1.2;
01132 obstacle_points.push_back(p);
01133 obstacle_polygon.push_back(Point2f(p.x,p.y));
01134
01135 p.x=8.5;
01136 p.y=-1.35;
01137 p.z=1.2;
01138 obstacle_points.push_back(p);
01139 obstacle_polygon.push_back(Point2f(p.x,p.y));
01140
01141 p.x=8.5;
01142 p.y=-0.35;
01143 p.z=1.2;
01144 obstacle_points.push_back(p);
01145 obstacle_polygon.push_back(Point2f(p.x,p.y));
01146
01147 p.x=7.5;
01148 p.y=-0.35;
01149 p.z=1.2;
01150 obstacle_points.push_back(p);
01151 obstacle_polygon.push_back(Point2f(p.x,p.y));
01152
01153 p.x=7.5;
01154 p.y=-1.35;
01155 p.z=1.2;
01156 obstacle_points.push_back(p);
01157 obstacle_polygon.push_back(Point2f(p.x,p.y));
01158
01159 p.x=7.8;
01160 p.y=-1.35;
01161 p.z=1.2;
01162 obstacle_points.push_back(p);
01163 obstacle_polygon.push_back(Point2f(p.x,p.y));
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298
01299
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462
01463
01464
01465
01466
01467
01468
01469
01470
01471
01472
01473
01474
01475
01476
01477
01478
01479
01480
01481
01482
01483
01484
01485
01486
01487
01488
01489
01490
01491
01492
01493
01494
01495
01496
01497
01498
01499
01500
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511
01512
01513
01514
01515
01516
01517
01518
01519
01520
01521
01522
01523
01524
01525
01526
01527
01528
01529
01530
01531
01532
01533
01534
01535
01536
01537 }
01538
01539 void Navigability_Map::getCell_inpolygon(void)
01540 {
01541 grid_nodePtr node_data;
01542 double x_cell=0;
01543 double y_cell=0;
01544
01545 for(uint row=0;row<grid.rows();row++)
01546 {
01547 for(uint col=0;col<grid.cols();col++)
01548 {
01549 node_data=grid(row,col);
01550
01551
01552
01553
01554
01555
01556 if ((node_data->num_points>0 && node_data->has_normal) || (node_data->interpolate_z_data && node_data->interpolate_normal_data) || (node_data->num_points>0 && node_data->interpolate_normal_data))
01557 {
01558
01559 x_cell = row*Sx+Sx/2;
01560
01561 y_cell = col*Sy-CARaxis_col*Sy;
01562
01563
01564
01565
01566
01567
01568
01569
01570
01571 Point2d test_pt;
01572 test_pt.x = x_cell;
01573 test_pt.y = y_cell;
01574
01575 if (pointPolygonTest(Mat(xy_polygon), test_pt, false) > 0)
01576 {
01577
01578 Matrix_Cell_inpolygon_rowcol.conservativeResize(Matrix_Cell_inpolygon_rowcol.rows()+1,2);
01579
01580 Matrix_Cell_inpolygon_rowcol(Matrix_Cell_inpolygon_rowcol.rows()-1,0)=row;
01581 Matrix_Cell_inpolygon_rowcol(Matrix_Cell_inpolygon_rowcol.rows()-1,1)=col;
01582 }
01583
01584 if (pointPolygonTest(Mat(obstacle_polygon), test_pt, false) > 0)
01585 {
01586
01587 Matrix_obstacle_inpolygon_rowcol.conservativeResize(Matrix_obstacle_inpolygon_rowcol.rows()+1,2);
01588
01589 Matrix_obstacle_inpolygon_rowcol(Matrix_obstacle_inpolygon_rowcol.rows()-1,0)=row;
01590 Matrix_obstacle_inpolygon_rowcol(Matrix_obstacle_inpolygon_rowcol.rows()-1,1)=col;
01591 }
01592
01593 }
01594
01595 }
01596
01597 }
01598
01599
01600 }
01601
01602 void Navigability_Map::dataCell_inpolygon(void)
01603 {
01604
01605 grid_nodePtr node_data;
01606 int row_poly=0;
01607 int col_poly=0;
01608 int row_obs=0;
01609 int col_obs=0;
01610
01611 int total_cells_poly=Matrix_Cell_inpolygon_rowcol.rows();
01612 int cell_goodacc_poly=0;
01613
01614 int total_cells_obs=Matrix_obstacle_inpolygon_rowcol.rows();
01615 int cell_badacc_obs=0;
01616
01617
01618 for (int i=0; i<total_cells_poly; i++)
01619 {
01620 row_poly=Matrix_Cell_inpolygon_rowcol(i,0);
01621 col_poly=Matrix_Cell_inpolygon_rowcol(i,1);
01622
01623 node_data=grid(row_poly,col_poly);
01624
01625 if (node_data->total_accessibility>0.25)
01626 cell_goodacc_poly++;
01627 }
01628
01629
01630 for (int i=0; i<total_cells_obs; i++)
01631 {
01632 row_obs=Matrix_obstacle_inpolygon_rowcol(i,0);
01633 col_obs=Matrix_obstacle_inpolygon_rowcol(i,1);
01634
01635 node_data=grid(row_obs,col_obs);
01636
01637 if (node_data->total_accessibility<=0.25)
01638 cell_badacc_obs++;
01639 }
01640
01641 double algorithm_efficiency=0;
01642 algorithm_efficiency=((double)cell_goodacc_poly/(double)total_cells_poly)*100;
01643
01644 std::cout<<"total cells in polygon: "<<total_cells_poly<<" good cells acc>0.25: "<<cell_goodacc_poly<<std::endl;
01645 std::cout<<" algorithm_efficiency_polygon: "<<algorithm_efficiency<<"%"<<std::endl;
01646 std::cout<<std::endl;
01647
01648
01649 double algorithm_efficiency_obstacle=0;
01650 algorithm_efficiency_obstacle=((double)cell_badacc_obs/(double)total_cells_obs)*100;
01651
01652 std::cout<<"total cells in obstalce: "<<total_cells_obs<<" bad cells acc<=0.25: "<<cell_badacc_obs<<std::endl;
01653 std::cout<<" algorithm_efficiency_obstalce: "<<algorithm_efficiency_obstacle<<"%"<<std::endl;
01654 std::cout<<std::endl;
01655 }