Fawkes API  Fawkes Development Version
720to360.cpp
1 
2 /***************************************************************************
3  * 720to360.cpp - Laser data data filter to downsample 720 to 360 values
4  *
5  * Created: Tue Jun 23 14:37:36 2009
6  * Copyright 2006-2009 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #include "720to360.h"
24 
25 #include <core/exception.h>
26 #include <utils/math/angle.h>
27 #include <utils/time/time.h>
28 #include <cstdlib>
29 
30 /** @class Laser720to360DataFilter "720to360.h"
31  * Downsample filter from 720 to 360 values.
32  * @author Tim Niemueller
33  */
34 
35 /** Constructor.
36  * @param filter_name name of this filter instance
37  * @param average if true, beams will be averaged by left and right neighbours,
38  * otherwise every second beam will be used
39  * @param in_data_size number of entries input value arrays
40  * @param in vector of input arrays
41  */
43  bool average,
44  unsigned int in_data_size,
45  std::vector<LaserDataFilter::Buffer *> &in)
46  : LaserDataFilter(filter_name, in_data_size, in, in.size())
47 {
48  if (in_data_size != 720) {
49  throw fawkes::Exception("720to360 filter needs input array size of "
50  "720 entries");
51  }
52  set_out_data_size(360);
53  __average = average;
54 }
55 
56 void
58 {
59  const unsigned int vecsize = std::min(in.size(), out.size());
60  for (unsigned int a = 0; a < vecsize; ++a) {
61  out[a]->frame = in[a]->frame;
62  out[a]->timestamp->set_time(in[a]->timestamp);
63  float *inbuf = in[a]->values;
64  float *outbuf = out[a]->values;
65 
66  if (__average) {
67  outbuf[0] = (inbuf[719] + inbuf[0]) / 2.0;
68  for (unsigned int i = 1; i < 360; ++i) {
69  outbuf[i] = (inbuf[i * 2 - 1] + inbuf[i * 2 + 1]) / 2.0;
70  }
71  } else {
72  for (unsigned int i = 0; i < 360; ++i) {
73  outbuf[i] = inbuf[i * 2];
74  }
75  }
76  }
77 }
std::vector< Buffer * > out
Vector of output arrays.
Definition: filter.h:76
void filter()
Filter the incoming data.
Definition: 720to360.cpp:57
Base class for exceptions in Fawkes.
Definition: exception.h:36
Laser720to360DataFilter(const std::string filter_name, bool average, unsigned int in_data_size, std::vector< LaserDataFilter::Buffer *> &in)
Constructor.
Definition: 720to360.cpp:42
virtual void set_out_data_size(unsigned int data_size)
Resize output arrays.
Definition: filter.cpp:157
std::vector< Buffer * > in
Vector of input arrays.
Definition: filter.h:75
Laser data filter.
Definition: filter.h:32