Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transform classic loops to range-based for loops in tools #2850

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tools/compute_hausdorff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ compute (Cloud &cloud_a, Cloud &cloud_b)
pcl::search::KdTree<PointType> tree_b;
tree_b.setInputCloud (cloud_b.makeShared ());
float max_dist_a = -std::numeric_limits<float>::max ();
for (size_t i = 0; i < cloud_a.points.size (); ++i)
for (const auto &point : cloud_a.points)
{
std::vector<int> indices (1);
std::vector<float> sqr_distances (1);

tree_b.nearestKSearch (cloud_a.points[i], 1, indices, sqr_distances);
tree_b.nearestKSearch (point, 1, indices, sqr_distances);
if (sqr_distances[0] > max_dist_a)
max_dist_a = sqr_distances[0];
}
Expand All @@ -102,12 +102,12 @@ compute (Cloud &cloud_a, Cloud &cloud_b)
pcl::search::KdTree<PointType> tree_a;
tree_a.setInputCloud (cloud_a.makeShared ());
float max_dist_b = -std::numeric_limits<float>::max ();
for (size_t i = 0; i < cloud_b.points.size (); ++i)
for (const auto &point : cloud_b.points)
{
std::vector<int> indices (1);
std::vector<float> sqr_distances (1);

tree_a.nearestKSearch (cloud_b.points[i], 1, indices, sqr_distances);
tree_a.nearestKSearch (point, 1, indices, sqr_distances);
if (sqr_distances[0] > max_dist_b)
max_dist_b = sqr_distances[0];
}
Expand Down
4 changes: 2 additions & 2 deletions tools/concatenate_points_pcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ main (int argc, char** argv)

//pcl::PointCloud<pcl::PointXYZ> cloud_all;
pcl::PCLPointCloud2 cloud_all;
for (size_t i = 0; i < file_indices.size (); ++i)
for (const int &file_index : file_indices)
{
// Load the Point Cloud
pcl::PCLPointCloud2 cloud;
loadCloud (argv[file_indices[i]], cloud);
loadCloud (argv[file_index], cloud);
//pcl::PointCloud<pcl::PointXYZ> cloud;
//pcl::io::loadPCDFile (argv[file_indices[i]], cloud);
//cloud_all += cloud;
Expand Down
6 changes: 3 additions & 3 deletions tools/elch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ main (int argc, char **argv)
}
}

for (size_t i = 0; i < clouds.size (); i++)
for (const auto &cloud : clouds)
{
std::string result_filename (clouds[i].first);
std::string result_filename (cloud.first);
result_filename = result_filename.substr (result_filename.rfind ('/') + 1);
pcl::io::savePCDFileBinary (result_filename.c_str (), *(clouds[i].second));
pcl::io::savePCDFileBinary (result_filename.c_str (), *(cloud.second));
std::cout << "saving result to " << result_filename << std::endl;
}

