58 ConditionPtr condp (
new pcl::ConditionAnd<pcl::PointXYZRGB> ());
60 int r_max, r_min, g_max, g_min, b_max, b_min;
87 ConditionPtr cond (
new pcl::ConditionAnd<pcl::PointXYZRGB> ());
90 cond->addComparison (le);
91 cond->addComparison (ge);
92 condp->addCondition(cond);
95 ConditionPtr cond (
new pcl::ConditionAnd<pcl::PointXYZRGB> ());
98 cond->addComparison (le);
99 cond->addComparison (ge);
100 condp->addCondition(cond);
103 ConditionPtr cond (
new pcl::ConditionAnd<pcl::PointXYZRGB> ());
106 cond->addComparison (le);
107 cond->addComparison (ge);
108 condp->addCondition(cond);
117 r_max_ = config.r_limit_max;
118 r_min_ = config.r_limit_min;
119 g_max_ = config.g_limit_max;
120 g_min_ = config.g_limit_min;
121 b_max_ = config.b_limit_max;
122 b_min_ = config.b_limit_min;
127 unsigned char r,
unsigned char g,
unsigned char b)
149 ConditionPtr condp (
new pcl::ConditionAnd<pcl::PointXYZRGB> ());
151 int h_max, h_min, s_max, s_min, i_max, i_min;
152 if ( h_max_ >= h_min_ ) {
160 if ( s_max_ >= s_min_ ) {
168 if ( i_max_ >= i_min_ ) {
178 ConditionPtr cond (
new pcl::ConditionAnd<pcl::PointXYZRGB> ());
181 cond->addComparison (le);
182 cond->addComparison (ge);
183 condp->addCondition(cond);
186 ConditionPtr cond (
new pcl::ConditionAnd<pcl::PointXYZRGB> ());
189 cond->addComparison (le);
190 cond->addComparison (ge);
191 condp->addCondition(cond);
194 ConditionPtr cond (
new pcl::ConditionAnd<pcl::PointXYZRGB> ());
197 cond->addComparison (le);
198 cond->addComparison (ge);
199 condp->addCondition(cond);
208 h_max_ = config.h_limit_max;
209 h_min_ = config.h_limit_min;
210 s_max_ = config.s_limit_max;
211 s_min_ = config.s_limit_min;
212 i_max_ = config.i_limit_max;
213 i_min_ = config.i_limit_min;
218 unsigned char r,
unsigned char g,
unsigned char b)
222 float hx = (2.0f * r - g - b) / 4.0
f;
223 float hy =
static_cast<float> (g - b) * 111.0
f / 255.0
f;
224 int8_t h_ =
static_cast<std::int8_t
> (std::atan2(hy, hx) * 128.0f /
M_PI);
226 int32_t i = (r+g+b)/3;
227 uint8_t i_ =
static_cast<std::uint8_t
> (i);
233 uint8_t s_ =
static_cast<std::uint8_t
> ((i == 0) ? 0 : 255 - (m * 255) / i);
235 x = (s_ *
cos(h_ *
M_PI / 128.0))/255.0;
236 y = (s_ *
sin(h_ *
M_PI / 128.0))/255.0;
241 template <
class PackedComparison,
typename Config>
243 const PCLIndicesMsg::ConstPtr& indices)
247 pcl::PointCloud<pcl::PointXYZRGB> tmp_in, tmp_out;
248 sensor_msgs::PointCloud2 out;
249 fromROSMsg(*input, tmp_in);
253 pcl::IndicesPtr vindices;
254 vindices.reset(
new std::vector<int> (indices->indices));
268 for (
unsigned int j=0; j<tmp_in.points.size(); j++) {
269 uint32_t rgb_data_ = *
reinterpret_cast<int*
> (&tmp_in.points[j].rgb);
270 unsigned char r_ = (rgb_data_>>16) & 0x0000ff;
271 unsigned char g_ = (rgb_data_>>8) & 0x0000ff;
272 unsigned char b_ = (rgb_data_) & 0x0000ff;
278 if ( std::isnan(tmp_in.points[j].x) && std::isnan(tmp_in.points[j].y) && std::isnan(tmp_in.points[j].z) ) {
282 memcpy((
void *)(&(
color_space_msg_.data[j*16+0])), (
const void *)&x_,
sizeof(
float));
283 memcpy((
void *)(&(
color_space_msg_.data[j*16+4])), (
const void *)&y_,
sizeof(
float));
284 memcpy((
void *)(&(
color_space_msg_.data[j*16+8])), (
const void *)&z_,
sizeof(
float));
286 if ( std::isnan(tmp_out.points[j].x) && std::isnan(tmp_out.points[j].y) && std::isnan(tmp_out.points[j].z) ) {
287 unsigned char gray_ = 16 + (r_/3 + g_/3 + b_/3)*(255-16)/255;
288 r_ = g_ = b_ = gray_;
291 unsigned char rgb_packed_[4] = {r_, g_, b_, 0};
292 memcpy((
void *)(&(
color_space_msg_.data[j*16+12])), (
const void *)rgb_packed_, 4*
sizeof(
unsigned char));
297 if (tmp_out.points.size() > 0) {
298 toROSMsg(tmp_out, out);
303 template <
class PackedComparison,
typename Config>
306 filter(input, PCLIndicesMsg::ConstPtr());
309 template <
class PackedComparison,
typename Config>
312 ConnectionBasedNodelet::onInit();
336 pnh_->param(
"keep_organized", keep_organized,
false);
338 pub_ = advertise<sensor_msgs::PointCloud2>(*
pnh_,
"output", 1);
341 filter_instance_.setKeepOrganized(keep_organized);
343 srv_ = boost::make_shared <dynamic_reconfigure::Server<Config> > (*pnh_);
344 typename dynamic_reconfigure::Server<Config>::CallbackType
f =
346 srv_->setCallback (f);
351 template <
class PackedComparison,
typename Config>
356 sync_ = boost::make_shared<message_filters::Synchronizer<SyncPolicy> >(10);
367 template <
class PackedComparison,
typename Config>
message_filters::Subscriber< PCLIndicesMsg > sub_indices_
void publish(const boost::shared_ptr< M > &message) const
pcl::PackedRGBComparison< pcl::PointXYZRGB > Comparison
virtual void configCallback(Config &config, uint32_t level)=0
boost::shared_ptr< message_filters::Synchronizer< SyncPolicy > > sync_
virtual void updateCondition()
pcl::ComparisonBase< pcl::PointXYZRGB >::Ptr ComparisonPtr
friend class RGBColorFilter
virtual void configCallback(jsk_pcl_ros::RGBColorFilterConfig &config, uint32_t level)
virtual void configCallback(jsk_pcl_ros::HSIColorFilterConfig &config, uint32_t level)
sensor_msgs::PointCloud2 color_space_msg_
boost::shared_ptr< dynamic_reconfigure::Server< jsk_pcl_ros::RGBColorFilterConfig > > srv_
virtual void updateCondition()
ros::Publisher color_space_pub_
friend class HSIColorFilter
pcl::ConditionBase< pcl::PointXYZRGB >::Ptr ConditionPtr
virtual void convertToColorSpace(float &x, float &y, float &z, unsigned char r, unsigned char g, unsigned char b)
message_filters::Subscriber< sensor_msgs::PointCloud2 > sub_input_
PLUGINLIB_EXPORT_CLASS(jsk_pcl_ros::RGBColorFilter, nodelet::Nodelet)
uint32_t getNumSubscribers() const
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)
pcl::ConditionalRemoval< pcl::PointXYZRGB > filter_instance_
virtual void convertToColorSpace(float &x, float &y, float &z, unsigned char r, unsigned char g, unsigned char b)
virtual void filter(const sensor_msgs::PointCloud2ConstPtr &input)
Connection registerCallback(const C &callback)
virtual void unsubscribe()