organized_pass_through_nodelet.cpp
Go to the documentation of this file.
1 // -*- mode: c++ -*-
2 /*********************************************************************
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2014, JSK Lab
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of the JSK Lab nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *********************************************************************/
35 
37 #include <jsk_topic_tools/diagnostic_utils.h>
38 #include <pcl/filters/extract_indices.h>
40 
41 namespace jsk_pcl_ros
42 {
44  DiagnosticNodelet("OrganizedPassThrough")
45  {
46 
47  }
48 
50  {
51  DiagnosticNodelet::onInit();
53  // Publisher
55  pub_ = advertise<sensor_msgs::PointCloud2>(*pnh_, "output", 1);
56 
58  // Dynamic Reconfigure
60  srv_ = boost::make_shared <dynamic_reconfigure::Server<Config> > (*pnh_);
61  dynamic_reconfigure::Server<Config>::CallbackType f =
62  boost::bind (
64  srv_->setCallback (f);
65  onInitPostProcess();
66  }
67 
69  {
71  // Subscriber
73  sub_ = pnh_->subscribe("input", 1, &OrganizedPassThrough::filter, this);
74  }
75 
77  {
78  sub_.shutdown();
79  }
80 
81  void OrganizedPassThrough::configCallback(Config &config, uint32_t level)
82  {
83  boost::mutex::scoped_lock lock(mutex_);
84  if (config.filter_field == 0) {
86  }
87  else {
89  }
90  min_index_ = config.min_index;
91  max_index_ = config.max_index;
92  filter_limit_negative_ = config.filter_limit_negative;
93  keep_organized_ = config.keep_organized;
94  remove_nan_ = config.remove_nan;
95  }
96 
97  pcl::PointIndices::Ptr OrganizedPassThrough::filterIndices(const pcl::PointCloud<PointT>::Ptr& pc)
98  {
99  pcl::PointIndices::Ptr indices (new pcl::PointIndices);
100 
101  if (filter_field_ == FIELD_X) {
102  for (size_t j = 0; j < pc->height; j++) {
103  for (size_t i = min_index_; i < max_index_ && i < pc->width; i++) {
104  size_t idx = i + j * pc->width;
105  if (!remove_nan_ || (remove_nan_ && !isPointNaN(pc->points[idx])))
106  indices->indices.push_back(idx);
107  }
108  }
109  }
110  else if (filter_field_ == FIELD_Y) {
111  for (size_t i = 0; i < pc->width; i++) {
112  for (size_t j = min_index_; j < max_index_ && j < pc->height; j++) {
113  size_t idx = i + j * pc->width;
114  if (!remove_nan_ || (remove_nan_ && !isPointNaN(pc->points[idx])))
115  indices->indices.push_back(idx);
116  }
117  }
118  }
119  return indices;
120  }
121 
122  void OrganizedPassThrough::filter(const sensor_msgs::PointCloud2::ConstPtr& msg)
123  {
124  boost::mutex::scoped_lock lock(mutex_);
125  vital_checker_->poke();
126  pcl::PointCloud<PointT>::Ptr cloud (new pcl::PointCloud<PointT>);
128  pcl::PointIndices::Ptr indices = filterIndices(cloud);
129  filtered_points_counter_.add(indices->indices.size());
130  pcl::ExtractIndices<PointT> ex;
131  ex.setInputCloud(cloud);
132  ex.setIndices(indices);
133  ex.setNegative(filter_limit_negative_);
134  ex.setKeepOrganized(keep_organized_);
135  pcl::PointCloud<PointT> output;
136  ex.filter(output);
137  sensor_msgs::PointCloud2 ros_output;
138  pcl::toROSMsg(output, ros_output);
139  ros_output.header = msg->header;
140  pub_.publish(ros_output);
141  diagnostic_updater_->update();
142  }
143 
146  {
147  if (vital_checker_->isAlive()) {
148  stat.summary(diagnostic_msgs::DiagnosticStatus::OK,
149  name_ + " running");
150  stat.add("Filtered points (Avg.)", filtered_points_counter_.mean());
151  if (filter_field_ == FIELD_X) {
152  stat.add("filter field", "x");
153  }
154  else if (filter_field_ == FIELD_Y) {
155  stat.add("filter field", "y");
156  }
157  stat.add("min index", min_index_);
158  stat.add("max index", max_index_);
159  jsk_topic_tools::addDiagnosticBooleanStat("keep organized",
161  stat);
162  jsk_topic_tools::addDiagnosticBooleanStat("remove_nan",
163  remove_nan_,
164  stat);
165  jsk_topic_tools::addDiagnosticBooleanStat("filter_limit_negative",
167  stat);
168  }
169  DiagnosticNodelet::updateDiagnostic(stat);
170  }
171 }
172 
extract_top_polygon_likelihood.ex
ex
Definition: extract_top_polygon_likelihood.py:51
jsk_pcl_ros::OrganizedPassThrough::filter_limit_negative_
bool filter_limit_negative_
Definition: organized_pass_through.h:170
depth_error_calibration.lock
lock
Definition: depth_error_calibration.py:32
jsk_pcl_ros::OrganizedPassThrough::onInit
virtual void onInit()
Definition: organized_pass_through_nodelet.cpp:81
jsk_pcl_ros::OrganizedPassThrough::remove_nan_
bool remove_nan_
Definition: organized_pass_through.h:172
i
int i
diagnostic_updater::DiagnosticStatusWrapper::add
void add(const std::string &key, const bool &b)
jsk_pcl_ros::OrganizedPassThrough::filter
virtual void filter(const sensor_msgs::PointCloud2::ConstPtr &msg)
Definition: organized_pass_through_nodelet.cpp:154
jsk_pcl_ros::OrganizedPassThrough::configCallback
virtual void configCallback(Config &config, uint32_t level)
Definition: organized_pass_through_nodelet.cpp:113
jsk_pcl_ros::OrganizedPassThrough::FIELD_X
@ FIELD_X
Definition: organized_pass_through.h:161
ros::Subscriber::shutdown
void shutdown()
jsk_pcl_ros::OrganizedPassThrough::max_index_
int max_index_
Definition: organized_pass_through.h:169
jsk_pcl_ros::OrganizedPassThrough::OrganizedPassThrough
OrganizedPassThrough()
Definition: organized_pass_through_nodelet.cpp:75
pcl::fromROSMsg
void fromROSMsg(const sensor_msgs::PointCloud2 &cloud, pcl::PointCloud< T > &pcl_cloud)
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
jsk_pcl_ros::OrganizedPassThrough::filterIndices
virtual pcl::PointIndices::Ptr filterIndices(const pcl::PointCloud< PointT >::Ptr &pc)
Definition: organized_pass_through_nodelet.cpp:129
cloud
cloud
jsk_pcl_ros::OrganizedPassThrough::mutex_
boost::mutex mutex_
Definition: organized_pass_through.h:152
PLUGINLIB_EXPORT_CLASS
PLUGINLIB_EXPORT_CLASS(jsk_pcl_ros::OrganizedPassThrough, nodelet::Nodelet)
class_list_macros.h
diagnostic_updater::DiagnosticStatusWrapper::summary
void summary(const diagnostic_msgs::DiagnosticStatus &src)
jsk_pcl_ros
Definition: add_color_from_image.h:51
jsk_pcl_ros::OrganizedPassThrough::subscribe
virtual void subscribe()
Definition: organized_pass_through_nodelet.cpp:100
jsk_pcl_ros::OrganizedPassThrough::filtered_points_counter_
jsk_topic_tools::Counter filtered_points_counter_
Definition: organized_pass_through.h:157
jsk_pcl_ros::OrganizedPassThrough::keep_organized_
bool keep_organized_
Definition: organized_pass_through.h:171
jsk_pcl_ros::OrganizedPassThrough::unsubscribe
virtual void unsubscribe()
Definition: organized_pass_through_nodelet.cpp:108
jsk_pcl_ros::OrganizedPassThrough::FIELD_Y
@ FIELD_Y
Definition: organized_pass_through.h:161
jsk_pcl_ros::OrganizedPassThrough::sub_
ros::Subscriber sub_
Definition: organized_pass_through.h:149
jsk_pcl_ros::OrganizedPassThrough::isPointNaN
bool isPointNaN(const PointT &p)
Definition: organized_pass_through.h:142
jsk_pcl_ros::OrganizedPassThrough::filter_field_
FilterField filter_field_
Definition: organized_pass_through.h:167
jsk_pcl_ros::OrganizedPassThrough::min_index_
int min_index_
Definition: organized_pass_through.h:168
nodelet::Nodelet
jsk_pcl_ros::OrganizedPassThrough
Definition: organized_pass_through.h:80
pcl_util.h
jsk_pcl_ros::OrganizedPassThrough::pub_
ros::Publisher pub_
Definition: organized_pass_through.h:150
dump_depth_error.f
f
Definition: dump_depth_error.py:39
diagnostic_updater::DiagnosticStatusWrapper
pcl::toROSMsg
void toROSMsg(const pcl::PointCloud< T > &cloud, sensor_msgs::Image &msg)
jsk_pcl_ros::OrganizedPassThrough::updateDiagnostic
virtual void updateDiagnostic(diagnostic_updater::DiagnosticStatusWrapper &stat)
Definition: organized_pass_through_nodelet.cpp:176
jsk_pcl_ros::OrganizedPassThrough::srv_
boost::shared_ptr< dynamic_reconfigure::Server< Config > > srv_
Definition: organized_pass_through.h:151
config
config
jsk_pcl_ros::OrganizedPassThrough::Config
jsk_pcl_ros::OrganizedPassThroughConfig Config
Definition: organized_pass_through.h:115
pose_with_covariance_sample.msg
msg
Definition: pose_with_covariance_sample.py:22
organized_pass_through.h


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