intensity_filter.h
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2008, 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 the Willow Garage 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 #ifndef LASER_SCAN_INTENSITY_FILTER_H
36 #define LASER_SCAN_INTENSITY_FILTER_H
37 
44 #include "filters/filter_base.h"
45 #include "sensor_msgs/LaserScan.h"
46 
47 namespace laser_filters
48 {
49 
50 class LaserScanIntensityFilter : public filters::FilterBase<sensor_msgs::LaserScan>
51 {
52 public:
53 
56  int disp_hist_ ;
58 
59  bool configure()
60  {
61  lower_threshold_ = 8000.0;
62  upper_threshold_ = 100000.0;
63  disp_hist_ = 1;
64  getParam("lower_threshold", lower_threshold_);
65  getParam("upper_threshold", upper_threshold_) ;
66  getParam("disp_histogram", disp_hist_) ;
67 
68  disp_hist_enabled_ = (disp_hist_ == 0) ? false : true;
69 
70  return true;
71  }
72 
74 
75  bool update(const sensor_msgs::LaserScan& input_scan, sensor_msgs::LaserScan& filtered_scan)
76  {
77  const double hist_max = 4*12000.0 ;
78  const int num_buckets = 24 ;
79  int histogram[num_buckets] ;
80  for (int i=0; i < num_buckets; i++)
81  histogram[i] = 0 ;
82 
83  filtered_scan = input_scan;
84 
85  // Need to check ever reading in the current scan
86  for (unsigned int i=0;
87  i < input_scan.ranges.size() && i < input_scan.intensities.size();
88  i++)
89  {
90  // Is this reading below our lower threshold?
91  // Is this reading above our upper threshold?
92  if (filtered_scan.intensities[i] <= lower_threshold_ ||
93  filtered_scan.intensities[i] >= upper_threshold_)
94  {
95  // If so, then make it an invalid value (NaN)
96  filtered_scan.ranges[i] = std::numeric_limits<float>::quiet_NaN();
97  }
98 
99  // Calculate histogram
100  if (disp_hist_enabled_){
101  // If intensity value is inf or NaN, skip voting histogram
102  if( std::isinf((double)filtered_scan.intensities[i]) ||
103  std::isnan((double)filtered_scan.intensities[i]) )
104  continue;
105 
106  // Choose bucket to vote on histogram,
107  // and check the index of bucket is in the histogram array
108  int cur_bucket = (int)(filtered_scan.intensities[i] / hist_max * num_buckets);
109  if (cur_bucket > num_buckets-1)
110  cur_bucket = num_buckets-1;
111  else if (cur_bucket < 0) cur_bucket = 0;
112  histogram[cur_bucket]++;
113  }
114  }
115 
116  // Display Histogram
117  if (disp_hist_enabled_)
118  {
119  printf("********** SCAN **********\n") ;
120  for (int i=0; i < num_buckets; i++)
121  {
122  printf("%u - %u: %u\n", (unsigned int) hist_max/num_buckets*i,
123  (unsigned int) hist_max/num_buckets*(i+1),
124  histogram[i]) ;
125  }
126  }
127  return true;
128  }
129 };
130 }
131 
132 #endif // LASER_SCAN_INTENSITY_FILTER_H
LaserScanMaskFilter removes points on directions defined in a mask from a laser scan.
bool getParam(const std::string &name, std::string &value)
bool update(const sensor_msgs::LaserScan &input_scan, sensor_msgs::LaserScan &filtered_scan)


laser_filters
Author(s): Tully Foote
autogenerated on Wed Jul 3 2019 19:33:47