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

Use range-based for loops with boost::filesystem::directory_iterator #3432

Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,16 @@ namespace pcl
//load views, poses and self-occlusions
std::vector < std::string > view_filenames;
int number_of_views = 0;
bf::directory_iterator end_itr;
for (bf::directory_iterator itr (trained_dir); itr != end_itr; ++itr)
for (const auto& dir_entry : bf::directory_iterator(trained_dir))
{
//check if its a directory, then get models in it
if (!(bf::is_directory (*itr)))
if (!(bf::is_directory (dir_entry)))
{
//check that it is a ply file and then add, otherwise ignore..
std::vector < std::string > strs;
std::vector < std::string > strs_;

std::string file = (itr->path ().filename ()).string();
std::string file = (dir_entry.path ().filename ()).string();

boost::split (strs, file, boost::is_any_of ("."));
boost::split (strs_, file, boost::is_any_of ("_"));
Expand All @@ -125,7 +124,7 @@ namespace pcl

if (extension == "pcd" && strs_[0] == "view")
{
view_filenames.push_back ((itr->path ().filename ()).string());
view_filenames.push_back ((dir_entry.path ().filename ()).string());

number_of_views++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,14 @@ namespace pcl
getViewsFilenames (bf::path & path_with_views, std::vector<std::string> & view_filenames)
{
int number_of_views = 0;
bf::directory_iterator end_itr;
for (bf::directory_iterator itr (path_with_views); itr != end_itr; ++itr)
for (const auto& dir_entry : bf::directory_iterator(path_with_views))
{
if (!(bf::is_directory (*itr)))
if (!(bf::is_directory (dir_entry)))
{
std::vector < std::string > strs;
std::vector < std::string > strs_;

std::string file = (itr->path ().filename ()).string();
std::string file = (dir_entry.path ().filename ()).string();

boost::split (strs, file, boost::is_any_of ("."));
boost::split (strs_, file, boost::is_any_of ("_"));
Expand All @@ -82,7 +81,7 @@ namespace pcl

if (extension == "pcd" && (strs_[0].compare (view_prefix_) == 0))
{
view_filenames.push_back ((itr->path ().filename ()).string());
view_filenames.push_back ((dir_entry.path ().filename ()).string());

number_of_views++;
}
Expand Down Expand Up @@ -116,8 +115,7 @@ namespace pcl
//load views and poses
std::vector < std::string > view_filenames;
int number_of_views = 0;
bf::directory_iterator end_itr;
for (bf::directory_iterator itr (trained_dir); itr != end_itr; ++itr)
for (const auto& dir_entry : bf::directory_iterator(trained_dir))
{
//check if its a directory, then get models in it
if (!(bf::is_directory (*itr)))
Expand All @@ -126,7 +124,7 @@ namespace pcl
std::vector < std::string > strs;
std::vector < std::string > strs_;

std::string file = (itr->path ().filename ()).string();
std::string file = (dir_entry.path ().filename ()).string();

boost::split (strs, file, boost::is_any_of ("."));
boost::split (strs_, file, boost::is_any_of ("_"));
Expand All @@ -135,7 +133,7 @@ namespace pcl

if (extension == "pcd" && strs_[0] == "view")
{
view_filenames.push_back ((itr->path ().filename ()).string());
view_filenames.push_back ((dir_entry.path ().filename ()).string());
number_of_views++;
}
}
Expand Down Expand Up @@ -256,11 +254,10 @@ namespace pcl
bool
isleafDirectory (bf::path & path)
{
bf::directory_iterator end_itr;
bool no_dirs_inside = true;
for (bf::directory_iterator itr (path); itr != end_itr; ++itr)
for (const auto& dir_entry : bf::directory_iterator(path))
{
if (bf::is_directory (*itr))
if (bf::is_directory (dir_entry))
{
no_dirs_inside = false;
}
Expand All @@ -272,18 +269,17 @@ namespace pcl
void
getModelsInDirectory (bf::path & dir, std::string & rel_path_so_far, std::vector<std::string> & relative_paths)
{
bf::directory_iterator end_itr;
for (bf::directory_iterator itr (dir); itr != end_itr; ++itr)
for (const auto& dir_entry : bf::directory_iterator(dir))
{
//check if its a directory, then get models in it
if (bf::is_directory (*itr))
if (bf::is_directory (dir_entry))
{
std::string so_far = rel_path_so_far + (itr->path ().filename ()).string() + "/";
bf::path curr_path = itr->path ();
std::string so_far = rel_path_so_far + (dir_entry.path ().filename ()).string() + "/";
bf::path curr_path = dir_entry.path ();

if (isleafDirectory (curr_path))
{
std::string path = rel_path_so_far + (itr->path ().filename ()).string();
std::string path = rel_path_so_far + (dir_entry.path ().filename ()).string();
relative_paths.push_back (path);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,29 +168,28 @@ namespace pcl
void
getModelsInDirectory (bf::path & dir, std::string & rel_path_so_far, std::vector<std::string> & relative_paths, std::string & ext)
{
bf::directory_iterator end_itr;
for (bf::directory_iterator itr (dir); itr != end_itr; ++itr)
for (const auto& dir_entry : bf::directory_iterator(dir))
{
//check if its a directory, then get models in it
if (bf::is_directory (*itr))
if (bf::is_directory (dir_entry))
{
std::string so_far = rel_path_so_far + (itr->path ().filename ()).string() + "/";
std::string so_far = rel_path_so_far + (dir_entry.path ().filename ()).string() + "/";

bf::path curr_path = itr->path ();
bf::path curr_path = dir_entry.path ();
getModelsInDirectory (curr_path, so_far, relative_paths, ext);
}
else
{
//check that it is a ply file and then add, otherwise ignore..
std::vector < std::string > strs;
std::string file = (itr->path ().filename ()).string();
std::string file = (dir_entry.path ().filename ()).string();

boost::split (strs, file, boost::is_any_of ("."));
std::string extension = strs[strs.size () - 1];

if (extension == ext)
{
std::string path = rel_path_so_far + (itr->path ().filename ()).string();
std::string path = rel_path_so_far + (dir_entry.path ().filename ()).string();

relative_paths.push_back (path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@ template<template<class > class Distance, typename PointInT, typename FeatureT>
for (size_t i = 0; i < models->size (); i++)
{
std::string path = source_->getModelDescriptorDir (models->at (i), training_dir_, descr_name_);
bf::path inside = path;
bf::directory_iterator end_itr;

for (bf::directory_iterator itr_in (inside); itr_in != end_itr; ++itr_in)
for (const auto& dir_entry : bf::directory_iterator(path))
{
std::string file_name = (itr_in->path ().filename ()).string();
std::string file_name = (dir_entry.path ().filename ()).string();

std::vector < std::string > strs;
boost::split (strs, file_name, boost::is_any_of ("_"));

if (strs[0] == "descriptor")
{
std::string full_file_name = itr_in->path ().string ();
std::string full_file_name = dir_entry.path ().string ();
std::vector < std::string > strs;
boost::split (strs, full_file_name, boost::is_any_of ("/"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,10 @@ template<template<class > class Distance, typename PointInT, typename FeatureT>
for (size_t i = 0; i < models->size (); i++)
{
std::string path = source_->getModelDescriptorDir (models->at (i), training_dir_, descr_name_);
bf::path inside = path;
bf::directory_iterator end_itr;

for (bf::directory_iterator itr_in (inside); itr_in != end_itr; ++itr_in)
for (const auto& dir_entry : bf::directory_iterator(path))
{
std::string file_name = (itr_in->path ().filename ()).string();
std::string file_name = (dir_entry.path ().filename ()).string();

std::vector < std::string > strs;
boost::split (strs, file_name, boost::is_any_of ("_"));
Expand All @@ -105,7 +103,7 @@ template<template<class > class Distance, typename PointInT, typename FeatureT>
boost::split (strs1, strs[2], boost::is_any_of ("."));
int descriptor_id = atoi (strs1[0].c_str ());

std::string full_file_name = itr_in->path ().string ();
std::string full_file_name = dir_entry.path ().string ();
typename pcl::PointCloud<FeatureT>::Ptr signature (new pcl::PointCloud<FeatureT>);
pcl::io::loadPCDFile (full_file_name, *signature);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,10 @@ template<template<class > class Distance, typename PointInT, typename FeatureT>
for (size_t i = 0; i < models->size (); i++)
{
std::string path = source_->getModelDescriptorDir (models->at (i), training_dir_, descr_name_);
bf::path inside = path;
bf::directory_iterator end_itr;

for (bf::directory_iterator itr_in (inside); itr_in != end_itr; ++itr_in)
for (const auto& dir_entry : bf::directory_iterator(path))
{
std::string file_name = (itr_in->path ().filename ()).string();
std::string file_name = (dir_entry.path ().filename ()).string();

std::vector < std::string > strs;
boost::split (strs, file_name, boost::is_any_of ("_"));
Expand All @@ -128,7 +126,7 @@ template<template<class > class Distance, typename PointInT, typename FeatureT>
boost::split (strs1, strs[2], boost::is_any_of ("."));
int descriptor_id = atoi (strs1[0].c_str ());

std::string full_file_name = itr_in->path ().string ();
std::string full_file_name = dir_entry.path ().string ();
typename pcl::PointCloud<FeatureT>::Ptr signature (new pcl::PointCloud<FeatureT>);
pcl::io::loadPCDFile (full_file_name, *signature);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,17 @@ template<template<class > class Distance, typename PointInT, typename FeatureT>
for (size_t i = 0; i < models->size (); i++)
{
std::string path = source_->getModelDescriptorDir (models->at (i), training_dir_, descr_name_);
bf::path inside = path;
bf::directory_iterator end_itr;

for (bf::directory_iterator itr_in (inside); itr_in != end_itr; ++itr_in)
for (const auto& dir_entry : bf::directory_iterator(path))
{
std::string file_name = (itr_in->path ().filename ()).string();
std::string file_name = (dir_entry.path ().filename ()).string();

std::vector < std::string > strs;
boost::split (strs, file_name, boost::is_any_of ("_"));

if (strs[0] == "descriptor")
{
std::string full_file_name = itr_in->path ().string ();
std::string full_file_name = dir_entry.path ().string ();
std::string name = file_name.substr (0, file_name.length () - 4);
std::vector < std::string > strs;
boost::split (strs, name, boost::is_any_of ("_"));
Expand Down
26 changes: 12 additions & 14 deletions apps/3d_rec_framework/src/tools/local_recognition_mian_dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,27 @@ void
getScenesInDirectory (bf::path & dir, std::string & rel_path_so_far, std::vector<std::string> & relative_paths)
{
//list models in MODEL_FILES_DIR_ and return list
bf::directory_iterator end_itr;
for (bf::directory_iterator itr (dir); itr != end_itr; ++itr)
for (const auto& dir_entry : bf::directory_iterator(dir))
{
//check if its a directory, then get models in it
if (bf::is_directory (*itr))
if (bf::is_directory (dir_entry))
{
std::string so_far = rel_path_so_far + (itr->path ().filename ()).string() + "/";
bf::path curr_path = itr->path ();
std::string so_far = rel_path_so_far + (dir_entry.path ().filename ()).string() + "/";
bf::path curr_path = dir_entry.path ();
getScenesInDirectory (curr_path, so_far, relative_paths);
}
else
{
//check that it is a ply file and then add, otherwise ignore..
std::vector < std::string > strs;
std::string file = (itr->path ().filename ()).string();
std::string file = (dir_entry.path ().filename ()).string();

boost::split (strs, file, boost::is_any_of ("."));
std::string extension = strs[strs.size () - 1];

if (extension == "pcd")
{
std::string path = rel_path_so_far + (itr->path ().filename ()).string();
std::string path = rel_path_so_far + (dir_entry.path ().filename ()).string();
relative_paths.push_back (path);
}
}
Expand Down Expand Up @@ -243,29 +242,28 @@ template<template<class > class DistT, typename PointT, typename FeatureT>
void
getModelsInDirectory (bf::path & dir, std::string & rel_path_so_far, std::vector<std::string> & relative_paths, std::string & ext)
{
bf::directory_iterator end_itr;
for (bf::directory_iterator itr (dir); itr != end_itr; ++itr)
for (const auto& dir_entry : bf::directory_iterator(dir))
{
//check if its a directory, then get models in it
if (bf::is_directory (*itr))
if (bf::is_directory (dir_entry))
{
std::string so_far = rel_path_so_far + (itr->path ().filename ()).string() + "/";
std::string so_far = rel_path_so_far + (dir_entry.path ().filename ()).string() + "/";

bf::path curr_path = itr->path ();
bf::path curr_path = dir_entry.path ();
getModelsInDirectory (curr_path, so_far, relative_paths, ext);
}
else
{
//check that it is a ply file and then add, otherwise ignore..
std::vector < std::string > strs;
std::string file = (itr->path ().filename ()).string();
std::string file = (dir_entry.path ().filename ()).string();

boost::split (strs, file, boost::is_any_of ("."));
std::string extension = strs[strs.size () - 1];

if (extension == ext)
{
std::string path = rel_path_so_far + (itr->path ().filename ()).string();
std::string path = rel_path_so_far + (dir_entry.path ().filename ()).string();

relative_paths.push_back (path);
}
Expand Down
17 changes: 6 additions & 11 deletions apps/include/pcl/apps/face_detection/face_detection_apps_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,31 +67,26 @@ namespace face_detection_apps_utils
inline
void getFilesInDirectory(bf::path & dir, std::string & rel_path_so_far, std::vector<std::string> & relative_paths, std::string & ext)
{
bf::directory_iterator end_itr;
for (bf::directory_iterator itr (dir); itr != end_itr; ++itr)
for (const auto& dir_entry : bf::directory_iterator(dir))
{
//check if its a directory, then get models in it
if (bf::is_directory (*itr))
if (bf::is_directory (dir_entry))
{
#if BOOST_FILESYSTEM_VERSION == 3
std::string so_far = rel_path_so_far + (itr->path().filename()).string() + "/";
#else
std::string so_far = rel_path_so_far + (itr->path ()).filename () + "/";
#endif
std::string so_far = rel_path_so_far + (dir_entry.path().filename()).string() + "/";

bf::path curr_path = itr->path ();
bf::path curr_path = dir_entry.path ();
getFilesInDirectory (curr_path, so_far, relative_paths, ext);
} else
{
//check that it is a ply file and then add, otherwise ignore..
std::vector < std::string > strs;
std::string file = (itr->path().filename()).string();
std::string file = (dir_entry.path().filename()).string();
boost::split (strs, file, boost::is_any_of ("."));
std::string extension = strs[strs.size () - 1];

if (extension == ext)
{
std::string path = rel_path_so_far + (itr->path().filename()).string();
std::string path = rel_path_so_far + (dir_entry.path().filename()).string();
relative_paths.push_back (path);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,24 @@ namespace bf = boost::filesystem;
inline void
getModelsInDirectory (bf::path & dir, std::string & rel_path_so_far, std::vector<std::string> & relative_paths)
{
bf::directory_iterator end_itr;
for (bf::directory_iterator itr (dir); itr != end_itr; ++itr)
for (const auto& dir_entry : bf::directory_iterator(dir))
{
//check if its a directory, then get models in it
if (bf::is_directory (*itr))
if (bf::is_directory (dir_entry))
{
std::string so_far = rel_path_so_far + itr->path ().filename ().string () + "/";
bf::path curr_path = itr->path ();
std::string so_far = rel_path_so_far + dir_entry.path ().filename ().string () + "/";
bf::path curr_path = dir_entry.path ();
getModelsInDirectory (curr_path, so_far, relative_paths);
}
else
{
std::vector<std::string> strs;
std::string file = itr->path ().filename ().string ();
std::string file = dir_entry.path ().filename ().string ();
boost::split (strs, file, boost::is_any_of ("."));
std::string extension = strs[strs.size () - 1];

if((file.compare (0, 3, "raw") == 0) && extension == "pcd") {
std::string path = rel_path_so_far + itr->path ().filename ().string ();
std::string path = rel_path_so_far + dir_entry.path ().filename ().string ();
relative_paths.push_back (path);
}
}
Expand Down
Loading