| 149 | |
| 150 | |
| 151 | MatrixXd SCManager::makeScancontext( pcl::PointCloud<SCPointType> & _scan_down ) |
| 152 | { |
| 153 | TicTocV2 t_making_desc; |
| 154 | |
| 155 | int num_pts_scan_down = _scan_down.points.size(); |
| 156 | |
| 157 | // main |
| 158 | const int NO_POINT = -1000; |
| 159 | MatrixXd desc = NO_POINT * MatrixXd::Ones(PC_NUM_RING, PC_NUM_SECTOR); |
| 160 | |
| 161 | SCPointType pt; |
| 162 | float azim_angle, azim_range; // wihtin 2d plane |
| 163 | int ring_idx, sctor_idx; |
| 164 | for (int pt_idx = 0; pt_idx < num_pts_scan_down; pt_idx++) |
| 165 | { |
| 166 | pt.x = _scan_down.points[pt_idx].x; |
| 167 | pt.y = _scan_down.points[pt_idx].y; |
| 168 | pt.z = _scan_down.points[pt_idx].z + LIDAR_HEIGHT; // naive adding is ok (all points should be > 0). |
| 169 | |
| 170 | // xyz to ring, sector |
| 171 | azim_range = sqrt(pt.x * pt.x + pt.y * pt.y); |
| 172 | azim_angle = xy2theta(pt.x, pt.y); |
| 173 | |
| 174 | // if range is out of roi, pass |
| 175 | if( azim_range > PC_MAX_RADIUS ) |
| 176 | continue; |
| 177 | |
| 178 | ring_idx = std::max( std::min( PC_NUM_RING, int(ceil( (azim_range / PC_MAX_RADIUS) * PC_NUM_RING )) ), 1 ); |
| 179 | sctor_idx = std::max( std::min( PC_NUM_SECTOR, int(ceil( (azim_angle / 360.0) * PC_NUM_SECTOR )) ), 1 ); |
| 180 | |
| 181 | // taking maximum z |
| 182 | if ( desc(ring_idx-1, sctor_idx-1) < pt.z ) // -1 means cpp starts from 0 |
| 183 | desc(ring_idx-1, sctor_idx-1) = pt.z; // update for taking maximum value at that bin |
| 184 | } |
| 185 | |
| 186 | // reset no points to zero (for cosine dist later) |
| 187 | for ( int row_idx = 0; row_idx < desc.rows(); row_idx++ ) |
| 188 | for ( int col_idx = 0; col_idx < desc.cols(); col_idx++ ) |
| 189 | if( desc(row_idx, col_idx) == NO_POINT ) |
| 190 | desc(row_idx, col_idx) = 0; |
| 191 | |
| 192 | t_making_desc.toc("PolarContext making"); |
| 193 | |
| 194 | return desc; |
| 195 | } // SCManager::makeScancontext |
| 196 | |
| 197 | |
| 198 | MatrixXd SCManager::makeRingkeyFromScancontext( Eigen::MatrixXd &_desc ) |