octree_change_publisher_nodelet.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2013, Yuto Inagaki and JSK Lab
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 the JSK Lab 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 
35 
38 
39 namespace jsk_pcl_ros
40 {
42  {
43  ConnectionBasedNodelet::onInit();
44  counter_ = 0;
45 
46  pnh_->param("resolution", resolution_, 0.02);
47  pnh_->param("noise_filter", noise_filter_, 2);
48 
49  srv_ = boost::make_shared <dynamic_reconfigure::Server<Config> >(*pnh_);
50  dynamic_reconfigure::Server<Config>::CallbackType f =
51  boost::bind(&OctreeChangePublisher::config_callback, this, _1, _2);
52  srv_->setCallback(f);
53 
54  octree_ = new pcl::octree::OctreePointCloudChangeDetector<pcl::PointXYZRGB>(resolution_);
55 
56  filtered_cloud.reset(new pcl::PointCloud<pcl::PointXYZRGB>);
57 
58  diff_pub_ = advertise<sensor_msgs::PointCloud2>(*pnh_, "octree_change_result", 1);
59 
60  onInitPostProcess();
61  }
62 
64  {
65  sub_ = pnh_->subscribe("input", 1, &OctreeChangePublisher::cloud_cb,this);
66  }
67 
69  {
70  sub_.shutdown();
71  }
72 
73  void OctreeChangePublisher::config_callback(Config &config, uint32_t level)
74  {
75  boost::mutex::scoped_lock lock(mtx_);
76  if(resolution_ != config.resolution){
77  resolution_ = config.resolution;
78  octree_ = new pcl::octree::OctreePointCloudChangeDetector<pcl::PointXYZRGB>(resolution_);
79  counter_ = 0;
80  }
81 
82  noise_filter_ = config.noise_filter;
83  }
84 
85  void OctreeChangePublisher::cloud_cb(const sensor_msgs::PointCloud2 &pc)
86  {
87  if(pc.fields.size() <= 0){
88  return;
89  }
90 
91  boost::mutex::scoped_lock lock(mtx_);
92  pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>());
93  std::vector<int> indices;
94  pcl::fromROSMsg(pc, *cloud);
95  octree_->setInputCloud (cloud);
96  octree_->addPointsFromInputCloud ();
97 
98  if (counter_ != 0){
99  boost::shared_ptr<std::vector<int> > newPointIdxVector (new std::vector<int>);
100 
101  octree_->getPointIndicesFromNewVoxels (*newPointIdxVector, noise_filter_);
102 
103  filtered_cloud.reset (new pcl::PointCloud<pcl::PointXYZRGB>);
104  filtered_cloud->points.reserve(newPointIdxVector->size());
105 
106  for (std::vector<int>::iterator it = newPointIdxVector->begin (); it != newPointIdxVector->end (); it++)
107  filtered_cloud->points.push_back(cloud->points[*it]);
108 
109  sensor_msgs::PointCloud2 octree_change_pointcloud2;
110  pcl::toROSMsg(*filtered_cloud, octree_change_pointcloud2);
111  octree_change_pointcloud2.header = pc.header;
112  octree_change_pointcloud2.is_dense = false;
113  diff_pub_.publish(octree_change_pointcloud2);
114  }
115 
116  octree_->switchBuffers ();
118  }
119 }
120 
jsk_pcl_ros::OctreeChangePublisher::unsubscribe
virtual void unsubscribe()
Definition: octree_change_publisher_nodelet.cpp:100
depth_error_calibration.lock
lock
Definition: depth_error_calibration.py:32
PLUGINLIB_EXPORT_CLASS
PLUGINLIB_EXPORT_CLASS(jsk_pcl_ros::OctreeChangePublisher, nodelet::Nodelet)
boost::shared_ptr
jsk_pcl_ros::OctreeChangePublisher
Realtime change detection of pointcloud using octree. See paper below:
Definition: octree_change_publisher.h:102
jsk_pcl_ros::OctreeChangePublisher::config_callback
virtual void config_callback(Config &config, uint32_t level)
Definition: octree_change_publisher_nodelet.cpp:105
ros::Subscriber::shutdown
void shutdown()
jsk_pcl_ros::OctreeChangePublisher::sub_
ros::Subscriber sub_
Definition: octree_change_publisher.h:144
pcl::fromROSMsg
void fromROSMsg(const sensor_msgs::PointCloud2 &cloud, pcl::PointCloud< T > &pcl_cloud)
jsk_pcl_ros::OctreeChangePublisher::srv_
boost::shared_ptr< dynamic_reconfigure::Server< Config > > srv_
Definition: octree_change_publisher.h:148
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
cloud
cloud
class_list_macros.h
jsk_pcl_ros::OctreeChangePublisher::noise_filter_
int noise_filter_
Definition: octree_change_publisher.h:140
jsk_pcl_ros::OctreeChangePublisher::cloud_cb
virtual void cloud_cb(const sensor_msgs::PointCloud2 &pc)
Definition: octree_change_publisher_nodelet.cpp:117
jsk_pcl_ros
Definition: add_color_from_image.h:51
jsk_pcl_ros::OctreeChangePublisher::counter_
int counter_
Definition: octree_change_publisher.h:139
nodelet::Nodelet
octree_change_publisher.h
jsk_pcl_ros::OctreeChangePublisher::subscribe
virtual void subscribe()
Definition: octree_change_publisher_nodelet.cpp:95
dump_depth_error.f
f
Definition: dump_depth_error.py:39
pcl::toROSMsg
void toROSMsg(const pcl::PointCloud< T > &cloud, sensor_msgs::Image &msg)
jsk_pcl_ros::OctreeChangePublisher::resolution_
double resolution_
Definition: octree_change_publisher.h:141
jsk_pcl_ros::OctreeChangePublisher::filtered_cloud
pcl::PointCloud< pcl::PointXYZRGB >::Ptr filtered_cloud
Definition: octree_change_publisher.h:147
config
config
jsk_pcl_ros::OctreeChangePublisher::Config
OctreeChangePublisherConfig Config
Definition: octree_change_publisher.h:137
jsk_pcl_ros::OctreeChangePublisher::onInit
virtual void onInit()
Definition: octree_change_publisher_nodelet.cpp:73
jsk_pcl_ros::OctreeChangePublisher::diff_pub_
ros::Publisher diff_pub_
Definition: octree_change_publisher.h:145
jsk_pcl_ros::OctreeChangePublisher::octree_
pcl::octree::OctreePointCloudChangeDetector< pcl::PointXYZRGB > * octree_
Definition: octree_change_publisher.h:146
jsk_pcl_ros::OctreeChangePublisher::mtx_
boost::mutex mtx_
Definition: octree_change_publisher.h:142


jsk_pcl_ros
Author(s): Yohei Kakiuchi
autogenerated on Tue Jan 7 2025 04:05:45