25 namespace perception {
54 assert(nr_bins_in_histogram > 0 && data_ep > data_sp);
56 step_bin = (data_ep -
data_sp) / static_cast<float>(nr_bins_in_histogram);
60 smooth_kernel_width = w;
61 smooth_kernel.resize(smooth_kernel_width);
63 sizeof(uint32_t) * smooth_kernel_width);
64 smooth_kernel_radius = smooth_kernel_width >> 1;
70 assert(histogram_mass_limit > 0);
73 assert(decay_factor > 0.0f);
80 static const int kMaxNrBins = 1000;
83 hist_.resize(kMaxNrBins);
84 std::fill(hist_.begin(), hist_.end(), 0);
86 hist_buffer_.resize(kMaxNrBins);
87 std::fill(hist_buffer_.begin(), hist_buffer_.end(), 0);
89 hist_hat_.resize(kMaxNrBins);
90 std::fill(hist_hat_.begin(), hist_hat_.end(), 0.0f);
100 if (val < params_.data_sp || val >= params_.data_ep) {
101 AERROR <<
"Input data to histogram: out-of-range";
102 AERROR << params_.data_sp;
103 AERROR << params_.data_ep;
107 int index = GetIndex(val);
108 if (index < 0 || index >= params_.nr_bins_in_histogram) {
117 std::fill(hist_.begin(), hist_.end(), 0);
118 val_cur_ = val_estimation_ = 0.0f;
121 const std::vector<uint32_t> &
get_hist()
const {
return hist_; }
128 assert(i >= 0 && i < params_.nr_bins_in_histogram);
137 int GetIndex(
float val)
const {
138 return static_cast<int>((val - params_.data_sp) * step_bin_reversed_);
141 float GetValFromIndex(
int index)
const {
142 return (params_.data_sp +
143 (static_cast<float>(index) + 0.5f) * params_.step_bin);
146 void Smooth(
const uint32_t *hist_input,
int nr_bins, uint32_t *hist_output);
148 bool IsGoodShape(
const uint32_t *hist,
int nr_bins,
int max_index);
150 void GetPeakIndexAndMass(
const uint32_t *hist,
int nr_bins,
int *index,
153 void Decay(uint32_t *hist,
int nr_bins) {
154 float df = params_.decay_factor;
155 for (
int i = 0; i < nr_bins; ++i) {
156 hist[i] =
static_cast<uint32_t
>(
static_cast<float>(hist[i]) * df);
160 void GenerateHat(
float *hist_hat,
int nr_bins);
166 std::vector<uint32_t> hist_ = {};
167 std::vector<uint32_t> hist_buffer_ = {};
169 std::vector<float> hist_hat_ = {};
173 float step_bin_reversed_ = 0.0f;
174 float val_cur_ = 0.0f;
175 float val_estimation_ = 0.0f;
uint32_t histogram_mass_limit
Definition: histogram_estimator.h:45
float decay_factor
Definition: histogram_estimator.h:47
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
int smooth_kernel_width
Definition: histogram_estimator.h:39
float data_sp
Definition: histogram_estimator.h:34
std::vector< uint32_t > smooth_kernel
Definition: histogram_estimator.h:38
float get_val_cur() const
Definition: histogram_estimator.h:123
const std::vector< uint32_t > & get_hist() const
Definition: histogram_estimator.h:121
void Clear()
Definition: histogram_estimator.h:116
bool Push(float val)
Definition: histogram_estimator.h:99
~HistogramEstimator()
Definition: histogram_estimator.h:95
float data_ep
Definition: histogram_estimator.h:35
Definition: histogram_estimator.h:78
int smooth_kernel_radius
Definition: histogram_estimator.h:40
uint32_t get_bin_value(int i) const
Definition: histogram_estimator.h:127
int nr_bins_in_histogram
Definition: histogram_estimator.h:33
HistogramEstimatorParams()
Definition: histogram_estimator.h:30
HistogramEstimator()
Definition: histogram_estimator.h:82
float hat_std_allowed
Definition: histogram_estimator.h:43
Definition: histogram_estimator.h:29
void operator=(const HistogramEstimatorParams ¶ms)
Definition: histogram_estimator.h:49
float get_val_estimation() const
Definition: histogram_estimator.h:125
#define AERROR
Definition: log.h:44
float step_bin
Definition: histogram_estimator.h:36
float hat_min_allowed
Definition: histogram_estimator.h:42