25#include <core/exception.h>
26#include <logging/logger.h>
27#include <utils/time/time.h>
46 unsigned int in_data_size,
47 std::vector<LaserDataFilter::Buffer *> &in)
50 timestamp_selection_method_(TIMESTAMP_LATEST),
65 const std::string & filter_name,
67 unsigned int in_data_size,
68 std::vector<LaserDataFilter::Buffer *> &in,
70 unsigned int timestamp_index)
73 timestamp_selection_method_(timestamp_selection_method),
74 timestamp_index_(timestamp_index)
76 if (timestamp_index_ >=
in.size()) {
77 throw fawkes::Exception(
"min_merge timestamp index larger than number of input buffers");
84 const unsigned int vecsize =
in.size();
88 if (ignored_.size() !=
in.size())
89 ignored_.resize(
in.size(),
false);
91 out[0]->frame =
in[0]->frame;
95 for (
unsigned int a = 0; a < vecsize; ++a) {
96 if (
in[a]->frame.empty()) {
99 "input buffer %s has no frame, ignoring",
100 in[a]->name.c_str());
106 "input buffer %s has recovered, frame %s",
108 in[a]->frame.c_str());
121 float *outbuf =
out[0]->values;
123 for (
unsigned int a = first + 1; a < vecsize; ++a) {
127 if (
in[a]->frame !=
out[0]->frame) {
128 throw fawkes::Exception(
"MinMerge[%s] frame mismatch: two frames with different frame IDs "
129 "(output has %s but input buffer %s has %s)",
131 out[0]->frame.c_str(),
133 in[a]->frame.c_str());
135 float *inbuf =
in[a]->values;
136 for (
unsigned int i = 0; i < (
const unsigned int)
out_data_size; ++i) {
139 && (!std::isfinite(outbuf[i])
140 || (std::isfinite(inbuf[1]) && (inbuf[i] < outbuf[i]))))) {
141 outbuf[i] = inbuf[i];
148 for (
unsigned int a = first + 1; a < vecsize; ++a) {
151 if (*
in[a]->timestamp < first_time) {
152 first_time =
in[a]->timestamp;
155 out[0]->timestamp->set_time(first_time);
157 out[0]->timestamp->set_time(
in[timestamp_index_]->timestamp);
160 for (
unsigned int a = first + 1; a < vecsize; ++a) {
163 if (*
in[a]->timestamp > latest) {
164 latest =
in[a]->timestamp;
167 out[0]->timestamp->set_time(latest);
unsigned int out_data_size
Number of entries in output arrays.
void copy_to_outbuf(Buffer *outbuf, const Buffer *inbuf)
Copies the readings from inbuf to outbuf.
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.
TimestampSelectionMethod
Timestamp selection method.
@ TIMESTAMP_FIRST
use the first (oldest) of all timestamps
@ TIMESTAMP_INDEX
use a specific index in the input buffer list
LaserMinMergeDataFilter(const std::string &filter_name, fawkes::Logger *logger, unsigned int in_data_size, std::vector< LaserDataFilter::Buffer * > &in)
Constructor.
virtual void filter()
Filter the incoming data.
Base class for exceptions in Fawkes.
virtual void log_warn(const char *component, const char *format,...)=0
Log warning message.
A class for handling time.