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
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 
72  {
73  sync_input_target_a_ = boost::make_shared <message_filters::Synchronizer<sync_policies::ApproximateTime<PointCloud, PointCloud> > > (max_queue_size_);
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_);
81  sync_input_target_e_->registerCallback (bind (&SegmentDifferences::input_target_callback, this, _1, _2));
82  }
83 }
84 
86 void
88 {
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 
std::string getFieldsList(const sensor_msgs::PointCloud2 &cloud)
#define NODELET_ERROR(...)
virtual void onInit()
Nodelet initialization routine. Reads in global parameters used by all nodelets.
Definition: pcl_nodelet.h:204
void config_callback(SegmentDifferencesConfig &config, uint32_t level)
Dynamic reconfigure callback.
f
SegmentDifferences()
Empty constructor.
void onInit()
Nodelet initialization routine.
bool isValid(const PointCloud2::ConstPtr &cloud, const std::string &topic_name="input")
Test whether a given PointCloud message is "valid" (i.e., has points, and width and height are non-ze...
Definition: pcl_nodelet.h:141
boost::shared_ptr< message_filters::Synchronizer< sync_policies::ApproximateTime< PointCloud, PointCloud > > > sync_input_target_a_
const std::string & getName() const
void publish(const boost::shared_ptr< M > &message) const
boost::shared_ptr< ros::NodeHandle > pnh_
boost::shared_ptr< message_filters::Synchronizer< sync_policies::ExactTime< PointCloud, PointCloud > > > sync_input_target_e_
Synchronized input, and planar hull.
pcl::PointCloud< pcl::PointXYZ > PointCloud
Definition: pcl_nodelet.h:78
void input_target_callback(const PointCloudConstPtr &cloud, const PointCloudConstPtr &cloud_target)
Input point cloud callback.
pcl::SegmentDifferences< pcl::PointXYZ > impl_
The PCL implementation used.
boost::shared_ptr< dynamic_reconfigure::Server< SegmentDifferencesConfig > > srv_
Pointer to a dynamic reconfigure service.
void subscribe(ros::NodeHandle &nh, const std::string &topic, uint32_t queue_size, const ros::TransportHints &transport_hints=ros::TransportHints(), ros::CallbackQueueInterface *callback_queue=0)
message_filters::Subscriber< PointCloud > sub_target_filter_
The message filter subscriber for PointCloud2.
void subscribe()
LazyNodelet connection routine.
bool approximate_sync_
True if we use an approximate time synchronizer versus an exact one (false by default).
Definition: pcl_nodelet.h:131
int max_queue_size_
The maximum queue size (default: 3).
Definition: pcl_nodelet.h:128
ros::Publisher pub_output_
The output PointCloud publisher.
Definition: pcl_nodelet.h:125
void fromPCL(const std::uint64_t &pcl_stamp, ros::Time &stamp)
uint32_t getNumSubscribers() const
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
boost::shared_ptr< T > pcl_ptr(const boost::shared_ptr< T > &p)
Definition: point_cloud.h:392
#define NODELET_DEBUG(...)
SegmentDifferences obtains the difference between two spatially aligned point clouds and returns the ...
boost::shared_ptr< T > ros_ptr(const boost::shared_ptr< T > &p)
Definition: point_cloud.h:354
message_filters::Subscriber< PointCloud > sub_input_filter_
The message filter subscriber for PointCloud2.
Definition: pcl_nodelet.h:119


pcl_ros
Author(s): Open Perception, Julius Kammerl , William Woodall
autogenerated on Thu Feb 16 2023 03:08:02