From 502e8a16b555434baea6c5d69f027fca0cab1a25 Mon Sep 17 00:00:00 2001 From: Carlos Guindel Date: Mon, 25 Feb 2019 13:06:16 +0100 Subject: [PATCH] Fix minor code issues --- src/laser_pattern.cpp | 27 +++++++++++++-------------- src/levinson.cpp | 25 +++++++------------------ src/pcl_coloring.cpp | 2 +- src/stereo_pattern.cpp | 6 +++--- src/velo2cam_calibration.cpp | 4 ++-- 5 files changed, 26 insertions(+), 38 deletions(-) diff --git a/src/laser_pattern.cpp b/src/laser_pattern.cpp index 2a99eb0..48650f4 100644 --- a/src/laser_pattern.cpp +++ b/src/laser_pattern.cpp @@ -132,22 +132,21 @@ void callback(const PointCloud2::ConstPtr& laser_cloud){ // Get edges points by range vector > rings = Velodyne::getRings(*velocloud); - for (vector >::iterator ring = rings.begin(); ring < rings.end(); ring++){ - Velodyne::Point *prev, *succ; + for (vector >::iterator ring = rings.begin(); ring < rings.end(); ++ring){ if (ring->empty()) continue; (*ring->begin())->intensity = 0; (*(ring->end() - 1))->intensity = 0; for (vector::iterator pt = ring->begin() + 1; pt < ring->end() - 1; pt++){ - prev = *(pt - 1); - succ = *(pt + 1); + Velodyne::Point *prev = *(pt - 1); + Velodyne::Point *succ = *(pt + 1); (*pt)->intensity = max( max( prev->range-(*pt)->range, succ->range-(*pt)->range), 0.f); } } pcl::PointCloud::Ptr edges_cloud(new pcl::PointCloud); float THRESHOLD = 0.5 ; - for (pcl::PointCloud::iterator pt = velocloud->points.begin(); pt < velocloud->points.end(); pt++){ + for (pcl::PointCloud::iterator pt = velocloud->points.begin(); pt < velocloud->points.end(); ++pt){ if(pt->intensity>THRESHOLD){ edges_cloud->push_back(*pt); } @@ -169,7 +168,7 @@ void callback(const PointCloud2::ConstPtr& laser_cloud){ pcl::PointCloud::Ptr circles_cloud(new pcl::PointCloud); vector > rings2 = Velodyne::getRings(*pattern_cloud); int ringsWithCircle = 0; - for (vector >::iterator ring = rings2.begin(); ring < rings2.end(); ring++){ + for (vector >::iterator ring = rings2.begin(); ring < rings2.end(); ++ring){ if(ring->size() < 4){ ring->clear(); }else{ // Remove first and last points in ring @@ -177,7 +176,7 @@ void callback(const PointCloud2::ConstPtr& laser_cloud){ ring->erase(ring->begin()); ring->pop_back(); - for (vector::iterator pt = ring->begin(); pt < ring->end(); pt++){ + for (vector::iterator pt = ring->begin(); pt < ring->end(); ++pt){ // Velodyne specific info no longer needed for calibration // so standard point is used from now on pcl::PointXYZ point; @@ -245,9 +244,9 @@ void callback(const PointCloud2::ConstPtr& laser_cloud){ //if(DEBUG) cout << cluster_indices.size() << " clusters found from " << xy_cloud->points.size() << " points in cloud" << endl; - for (std::vector::iterator it=cluster_indices.begin(); it::iterator it=cluster_indices.begin(); it::iterator it2=it->indices.begin(); it2indices.end(); it2++){ + for(vector::iterator it2=it->indices.begin(); it2indices.end(); ++it2){ accx+=xy_cloud->at(*it2).x; accy+=xy_cloud->at(*it2).y; accz+=xy_cloud->at(*it2).z; @@ -279,7 +278,7 @@ void callback(const PointCloud2::ConstPtr& laser_cloud){ pcl::PointCloud::Ptr cloud_f(new pcl::PointCloud); // Temp pc used for swaping // Force pattern points to belong to computed plane - for (pcl::PointCloud::iterator pt = copy_cloud->points.begin(); pt < copy_cloud->points.end(); pt++){ + for (pcl::PointCloud::iterator pt = copy_cloud->points.begin(); pt < copy_cloud->points.end(); ++pt){ pt->z = zcoord_xyplane; } @@ -318,7 +317,7 @@ void callback(const PointCloud2::ConstPtr& laser_cloud){ // if(DEBUG) ROS_INFO("Distance to centroid %f", centroid_distance); if (centroid_distance < centroid_distance_min_){ valid = false; - for (pcl::PointCloud::iterator pt = circle_cloud->points.begin(); pt < circle_cloud->points.end(); pt++){ + for (pcl::PointCloud::iterator pt = circle_cloud->points.begin(); pt < circle_cloud->points.end(); ++pt){ centroid_cloud_inliers.push_back(*pt); } }else if(centroid_distance > centroid_distance_max_){ @@ -334,13 +333,13 @@ void callback(const PointCloud2::ConstPtr& laser_cloud){ } // If center is valid, check if any point from wrong_circle belongs to it, and pop it if true - for (std::vector::iterator pt = centroid_cloud_inliers.begin(); pt < centroid_cloud_inliers.end(); pt++){ + for (std::vector::iterator pt = centroid_cloud_inliers.begin(); pt < centroid_cloud_inliers.end(); ++pt){ pcl::PointXYZ schrodinger_pt((*pt).x, (*pt).y, (*pt).z); double distance_to_cluster = sqrt(pow(schrodinger_pt.x-center.x,2) + pow(schrodinger_pt.y-center.y,2) + pow(schrodinger_pt.z-center.z,2)); // if(DEBUG) ROS_INFO("Distance to cluster: %lf", distance_to_cluster); if(distance_to_cluster= min_centers_found_ && found_centers.size() < 5){ - for (std::vector >::iterator it = found_centers.begin(); it < found_centers.end(); it++){ + for (std::vector >::iterator it = found_centers.begin(); it < found_centers.end(); ++it){ pcl::PointXYZ center; center.x = (*it)[0]; center.y = (*it)[1]; diff --git a/src/levinson.cpp b/src/levinson.cpp index af6b35a..195d908 100644 --- a/src/levinson.cpp +++ b/src/levinson.cpp @@ -112,15 +112,14 @@ COLOUR GetColour(double v,double vmin,double vmax) void edges_pointcloud(pcl::PointCloud::Ptr pc){ std::vector > rings = Velodyne::getRings(*pc); - for (std::vector >::iterator ring = rings.begin(); ring < rings.end(); ring++){ - Velodyne::Point *prev, *succ; + for (std::vector >::iterator ring = rings.begin(); ring < rings.end(); ++ring){ if (ring->empty()) continue; (*ring->begin())->intensity = 0; (*(ring->end() - 1))->intensity = 0; - for (vector::iterator pt = ring->begin() + 1; pt < ring->end() - 1; pt++){ - prev = *(pt - 1); - succ = *(pt + 1); + for (vector::iterator pt = ring->begin() + 1; pt < ring->end() - 1; ++pt){ + Velodyne::Point *prev = *(pt - 1); + Velodyne::Point *succ = *(pt + 1); (*pt)->intensity = pow(std::max( std::max( prev->range-(*pt)->range, succ->range-(*pt)->range), 0.f), 0.5); } } @@ -201,10 +200,9 @@ inline float calc(float &val, const float &psi, int row, int col, const cv::Mat& template inline void neighbors_x_pos(cv::Mat &in, cv::Mat &out, float psi, float alpha){ - float val = 0; - for(int row = 0; row < in.rows; ++row) { + float val = 0; val = 0; for(int col = 0; col < in.cols; ++col) { @@ -411,15 +409,6 @@ void checkExtrinics(const sensor_msgs::CameraInfoConstPtr& cinfo_msg){ for (int iter_r=0; iter_r::iterator pt = trans_cloud->points.begin(); pt < trans_cloud->points.end(); pt++) + for (pcl::PointCloud::iterator pt = trans_cloud->points.begin(); pt < trans_cloud->points.end(); ++pt) { cv::Point3d pt_cv((*pt).x, (*pt).y, (*pt).z); cv::Point2d uv; @@ -494,7 +483,7 @@ void laser_callback(const sensor_msgs::PointCloud2::ConstPtr& velo_cloud){ edges_cloud = pcl::PointCloud::Ptr(new pcl::PointCloud); float THRESHOLD = 0.30; - for (pcl::PointCloud::iterator pt = laser_cloud->points.begin(); pt < laser_cloud->points.end(); pt++){ + for (pcl::PointCloud::iterator pt = laser_cloud->points.begin(); pt < laser_cloud->points.end(); ++pt){ if(pow(pt->intensity,2)>THRESHOLD){ edges_cloud->push_back(*pt); } diff --git a/src/pcl_coloring.cpp b/src/pcl_coloring.cpp index 3237290..07f36e8 100644 --- a/src/pcl_coloring.cpp +++ b/src/pcl_coloring.cpp @@ -83,7 +83,7 @@ void callback(const PointCloud2::ConstPtr& pcl_msg, const CameraInfoConstPtr& ci pcl::copyPointCloud(*trans_cloud, *coloured); - for (pcl::PointCloud::iterator pt = coloured->points.begin(); pt < coloured->points.end(); pt++) + for (pcl::PointCloud::iterator pt = coloured->points.begin(); pt < coloured->points.end(); ++pt) { cv::Point3d pt_cv((*pt).x, (*pt).y, (*pt).z); cv::Point2d uv; diff --git a/src/stereo_pattern.cpp b/src/stereo_pattern.cpp index 5715f91..6bf936a 100644 --- a/src/stereo_pattern.cpp +++ b/src/stereo_pattern.cpp @@ -205,7 +205,7 @@ void callback(const PointCloud2::ConstPtr& camera_cloud, pcl::PointCloud::Ptr cam_plane_wol_cloud (new pcl::PointCloud ()); // Remove them - for (vector::iterator it=out_lines.begin(); it::iterator it=out_lines.begin(); it::Ptr dil (new pcl::SampleConsensusModelLine (cam_plane_cloud)); @@ -270,7 +270,7 @@ void callback(const PointCloud2::ConstPtr& camera_cloud, // Force pattern points to belong to computed plane for (pcl::PointCloud::iterator pt = xy_cloud->points.begin(); - pt < xy_cloud->points.end(); pt++){ + pt < xy_cloud->points.end(); ++pt){ pt->z = zcoord_xyplane; } @@ -348,7 +348,7 @@ void callback(const PointCloud2::ConstPtr& camera_cloud, ROS_WARN("Not enough centers: %ld", found_centers.size()); return; }else{ - for (std::vector >::iterator it = found_centers.begin(); it < found_centers.end(); it++){ + for (std::vector >::iterator it = found_centers.begin(); it < found_centers.end(); ++it){ pcl::PointXYZ center; center.x = (*it)[0]; center.y = (*it)[1]; diff --git a/src/velo2cam_calibration.cpp b/src/velo2cam_calibration.cpp index cfe891c..a239c7c 100644 --- a/src/velo2cam_calibration.cpp +++ b/src/velo2cam_calibration.cpp @@ -306,7 +306,7 @@ void laser_callback(const velo2cam_calibration::ClusterCentroids::ConstPtr velo_ if(DEBUG) ROS_INFO("[V2C] LASER"); - for(vector::iterator it=lv.begin(); it::iterator it=lv.begin(); it::iterator it=cv.begin(); it::iterator it=cv.begin(); it