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

Prefer lambdas over binds #3189

Merged
merged 6 commits into from
Jun 24, 2019
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
6 changes: 4 additions & 2 deletions people/apps/main_ground_based_people_detection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,10 @@ int main (int argc, char** argv)
PointCloudT::Ptr cloud (new PointCloudT);
bool new_cloud_available_flag = false;
pcl::Grabber* interface = new pcl::OpenNIGrabber();
std::function<void (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)> f =
boost::bind (&cloud_cb_, _1, cloud, &new_cloud_available_flag);
std::function<void (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)> f = [&] (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr& p1)
{
cloud_cb_ (p1, cloud, &new_cloud_available_flag);
};
interface->registerCallback (f);
interface->start ();

Expand Down
4 changes: 2 additions & 2 deletions recognition/include/pcl/recognition/impl/hv/hv_go.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,12 +677,12 @@ void pcl::GlobalHypothesesVerification<ModelT, SceneT>::computeClutterCue(Recogn

//sort neighborhood indices by id
std::sort (neighborhood_indices.begin (), neighborhood_indices.end (),
boost::bind (&std::pair<int, int>::first, _1) < boost::bind (&std::pair<int, int>::first, _2));
[] (const auto& p1, const auto& p2) { return p1.first < p2.first; });

//erase duplicated unexplained points
neighborhood_indices.erase (
std::unique (neighborhood_indices.begin (), neighborhood_indices.end (),
boost::bind (&std::pair<int, int>::first, _1) == boost::bind (&std::pair<int, int>::first, _2)), neighborhood_indices.end ());
[] (const auto& p1, const auto& p2) { return p1.first == p2.first; }), neighborhood_indices.end ());

//sort explained points
std::vector<int> exp_idces (recog_model->explained_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void pcl::RFFaceDetectorTrainer::faceVotesClustering()
uncertainty.emplace_back (index, uncertainties_[index]);
}

std::sort (uncertainty.begin (), uncertainty.end (), boost::bind (&std::pair<int, float>::second, _1) < boost::bind (&std::pair<int, float>::second, _2));
std::sort (uncertainty.begin (), uncertainty.end (), [] (const auto& p1, const auto& p2) { return p1.second < p2.second; });

Eigen::Vector3f rot;
rot.setZero ();
Expand Down
1 change: 0 additions & 1 deletion registration/include/pcl/registration/boost.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,3 @@

#include <boost/noncopyable.hpp>
#include <boost/make_shared.hpp>
#include <boost/bind.hpp>
11 changes: 8 additions & 3 deletions registration/include/pcl/registration/gicp.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,14 @@ namespace pcl
max_iterations_ = 200;
transformation_epsilon_ = 5e-4;
corr_dist_threshold_ = 5.;
rigid_transformation_estimation_ =
boost::bind (&GeneralizedIterativeClosestPoint<PointSource, PointTarget>::estimateRigidTransformationBFGS,
this, _1, _2, _3, _4, _5);
rigid_transformation_estimation_ = [this] (const PointCloudSource& cloud_src,
const std::vector<int>& indices_src,
const PointCloudTarget& cloud_tgt,
const std::vector<int>& indices_tgt,
Eigen::Matrix4f& transformation_matrix)
{
estimateRigidTransformationBFGS (cloud_src, indices_src, cloud_tgt, indices_tgt, transformation_matrix);
};
}

/** \brief Provide a pointer to the input dataset
Expand Down
4 changes: 2 additions & 2 deletions stereo/src/stereo_grabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pcl::StereoGrabberBase::StereoGrabberImpl::StereoGrabberImpl (pcl::StereoGrabber
, frames_per_second_ (frames_per_second)
, repeat_ (repeat)
, running_ (false)
, time_trigger_ (1.0 / static_cast<double> (std::max (frames_per_second, 0.001f)), boost::bind (&StereoGrabberImpl::trigger, this))
, time_trigger_ (1.0 / static_cast<double> (std::max (frames_per_second, 0.001f)), [this]{ trigger (); })
, valid_ (false)
{
pair_files_.push_back (pair_files);
Expand All @@ -93,7 +93,7 @@ pcl::StereoGrabberBase::StereoGrabberImpl::StereoGrabberImpl (pcl::StereoGrabber
, frames_per_second_ (frames_per_second)
, repeat_ (repeat)
, running_ (false)
, time_trigger_ (1.0 / static_cast<double> (std::max (frames_per_second, 0.001f)), boost::bind (&StereoGrabberImpl::trigger, this))
, time_trigger_ (1.0 / static_cast<double> (std::max (frames_per_second, 0.001f)), [this]{ trigger (); })
, valid_ (false)
{
pair_files_ = files;
Expand Down
1 change: 0 additions & 1 deletion surface/include/pcl/surface/boost.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,5 @@
# pragma GCC system_header
#endif

#include <boost/bind.hpp>
#include <boost/dynamic_bitset/dynamic_bitset.hpp>
#include <boost/shared_ptr.hpp>
6 changes: 1 addition & 5 deletions surface/include/pcl/surface/impl/mls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
#include <pcl/common/centroid.h>
#include <pcl/common/eigen.h>
#include <pcl/common/geometry.h>
#include <boost/bind.hpp>

#ifdef _OPENMP
#include <omp.h>
Expand Down Expand Up @@ -778,10 +777,7 @@ pcl::MLSResult::computeMLSSurface (const pcl::PointCloud<PointT> &cloud,
// Note: The max_sq_radius parameter is only used if weight_func was not defined
double max_sq_radius = 1;
if (!weight_func)
{
max_sq_radius = search_radius * search_radius;
weight_func = boost::bind (&pcl::MLSResult::computeMLSWeight, this, _1, max_sq_radius);
}
weight_func = [=] (const double sq_dist) { return this->computeMLSWeight (sq_dist, search_radius * search_radius); };

// Allocate matrices and vectors to hold the data used for the polynomial fit
Eigen::VectorXd weight_vec (num_neighbors);
Expand Down
6 changes: 4 additions & 2 deletions surface/include/pcl/surface/mls.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,10 @@ namespace pcl
{
tree_ = tree;
// Declare the search locator definition
int (KdTree::*radiusSearch)(int index, double radius, std::vector<int> &k_indices, std::vector<float> &k_sqr_distances, unsigned int max_nn) const = &KdTree::radiusSearch;
search_method_ = boost::bind (radiusSearch, boost::ref (tree_), _1, _2, _3, _4, 0);
search_method_ = [this] (int index, double radius, std::vector<int>& k_indices, std::vector<float>& k_sqr_distances)
{
return tree_->radiusSearch (index, radius, k_indices, k_sqr_distances, 0);
};
}

/** \brief Get a pointer to the search method used. */
Expand Down
42 changes: 17 additions & 25 deletions test/io/test_grabbers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,21 @@ vector<std::string> pcd_files_;

