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 
29 #include <cstdlib>
30 
31 /** @class Laser720to360DataFilter "720to360.h"
32  * Downsample filter from 720 to 360 values.
33  * @author Tim Niemueller
34  */
35 
36 /** Constructor.
37  * @param filter_name name of this filter instance
38  * @param average if true, beams will be averaged by left and right neighbours,
39  * otherwise every second beam will be used
40  * @param in_data_size number of entries input value arrays
41  * @param in vector of input arrays
42  */
43 Laser720to360DataFilter::Laser720to360DataFilter(const std::string &filter_name,
44  bool average,
45  unsigned int in_data_size,
46  std::vector<LaserDataFilter::Buffer *> &in)
47 : LaserDataFilter(filter_name, in_data_size, in, in.size())
48 {
49  if (in_data_size != 720) {
50  throw fawkes::Exception("720to360 filter needs input array size of "
51  "720 entries");
52  }
53  set_out_data_size(360);
54  average_ = average;
55 }
56 
57 void
59 {
60  const unsigned int vecsize = std::min(in.size(), out.size());
61  for (unsigned int a = 0; a < vecsize; ++a) {
62  out[a]->frame = in[a]->frame;
63  out[a]->timestamp->set_time(in[a]->timestamp);
64  float *inbuf = in[a]->values;
65  float *outbuf = out[a]->values;
66 
67  if (average_) {
68  outbuf[0] = (inbuf[719] + inbuf[0]) / 2.0;
69  for (unsigned int i = 1; i < 360; ++i) {
70  outbuf[i] = (inbuf[i * 2 - 1] + inbuf[i * 2 + 1]) / 2.0;
71  }
72  } else {
73  for (unsigned int i = 0; i < 360; ++i) {
74  outbuf[i] = inbuf[i * 2];
75  }
76  }
77  }
78 }
LaserDataFilter::in_data_size
unsigned int in_data_size
Number of entries in input arrays.
Definition: filter.h:88
LaserDataFilter::in
std::vector< Buffer * > in
Vector of input arrays.
Definition: filter.h:89
Laser720to360DataFilter::Laser720to360DataFilter
Laser720to360DataFilter(const std::string &filter_name, bool average, unsigned int in_data_size, std::vector< LaserDataFilter::Buffer * > &in)
Constructor.
Definition: 720to360.cpp:43
Laser720to360DataFilter::filter
void filter()
Filter the incoming data.
Definition: 720to360.cpp:58
LaserDataFilter::set_out_data_size
virtual void set_out_data_size(unsigned int data_size)
Resize output arrays.
Definition: filter.cpp:156
LaserDataFilter
Laser data filter.
Definition: filter.h:33
LaserDataFilter::out
std::vector< Buffer * > out
Vector of output arrays.
Definition: filter.h:90
fawkes::Exception
Base class for exceptions in Fawkes.
Definition: exception.h:36