Expand Down
6 changes: 3 additions & 3 deletions tools/grid_min.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,19 @@ batchProcess (const vector<string> &pcd_files, string &output_dir,
float resolution)
{
vector<string> st;
for (size_t i = 0; i < pcd_files.size (); ++i)
for (const auto &pcd_file : pcd_files)
{
// Load the first file
Cloud::Ptr cloud (new Cloud);
if (!loadCloud (pcd_files[i], *cloud))
if (!loadCloud (pcd_file, *cloud))
return (-1);

// Perform the feature estimation
Cloud output;
compute (cloud, output, resolution);

// Prepare output file name
string filename = pcd_files[i];
string filename = pcd_file;
boost::trim (filename);
boost::split (st, filename, boost::is_any_of ("/\\"), boost::token_compress_on);

Expand Down
6 changes: 3 additions & 3 deletions tools/icp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ main (int argc, char **argv)
pcl::registration::IncrementalRegistration<PointType> iicp;
iicp.setRegistration (icp);

for (size_t i = 0; i < pcd_indices.size (); i++)
for (const int &pcd_index : pcd_indices)
{
CloudPtr data (new Cloud);
if (pcl::io::loadPCDFile (argv[pcd_indices[i]], *data) == -1)
if (pcl::io::loadPCDFile (argv[pcd_index], *data) == -1)
{
std::cout << "Could not read file" << std::endl;
return -1;
Expand All @@ -111,7 +111,7 @@ main (int argc, char **argv)

std::cout << iicp.getAbsoluteTransform () << std::endl;

std::string result_filename (argv[pcd_indices[i]]);
std::string result_filename (argv[pcd_index]);
result_filename = result_filename.substr (result_filename.rfind ('/') + 1);
pcl::io::savePCDFileBinary (result_filename.c_str (), *tmp);
std::cout << "saving result to " << result_filename << std::endl;
Expand Down
7 changes: 3 additions & 4 deletions tools/linemod_detection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ main (int argc, char** argv)
line_rgbd.setDetectionThreshold (detect_thresh);

// Load the template LMT and PCD files
for (size_t i = 0; i < lmt_file_indices.size (); ++i)
for (const int &lmt_file_index : lmt_file_indices)
{
// Load the LMT file
std::string lmt_filename = argv[lmt_file_indices[i]];
std::string lmt_filename = argv[lmt_file_index];
line_rgbd.loadTemplates (lmt_filename);
}

Expand All @@ -106,9 +106,8 @@ main (int argc, char** argv)
std::vector<LineRGBD<PointXYZRGBA>::Detection> detections;
line_rgbd.detect (detections);

for (size_t i = 0; i < detections.size (); ++i)
for (const auto &d : detections)
{
const LineRGBD<PointXYZRGBA>::Detection & d = detections[i];
const BoundingBoxXYZ & bb = d.bounding_box;
print_info ("%lu %lu %f (%f %f %f) (%f %f %f)\n",
d.detection_id, d.template_id, d.response,
Expand Down
6 changes: 3 additions & 3 deletions tools/local_max.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,19 @@ batchProcess (const vector<string> &pcd_files, string &output_dir,
float radius)
{
vector<string> st;
for (size_t i = 0; i < pcd_files.size (); ++i)
for (const auto &pcd_file : pcd_files)
{
// Load the first file
Cloud::Ptr cloud (new Cloud);
if (!loadCloud (pcd_files[i], *cloud))
if (!loadCloud (pcd_file, *cloud))
return (-1);

// Perform the feature estimation
Cloud output;
compute (cloud, output, radius);

// Prepare output file name
string filename = pcd_files[i];
string filename = pcd_file;
boost::trim (filename);
boost::split (st, filename, boost::is_any_of ("/\\"), boost::token_compress_on);

Expand Down
4 changes: 2 additions & 2 deletions tools/mesh2pcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ main (int argc, char **argv)

// Fuse clouds
PointCloud<PointXYZ>::Ptr big_boy (new PointCloud<PointXYZ> ());
for (size_t i = 0; i < aligned_clouds.size (); i++)
*big_boy += *aligned_clouds[i];
for (const auto &aligned_cloud : aligned_clouds)
*big_boy += *aligned_cloud;

if (vis_result)
{
Expand Down
6 changes: 3 additions & 3 deletions tools/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,19 @@ batchProcess (const vector<string> &pcd_files, string &output_dir,
float resolution, const std::string &method)
{
vector<string> st;
for (size_t i = 0; i < pcd_files.size (); ++i)
for (const auto &pcd_file : pcd_files)
{
// Load the first file
Cloud::Ptr cloud (new Cloud);
if (!loadCloud (pcd_files[i], *cloud))
if (!loadCloud (pcd_file, *cloud))
return (-1);

// Perform the feature estimation
Cloud output;
compute (cloud, output, resolution, method);

// Prepare output file name
string filename = pcd_files[i];
string filename = pcd_file;
boost::trim (filename);
boost::split (st, filename, boost::is_any_of ("/\\"), boost::token_compress_on);

Expand Down
8 changes: 4 additions & 4 deletions tools/obj_rec_ransac_accepted_hypotheses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,12 @@ update (CallbackParameters* params)

// Clear the visualizer
vtkRenderer *renderer = params->viz_.getRenderWindow ()->GetRenderers ()->GetFirstRenderer ();
for ( list<vtkActor*>::iterator it = params->actors_.begin () ; it != params->actors_.end () ; ++it )
renderer->RemoveActor (*it);
for (const auto &actor : params->actors_)
renderer->RemoveActor (actor);
params->actors_.clear ();

for ( list<vtkActor*>::iterator it = params->model_actors_.begin () ; it != params->model_actors_.end () ; ++it )
renderer->RemoveActor (*it);
for (const auto &model_actor : params->model_actors_)
renderer->RemoveActor (model_actor);
params->model_actors_.clear ();

params->viz_.removeAllShapes ();
Expand Down
10 changes: 5 additions & 5 deletions tools/obj_rec_ransac_model_opps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,16 @@ void showModelOpps (PCLVisualizer& viz, const ModelLibrary::HashTable& hash_tabl
// Get the opps in the current cell
const ModelLibrary::node_data_pair_list& data_pairs = res->second;

for ( ModelLibrary::node_data_pair_list::const_iterator dp = data_pairs.begin () ; dp != data_pairs.end () ; ++dp )
for (const auto &data_pair : data_pairs)
{
vtk_opps_points->InsertNextPoint (dp->first->getPoint ());
vtk_opps_points->InsertNextPoint (dp->second->getPoint ());
vtk_opps_points->InsertNextPoint (data_pair.first->getPoint ());
vtk_opps_points->InsertNextPoint (data_pair.second->getPoint ());
vtk_opps_lines->InsertNextCell (2, ids);
ids[0] += 2;
ids[1] += 2;
#ifndef _SHOW_MODEL_OCTREE_NORMALS_
vtk_normals->InsertNextTuple3 (dp->first->getNormal ()[0], dp->first->getNormal ()[1], dp->first->getNormal ()[2]);
vtk_normals->InsertNextTuple3 (dp->second->getNormal ()[0], dp->second->getNormal ()[1], dp->second->getNormal ()[2]);
vtk_normals->InsertNextTuple3 (data_pair.first->getNormal ()[0], data_pair.first->getNormal ()[1], data_pair.first->getNormal ()[2]);
vtk_normals->InsertNextTuple3 (data_pair.second->getNormal ()[0], data_pair.second->getNormal ()[1], data_pair.second->getNormal ()[2]);
#endif
}
}
Expand Down
8 changes: 4 additions & 4 deletions tools/obj_rec_ransac_orr_octree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ void updateViewer (ORROctree& octree, PCLVisualizer& viz, std::vector<ORROctree:
int i = 0;

// Show the cubes
for ( std::list<ORROctree::Node*>::iterator it = intersected_leaves.begin () ; it != intersected_leaves.end () ; ++it )
for (const auto &intersected_leave : intersected_leaves)
SunBlack marked this conversation as resolved.
Show resolved Hide resolved
{
sprintf(cube_id, "cube %i", ++i);
b = (*it)->getBounds ();
b = intersected_leave->getBounds ();
SunBlack marked this conversation as resolved.
Show resolved Hide resolved
viz.addCube (b[0], b[1], b[2], b[3], b[4], b[5], 1.0, 1.0, 0.0, cube_id);
}

Expand Down Expand Up @@ -320,9 +320,9 @@ void show_octree (ORROctree* octree, PCLVisualizer& viz, bool show_full_leaves_o
if ( show_full_leaves_only )
{
std::vector<ORROctree::Node*>& full_leaves = octree->getFullLeaves ();
for ( std::vector<ORROctree::Node*>::iterator it = full_leaves.begin () ; it != full_leaves.end () ; ++it )
for (auto &full_leave : full_leaves)
SunBlack marked this conversation as resolved.
Show resolved Hide resolved
// Add it to the other cubes
node_to_cube (*it, append);
node_to_cube (full_leave, append);
SunBlack marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions tools/obj_rec_ransac_orr_octree_zprojection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ void show_octree (ORROctree* octree, PCLVisualizer& viz)
cout << "There are " << octree->getFullLeaves ().size () << " full leaves.\n";

std::vector<ORROctree::Node*>& full_leaves = octree->getFullLeaves ();
for ( std::vector<ORROctree::Node*>::iterator it = full_leaves.begin () ; it != full_leaves.end () ; ++it )
for (auto &full_leave : full_leaves)
SunBlack marked this conversation as resolved.
Show resolved Hide resolved
// Add it to the other cubes
node_to_cube (*it, append);
node_to_cube (full_leave, append);
SunBlack marked this conversation as resolved.
Show resolved Hide resolved

// Save the result
append->Update();
Expand Down
10 changes: 5 additions & 5 deletions tools/obj_rec_ransac_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ run (float pair_width, float voxel_size, float max_coplanarity_angle)
list<vtkSmartPointer<vtkPolyData> > vtk_models_list;

// Load the models and add them to the recognizer
for ( list<string>::iterator it = model_names.begin () ; it != model_names.end () ; ++it )
for (auto &model_name : model_names)
SunBlack marked this conversation as resolved.
Show resolved Hide resolved
{
PointCloud<PointXYZ>::Ptr model_points (new PointCloud<PointXYZ> ());
model_points_list.push_back (model_points);
Expand All @@ -163,14 +163,14 @@ run (float pair_width, float voxel_size, float max_coplanarity_angle)
vtk_models_list.push_back (vtk_model);

// Compose the file
string file_name = string("../../test/") + *it + string (".vtk");
string file_name = string("../../test/") + model_name + string (".vtk");

// Get the points and normals from the input model
if ( !vtk2PointCloud (file_name.c_str (), *model_points, *model_normals, vtk_model) )
continue;

// Add the model
objrec.addModel (*model_points, *model_normals, *it, vtk_model);
objrec.addModel (*model_points, *model_normals, model_name, vtk_model);
}

// The scene in which the models are supposed to be recognized
Expand Down Expand Up @@ -241,8 +241,8 @@ update (CallbackParameters* params)
{
// Clear the visualizer from old object instances
vtkRenderer *renderer = params->viz_.getRenderWindow ()->GetRenderers ()->GetFirstRenderer ();
for ( list<vtkActor*>::iterator it = params->actors_.begin () ; it != params->actors_.end () ; ++it )
renderer->RemoveActor (*it);
for (auto &actor : params->actors_)
SergioRAgostinho marked this conversation as resolved.
Show resolved Hide resolved
renderer->RemoveActor (actor);
params->actors_.clear ();

// This will be the output of the recognition
Expand Down
10 changes: 5 additions & 5 deletions tools/obj_rec_ransac_scene_opps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ void update (CallbackParameters* params)
vtkIdType ids[2] = {0, 1};

// Insert the points and compute the lines
for ( list<ObjRecRANSAC::OrientedPointPair>::const_iterator it = opps.begin () ; it != opps.end () ; ++it )
for (const auto &opp : opps)
{
vtk_opps_points->SetPoint (ids[0], it->p1_[0], it->p1_[1], it->p1_[2]);
vtk_opps_points->SetPoint (ids[1], it->p2_[0], it->p2_[1], it->p2_[2]);
vtk_opps_points->SetPoint (ids[0], opp.p1_[0], opp.p1_[1], opp.p1_[2]);
vtk_opps_points->SetPoint (ids[1], opp.p2_[0], opp.p2_[1], opp.p2_[2]);
vtk_opps_lines->InsertNextCell (2, ids);

vtk_normals->SetTuple3 (ids[0], it->n1_[0], it->n1_[1], it->n1_[2]);
vtk_normals->SetTuple3 (ids[1], it->n2_[0], it->n2_[1], it->n2_[2]);
vtk_normals->SetTuple3 (ids[0], opp.n1_[0], opp.n1_[1], opp.n1_[2]);
vtk_normals->SetTuple3 (ids[1], opp.n2_[0], opp.n2_[1], opp.n2_[2]);

ids[0] += 2;
ids[1] += 2;
Expand Down
12 changes: 6 additions & 6 deletions tools/octree_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,11 @@ class OctreeViewer

// Create every cubes to be displayed
double s = voxelSideLen / 2.0;
for (size_t i = 0; i < cloudVoxel->points.size (); i++)
for (const auto &point : cloudVoxel->points)
{
double x = cloudVoxel->points[i].x;
double y = cloudVoxel->points[i].y;
double z = cloudVoxel->points[i].z;
double x = point.x;
double y = point.y;
double z = point.z;

vtkSmartPointer<vtkCubeSource> wk_cubeSource = vtkSmartPointer<vtkCubeSource>::New ();

Expand Down Expand Up @@ -402,9 +402,9 @@ class OctreeViewer

// Iterate over the leafs to compute the centroid of all of them
pcl::CentroidPoint<pcl::PointXYZ> centroid;
for (size_t j = 0; j < voxelCentroids.size (); ++j)
for (const auto &voxelCentroid : voxelCentroids)
{
centroid.add (voxelCentroids[j]);
centroid.add (voxelCentroid);
}
centroid.get (pt_centroid);
}
Expand Down
6 changes: 3 additions & 3 deletions tools/passthrough_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,19 @@ batchProcess (const vector<string> &pcd_files, string &output_dir,
const std::string &field_name, float min, float max, bool inside, bool keep_organized)
{
vector<string> st;
for (size_t i = 0; i < pcd_files.size (); ++i)
for (const auto &pcd_file : pcd_files)
{
// Load the first file
pcl::PCLPointCloud2::Ptr cloud (new pcl::PCLPointCloud2);
if (!loadCloud (pcd_files[i], *cloud))
if (!loadCloud (pcd_file, *cloud))
return (-1);

// Perform the feature estimation
pcl::PCLPointCloud2 output;
compute (cloud, output, field_name, min, max, inside, keep_organized);

// Prepare output file name
string filename = pcd_files[i];
string filename = pcd_file;
boost::trim (filename);
boost::split (st, filename, boost::is_any_of ("/\\"), boost::token_compress_on);

Expand Down
6 changes: 3 additions & 3 deletions tools/progressive_morphological_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,19 @@ int
batchProcess (const vector<string> &pcd_files, string &output_dir, int max_window_size, float slope, float max_distance, float initial_distance, float cell_size, float base, bool exponential, bool approximate)
{
vector<string> st;
for (size_t i = 0; i < pcd_files.size (); ++i)
for (const auto &pcd_file : pcd_files)
{
// Load the first file
Cloud::Ptr cloud (new Cloud);
if (!loadCloud (pcd_files[i], *cloud))
if (!loadCloud (pcd_file, *cloud))
return (-1);

// Perform the feature estimation
Cloud output;
compute (cloud, output, max_window_size, slope, max_distance, initial_distance, cell_size, base, exponential, approximate);

// Prepare output file name
string filename = pcd_files[i];
string filename = pcd_file;
boost::trim (filename);
boost::split (st, filename, boost::is_any_of ("/\\"), boost::token_compress_on);

Expand Down
Loading