From b72e9ee94b656a8f12c2683b09e7e4f70acfa04b Mon Sep 17 00:00:00 2001 From: Heiko Thiel Date: Thu, 18 Apr 2019 23:40:21 +0200 Subject: [PATCH 1/2] Changes are done by run-clang-tidy -header-filter='.*' -checks='-*,modernize-use-nullptr' -fix --- .../pcl/segmentation/impl/crf_segmentation.hpp | 8 ++++---- .../pcl/segmentation/impl/extract_clusters.hpp | 4 ++-- .../segmentation/impl/extract_labeled_clusters.hpp | 4 ++-- .../pcl/segmentation/impl/min_cut_segmentation.hpp | 12 ++++++------ .../pcl/segmentation/impl/region_growing.hpp | 14 +++++++------- .../pcl/segmentation/impl/region_growing_rgb.hpp | 2 +- .../segmentation/impl/seeded_hue_segmentation.hpp | 4 ++-- .../segmentation/impl/supervoxel_clustering.hpp | 8 ++++---- .../pcl/segmentation/impl/unary_classifier.hpp | 2 +- .../pcl/segmentation/supervoxel_clustering.h | 2 +- 10 files changed, 30 insertions(+), 30 deletions(-) diff --git a/segmentation/include/pcl/segmentation/impl/crf_segmentation.hpp b/segmentation/include/pcl/segmentation/impl/crf_segmentation.hpp index 1c8603222e1..37dd0b46d9f 100644 --- a/segmentation/include/pcl/segmentation/impl/crf_segmentation.hpp +++ b/segmentation/include/pcl/segmentation/impl/crf_segmentation.hpp @@ -71,7 +71,7 @@ pcl::CrfSegmentation::~CrfSegmentation () template void pcl::CrfSegmentation::setInputCloud (typename pcl::PointCloud::Ptr input_cloud) { - if (input_cloud_ != NULL) + if (input_cloud_ != nullptr) input_cloud_.reset (); input_cloud_ = input_cloud; @@ -81,7 +81,7 @@ pcl::CrfSegmentation::setInputCloud (typename pcl::PointCloud::P template void pcl::CrfSegmentation::setAnnotatedCloud (typename pcl::PointCloud::Ptr anno_cloud) { - if (anno_cloud_ != NULL) + if (anno_cloud_ != nullptr) anno_cloud_.reset (); anno_cloud_ = anno_cloud; @@ -91,7 +91,7 @@ pcl::CrfSegmentation::setAnnotatedCloud (typename pcl::PointCloud void pcl::CrfSegmentation::setNormalCloud (typename pcl::PointCloud::Ptr normal_cloud) { - if (normal_cloud_ != NULL) + if (normal_cloud_ != nullptr) normal_cloud_.reset (); normal_cloud_ = normal_cloud; @@ -329,7 +329,7 @@ pcl::CrfSegmentation::createUnaryPotentials (std::vector &unary, unsigned int n_labels) { /* initialize random seed: */ - srand ( static_cast (time (NULL)) ); + srand ( static_cast (time (nullptr)) ); //srand ( time (NULL) ); // Certainty that the groundtruth is correct diff --git a/segmentation/include/pcl/segmentation/impl/extract_clusters.hpp b/segmentation/include/pcl/segmentation/impl/extract_clusters.hpp index 7203041a403..7114dd9d0c5 100644 --- a/segmentation/include/pcl/segmentation/impl/extract_clusters.hpp +++ b/segmentation/include/pcl/segmentation/impl/extract_clusters.hpp @@ -210,8 +210,8 @@ template void pcl::EuclideanClusterExtraction::extract (std::vector &clusters) { if (!initCompute () || - (input_ != 0 && input_->points.empty ()) || - (indices_ != 0 && indices_->empty ())) + (input_ != nullptr && input_->points.empty ()) || + (indices_ != nullptr && indices_->empty ())) { clusters.clear (); return; diff --git a/segmentation/include/pcl/segmentation/impl/extract_labeled_clusters.hpp b/segmentation/include/pcl/segmentation/impl/extract_labeled_clusters.hpp index 4f49c277efd..26533809f89 100644 --- a/segmentation/include/pcl/segmentation/impl/extract_labeled_clusters.hpp +++ b/segmentation/include/pcl/segmentation/impl/extract_labeled_clusters.hpp @@ -123,8 +123,8 @@ template void pcl::LabeledEuclideanClusterExtraction::extract (std::vector > &labeled_clusters) { if (!initCompute () || - (input_ != 0 && input_->points.empty ()) || - (indices_ != 0 && indices_->empty ())) + (input_ != nullptr && input_->points.empty ()) || + (indices_ != nullptr && indices_->empty ())) { labeled_clusters.clear (); return; diff --git a/segmentation/include/pcl/segmentation/impl/min_cut_segmentation.hpp b/segmentation/include/pcl/segmentation/impl/min_cut_segmentation.hpp index 4169378e712..afb202306da 100644 --- a/segmentation/include/pcl/segmentation/impl/min_cut_segmentation.hpp +++ b/segmentation/include/pcl/segmentation/impl/min_cut_segmentation.hpp @@ -76,13 +76,13 @@ pcl::MinCutSegmentation::MinCutSegmentation () : template pcl::MinCutSegmentation::~MinCutSegmentation () { - if (search_ != 0) + if (search_ != nullptr) search_.reset (); - if (graph_ != 0) + if (graph_ != nullptr) graph_.reset (); - if (capacity_ != 0) + if (capacity_ != nullptr) capacity_.reset (); - if (reverse_edges_ != 0) + if (reverse_edges_ != nullptr) reverse_edges_.reset (); foreground_points_.clear (); @@ -167,7 +167,7 @@ pcl::MinCutSegmentation::getSearchMethod () const template void pcl::MinCutSegmentation::setSearchMethod (const KdTreePtr& tree) { - if (search_ != 0) + if (search_ != nullptr) search_.reset (); search_ = tree; @@ -327,7 +327,7 @@ pcl::MinCutSegmentation::buildGraph () if (input_->points.size () == 0 || number_of_points == 0 || foreground_points_.empty () == true ) return (false); - if (search_ == 0) + if (search_ == nullptr) search_.reset (new pcl::search::KdTree); graph_.reset (new mGraph); diff --git a/segmentation/include/pcl/segmentation/impl/region_growing.hpp b/segmentation/include/pcl/segmentation/impl/region_growing.hpp index 559de6417d8..ac1d671b8fc 100644 --- a/segmentation/include/pcl/segmentation/impl/region_growing.hpp +++ b/segmentation/include/pcl/segmentation/impl/region_growing.hpp @@ -79,9 +79,9 @@ pcl::RegionGrowing::RegionGrowing () : template pcl::RegionGrowing::~RegionGrowing () { - if (search_ != 0) + if (search_ != nullptr) search_.reset (); - if (normals_ != 0) + if (normals_ != nullptr) normals_.reset (); point_neighbours_.clear (); @@ -233,7 +233,7 @@ pcl::RegionGrowing::getSearchMethod () const template void pcl::RegionGrowing::setSearchMethod (const KdTreePtr& tree) { - if (search_ != 0) + if (search_ != nullptr) search_.reset (); search_ = tree; @@ -250,7 +250,7 @@ pcl::RegionGrowing::getInputNormals () const template void pcl::RegionGrowing::setInputNormals (const NormalPtr& norm) { - if (normals_ != 0) + if (normals_ != nullptr) normals_.reset (); normals_ = norm; @@ -312,7 +312,7 @@ pcl::RegionGrowing::prepareForSegmentation () return (false); // if user forgot to pass normals or the sizes of point and normal cloud are different - if ( normals_ == 0 || input_->points.size () != normals_->points.size () ) + if ( normals_ == nullptr || input_->points.size () != normals_->points.size () ) return (false); // if residual test is on then we need to check if all needed parameters were correctly initialized @@ -656,7 +656,7 @@ pcl::RegionGrowing::getColoredCloud () { colored_cloud = (new pcl::PointCloud)->makeShared (); - srand (static_cast (time (0))); + srand (static_cast (time (nullptr))); std::vector colors; for (size_t i_segment = 0; i_segment < clusters_.size (); i_segment++) { @@ -708,7 +708,7 @@ pcl::RegionGrowing::getColoredCloudRGBA () { colored_cloud = (new pcl::PointCloud)->makeShared (); - srand (static_cast (time (0))); + srand (static_cast (time (nullptr))); std::vector colors; for (size_t i_segment = 0; i_segment < clusters_.size (); i_segment++) { diff --git a/segmentation/include/pcl/segmentation/impl/region_growing_rgb.hpp b/segmentation/include/pcl/segmentation/impl/region_growing_rgb.hpp index 2d47662f42d..1c7ae075fb9 100644 --- a/segmentation/include/pcl/segmentation/impl/region_growing_rgb.hpp +++ b/segmentation/include/pcl/segmentation/impl/region_growing_rgb.hpp @@ -225,7 +225,7 @@ pcl::RegionGrowingRGB::prepareForSegmentation () if (normal_flag_) { // if user forgot to pass normals or the sizes of point and normal cloud are different - if ( normals_ == 0 || input_->points.size () != normals_->points.size () ) + if ( normals_ == nullptr || input_->points.size () != normals_->points.size () ) return (false); } diff --git a/segmentation/include/pcl/segmentation/impl/seeded_hue_segmentation.hpp b/segmentation/include/pcl/segmentation/impl/seeded_hue_segmentation.hpp index fc8a83cfb8c..8a9e7ec4fdf 100644 --- a/segmentation/include/pcl/segmentation/impl/seeded_hue_segmentation.hpp +++ b/segmentation/include/pcl/segmentation/impl/seeded_hue_segmentation.hpp @@ -197,8 +197,8 @@ void pcl::SeededHueSegmentation::segment (PointIndices &indices_in, PointIndices &indices_out) { if (!initCompute () || - (input_ != 0 && input_->points.empty ()) || - (indices_ != 0 && indices_->empty ())) + (input_ != nullptr && input_->points.empty ()) || + (indices_ != nullptr && indices_->empty ())) { indices_out.indices.clear (); return; diff --git a/segmentation/include/pcl/segmentation/impl/supervoxel_clustering.hpp b/segmentation/include/pcl/segmentation/impl/supervoxel_clustering.hpp index 156f10d8ccd..28f6c908309 100644 --- a/segmentation/include/pcl/segmentation/impl/supervoxel_clustering.hpp +++ b/segmentation/include/pcl/segmentation/impl/supervoxel_clustering.hpp @@ -246,7 +246,7 @@ pcl::SupervoxelClustering::computeVoxelData () { VoxelData& voxel_data = (*leaf_itr)->getData (); voxel_data.normal_.normalize (); - voxel_data.owner_ = 0; + voxel_data.owner_ = nullptr; voxel_data.distance_ = std::numeric_limits::max (); //Get the number of points in this leaf int num_points = (*leaf_itr)->getPointCounter (); @@ -280,7 +280,7 @@ pcl::SupervoxelClustering::computeVoxelData () pcl::flipNormalTowardsViewpoint (voxel_centroid_cloud_->points[new_voxel_data.idx_], 0.0f,0.0f,0.0f, new_voxel_data.normal_); new_voxel_data.normal_[3] = 0.0f; new_voxel_data.normal_.normalize (); - new_voxel_data.owner_ = 0; + new_voxel_data.owner_ = nullptr; new_voxel_data.distance_ = std::numeric_limits::max (); } } @@ -384,7 +384,7 @@ pcl::SupervoxelClustering::selectInitialSupervoxelSeeds (std::vector distance; closest_index.resize(1,0); distance.resize(1,0); - if (voxel_kdtree_ == 0) + if (voxel_kdtree_ == nullptr) { voxel_kdtree_.reset (new pcl::search::KdTree); voxel_kdtree_ ->setInputCloud (voxel_centroid_cloud_); @@ -781,7 +781,7 @@ pcl::SupervoxelClustering::SupervoxelHelper::removeAllLeaves () for (auto leaf_itr = leaves_.cbegin (); leaf_itr != leaves_.cend (); ++leaf_itr) { VoxelData& voxel = ((*leaf_itr)->getData ()); - voxel.owner_ = 0; + voxel.owner_ = nullptr; voxel.distance_ = std::numeric_limits::max (); } leaves_.clear (); diff --git a/segmentation/include/pcl/segmentation/impl/unary_classifier.hpp b/segmentation/include/pcl/segmentation/impl/unary_classifier.hpp index 410ff06f314..e751fc56b7c 100644 --- a/segmentation/include/pcl/segmentation/impl/unary_classifier.hpp +++ b/segmentation/include/pcl/segmentation/impl/unary_classifier.hpp @@ -68,7 +68,7 @@ pcl::UnaryClassifier::~UnaryClassifier () template void pcl::UnaryClassifier::setInputCloud (typename pcl::PointCloud::Ptr input_cloud) { - if (input_cloud_ != NULL) + if (input_cloud_ != nullptr) input_cloud_.reset (); input_cloud_ = input_cloud; diff --git a/segmentation/include/pcl/segmentation/supervoxel_clustering.h b/segmentation/include/pcl/segmentation/supervoxel_clustering.h index e00b76cfb88..d0cceedd73b 100644 --- a/segmentation/include/pcl/segmentation/supervoxel_clustering.h +++ b/segmentation/include/pcl/segmentation/supervoxel_clustering.h @@ -138,7 +138,7 @@ namespace pcl rgb_ (0.0f, 0.0f, 0.0f), normal_ (0.0f, 0.0f, 0.0f, 0.0f), curvature_ (0.0f), - owner_ (0) + owner_ (nullptr) {} /** \brief Gets the data of in the form of a point From 21e81a03a48404a9e8b9d6c362ecf6649e99a0e8 Mon Sep 17 00:00:00 2001 From: Heiko Thiel Date: Sat, 20 Apr 2019 16:59:40 +0200 Subject: [PATCH 2/2] * It's not necessary to call reset manually on a shared_ptr in a destructor * Remove unnecessary reset call to boost::shared_ptr before assigning a new value --- .../pcl/segmentation/impl/crf_segmentation.hpp | 9 --------- .../pcl/segmentation/impl/extract_clusters.hpp | 4 ++-- .../segmentation/impl/extract_labeled_clusters.hpp | 4 ++-- .../pcl/segmentation/impl/min_cut_segmentation.hpp | 14 +------------- .../pcl/segmentation/impl/region_growing.hpp | 13 +------------ .../pcl/segmentation/impl/region_growing_rgb.hpp | 2 +- .../segmentation/impl/seeded_hue_segmentation.hpp | 4 ++-- .../segmentation/impl/supervoxel_clustering.hpp | 2 +- .../pcl/segmentation/impl/unary_classifier.hpp | 3 --- 9 files changed, 10 insertions(+), 45 deletions(-) diff --git a/segmentation/include/pcl/segmentation/impl/crf_segmentation.hpp b/segmentation/include/pcl/segmentation/impl/crf_segmentation.hpp index 37dd0b46d9f..9275d7de5d8 100644 --- a/segmentation/include/pcl/segmentation/impl/crf_segmentation.hpp +++ b/segmentation/include/pcl/segmentation/impl/crf_segmentation.hpp @@ -71,9 +71,6 @@ pcl::CrfSegmentation::~CrfSegmentation () template void pcl::CrfSegmentation::setInputCloud (typename pcl::PointCloud::Ptr input_cloud) { - if (input_cloud_ != nullptr) - input_cloud_.reset (); - input_cloud_ = input_cloud; } @@ -81,9 +78,6 @@ pcl::CrfSegmentation::setInputCloud (typename pcl::PointCloud::P template void pcl::CrfSegmentation::setAnnotatedCloud (typename pcl::PointCloud::Ptr anno_cloud) { - if (anno_cloud_ != nullptr) - anno_cloud_.reset (); - anno_cloud_ = anno_cloud; } @@ -91,9 +85,6 @@ pcl::CrfSegmentation::setAnnotatedCloud (typename pcl::PointCloud void pcl::CrfSegmentation::setNormalCloud (typename pcl::PointCloud::Ptr normal_cloud) { - if (normal_cloud_ != nullptr) - normal_cloud_.reset (); - normal_cloud_ = normal_cloud; } diff --git a/segmentation/include/pcl/segmentation/impl/extract_clusters.hpp b/segmentation/include/pcl/segmentation/impl/extract_clusters.hpp index 7114dd9d0c5..a153651572a 100644 --- a/segmentation/include/pcl/segmentation/impl/extract_clusters.hpp +++ b/segmentation/include/pcl/segmentation/impl/extract_clusters.hpp @@ -210,8 +210,8 @@ template void pcl::EuclideanClusterExtraction::extract (std::vector &clusters) { if (!initCompute () || - (input_ != nullptr && input_->points.empty ()) || - (indices_ != nullptr && indices_->empty ())) + (input_ && input_->points.empty ()) || + (indices_ && indices_->empty ())) { clusters.clear (); return; diff --git a/segmentation/include/pcl/segmentation/impl/extract_labeled_clusters.hpp b/segmentation/include/pcl/segmentation/impl/extract_labeled_clusters.hpp index 26533809f89..c984e181fde 100644 --- a/segmentation/include/pcl/segmentation/impl/extract_labeled_clusters.hpp +++ b/segmentation/include/pcl/segmentation/impl/extract_labeled_clusters.hpp @@ -123,8 +123,8 @@ template void pcl::LabeledEuclideanClusterExtraction::extract (std::vector > &labeled_clusters) { if (!initCompute () || - (input_ != nullptr && input_->points.empty ()) || - (indices_ != nullptr && indices_->empty ())) + (input_ && input_->points.empty ()) || + (indices_ && indices_->empty ())) { labeled_clusters.clear (); return; diff --git a/segmentation/include/pcl/segmentation/impl/min_cut_segmentation.hpp b/segmentation/include/pcl/segmentation/impl/min_cut_segmentation.hpp index afb202306da..8a46ca718e4 100644 --- a/segmentation/include/pcl/segmentation/impl/min_cut_segmentation.hpp +++ b/segmentation/include/pcl/segmentation/impl/min_cut_segmentation.hpp @@ -76,15 +76,6 @@ pcl::MinCutSegmentation::MinCutSegmentation () : template pcl::MinCutSegmentation::~MinCutSegmentation () { - if (search_ != nullptr) - search_.reset (); - if (graph_ != nullptr) - graph_.reset (); - if (capacity_ != nullptr) - capacity_.reset (); - if (reverse_edges_ != nullptr) - reverse_edges_.reset (); - foreground_points_.clear (); background_points_.clear (); clusters_.clear (); @@ -167,9 +158,6 @@ pcl::MinCutSegmentation::getSearchMethod () const template void pcl::MinCutSegmentation::setSearchMethod (const KdTreePtr& tree) { - if (search_ != nullptr) - search_.reset (); - search_ = tree; } @@ -327,7 +315,7 @@ pcl::MinCutSegmentation::buildGraph () if (input_->points.size () == 0 || number_of_points == 0 || foreground_points_.empty () == true ) return (false); - if (search_ == nullptr) + if (!search_) search_.reset (new pcl::search::KdTree); graph_.reset (new mGraph); diff --git a/segmentation/include/pcl/segmentation/impl/region_growing.hpp b/segmentation/include/pcl/segmentation/impl/region_growing.hpp index ac1d671b8fc..298e87b56f3 100644 --- a/segmentation/include/pcl/segmentation/impl/region_growing.hpp +++ b/segmentation/include/pcl/segmentation/impl/region_growing.hpp @@ -79,11 +79,6 @@ pcl::RegionGrowing::RegionGrowing () : template pcl::RegionGrowing::~RegionGrowing () { - if (search_ != nullptr) - search_.reset (); - if (normals_ != nullptr) - normals_.reset (); - point_neighbours_.clear (); point_labels_.clear (); num_pts_in_segment_.clear (); @@ -233,9 +228,6 @@ pcl::RegionGrowing::getSearchMethod () const template void pcl::RegionGrowing::setSearchMethod (const KdTreePtr& tree) { - if (search_ != nullptr) - search_.reset (); - search_ = tree; } @@ -250,9 +242,6 @@ pcl::RegionGrowing::getInputNormals () const template void pcl::RegionGrowing::setInputNormals (const NormalPtr& norm) { - if (normals_ != nullptr) - normals_.reset (); - normals_ = norm; } @@ -312,7 +301,7 @@ pcl::RegionGrowing::prepareForSegmentation () return (false); // if user forgot to pass normals or the sizes of point and normal cloud are different - if ( normals_ == nullptr || input_->points.size () != normals_->points.size () ) + if ( !normals_ || input_->points.size () != normals_->points.size () ) return (false); // if residual test is on then we need to check if all needed parameters were correctly initialized diff --git a/segmentation/include/pcl/segmentation/impl/region_growing_rgb.hpp b/segmentation/include/pcl/segmentation/impl/region_growing_rgb.hpp index 1c7ae075fb9..7fd12c1a0fc 100644 --- a/segmentation/include/pcl/segmentation/impl/region_growing_rgb.hpp +++ b/segmentation/include/pcl/segmentation/impl/region_growing_rgb.hpp @@ -225,7 +225,7 @@ pcl::RegionGrowingRGB::prepareForSegmentation () if (normal_flag_) { // if user forgot to pass normals or the sizes of point and normal cloud are different - if ( normals_ == nullptr || input_->points.size () != normals_->points.size () ) + if ( !normals_ || input_->points.size () != normals_->points.size () ) return (false); } diff --git a/segmentation/include/pcl/segmentation/impl/seeded_hue_segmentation.hpp b/segmentation/include/pcl/segmentation/impl/seeded_hue_segmentation.hpp index 8a9e7ec4fdf..72a875021a5 100644 --- a/segmentation/include/pcl/segmentation/impl/seeded_hue_segmentation.hpp +++ b/segmentation/include/pcl/segmentation/impl/seeded_hue_segmentation.hpp @@ -197,8 +197,8 @@ void pcl::SeededHueSegmentation::segment (PointIndices &indices_in, PointIndices &indices_out) { if (!initCompute () || - (input_ != nullptr && input_->points.empty ()) || - (indices_ != nullptr && indices_->empty ())) + (input_ && input_->points.empty ()) || + (indices_ && indices_->empty ())) { indices_out.indices.clear (); return; diff --git a/segmentation/include/pcl/segmentation/impl/supervoxel_clustering.hpp b/segmentation/include/pcl/segmentation/impl/supervoxel_clustering.hpp index 28f6c908309..bbcc1c4c094 100644 --- a/segmentation/include/pcl/segmentation/impl/supervoxel_clustering.hpp +++ b/segmentation/include/pcl/segmentation/impl/supervoxel_clustering.hpp @@ -384,7 +384,7 @@ pcl::SupervoxelClustering::selectInitialSupervoxelSeeds (std::vector distance; closest_index.resize(1,0); distance.resize(1,0); - if (voxel_kdtree_ == nullptr) + if (!voxel_kdtree_) { voxel_kdtree_.reset (new pcl::search::KdTree); voxel_kdtree_ ->setInputCloud (voxel_centroid_cloud_); diff --git a/segmentation/include/pcl/segmentation/impl/unary_classifier.hpp b/segmentation/include/pcl/segmentation/impl/unary_classifier.hpp index e751fc56b7c..78b37d72bbd 100644 --- a/segmentation/include/pcl/segmentation/impl/unary_classifier.hpp +++ b/segmentation/include/pcl/segmentation/impl/unary_classifier.hpp @@ -68,9 +68,6 @@ pcl::UnaryClassifier::~UnaryClassifier () template void pcl::UnaryClassifier::setInputCloud (typename pcl::PointCloud::Ptr input_cloud) { - if (input_cloud_ != nullptr) - input_cloud_.reset (); - input_cloud_ = input_cloud; pcl::PointCloud point;