segment_differences.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2010, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage, Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  * $Id: segment_differences.cpp 35361 2011-01-20 04:34:49Z rusu $
35  *
36  */
37 
40 
42 void
44 {
45  // Call the super onInit ()
47 
48  pub_output_ = advertise<PointCloud> (*pnh_, "output", max_queue_size_);
49 
50  NODELET_DEBUG ("[%s::onInit] Nodelet successfully created with the following parameters:\n"
51  " - max_queue_size : %d",
52  getName ().c_str (),
54 
56 }
57 
59 void
61 {
62  // Subscribe to the input using a filter
63  sub_input_filter_.subscribe (*pnh_, "input", max_queue_size_);
64  sub_target_filter_.subscribe (*pnh_, "target", max_queue_size_);
65 
66  // Enable the dynamic reconfigure service
67  srv_ = boost::make_shared <dynamic_reconfigure::Server<SegmentDifferencesConfig> > (*pnh_);
68  dynamic_reconfigure::Server<SegmentDifferencesConfig>::CallbackType f = boost::bind (&SegmentDifferences::config_callback, this, _1, _2);
69  srv_->setCallback (f);
70 
71  if (approximate_sync_)
72  {
73  sync_input_target_a_ = boost::make_shared <message_filters::Synchronizer<sync_policies::ApproximateTime<PointCloud, PointCloud> > > (max_queue_size_);
74  sync_input_target_a_->connectInput (sub_input_filter_, sub_target_filter_);
75  sync_input_target_a_->registerCallback (bind (&SegmentDifferences::input_target_callback, this, _1, _2));
76  }
77  else
78  {
79  sync_input_target_e_ = boost::make_shared <message_filters::Synchronizer<sync_policies::ExactTime<PointCloud, PointCloud> > > (max_queue_size_);
80  sync_input_target_e_->connectInput (sub_input_filter_, sub_target_filter_);
81  sync_input_target_e_->registerCallback (bind (&SegmentDifferences::input_target_callback, this, _1, _2));
82  }
83 }
84 
86 void
88 {
89  sub_input_filter_.unsubscribe ();
90  sub_target_filter_.unsubscribe ();
91 }
92 
94 void
95 pcl_ros::SegmentDifferences::config_callback (SegmentDifferencesConfig &config, uint32_t /*level*/)
96 {
97  if (impl_.getDistanceThreshold () != config.distance_threshold)
98  {
99  impl_.setDistanceThreshold (config.distance_threshold);
100  NODELET_DEBUG ("[%s::config_callback] Setting new distance threshold to: %f.", getName ().c_str (), config.distance_threshold);
101  }
102 }
103 
104 
106 void
108  const PointCloudConstPtr &cloud_target)
109 {
110  if (pub_output_.getNumSubscribers () <= 0)
111  return;
112 
113  if (!isValid (cloud) || !isValid (cloud_target, "target"))
114  {
115  NODELET_ERROR ("[%s::input_indices_callback] Invalid input!", getName ().c_str ());
116  PointCloud output;
117  output.header = cloud->header;
118  pub_output_.publish (ros_ptr(output.makeShared ()));
119  return;
120  }
121 
122  NODELET_DEBUG ("[%s::input_indices_callback]\n"
123  " - PointCloud with %d data points (%s), stamp %f, and frame %s on topic %s received.\n"
124  " - PointCloud with %d data points (%s), stamp %f, and frame %s on topic %s received.",
125  getName ().c_str (),
126  cloud->width * cloud->height, pcl::getFieldsList (*cloud).c_str (), fromPCL(cloud->header).stamp.toSec (), cloud->header.frame_id.c_str (), pnh_->resolveName ("input").c_str (),
127  cloud_target->width * cloud_target->height, pcl::getFieldsList (*cloud_target).c_str (), fromPCL(cloud_target->header).stamp.toSec (), cloud_target->header.frame_id.c_str (), pnh_->resolveName ("target").c_str ());
128 
129  impl_.setInputCloud (pcl_ptr(cloud));
130  impl_.setTargetCloud (pcl_ptr(cloud_target));
131 
132  PointCloud output;
133  impl_.segment (output);
134 
135  pub_output_.publish (ros_ptr(output.makeShared ()));
136  NODELET_DEBUG ("[%s::segmentAndPublish] Published PointCloud2 with %zu points and stamp %f on topic %s", getName ().c_str (),
137  output.points.size (), fromPCL(output.header).stamp.toSec (), pnh_->resolveName ("output").c_str ());
138 }
139 
142 
NODELET_ERROR
#define NODELET_ERROR(...)
segment_differences.h
nodelet_topic_tools::NodeletLazy::pnh_
boost::shared_ptr< ros::NodeHandle > pnh_
pcl_ros::SegmentDifferences::unsubscribe
void unsubscribe()
Definition: segment_differences.cpp:87
boost::shared_ptr
pcl::getFieldsList
std::string getFieldsList(const sensor_msgs::PointCloud2 &cloud)
getName
ROSCONSOLE_CONSOLE_IMPL_DECL std::string getName(void *handle)
f
f
pcl_ros::PCLNodelet::PointCloud
pcl::PointCloud< pcl::PointXYZ > PointCloud
Definition: pcl_nodelet.h:78
fromPCL
void fromPCL(const pcl::ModelCoefficients &pcl_mc, pcl_msgs::ModelCoefficients &mc)
pcl_ros::PCLNodelet::max_queue_size_
int max_queue_size_
The maximum queue size (default: 3).
Definition: pcl_nodelet.h:128
PLUGINLIB_EXPORT_CLASS
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
pcl_ros::PCLNodelet::pub_output_
ros::Publisher pub_output_
The output PointCloud publisher.
Definition: pcl_nodelet.h:125
pcl_ros::PCLNodelet::onInit
virtual void onInit()
Nodelet initialization routine. Reads in global parameters used by all nodelets.
Definition: pcl_nodelet.h:204
pcl_ros::SegmentDifferences::onInit
void onInit()
Nodelet initialization routine.
Definition: segment_differences.cpp:43
nodelet::Nodelet
nodelet_topic_tools::NodeletLazy::onInitPostProcess
virtual void onInitPostProcess()
pcl::pcl_ptr
boost::shared_ptr< T > pcl_ptr(const boost::shared_ptr< T > &p)
Definition: point_cloud.h:392
class_list_macros.hpp
nodelet::Nodelet::getName
const std::string & getName() const
pcl_ros::SegmentDifferences::input_target_callback
void input_target_callback(const PointCloudConstPtr &cloud, const PointCloudConstPtr &cloud_target)
Input point cloud callback.
Definition: segment_differences.cpp:107
pcl_ros::SegmentDifferences::subscribe
void subscribe()
LazyNodelet connection routine.
Definition: segment_differences.cpp:60
pcl_ros::SegmentDifferences::config_callback
void config_callback(SegmentDifferencesConfig &config, uint32_t level)
Dynamic reconfigure callback.
Definition: segment_differences.cpp:95
pcl_ros::SegmentDifferences
SegmentDifferences obtains the difference between two spatially aligned point clouds and returns the ...
Definition: segment_differences.h:60
NODELET_DEBUG
#define NODELET_DEBUG(...)
SegmentDifferences
pcl_ros::SegmentDifferences SegmentDifferences
Definition: segment_differences.cpp:140
pcl::ros_ptr
boost::shared_ptr< T > ros_ptr(const boost::shared_ptr< T > &p)
Definition: point_cloud.h:354


pcl_ros
Author(s): Open Perception, Julius Kammerl , William Woodall
autogenerated on Sat Feb 18 2023 03:54:54