voxel_grid.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2009, 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: voxel_grid.cpp 35876 2011-02-09 01:04:36Z rusu $
35  *
36  */
37 
40 
42 bool
44 {
45  // Enable the dynamic reconfigure service
46  has_service = true;
47  srv_ = boost::make_shared <dynamic_reconfigure::Server<pcl_ros::VoxelGridConfig> > (nh);
48  dynamic_reconfigure::Server<pcl_ros::VoxelGridConfig>::CallbackType f = boost::bind (&VoxelGrid::config_callback, this, _1, _2);
49  srv_->setCallback (f);
50 
51  return (true);
52 }
53 
55 void
56 pcl_ros::VoxelGrid::filter (const PointCloud2::ConstPtr &input,
57  const IndicesPtr &indices,
58  PointCloud2 &output)
59 {
60  boost::mutex::scoped_lock lock (mutex_);
61  pcl::PCLPointCloud2::Ptr pcl_input(new pcl::PCLPointCloud2);
62  pcl_conversions::toPCL (*(input), *(pcl_input));
63  impl_.setInputCloud (pcl_input);
64  impl_.setIndices (indices);
65  pcl::PCLPointCloud2 pcl_output;
66  impl_.filter (pcl_output);
67  pcl_conversions::moveFromPCL(pcl_output, output);
68 }
69 
71 void
72 pcl_ros::VoxelGrid::config_callback (pcl_ros::VoxelGridConfig &config, uint32_t level)
73 {
74  boost::mutex::scoped_lock lock (mutex_);
75 
76  Eigen::Vector3f leaf_size = impl_.getLeafSize ();
77 
78  if (leaf_size[0] != config.leaf_size)
79  {
80  leaf_size.setConstant (config.leaf_size);
81  NODELET_DEBUG ("[config_callback] Setting the downsampling leaf size to: %f.", leaf_size[0]);
82  impl_.setLeafSize (leaf_size[0], leaf_size[1], leaf_size[2]);
83  }
84 
85  double filter_min, filter_max;
86  impl_.getFilterLimits (filter_min, filter_max);
87  if (filter_min != config.filter_limit_min)
88  {
89  filter_min = config.filter_limit_min;
90  NODELET_DEBUG ("[config_callback] Setting the minimum filtering value a point will be considered from to: %f.", filter_min);
91  }
92  if (filter_max != config.filter_limit_max)
93  {
94  filter_max = config.filter_limit_max;
95  NODELET_DEBUG ("[config_callback] Setting the maximum filtering value a point will be considered from to: %f.", filter_max);
96  }
97  impl_.setFilterLimits (filter_min, filter_max);
98 
99  if (impl_.getFilterLimitsNegative () != config.filter_limit_negative)
100  {
101  impl_.setFilterLimitsNegative (config.filter_limit_negative);
102  NODELET_DEBUG ("[%s::config_callback] Setting the filter negative flag to: %s.", getName ().c_str (), config.filter_limit_negative ? "true" : "false");
103  }
104 
105  if (impl_.getFilterFieldName () != config.filter_field_name)
106  {
107  impl_.setFilterFieldName (config.filter_field_name);
108  NODELET_DEBUG ("[config_callback] Setting the filter field name to: %s.", config.filter_field_name.c_str ());
109  }
110 
111  // ---[ These really shouldn't be here, and as soon as dynamic_reconfigure improves, we'll remove them and inherit from Filter
112  if (tf_input_frame_ != config.input_frame)
113  {
114  tf_input_frame_ = config.input_frame;
115  NODELET_DEBUG ("[config_callback] Setting the input TF frame to: %s.", tf_input_frame_.c_str ());
116  }
117  if (tf_output_frame_ != config.output_frame)
118  {
119  tf_output_frame_ = config.output_frame;
120  NODELET_DEBUG ("[config_callback] Setting the output TF frame to: %s.", tf_output_frame_.c_str ());
121  }
122  // ]---
123 }
124 
127 
virtual void filter(const PointCloud2::ConstPtr &input, const IndicesPtr &indices, PointCloud2 &output)
Call the actual filter.
Definition: voxel_grid.cpp:56
f
pcl_ros::VoxelGrid VoxelGrid
Definition: voxel_grid.cpp:125
std::string tf_input_frame_
The input TF frame the data should be transformed into, if input.header.frame_id is different...
Definition: filter.h:86
bool child_init(ros::NodeHandle &nh, bool &has_service)
Child initialization routine.
Definition: voxel_grid.cpp:43
std::string tf_output_frame_
The output TF frame the data should be transformed into, if input.header.frame_id is different...
Definition: filter.h:92
const std::string & getName() const
boost::shared_ptr< dynamic_reconfigure::Server< pcl_ros::VoxelGridConfig > > srv_
Pointer to a dynamic reconfigure service.
Definition: voxel_grid.h:57
sensor_msgs::PointCloud2 PointCloud2
Definition: filter.h:60
VoxelGrid assembles a local 3D grid over a given PointCloud, and downsamples + filters the data...
Definition: voxel_grid.h:53
void config_callback(pcl_ros::VoxelGridConfig &config, uint32_t level)
Dynamic reconfigure callback.
Definition: voxel_grid.cpp:72
boost::mutex mutex_
Internal mutex.
Definition: filter.h:95
pcl::VoxelGrid< pcl::PCLPointCloud2 > impl_
The PCL filter implementation used.
Definition: voxel_grid.h:60
void moveFromPCL(pcl::PCLImage &pcl_image, sensor_msgs::Image &image)
PLUGINLIB_EXPORT_CLASS(VoxelGrid, nodelet::Nodelet)
#define NODELET_DEBUG(...)
void toPCL(const ros::Time &stamp, pcl::uint64_t &pcl_stamp)


pcl_ros
Author(s): Open Perception, Julius Kammerl , William Woodall
autogenerated on Mon Jun 10 2019 14:19:18