Skip to content

Commit

Permalink
* It's not necessary to call reset manually on a shared_ptr in a dest…
Browse files Browse the repository at this point in the history
…ructor

* Remove unnecessary reset call to boost::shared_ptr before assigning a new value
  • Loading branch information
Heiko Thiel committed Apr 23, 2019
1 parent b72e9ee commit 21e81a0
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,29 +71,20 @@ pcl::CrfSegmentation<PointT>::~CrfSegmentation ()
template <typename PointT> void
pcl::CrfSegmentation<PointT>::setInputCloud (typename pcl::PointCloud<PointT>::Ptr input_cloud)
{
if (input_cloud_ != nullptr)
input_cloud_.reset ();

input_cloud_ = input_cloud;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::CrfSegmentation<PointT>::setAnnotatedCloud (typename pcl::PointCloud<pcl::PointXYZRGBL>::Ptr anno_cloud)
{
if (anno_cloud_ != nullptr)
anno_cloud_.reset ();

anno_cloud_ = anno_cloud;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::CrfSegmentation<PointT>::setNormalCloud (typename pcl::PointCloud<pcl::PointNormal>::Ptr normal_cloud)
{
if (normal_cloud_ != nullptr)
normal_cloud_.reset ();

normal_cloud_ = normal_cloud;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ template <typename PointT> void
pcl::EuclideanClusterExtraction<PointT>::extract (std::vector<PointIndices> &clusters)
{
if (!initCompute () ||
(input_ != nullptr && input_->points.empty ()) ||
(indices_ != nullptr && indices_->empty ()))
(input_ && input_->points.empty ()) ||
(indices_ && indices_->empty ()))
{
clusters.clear ();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ template <typename PointT> void
pcl::LabeledEuclideanClusterExtraction<PointT>::extract (std::vector<std::vector<PointIndices> > &labeled_clusters)
{
if (!initCompute () ||
(input_ != nullptr && input_->points.empty ()) ||
(indices_ != nullptr && indices_->empty ()))
(input_ && input_->points.empty ()) ||
(indices_ && indices_->empty ()))
{
labeled_clusters.clear ();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,6 @@ pcl::MinCutSegmentation<PointT>::MinCutSegmentation () :
template <typename PointT>
pcl::MinCutSegmentation<PointT>::~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 ();
Expand Down Expand Up @@ -167,9 +158,6 @@ pcl::MinCutSegmentation<PointT>::getSearchMethod () const
template <typename PointT> void
pcl::MinCutSegmentation<PointT>::setSearchMethod (const KdTreePtr& tree)
{
if (search_ != nullptr)
search_.reset ();

search_ = tree;
}

Expand Down Expand Up @@ -327,7 +315,7 @@ pcl::MinCutSegmentation<PointT>::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<PointT>);

graph_.reset (new mGraph);
Expand Down
13 changes: 1 addition & 12 deletions segmentation/include/pcl/segmentation/impl/region_growing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ pcl::RegionGrowing<PointT, NormalT>::RegionGrowing () :
template <typename PointT, typename NormalT>
pcl::RegionGrowing<PointT, NormalT>::~RegionGrowing ()
{
if (search_ != nullptr)
search_.reset ();
if (normals_ != nullptr)
normals_.reset ();

point_neighbours_.clear ();
point_labels_.clear ();
num_pts_in_segment_.clear ();
Expand Down Expand Up @@ -233,9 +228,6 @@ pcl::RegionGrowing<PointT, NormalT>::getSearchMethod () const
template <typename PointT, typename NormalT> void
pcl::RegionGrowing<PointT, NormalT>::setSearchMethod (const KdTreePtr& tree)
{
if (search_ != nullptr)
search_.reset ();

search_ = tree;
}

Expand All @@ -250,9 +242,6 @@ pcl::RegionGrowing<PointT, NormalT>::getInputNormals () const
template <typename PointT, typename NormalT> void
pcl::RegionGrowing<PointT, NormalT>::setInputNormals (const NormalPtr& norm)
{
if (normals_ != nullptr)
normals_.reset ();

normals_ = norm;
}

Expand Down Expand Up @@ -312,7 +301,7 @@ pcl::RegionGrowing<PointT, NormalT>::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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ pcl::RegionGrowingRGB<PointT, NormalT>::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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ pcl::SupervoxelClustering<PointT>::selectInitialSupervoxelSeeds (std::vector<int
std::vector<float> distance;
closest_index.resize(1,0);
distance.resize(1,0);
if (voxel_kdtree_ == nullptr)
if (!voxel_kdtree_)
{
voxel_kdtree_.reset (new pcl::search::KdTree<PointT>);
voxel_kdtree_ ->setInputCloud (voxel_centroid_cloud_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ pcl::UnaryClassifier<PointT>::~UnaryClassifier ()
template <typename PointT> void
pcl::UnaryClassifier<PointT>::setInputCloud (typename pcl::PointCloud<PointT>::Ptr input_cloud)
{
if (input_cloud_ != nullptr)
input_cloud_.reset ();

input_cloud_ = input_cloud;

pcl::PointCloud <PointT> point;
Expand Down

0 comments on commit 21e81a0

Please sign in to comment.