Skip to content

Commit

Permalink
Transform classic loops to range-based for loops in module octree (#2847
Browse files Browse the repository at this point in the history
)

* Transform classic loops to range-based for loops in module octree

Changes are based on the result of run-clang-tidy -header-filter='.*' -checks='-*,modernize-loop-convert' -fix
Use always const reference in for-ranged loop instead of copying primitive data types
  • Loading branch information
SunBlack authored and SergioRAgostinho committed Mar 8, 2019
1 parent 7c26e97 commit 47b07f7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
14 changes: 7 additions & 7 deletions octree/include/pcl/octree/impl/octree_pointcloud.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ pcl::octree::OctreePointCloud<PointT, LeafContainerT, BranchContainerT, OctreeT>
{
if (indices_)
{
for (std::vector<int>::const_iterator current = indices_->begin (); current != indices_->end (); ++current)
for (const int &index : *indices_)
{
assert( (*current>=0) && (*current < static_cast<int> (input_->points.size ())));
assert( (index >= 0) && (index < static_cast<int> (input_->points.size ())));

if (isFinite (input_->points[*current]))
if (isFinite (input_->points[index]))
{
// add points to octree
this->addPointIdx (*current);
this->addPointIdx (index);
}
}
}
Expand Down Expand Up @@ -539,18 +539,18 @@ pcl::octree::OctreePointCloud<PointT, LeafContainerT, BranchContainerT, OctreeT>
// add data to new branch
OctreeKey new_index_key;

for (auto it = leafIndices.cbegin(), it_end = leafIndices.cend(); it!=it_end; ++it)
for (const int &leafIndex : leafIndices)
{

const PointT& point_from_index = input_->points[*it];
const PointT& point_from_index = input_->points[leafIndex];
// generate key
genOctreeKeyforPoint (point_from_index, new_index_key);

LeafNode* newLeaf;
BranchNode* newBranchParent;
this->createLeafRecursive (new_index_key, depth_mask, childBranch, newLeaf, newBranchParent);

(*newLeaf)->addPointIndex(*it);
(*newLeaf)->addPointIndex(leafIndex);
}
}

Expand Down
24 changes: 12 additions & 12 deletions octree/include/pcl/octree/impl/octree_search.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,10 @@ pcl::octree::OctreePointCloudSearch<PointT, LeafContainerT, BranchContainerT>::g
(*child_leaf)->getPointIndices (decoded_point_vector);

// Linearly iterate over all decoded (unsorted) points
for (size_t i = 0; i < decoded_point_vector.size (); i++)
for (const int &point_index : decoded_point_vector)
{

const PointT& candidate_point = this->getPointByIndex (decoded_point_vector[i]);
const PointT& candidate_point = this->getPointByIndex (point_index);

// calculate point distance to search point
float squared_dist = pointSquaredDist (candidate_point, point);
Expand All @@ -284,7 +284,7 @@ pcl::octree::OctreePointCloudSearch<PointT, LeafContainerT, BranchContainerT>::g
prioPointQueueEntry point_entry;

point_entry.point_distance_ = squared_dist;
point_entry.point_idx_ = decoded_point_vector[i];
point_entry.point_idx_ = point_index;
point_candidates.push_back (point_entry);
}
}
Expand Down Expand Up @@ -361,9 +361,9 @@ pcl::octree::OctreePointCloudSearch<PointT, LeafContainerT, BranchContainerT>::g
(*child_leaf)->getPointIndices (decoded_point_vector);

// Linearly iterate over all decoded (unsorted) points
for (size_t i = 0; i < decoded_point_vector.size (); i++)
for (const int &index : decoded_point_vector)
{
const PointT& candidate_point = this->getPointByIndex (decoded_point_vector[i]);
const PointT& candidate_point = this->getPointByIndex (index);

// calculate point distance to search point
squared_dist = pointSquaredDist (candidate_point, point);
Expand All @@ -373,7 +373,7 @@ pcl::octree::OctreePointCloudSearch<PointT, LeafContainerT, BranchContainerT>::g
continue;

// add point to result vector
k_indices.push_back (decoded_point_vector[i]);
k_indices.push_back (index);
k_sqr_distances.push_back (squared_dist);

if (max_nn != 0 && k_indices.size () == static_cast<unsigned int> (max_nn))
Expand Down Expand Up @@ -454,9 +454,9 @@ pcl::octree::OctreePointCloudSearch<PointT, LeafContainerT, BranchContainerT>::a
(**child_leaf).getPointIndices (decoded_point_vector);

// Linearly iterate over all decoded (unsorted) points
for (size_t i = 0; i < decoded_point_vector.size (); i++)
for (const int &index : decoded_point_vector)
{
const PointT& candidate_point = this->getPointByIndex (decoded_point_vector[i]);
const PointT& candidate_point = this->getPointByIndex (index);

// calculate point distance to search point
double squared_dist = pointSquaredDist (candidate_point, point);
Expand All @@ -465,7 +465,7 @@ pcl::octree::OctreePointCloudSearch<PointT, LeafContainerT, BranchContainerT>::a
if (squared_dist >= smallest_squared_dist)
continue;

result_index = decoded_point_vector[i];
result_index = index;
smallest_squared_dist = squared_dist;
sqr_distance = static_cast<float> (squared_dist);
}
Expand Down Expand Up @@ -535,9 +535,9 @@ pcl::octree::OctreePointCloudSearch<PointT, LeafContainerT, BranchContainerT>::b
(**child_leaf).getPointIndices (decoded_point_vector);

// Linearly iterate over all decoded (unsorted) points
for (size_t i = 0; i < decoded_point_vector.size (); i++)
for (const int &index : decoded_point_vector)
{
const PointT& candidate_point = this->getPointByIndex (decoded_point_vector[i]);
const PointT& candidate_point = this->getPointByIndex (index);

// check if point falls within search box
bInBox = ( (candidate_point.x >= min_pt (0)) && (candidate_point.x <= max_pt (0)) &&
Expand All @@ -546,7 +546,7 @@ pcl::octree::OctreePointCloudSearch<PointT, LeafContainerT, BranchContainerT>::b

if (bInBox)
// add to result vector
k_indices.push_back (decoded_point_vector[i]);
k_indices.push_back (index);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions octree/include/pcl/octree/octree_pointcloud_changedetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ namespace pcl
std::vector<OctreeContainerPointIndices*> leaf_containers;
this->serializeNewLeafs (leaf_containers);

for (auto it = leaf_containers.cbegin(), it_end = leaf_containers.cend(); it != it_end; ++it)
for (const auto &leaf_container : leaf_containers)
{
if (static_cast<int> ((*it)->getSize ()) >= minPointsPerLeaf_arg)
(*it)->getPointIndices(indicesVector_arg);
if (static_cast<int> (leaf_container->getSize ()) >= minPointsPerLeaf_arg)
leaf_container->getPointIndices(indicesVector_arg);
}

return (indicesVector_arg.size ());
Expand Down

0 comments on commit 47b07f7

Please sign in to comment.