6 typedef unsigned char uchar;
    14     sockClient = socket(AF_INET, SOCK_STREAM, 0);
    15     struct sockaddr_in serveraddr;
    16     bzero(&serveraddr, 
sizeof(serveraddr));
    17     serveraddr.sin_family = AF_INET;
    18     serveraddr.sin_port = htons(
PORT);
    19     inet_pton(AF_INET, server_ip, &serveraddr.sin_addr);
    21     printf(
"connecting server...");
    22     if(connect(sockClient, (
struct sockaddr*)&serveraddr, 
sizeof(serveraddr)) == -1)
    27     printf(
"connected.\n");
    36     cerr<<
"command message "<<data<<endl;
    37     int rtn_num = send(sockClient, data, data_lengh, 0);
    38     cerr << 
"socket_send_thread: send command to server ... ";
    43         cerr<<
"command message "<<data<<endl;
    44         int rtn_num = send(sockClient, data, data_lengh, 0);
    45         cerr << 
"socket_send_thread: send command to server ... ";
    71 getRGBDFromGazebo_begin:
    72     cerr << 
"getting rgbd data..." << endl;
    86         int data_len = (480 * 640 * 3 * (
sizeof(
uchar)) * 
rbt_num);
    87         char* rcvData = 
new char[data_len];
    90         char pkgData[MAXRECV];
    96             if (count == data_len) 
   100             if (count + MAXRECV >= data_len) 
   102                 n = recv(sockClient, pkgData, data_len - count, 0); 
   105                 while (rst < data_len - count){
   106                     memcpy(&rcvData[count], &pkgData, rst);
   110                     rst = recv(sockClient, pkgData, data_len - count, 0); 
   113                 if (rst > data_len - count)
   115                     cout << 
"error: recieve more than data_len." << endl;
   117                     memcpy(&rcvData[count], &pkgData, data_len - count);
   121                 memcpy(&rcvData[count], &pkgData, rst);
   127             n = recv(sockClient, pkgData, MAXRECV, 0);
   134                 cout << 
"n = " << n << 
", data_len = " << data_len << 
", count = " << count << endl;
   143                     goto getRGBDFromGazebo_begin;
   151                     cout << 
"before memcpy..." << endl;
   154                 memcpy(&rcvData[count], &pkgData, n); 
   158                     cout << 
"after memcpy, count = " << count << 
", n = " << n << endl;
   167         for (
int id = 0; 
id < 
rbt_num; 
id++)
   169             for (
int i = 0; i < 480; i++)
   171                 for (
int j = 0; j < 640; j++)
   173                     memcpy(&m_rgb[
id].ptr<cv::Vec3b>(i)[j][2], &rcvData[ind], 
sizeof(
uchar));
   174                     ind += 
sizeof(
uchar);
   175                     memcpy(&m_rgb[
id].ptr<cv::Vec3b>(i)[j][1], &rcvData[ind], 
sizeof(
uchar));
   176                     ind += 
sizeof(
uchar);
   177                     memcpy(&m_rgb[
id].ptr<cv::Vec3b>(i)[j][0], &rcvData[ind], 
sizeof(
uchar));
   178                     ind += 
sizeof(
uchar);
   188         int data_len = (480 * 640 * (
sizeof(short)) * 
rbt_num);
   189         char* rcvData = 
new char[data_len];
   192         char pkgData[MAXRECV];
   196             if (count + MAXRECV >= data_len){
   197                 n = recv(sockClient, pkgData, data_len - count, 0);
   199                 while (rst < data_len - count){
   200                     memcpy(&rcvData[count], &pkgData, rst);
   202                     rst = data_len - count;
   203                     rst = recv(sockClient, pkgData, rst, 0);
   205                 memcpy(&rcvData[count], &pkgData, rst);
   209             n = recv(sockClient, pkgData, MAXRECV, 0);
   210             memcpy(&rcvData[count], &pkgData, n);
   215         for (
int id = 0; 
id < 
rbt_num; 
id++)
   217             for (
int i = 0; i < 480; i++)
   219                 for (
int j = 0; j < 640; j++)
   221                     memcpy(&m_depth[
id].ptr<ushort>(i)[j], &rcvData[ind], 
sizeof(
short));
   222                     ind += 
sizeof(short);
   239     cerr << 
"done." << endl;
   247     int data_len = (7 * 
sizeof(float) * 
rbt_num);
   248     char* rcvData = 
new char[data_len];
   249     char pkgData[MAXRECV];
   256 getPoseFromLinux_begin:
   258     cerr << 
"getting pose data ... " << endl;
   275         if (count + MAXRECV >= data_len)
   277             n = recv(sockClient, pkgData, data_len - count, 0);
   282                 if (count == data_len) 
   284                 cout << 
"count = " << count << endl;
   285                 cerr << 
"recv return < 0, input to retry..." << endl;
   291                 goto getPoseFromLinux_begin;
   294             while (rst < data_len - count){
   295                 memcpy(&rcvData[count], &pkgData, rst);
   297                 rst = data_len - count;
   298                 rst = recv(sockClient, pkgData, rst, 0);
   300             memcpy(&rcvData[count], &pkgData, rst);
   305         n = recv(sockClient, pkgData, MAXRECV, 0);
   306         memcpy(&rcvData[count], &pkgData, n);
   311     for (
int id = 0; 
id < 
rbt_num; 
id++)
   313         for (
int i = 0; i < 7; i++)
   315             memcpy(&m_pose[
id][i], &rcvData[ind], 
sizeof(
float));
   316             ind += 
sizeof(float);
   320     for (
int rid = 0; rid < 
rbt_num; rid++)
   322         cerr<<
"pose "<<rid<<
":"<<endl;
   323         for (
int vid = 0; vid < 7; ++vid)
   325             cerr<<m_pose[rid][vid]<<
" ";
   328         if (m_pose[rid][3]==m_pose[rid][4]&&m_pose[rid][4]==m_pose[rid][5]&&m_pose[rid][5]==m_pose[rid][6])
   330             cerr<<m_pose[rid][0]<<
" "<<m_pose[rid][1]<<
" "<<m_pose[rid][2]<<
" "<<m_pose[rid][3]<<
" "<<m_pose[rid][4]<<
" "<<m_pose[rid][5]<<
" "<<m_pose[rid][6]<<
" "<<endl;
   334             goto getPoseFromLinux_begin;
   336         if (__isnan(m_pose[rid][0]))
   338             cerr<<m_pose[rid][0]<<
" "<<m_pose[rid][1]<<
" "<<m_pose[rid][2]<<
" "<<m_pose[rid][3]<<
" "<<m_pose[rid][4]<<
" "<<m_pose[rid][5]<<
" "<<m_pose[rid][6]<<
" "<<endl;
   342             goto getPoseFromLinux_begin;
   346     cerr << 
"done." << endl;
   352     cerr << 
"waitting for rgbd data ... ";
   357         int data_len = (480 * 640 * 3 * (
sizeof(
uchar)) * 
rbt_num);
   358         char* rcvData = 
new char[data_len];
   361         char pkgData[MAXRECV];
   368             if (count + MAXRECV >= data_len){
   369                 n = recv(sockClient, pkgData, data_len - count, 0);
   372                 while (rst < data_len - count){
   373                     memcpy(&rcvData[count], &pkgData, rst);
   375                     rst = data_len - count;
   376                     rst = recv(sockClient, pkgData, rst, 0);
   378                 memcpy(&rcvData[count], &pkgData, rst);
   382             n = recv(sockClient, pkgData, MAXRECV, 0);
   384             memcpy(&rcvData[count], &pkgData, n);
   391         for (
int id = 0; 
id < 
rbt_num; 
id++)
   393             for (
int i = 0; i < 480; i++)
   395                 for (
int j = 0; j < 640; j++)
   397                     memcpy(&m_rgb[
id].ptr<cv::Vec3b>(i)[j][2], &rcvData[ind], 
sizeof(
uchar));
   398                     ind += 
sizeof(
uchar);
   399                     memcpy(&m_rgb[
id].ptr<cv::Vec3b>(i)[j][1], &rcvData[ind], 
sizeof(
uchar));
   400                     ind += 
sizeof(
uchar);
   401                     memcpy(&m_rgb[
id].ptr<cv::Vec3b>(i)[j][0], &rcvData[ind], 
sizeof(
uchar));
   402                     ind += 
sizeof(
uchar);
   422         int data_len = (480 * 640 * (
sizeof(short)) * 
rbt_num);
   423         char* rcvData = 
new char[data_len];
   426         char pkgData[MAXRECV];
   433             if (count + MAXRECV >= data_len){
   434                 n = recv(sockClient, pkgData, data_len - count, 0);
   437                 while (rst < data_len - count){
   438                     memcpy(&rcvData[count], &pkgData, rst);
   440                     rst = data_len - count;
   441                     rst = recv(sockClient, pkgData, rst, 0);
   443                 memcpy(&rcvData[count], &pkgData, rst);
   447             n = recv(sockClient, pkgData, MAXRECV, 0);
   449             memcpy(&rcvData[count], &pkgData, n);
   456         for (
int id = 0; 
id < 
rbt_num; 
id++)
   458             for (
int i = 0; i < 480; i++)
   460                 for (
int j = 0; j < 640; j++)
   462                     memcpy(&m_depth[
id].ptr<ushort>(i)[j], &rcvData[ind], 
sizeof(
short));
   463                     ind += 
sizeof(short);
   479     cerr << 
"done" << endl;
   485     cerr << 
"waitting for pose data ... ";
   487     int data_len = (7 * 
sizeof(float) * 
rbt_num);
   488     char* rcvData = 
new char[data_len];
   491     char pkgData[MAXRECV];
   493         if (count + MAXRECV >= data_len){
   494             n = recv(sockClient, pkgData, data_len - count, 0);
   497             while (rst < data_len - count){
   498                 memcpy(&rcvData[count], &pkgData, rst);
   500                 rst = data_len - count;
   501                 rst = recv(sockClient, pkgData, rst, 0);
   503             memcpy(&rcvData[count], &pkgData, rst);
   514         n = recv(sockClient, pkgData, MAXRECV, 0);
   517         memcpy(&rcvData[count], &pkgData, n);
   525     for (
int id = 0; 
id < 
rbt_num; 
id++)
   527         for (
int i = 0; i < 7; i++)
   529             memcpy(&m_pose[
id][i], &rcvData[ind], 
sizeof(
float));
   530             ind += 
sizeof(float);
   540     cerr << 
"done" << endl;
   550     send(sockClient, sendData, 1, 0);
   563     send(sockClient, sendData, 1, 0);
   566     int data_len = 
rbt_num * 7 * 
sizeof(float);
   567     char* poseData = 
new char[data_len];
   569     for (
int rid = 0; rid < 
rbt_num; rid++)
   571         for (
int i = 0; i < 7; i++)
   573             float pass = (float)poses[rid][i];
   574             memcpy(&poseData[ind], &pass, 
sizeof(
float));
   575             ind += 
sizeof(float);
   578     int rtn_num = send(sockClient, poseData, data_len, 0);
   587     scanSurroundingsCmd();
   588     for (
int i = 0; i < 6; i++)
   592         fuseScans2MapAndTree(); 
   602     Eigen::Vector3d t(pose[0], pose[1], pose[2]);
   603     return pair<Eigen::MatrixXd, Eigen::Vector3d>(r, t);
   609     pair<Eigen::MatrixXd, Eigen::Vector3d> rt = coord_trans_7f_rt(pose);
   610     Eigen::MatrixXd r = rt.first;
   611     Eigen::Vector3d t = rt.second;
   612     double theta = 
asin(pose[5]) * 2;
   613     Eigen::Vector3d origin(0, 0, 0); 
   614     origin = r*origin + t;
   620     double v = ((-origin[1] - 
xmin_oc_g) / nodesize)*scale;
   621     double u = ((
zmax_oc_g - origin[0]) / nodesize)*scale;
   626     if(__isnan(v)||__isnan(u)||__isnan(theta))
   628         cerr<<
"se2 nan: "<<v<<
" "<<u<<
" "<<theta<<endl;
   629         cerr<<pose[0]<<
" "<<pose[1]<<
" "<<pose[2]<<
" "<<pose[3]<<
" "<<pose[4]<<
" "<<pose[5]<<
" "<<pose[6]<<
" "<<endl;
   630         getchar();getchar();getchar();
   639     Eigen::Vector2i result = Eigen::Vector2i::Zero(2, 1);
   642     if (result[0] < 0) result[0] = 0;
   644     if (result[1] < 0) result[1] = 0;
   652     Eigen::Vector2i result = Eigen::Vector2i::Zero(2, 1);
   653     result[1] = (int)((p_oc[0] - 
xmin_oc_g) / node_size)*scale;
   654     result[0] = (int)((
zmax_oc_g - p_oc[2]) / node_size)*scale;
   662     vector<double> result;
   667     if (v < 10 || u < 10)
   669         cerr << 
"error: out of boundary" << endl;
   678     result[0] = octree_z;
   679     result[1] = -octree_x;
   683     result[5] = 
sin(theta / 2);
   684     result[6] = 
cos(theta / 2);
   692     for (octomap::OcTree::leaf_iterator it = m_recon3D.m_tree->begin_leafs(), end = m_recon3D.m_tree->end_leafs(); it != end; ++it)
   698         double nodesize = it.getSize();
   700         int v = (int)((it.getX() - 
xmin_oc_g) / nodesize)*scale;
   701         int u = (int)((
zmax_oc_g - it.getZ()) / nodesize)*scale;
   706         if (m_recon2D.m_cellmap[u][v].isScanned) 
   708         m_recon2D.m_cellmap[u][v].coordinate.x = it.getX();
   709         m_recon2D.m_cellmap[u][v].coordinate.y = it.getZ();
   715             m_recon2D.m_cellmap[u][v].isScanned = 
true;
   716             m_recon2D.m_cellmap[u][v].isOccupied = 
false;
   717             m_recon2D.m_cellmap[u][v].isFree = 
true;
   720                 for (
int i = 0; i < scale; i++)
   722                     for (
int j = 0; j < scale; j++)
   724                         if (!m_recon2D.m_cellmap[u + i][v + j].isOccupied)
   726                             m_recon2D.m_cellmap[u + i][v + j].isScanned = 
true;
   727                             m_recon2D.m_cellmap[u + i][v + j].coordinate.x = it.getX();
   728                             m_recon2D.m_cellmap[u + i][v + j].coordinate.y = it.getZ();
   729                             m_recon2D.m_cellmap[u + i][v + j].isOccupied = 
false;
   730                             m_recon2D.m_cellmap[u + i][v + j].isFree = 
true;
   738     for (octomap::OcTree::leaf_iterator it = m_recon3D.m_tree->begin_leafs(), end = m_recon3D.m_tree->end_leafs(); it != end; ++it)
   744         double nodesize = it.getSize();
   746         int v = (int)((it.getX() - 
xmin_oc_g) / nodesize)*scale;
   747         int u = (int)((
zmax_oc_g - it.getZ()) / nodesize)*scale;
   752         m_recon2D.m_cellmap[u][v].coordinate.x = it.getX();
   753         m_recon2D.m_cellmap[u][v].coordinate.y = it.getZ();
   756         if (m_recon3D.m_tree->search(it.getKey())->getOccupancy() > 0.5)
   765             m_recon2D.m_cellmap[u][v].isScanned = 
true;
   766             m_recon2D.m_cellmap[u][v].isOccupied = 
true;
   767             m_recon2D.m_cellmap[u][v].isFree = 
false;
   770                 for (
int i = 0; i < scale; i++)
   772                     for (
int j = 0; j < scale; j++)
   774                         m_recon2D.m_cellmap[u + i][v + j].isScanned = 
true;
   775                         m_recon2D.m_cellmap[u + i][v + j].coordinate.x = it.getX();
   776                         m_recon2D.m_cellmap[u + i][v + j].coordinate.y = it.getZ();
   777                         m_recon2D.m_cellmap[u + i][v + j].isOccupied = 
true;
   778                         m_recon2D.m_cellmap[u + i][v + j].isFree = 
false;
   785     for (
int cid = 0; cid < m_free_space_contours2d.size(); cid++)
   787         if (m_free_space_contours2d[cid].empty()) 
continue;
   792                 if (!m_recon2D.m_cellmap[r][c].isScanned)
   794                     if (cv::pointPolygonTest(m_free_space_contours2d[cid], cv::Point(c, r), 
false) >= 0)
   796                         m_recon2D.m_cellmap[r][c].isScanned = 
true;
   797                         m_recon2D.m_cellmap[r][c].isFree = 
true;
   798                         m_recon2D.m_cellmap[r][c].isOccupied = 
false;
   806     fillTrivialHolesKnownRegion();
   816                 if (m_recon2D.m_cellmap[r][c].isScanned)
   820                         m_recon2D.m_cellmap[r][c].isScanned = 
false;
   821                         m_recon2D.m_cellmap[r][c].isFree = 
false;
   822                         m_recon2D.m_cellmap[r][c].isOccupied = 
true;
   849     cv::Mat dpth = depth.clone();
   852     pair<Eigen::MatrixXd, Eigen::Vector3d> rt = coord_trans_7f_rt(pose);
   853     Eigen::MatrixXd r = rt.first;
   854     Eigen::Vector3d t = rt.second;
   857     cv::Mat depth_vec = cv::Mat::zeros(1, dpth.cols, CV_8UC1);
   858     for (
int c = 0; c < dpth.cols; c++)
   860         bool value_valid = 
false;
   861         for (
int r = 0; r < dpth.rows; r++)
   864             if (dpth.ptr<ushort>(r)[c] != 0)
   871             depth_vec.ptr<
uchar>(0)[c] = 255;
   873     vector<int> free_indexes;
   874     for (
int crt = 0; crt < depth_vec.cols; crt++)
   876         if (depth_vec.ptr<
uchar>(0)[crt] == 0)
   877             free_indexes.push_back(crt);
   879     vector<pair<int, int>> free_spaces;
   881     if (free_indexes.size() > 1)
   884         int begin_index = -1;
   886         for (
int crt = 0; crt < free_indexes.size(); crt++)
   889                 begin_index = free_indexes[crt];
   893             if (free_indexes[crt] - free_indexes[last] > 1)
   895                 end_index = free_indexes[last];
   896                 if (begin_index != end_index)
   897                     free_spaces.push_back(pair<int, int>(begin_index, end_index));
   898                 begin_index = free_indexes[crt];
   900             if (crt == free_indexes.size() - 1){ 
   901                 end_index = free_indexes[crt];
   902                 if (begin_index != end_index)
   903                     free_spaces.push_back(pair<int, int>(begin_index, end_index));
   908     if (!free_spaces.empty())
   912         for (
int sid = 0; sid < free_spaces.size(); sid++)
   914             vector<cv::Point> space_contour;
   920                 ushort 
d = scan_max_range;
   922                 double z = double(d) / camera_factor;
   923                 double x = (free_spaces[sid].second - camera_cx) * z / camera_fx;
   924                 double y = (0 - camera_cy) * z / camera_fy;
   926                 p[0] = z, p[1] = -x, p[2] = -y; 
   929                 int v = (int)((-p[1] - 
xmin_oc_g) / nodesize)*scale;
   930                 int u = (int)((
zmax_oc_g - p[0]) / nodesize)*scale;
   936                 space_contour.push_back(cv::Point(v, u));
   941                 ushort 
d = scan_max_range;
   942                 double z = double(d) / camera_factor;
   943                 double x = (free_spaces[sid].first - camera_cx) * z / camera_fx;
   944                 double y = (0 - camera_cy) * z / camera_fy;
   946                 p[0] = z, p[1] = -x, p[2] = -y; 
   948                 int v = (int)((-p[1] - 
xmin_oc_g) / nodesize)*scale;
   949                 int u = (int)((
zmax_oc_g - p[0]) / nodesize)*scale;
   954                 space_contour.push_back(cv::Point(v, u));
   962                 p[0] = z, p[1] = -x, p[2] = -y;
   964                 int v = (int)((-p[1] - 
xmin_oc_g) / nodesize)*scale;
   965                 int u = (int)((
zmax_oc_g - p[0]) / nodesize)*scale;
   970                 space_contour.push_back(cv::Point(v, u));
   972             m_free_space_contours2d[rid] = space_contour; 
   990     vector<cv::Point> result;
   994         ushort 
d = scan_max_range;
   995         double z = double(d) / camera_factor;
   996         double x = (
map_cols - 1 - camera_cx) * z / camera_fx;
   997         double y = (0 - camera_cy) * z / camera_fy;
   998         Eigen::Vector3d p_cam;
   999         p_cam[0] = x; p_cam[1] = y; p_cam[2] = z;
  1000         Eigen::Vector3d p_gz;
  1001         p_gz[0] = p_cam.z(), p_gz[1] = -p_cam.x(), p_gz[2] = -p_cam.y(); 
  1003         Eigen::Vector3d p_oc;
  1004         p_oc[0] = -p_gz[1]; p_oc[1] = -p_gz[2]; p_oc[2] = p_gz[0]; 
  1007         Eigen::Vector2i rc = coord_trans_oc2cell(p_oc, node_size, scale);
  1015         result.push_back(cv::Point(v, u));
  1020         ushort 
d = scan_max_range;
  1021         double z = double(d) / camera_factor;
  1022         double x = (0 - camera_cx) * z / camera_fx;
  1023         double y = (0 - camera_cy) * z / camera_fy;
  1025         p[0] = z, p[1] = -x, p[2] = -y; 
  1030         int v = (int)((-p[1] - 
xmin_oc_g) / nodesize)*scale;
  1031         int u = (int)((
zmax_oc_g - p[0]) / nodesize)*scale;
  1037         result.push_back(cv::Point(v, u));
  1045         p[0] = z, p[1] = -x, p[2] = -y; 
  1050         int v = (int)((-p[1] - 
xmin_oc_g) / nodesize)*scale;
  1051         int u = (int)((
zmax_oc_g - p[0]) / nodesize)*scale;
  1057         result.push_back(cv::Point(v, u));
  1066     for (
int r = 0; r < cellmap_mat.rows; r++)
  1068         for (
int c = 0; c < cellmap_mat.cols; c++)
  1070             if (m_recon2D.m_cellmap[r][c].isScanned){
  1071                 if (m_recon2D.m_cellmap[r][c].isFree)
  1072                     cellmap_mat.ptr<cv::Vec3b>(r)[c][1] = 255;
  1074                     cellmap_mat.ptr<cv::Vec3b>(r)[c][2] = 255;
  1080     cv::resize(cellmap_mat, trans_mat, trans_mat.size(), 0, 0);
  1082     for (
int r = 0; r < trans_mat.rows; r++)
  1084         for (
int c = 0; c < trans_mat.cols; c++)
  1086             if (trans_mat.ptr<cv::Vec3b>(r)[c][1] > trans_mat.ptr<cv::Vec3b>(r)[c][2]){ 
  1087                 trans_mat.ptr<cv::Vec3b>(r)[c][2] = 0;
  1088                 trans_mat.ptr<cv::Vec3b>(r)[c][1] = 255;
  1089                 trans_mat.ptr<cv::Vec3b>(r)[c][0] = 0;
  1091             else if (trans_mat.ptr<cv::Vec3b>(r)[c][1] < trans_mat.ptr<cv::Vec3b>(r)[c][2]){ 
  1092                 trans_mat.ptr<cv::Vec3b>(r)[c][2] = 255;
  1093                 trans_mat.ptr<cv::Vec3b>(r)[c][1] = 0;
  1094                 trans_mat.ptr<cv::Vec3b>(r)[c][0] = 0;
  1098     cv::resize(trans_mat, cellmap_mat, cellmap_mat.size(), 0, 0);
  1100     for (
int r = 0; r < cellmap_mat.rows; r++)
  1102         for (
int c = 0; c < cellmap_mat.cols; c++)
  1104             if (cellmap_mat.ptr<cv::Vec3b>(r)[c][1] > cellmap_mat.ptr<cv::Vec3b>(r)[c][2]){ 
  1105                 cellmap_mat.ptr<cv::Vec3b>(r)[c][2] = 0;
  1106                 cellmap_mat.ptr<cv::Vec3b>(r)[c][1] = 255;
  1107                 cellmap_mat.ptr<cv::Vec3b>(r)[c][0] = 0;
  1109             else if (cellmap_mat.ptr<cv::Vec3b>(r)[c][1] < cellmap_mat.ptr<cv::Vec3b>(r)[c][2]){ 
  1110                 cellmap_mat.ptr<cv::Vec3b>(r)[c][2] = 255;
  1111                 cellmap_mat.ptr<cv::Vec3b>(r)[c][1] = 0;
  1112                 cellmap_mat.ptr<cv::Vec3b>(r)[c][0] = 0;
  1117     for (
int rid = 0; rid < 
rbt_num; rid++)
  1119         if (m_frustum_contours[rid].size() == 0)
  1121             cerr << 
"empty frustum." << endl;
  1122             getchar(); getchar(); getchar();
  1130         for (
int pid = 0; pid < m_frustum_contours[rid].size(); pid++)
  1132             if (m_frustum_contours[rid][pid].x > maxX)
  1133                 maxX = m_frustum_contours[rid][pid].x;
  1134             if (m_frustum_contours[rid][pid].y > maxY)
  1135                 maxY = m_frustum_contours[rid][pid].y;
  1136             if (m_frustum_contours[rid][pid].x < minX)
  1137                 minX = m_frustum_contours[rid][pid].x;
  1138             if (m_frustum_contours[rid][pid].y < minY)
  1139                 minY = m_frustum_contours[rid][pid].y;
  1143         for (
int r = minY; r <= maxY; r++)
  1145             for (
int c = minX; c <= maxX; c++)
  1147                 if (m_recon2D.m_cellmap[r][c].isScanned) 
  1149                     if (cv::pointPolygonTest(m_frustum_contours[rid], cv::Point(c, r), 
false) >= 0) 
  1151                         inerCellMap.ptr<
uchar>(r)[c] = 255;
  1157         vector<vector<cv::Point>> contours;
  1158         vector<cv::Vec4i> hierarchy;
  1159         cv::findContours(inerCellMap, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE);
  1160         for (
int cid = 0; cid < contours.size(); cid++)
  1162             if (contours[cid].size() <= 4) 
continue;
  1163             for (
int r = minY; r <= maxY; r++)
  1165                 for (
int c = minX; c <= maxX; c++)
  1167                     if (!m_recon2D.m_cellmap[r][c].isScanned) 
  1169                         if (cv::pointPolygonTest(contours[cid], cv::Point(c, r), 
false) >= 0) 
  1171                             if (cellmap_mat.ptr<cv::Vec3b>(r)[c][1] == 255) 
  1173                                 m_recon2D.m_cellmap[r][c].isScanned = 
true;
  1174                                 m_recon2D.m_cellmap[r][c].isFree = 
true;
  1175                                 m_recon2D.m_cellmap[r][c].isOccupied = 
false;
  1177                             else if (cellmap_mat.ptr<cv::Vec3b>(r)[c][2] == 255) 
  1179                                 m_recon2D.m_cellmap[r][c].isScanned = 
true;
  1180                                 m_recon2D.m_cellmap[r][c].isFree = 
false;
  1181                                 m_recon2D.m_cellmap[r][c].isOccupied = 
true;
  1196     cerr<<
"fuseScans2MapAndTree..."<<endl;
  1197     for (
int rid = 0; rid < 
rbt_num; ++rid)
  1200         cerr<<
"insertAFrame2Tree..."<<endl;
  1201         insertAFrame2Tree(m_depth[rid], m_pose[rid]);
  1203         findExtraFreeSpace(rid, m_depth[rid], m_pose[rid]);
  1210         m_pose2d[rid] = coord_trans_7f_se2(m_pose[rid]);
  1212         pair<Eigen::MatrixXd, Eigen::Vector3d> rt = coord_trans_7f_rt(m_pose[rid]);
  1213         m_frustum_contours[rid] = loadIdealFrustum(rt.first, rt.second);
  1224     double tb = clock(); 
  1226     for (
int i = 0; i < pose.size(); ++i)
  1228         if (__isnan(pose[i]))
  1230             cerr<<
"pose nan:"<<endl;
  1231             cerr<<pose[0]<<
" "<<pose[1]<<
" "<<pose[2]<<
" "<<pose[3]<<
" "<<pose[4]<<
" "<<pose[5]<<
" "<<pose[6]<<
" "<<endl;
  1232             getchar();getchar();getchar();
  1236     if (pose[3]==pose[4] && pose[4]==pose[5] && pose[5]==pose[6])
  1238         cerr<<
"invalid pose"<<endl;
  1239         cerr<<pose[0]<<
" "<<pose[1]<<
" "<<pose[2]<<
" "<<pose[3]<<
" "<<pose[4]<<
" "<<pose[5]<<
" "<<pose[6]<<
" "<<endl;
  1240         getchar();getchar();getchar();
  1245     octomap::Pointcloud* pc = 
new octomap::Pointcloud();
  1246     for (
int r = 0; r < depth.rows; r++)
  1248         for (
int c = 0; c < depth.cols; c++)
  1250             if (depth.ptr<ushort>(r)[c] > scan_max_range) 
  1251                 depth.ptr<ushort>(r)[c] = 0;
  1253             if (depth.ptr<ushort>(r)[c] == 1000) 
  1254                 depth.ptr<ushort>(r)[c] = 0;
  1280     Eigen::Vector3d t(pose[0], pose[1], pose[2]);
  1310     for (
int m = 0; m < depth.rows; m++){
  1311         for (
int n = 0; n < depth.cols; n++){
  1313             ushort 
d = depth.ptr<ushort>(m)[n];
  1316             if (d > scan_max_range) 
  1319             double z = double(d) / camera_factor;
  1320             double x = (n - camera_cx) * z / camera_fx;
  1321             double y = (m - camera_cy) * z / camera_fy;
  1324             p[0] = z, p[1] = -x, p[2] = -y; 
  1326             if (__isnan(p[0])||__isnan(p[1])||__isnan(p[2]))
  1328                 cerr<<
"point nan in pc"<<endl;
  1329                 getchar();getchar();getchar();
  1333             pc->push_back(-p[1], -p[2], p[0]); 
  1336     Eigen::Vector3d origin(0, 0, 0);
  1337     origin = r*origin + t; 
  1350         m_recon3D.m_tree->insertPointCloud(pc, octomap::point3d(-origin[1], -origin[2], origin[0])); 
  1352         m_recon3D.m_tree->updateInnerOccupancy();
  1355     double te = clock(); 
  1356     cerr << 
"inserted a frame to octree, timing " << (te - tb)/CLOCKS_PER_SEC << 
" s" << endl;
  1364     for (
int r = 0; r < vis_mat.rows; r++)
  1366         for (
int c = 0; c < vis_mat.cols; c++)
  1368             if (m_recon2D.m_cellmap[r][c].isScanned)
  1370                 if (m_recon2D.m_cellmap[r][c].isFree)
  1371                     vis_mat.ptr<cv::Vec3b>(r)[c][1] = 255;
  1373                     vis_mat.ptr<cv::Vec3b>(r)[c][2] = 255;
  1383     cv::Mat vis_mat = visCellMap();
  1384     cv::imshow(
"2d", vis_mat);
  1393     cv::Mat vis_mat = visCellMap();
  1395     for (
int rid = 0; rid < 
rbt_num; ++rid)
  1397         cv::circle(vis_mat, cv::Point(
round(m_pose2d[rid].translation().x()), 
round(-m_pose2d[rid].translation().y())), 1, CV_RGB(255, 255, 255));
  1398         cv::circle(vis_mat, cv::Point(
round(m_pose2d[rid].translation().x()), 
round(-m_pose2d[rid].translation().y())), 3, CV_RGB(0, 0, 255));
  1400     cv::imshow(
"statement2d", vis_mat);
 
iro::SE2 coord_trans_7f_se2(std::vector< float > pose)
EIGEN_DEVICE_FUNC const CosReturnType cos() const
std::vector< cv::Point > g_scene_boundary
std::vector< cv::Point > loadIdealFrustum(Eigen::MatrixXd r, Eigen::Vector3d t)
const Eigen::Rotation2Dd & rotation() const
void fuseScans2MapAndTree()
Eigen::Vector2i coord_trans_oc2cell(Eigen::Vector3d p_oc)
std::vector< double > coord_trans_se22gazebo(iro::SE2 pose)
const double free_voxel_porject_height
void insertAFrame2Tree(cv::Mat &depth, std::vector< float > pose)
void scanSurroundingsCmd()
const double project_min_height
std::pair< Eigen::MatrixXd, Eigen::Vector3d > coord_trans_7f_rt(std::vector< float > pose)
void findExtraFreeSpace(int rid, cv::Mat depth, std::vector< float > pose)
void stopThread(int sockClient)
bool socket_move_to_views(std::vector< std::vector< double >> poses)
The quaternion class used to represent 3D orientations and rotations. 
const double project_max_height
EIGEN_DEVICE_FUNC Matrix3 toRotationMatrix() const
void socketSendThread(int sockClient, char *data, int data_lengh)
EIGEN_DEVICE_FUNC Scalar angle() const
EIGEN_DEVICE_FUNC const AsinReturnType asin() const
const Eigen::Vector2d & translation() const
void fillTrivialHolesKnownRegion()
struct thread_data * data
EIGEN_DEVICE_FUNC const SinReturnType sin() const
EIGEN_DEVICE_FUNC const RoundReturnType round() const