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 #3178

Merged
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
3 changes: 1 addition & 2 deletions tools/davidsdk_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ main (int argc,
//davidsdk_ptr->setFileFormatToPLY();
std::cout << "Using " << davidsdk_ptr->getFileFormat () << " file format" << std::endl;

std::function<void
(const PointCloudXYZ::Ptr&)> f = boost::bind (&grabberCallback, _1);
std::function<void (const PointCloudXYZ::Ptr&)> f = [] (const PointCloudXYZ::Ptr& cloud) { grabberCallback (cloud); };
davidsdk_ptr->registerCallback (f);
davidsdk_ptr->start ();

Expand Down
5 changes: 4 additions & 1 deletion tools/depth_sense_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ class DepthSenseViewer
void
run ()
{
std::function<void (const typename PointCloudT::ConstPtr&)> f = boost::bind (&DepthSenseViewer::cloudCallback, this, _1);
std::function<void (const typename PointCloudT::ConstPtr&)> f = [this] (const typename PointCloudT::ConstPtr& cloud)
{
cloudCallback (cloud);
};
connection_ = grabber_.registerCallback (f);
grabber_.start ();
while (!viewer_.wasStopped ())
Expand Down
3 changes: 1 addition & 2 deletions tools/ensenso_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ main (void)
ensenso_ptr->openTcpPort ();
ensenso_ptr->openDevice ();

std::function<void
(const PointCloudXYZ::Ptr&)> f = boost::bind (&grabberCallback, _1);
std::function<void (const PointCloudXYZ::Ptr&)> f = [] (const PointCloudXYZ::Ptr& cloud) { grabberCallback (cloud); };
ensenso_ptr->registerCallback (f);
ensenso_ptr->start ();

Expand Down
3 changes: 1 addition & 2 deletions tools/hdl_viewer_simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ class SimpleHDLViewer
cloud_viewer_->setCameraPosition (0.0, 0.0, 30.0, 0.0, 1.0, 0.0, 0);
cloud_viewer_->setCameraClipDistances (0.0, 50.0);

std::function<void (const CloudConstPtr&)> cloud_cb = boost::bind (
&SimpleHDLViewer::cloud_callback, this, _1);
std::function<void (const CloudConstPtr&)> cloud_cb = [this] (const CloudConstPtr& cloud) { cloud_callback (cloud); };
boost::signals2::connection cloud_connection = grabber_.registerCallback (
cloud_cb);

Expand Down
5 changes: 4 additions & 1 deletion tools/image_grabber_saver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ main (int argc, char** argv)
//grabber->setFocalLength(focal_length); // FIXME

EventHelper h;
std::function<void(const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&) > f = boost::bind (&EventHelper::cloud_cb, &h, _1);
std::function<void(const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&) > f = [&] (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr& cloud)
{
h.cloud_cb (cloud);
};
boost::signals2::connection c1 = grabber->registerCallback (f);

do
Expand Down
5 changes: 4 additions & 1 deletion tools/image_grabber_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,10 @@ main (int argc, char** argv)


EventHelper h;
std::function<void(const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&) > f = boost::bind (&EventHelper::cloud_cb, &h, _1);
std::function<void(const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&) > f = [&] (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr & cloud)
{
h.cloud_cb (cloud);
};
boost::signals2::connection c1 = grabber->registerCallback (f);

std::string mouse_msg_3D ("Mouse coordinates in PCL Visualizer");
Expand Down
2 changes: 1 addition & 1 deletion tools/oni2pcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ main (int argc, char **argv)
}

pcl::ONIGrabber* grabber = new pcl::ONIGrabber (argv[1], false, false);
std::function<void (const CloudConstPtr&) > f = boost::bind (&cloud_cb, _1);
std::function<void (const CloudConstPtr&) > f = [] (const CloudConstPtr& cloud) { cloud_cb (cloud); };
boost::signals2::connection c = grabber->registerCallback (f);

while (grabber->hasDataLeft ())
Expand Down
4 changes: 2 additions & 2 deletions tools/oni_viewer_simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class SimpleONIViewer
{
//pcl::Grabber* interface = new pcl::OpenNIGrabber(device_id_, pcl::OpenNIGrabber::OpenNI_QQVGA_30Hz, pcl::OpenNIGrabber::OpenNI_VGA_30Hz);

std::function<void (const CloudConstPtr&) > f = boost::bind (&SimpleONIViewer::cloud_cb_, this, _1);
std::function<void (const CloudConstPtr&) > f = [this] (const CloudConstPtr& cloud) { cloud_cb_ (cloud); };

boost::signals2::connection c = grabber_.registerCallback (f);

Expand Down Expand Up @@ -192,7 +192,7 @@ main(int argc, char ** argv)
{
grabber = new pcl::ONIGrabber(arg, true, false);
trigger.setInterval (1.0 / static_cast<double> (frame_rate));
trigger.registerCallback (boost::bind(&pcl::ONIGrabber::start, grabber));
trigger.registerCallback ([=] { grabber->start (); });
trigger.start();
}
if (grabber->providesCallback<pcl::ONIGrabber::sig_cb_openni_point_cloud_rgb > () && !pcl::console::find_switch (argc, argv, "-xyz"))
Expand Down
4 changes: 2 additions & 2 deletions tools/openni2_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class OpenNI2Viewer
cloud_viewer_->registerMouseCallback (&OpenNI2Viewer::mouse_callback, *this);
cloud_viewer_->registerKeyboardCallback (&OpenNI2Viewer::keyboard_callback, *this);
cloud_viewer_->setCameraFieldOfView (1.02259994f);
std::function<void (const CloudConstPtr&) > cloud_cb = boost::bind (&OpenNI2Viewer::cloud_callback, this, _1);
std::function<void (const CloudConstPtr&) > cloud_cb = [this] (const CloudConstPtr& cloud) { cloud_callback (cloud); };
boost::signals2::connection cloud_connection = grabber_.registerCallback (cloud_cb);

boost::signals2::connection image_connection;
Expand All @@ -186,7 +186,7 @@ class OpenNI2Viewer
image_viewer_.reset (new pcl::visualization::ImageViewer ("PCL OpenNI image"));
image_viewer_->registerMouseCallback (&OpenNI2Viewer::mouse_callback, *this);
image_viewer_->registerKeyboardCallback (&OpenNI2Viewer::keyboard_callback, *this);
std::function<void (const boost::shared_ptr<pcl::io::openni2::Image>&) > image_cb = boost::bind (&OpenNI2Viewer::image_callback, this, _1);
std::function<void (const pcl::io::openni2::Image::Ptr&)> image_cb = [this] (const pcl::io::openni2::Image::Ptr& img) { image_callback (img); };
image_connection = grabber_.registerCallback (image_cb);
}

Expand Down
7 changes: 6 additions & 1 deletion tools/openni_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,12 @@ class Driver
void
grabAndSend ()
{
std::function<void (const boost::shared_ptr<openni_wrapper::Image>&, const boost::shared_ptr<openni_wrapper::DepthImage>&, float) > image_cb = boost::bind (&Driver::image_callback, this, _1, _2, _3);
std::function<
void (const openni_wrapper::Image::Ptr&, const openni_wrapper::DepthImage::Ptr&, float)
> image_cb = [this] (const openni_wrapper::Image::Ptr& img, const openni_wrapper::DepthImage::Ptr& depth, float f)
{
image_callback (img, depth, f);
};
boost::signals2::connection image_connection = grabber_.registerCallback (image_cb);

grabber_.start ();
Expand Down
7 changes: 6 additions & 1 deletion tools/openni_save_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ class SimpleOpenNIViewer
void
run ()
{
std::function<void (const openni_wrapper::Image::Ptr&, const openni_wrapper::DepthImage::Ptr&, float) > image_cb = boost::bind (&SimpleOpenNIViewer::image_callback, this, _1, _2, _3);
std::function<
void (const openni_wrapper::Image::Ptr&, const openni_wrapper::DepthImage::Ptr&, float)
> image_cb = [this] (const openni_wrapper::Image::Ptr& img, const openni_wrapper::DepthImage::Ptr& depth, float f)
{
image_callback (img, depth, f);
};
boost::signals2::connection image_connection = grabber_.registerCallback (image_cb);

grabber_.start ();
Expand Down
4 changes: 2 additions & 2 deletions tools/openni_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class OpenNIViewer
{
cloud_viewer_->registerMouseCallback (&OpenNIViewer::mouse_callback, *this);
cloud_viewer_->registerKeyboardCallback(&OpenNIViewer::keyboard_callback, *this);
std::function<void (const CloudConstPtr&) > cloud_cb = boost::bind (&OpenNIViewer::cloud_callback, this, _1);
std::function<void (const CloudConstPtr&)> cloud_cb = [this] (const CloudConstPtr& cloud) { cloud_callback (cloud); };
boost::signals2::connection cloud_connection = grabber_.registerCallback (cloud_cb);

boost::signals2::connection image_connection;
Expand All @@ -183,7 +183,7 @@ class OpenNIViewer
image_viewer_.reset (new pcl::visualization::ImageViewer ("PCL OpenNI image"));
image_viewer_->registerMouseCallback (&OpenNIViewer::mouse_callback, *this);
image_viewer_->registerKeyboardCallback(&OpenNIViewer::keyboard_callback, *this);
std::function<void (const boost::shared_ptr<openni_wrapper::Image>&) > image_cb = boost::bind (&OpenNIViewer::image_callback, this, _1);
std::function<void (const openni_wrapper::Image::Ptr&)> image_cb = [this] (const openni_wrapper::Image::Ptr& img) { image_callback (img); };
image_connection = grabber_.registerCallback (image_cb);
}

Expand Down
4 changes: 2 additions & 2 deletions tools/openni_viewer_simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class SimpleOpenNIViewer
string keyMsg3D("Key event for PCL Visualizer");
cloud_viewer_.registerMouseCallback (&SimpleOpenNIViewer::mouse_callback, *this, (void*)(&mouseMsg3D));
cloud_viewer_.registerKeyboardCallback(&SimpleOpenNIViewer::keyboard_callback, *this, (void*)(&keyMsg3D));
std::function<void (const CloudConstPtr&) > cloud_cb = boost::bind (&SimpleOpenNIViewer::cloud_callback, this, _1);
std::function<void (const CloudConstPtr&)> cloud_cb = [this] (const CloudConstPtr& cloud) { cloud_callback (cloud); };
boost::signals2::connection cloud_connection = grabber_.registerCallback (cloud_cb);

boost::signals2::connection image_connection;
Expand All @@ -182,7 +182,7 @@ class SimpleOpenNIViewer
string keyMsg2D("Key event for image viewer");
image_viewer_.registerMouseCallback (&SimpleOpenNIViewer::mouse_callback, *this, (void*)(&mouseMsg2D));
image_viewer_.registerKeyboardCallback(&SimpleOpenNIViewer::keyboard_callback, *this, (void*)(&keyMsg2D));
std::function<void (const boost::shared_ptr<openni_wrapper::Image>&) > image_cb = boost::bind (&SimpleOpenNIViewer::image_callback, this, _1);
std::function<void (const openni_wrapper::Image::Ptr&)> image_cb = [this] (const openni_wrapper::Image::Ptr& img) { image_callback (img); };
image_connection = grabber_.registerCallback (image_cb);
}
unsigned char* rgb_data = 0;
Expand Down
5 changes: 4 additions & 1 deletion tools/pcd_grabber_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ main (int argc, char** argv)
}

EventHelper h;
std::function<void(const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&) > f = boost::bind (&EventHelper::cloud_cb, &h, _1);
std::function<void (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)> f = [&] (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr& cloud)
{
h.cloud_cb (cloud);
};
boost::signals2::connection c1 = grabber->registerCallback (f);

std::string mouse_msg_3D ("Mouse coordinates in PCL Visualizer");
Expand Down
5 changes: 3 additions & 2 deletions tools/pcl_video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ class Recorder
// Set up a callback to get clouds from a grabber and write them to the
// file.
pcl::Grabber* interface(new pcl::OpenNIGrabber());
std::function<void (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr&)> f(
boost::bind(&Recorder::Callback, this, _1));
std::function<void (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr&)> f (
[this] (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr&) { Callback (cloud); }
);
interface->registerCallback(f);
// Start the first cluster
cltr_start_ = bpt::microsec_clock::local_time();
Expand Down
2 changes: 1 addition & 1 deletion tools/real_sense_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class RealSenseViewer
void
run ()
{
std::function<void (const typename PointCloudT::ConstPtr&)> f = boost::bind (&RealSenseViewer::cloudCallback, this, _1);
std::function<void (const typename PointCloudT::ConstPtr&)> f = [this] (const typename PointCloudT::ConstPtr& cloud) { cloudCallback (cloud); };
connection_ = grabber_.registerCallback (f);
grabber_.start ();
printMode (grabber_.getMode ());
Expand Down
2 changes: 1 addition & 1 deletion tools/timed_trigger_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int main ()
global_time = pcl::getTime ();
trigger.start ();
std::this_thread::sleep_for(2s);
trigger.registerCallback ( boost::bind(&Dummy::myTimer, dummy));
trigger.registerCallback ([&]{ dummy.myTimer (); });
std::this_thread::sleep_for(3s);
trigger.setInterval (0.2);
std::this_thread::sleep_for(2s);
Expand Down
3 changes: 1 addition & 2 deletions tools/vlp_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ class SimpleVLPViewer
cloud_viewer_->setCameraClipDistances (0.0, 50.0);
cloud_viewer_->registerKeyboardCallback (&SimpleVLPViewer::keyboard_callback, *this);

std::function<void
(const CloudConstPtr&)> cloud_cb = boost::bind (&SimpleVLPViewer::cloud_callback, this, _1);
std::function<void (const CloudConstPtr&)> cloud_cb = [this] (const CloudConstPtr& cloud){ cloud_callback (cloud); };
boost::signals2::connection cloud_connection = grabber_.registerCallback (cloud_cb);

grabber_.start ();
Expand Down