// Helper function for grabbing a cloud
void
cloud_callback (bool *signal_received,
CloudT::ConstPtr *ptr_to_fill,
const CloudT::ConstPtr &input_cloud)
cloud_callback (bool& signal_received,
CloudT::ConstPtr& ptr_to_fill,
const CloudT::ConstPtr& input_cloud)
{
*signal_received = true;
*ptr_to_fill = input_cloud;
}

// Helper function for grabbing a cloud (vector
void
cloud_callback_vector (std::vector<CloudT::ConstPtr> *vector_to_fill,
const CloudT::ConstPtr &input_cloud)
{
vector_to_fill->push_back (input_cloud);
signal_received = true;
ptr_to_fill = input_cloud;
}

TEST (PCL, PCDGrabber)
{
pcl::PCDGrabber<PointT> grabber (pcd_files_, 10, false); // TODO add directory functionality
EXPECT_EQ (grabber.size (), pcds_.size ());
vector<CloudT::ConstPtr> grabbed_clouds;
std::function<void (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)>
fxn = boost::bind (cloud_callback_vector, &grabbed_clouds, _1);
std::function<void (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)>
fxn = [&] (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr& input_cloud) { grabbed_clouds.push_back (input_cloud); };
grabber.registerCallback (fxn);
grabber.start ();
// 1 second should be /plenty/ of time
Expand Down Expand Up @@ -116,8 +108,8 @@ TEST (PCL, ImageGrabberTIFF)
vector<CloudT::ConstPtr> tiff_clouds;
CloudT::ConstPtr cloud_buffer;
bool signal_received = false;
std::function<void (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)>
fxn = boost::bind (cloud_callback, &signal_received, &cloud_buffer, _1);
std::function<void (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)>
fxn = [&] (const CloudT::ConstPtr& input_cloud) { cloud_callback (signal_received, cloud_buffer, input_cloud); };
grabber.registerCallback (fxn);
grabber.setCameraIntrinsics (525., 525., 320., 240.); // Setting old intrinsics which were used to generate these tests
grabber.start ();
Expand Down Expand Up @@ -199,8 +191,8 @@ TEST (PCL, ImageGrabberPCLZF)
vector <CloudT::ConstPtr> pclzf_clouds;
CloudT::ConstPtr cloud_buffer;
bool signal_received = false;
std::function<void (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)>
fxn = boost::bind (cloud_callback, &signal_received, &cloud_buffer, _1);
std::function<void (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)>
fxn = [&] (const CloudT::ConstPtr& input_cloud) { cloud_callback (signal_received, cloud_buffer, input_cloud); };
grabber.registerCallback (fxn);
grabber.start ();
for (size_t i = 0; i < grabber.size (); i++)
Expand Down Expand Up @@ -278,8 +270,8 @@ TEST (PCL, ImageGrabberOMP)
vector <CloudT::ConstPtr> pclzf_clouds;
CloudT::ConstPtr cloud_buffer;
bool signal_received = false;
std::function<void (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)>
fxn = boost::bind (cloud_callback, &signal_received, &cloud_buffer, _1);
std::function<void (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)>
fxn = [&] (const CloudT::ConstPtr& input_cloud) { cloud_callback (signal_received, cloud_buffer, input_cloud); };
grabber.registerCallback (fxn);
grabber.setNumberOfThreads (0); // Let OMP select
grabber.start ();
Expand Down Expand Up @@ -371,8 +363,8 @@ TEST (PCL, ImageGrabberSetIntrinsicsTIFF)
vector <CloudT::ConstPtr> tiff_clouds;
CloudT::ConstPtr cloud_buffer;
bool signal_received = false;
std::function<void (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)>
fxn = boost::bind (cloud_callback, &signal_received, &cloud_buffer, _1);
std::function<void (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)>
fxn = [&] (const CloudT::ConstPtr& input_cloud) { cloud_callback (signal_received, cloud_buffer, input_cloud); };
grabber.registerCallback (fxn);
grabber.start ();
// Change the camera parameters
Expand Down Expand Up @@ -449,8 +441,8 @@ TEST (PCL, ImageGrabberSetIntrinsicsPCLZF)
vector <CloudT::ConstPtr> pclzf_clouds;
CloudT::ConstPtr cloud_buffer;
bool signal_received = false;
std::function<void (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)>
fxn = boost::bind (cloud_callback, &signal_received, &cloud_buffer, _1);
std::function<void (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)>
fxn = [&] (const CloudT::ConstPtr& input_cloud) { cloud_callback (signal_received, cloud_buffer, input_cloud); };
grabber.registerCallback (fxn);
grabber.start ();
// Change the camera parameters
Expand Down