25#include <config/config.h>
26#include <core/exception.h>
27#include <core/macros.h>
28#include <logging/logger.h>
30#include <utils/math/angle.h>
31#include <utils/time/time.h>
59 const std::string & prefix,
60 unsigned int in_data_size,
61 std::vector<LaserDataFilter::Buffer *> &in)
68 if ((error = regcomp(&pathre, (prefix +
"\\([^/]\\+\\)/\\(start\\|end\\)").c_str(), 0)) != 0) {
69 size_t errsize = regerror(error, &pathre, NULL, 0);
71 regerror(error, &pathre, tmp, errsize);
73 throw Exception(
"Failed to compile regular expression: %s", tmp);
76 regmatch_t matches[2];
78 std::list<std::string> entries;
82 const char *path = vit->
path();
83 if (regexec(&pathre, path, 2, matches, 0) == 0) {
84 size_t match1_length = matches[1].rm_eo - matches[1].rm_so;
86 char entry[match1_length + 1];
87 entry[match1_length] = 0;
88 strncpy(entry, &(path[matches[1].rm_so]), match1_length);
89 entries.push_back(entry);
96 dead_spots_size_ = entries.size() * 2;
97 dead_spots_ =
new unsigned int[dead_spots_size_];
99 for (std::list<std::string>::iterator i = entries.begin(); i != entries.end(); ++i) {
100 std::string path = prefix + *i +
"/";
101 float start = config->
get_float((path +
"start").c_str());
102 float end = config->
get_float((path +
"end").c_str());
105 "LaserDeadSpotsDataFilter",
"Adding dead range [%3.3f, %3.3f] (%s)", start, end, i->c_str());
106 cfg_dead_spots_.push_back(std::make_pair(start, end));
109 num_spots_ = cfg_dead_spots_.size();
111 if (num_spots_ == 0) {
113 "Dead spots filter enabled but no calibration data exists. Run fflaser_deadspots.");
123:
LaserDataFilter(other.filter_name, other.in_data_size, other.in, other.in.size()),
124 logger_(other.logger_),
125 num_spots_(other.num_spots_),
126 dead_spots_size_(other.dead_spots_size_),
127 cfg_dead_spots_(other.cfg_dead_spots_)
129 dead_spots_ =
new unsigned int[dead_spots_size_];
130 for (
unsigned int i = 0; i < dead_spots_size_; ++i) {
131 dead_spots_[i] = other.dead_spots_[i];
135LaserDeadSpotsDataFilter::~LaserDeadSpotsDataFilter()
137 delete[] dead_spots_;
150 delete[] dead_spots_;
155 logger_ = other.logger_;
157 cfg_dead_spots_ = other.cfg_dead_spots_;
158 num_spots_ = other.num_spots_;
159 dead_spots_size_ = other.dead_spots_size_;
160 dead_spots_ =
new unsigned int[dead_spots_size_];
161 for (
unsigned int i = 0; i < dead_spots_size_; ++i) {
162 dead_spots_[i] = other.dead_spots_[i];
169LaserDeadSpotsDataFilter::set_out_vector(std::vector<LaserDataFilter::Buffer *> &out)
176LaserDeadSpotsDataFilter::calc_spots()
179 throw Exception(
"Dead spots filter requires equal input and output data size");
184 for (
unsigned int i = 0; i < num_spots_; ++i) {
186 std::min(
in_data_size - 1, (
unsigned int)ceilf(cfg_dead_spots_[i].first / angle_factor));
187 dead_spots_[i * 2 + 1] =
188 std::min(
in_data_size - 1, (
unsigned int)ceilf(cfg_dead_spots_[i].second / angle_factor));
195 const unsigned int vecsize = std::min(
in.size(),
out.size());
196 for (
unsigned int a = 0; a < vecsize; ++a) {
197 out[a]->frame =
in[a]->frame;
198 out[a]->timestamp->set_time(
in[a]->timestamp);
199 float *inbuf =
in[a]->values;
200 float *outbuf =
out[a]->values;
202 unsigned int start = 0;
203 for (
unsigned int i = 0; i < num_spots_; ++i) {
204 const unsigned int spot_start = dead_spots_[i * 2];
205 const unsigned int spot_end = dead_spots_[i * 2 + 1];
206 for (
unsigned int j = start; j < spot_start; ++j) {
207 outbuf[j] = inbuf[j];
209 for (
unsigned int j = spot_start; j <= spot_end; ++j) {
212 start = spot_end + 1;
215 outbuf[j] = inbuf[j];
unsigned int out_data_size
Number of entries in output arrays.
unsigned int in_data_size
Number of entries in input arrays.
std::string filter_name
Name of the specific filter instance.
std::vector< Buffer * > out
Vector of output arrays.
std::vector< Buffer * > in
Vector of input arrays.
virtual void set_out_vector(std::vector< Buffer * > &out)
Set filtered data array.
void filter()
Filter the incoming data.
LaserDeadSpotsDataFilter(const std::string &filter_name, fawkes::Configuration *config, fawkes::Logger *logger, const std::string &prefix, unsigned int data_size, std::vector< LaserDataFilter::Buffer * > &in)
Constructor.
LaserDeadSpotsDataFilter & operator=(const LaserDeadSpotsDataFilter &other)
Assignment operator.
Iterator interface to iterate over config values.
virtual const char * path() const =0
Path of value.
virtual bool next()=0
Check if there is another element and advance to this if possible.
Interface for configuration handling.
virtual float get_float(const char *path)=0
Get value from configuration which is of type float.
virtual ValueIterator * search(const char *path)=0
Iterator with search results.
Base class for exceptions in Fawkes.
virtual void log_debug(const char *component, const char *format,...)=0
Log debug message.
Fawkes library namespace.