Fawkes API  Fawkes Development Version
circle_sector.cpp
1 
2 /***************************************************************************
3  * circle_sector.cpp - Filter laser data for circle sector
4  *
5  * Created: Sat Feb 19 00:28:41 2011
6  * Copyright 2006-2011 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 "circle_sector.h"
24 
25 #include <core/exception.h>
26 #include <utils/math/angle.h>
27 #include <utils/time/time.h>
28 #include <algorithm>
29 #include <cstring>
30 
31 using namespace fawkes;
32 
33 /** @class LaserCircleSectorDataFilter "circle.h"
34  * Erase beams outside specified circle sector.
35  * Only data inside the specified circle sector is copied, all other data is
36  * set to zero.
37  * @author Tim Niemueller
38  */
39 
40 /** Constructor.
41  * @param filter_name name of this filter instance
42  * @param from start angle (index in data)
43  * @param to end angle (index in data)
44  * @param in_data_size number of entries in value arrays
45  * @param in vector of input arrays
46  */
48  unsigned int from,
49  unsigned int to,
50  unsigned int in_data_size,
51  std::vector<LaserDataFilter::Buffer *> &in)
52  : LaserDataFilter(filter_name, in_data_size, in, in.size())
53 {
54  __from = from;
55  __to = to;
56 }
57 
58 
59 void
61 {
62  const unsigned int vecsize = std::min(in.size(), out.size());
63  const unsigned int arrsize = std::min(in_data_size, out_data_size);
64  for (unsigned int a = 0; a < vecsize; ++a) {
65 
66  reset_outbuf(out[a]);
67  out[a]->frame = in[a]->frame;
68  out[a]->timestamp->set_time(in[a]->timestamp);
69 
70  float *inbuf = in[a]->values;
71  float *outbuf = out[a]->values;
72 
73  if (__from > __to) {
74  for (unsigned int i = __from; i < arrsize; ++i) {
75  outbuf[i] = inbuf[i];
76  }
77  for (unsigned int i = 0; i <= std::min(__to, arrsize-1); ++i) {
78  outbuf[i] = inbuf[i];
79  }
80  } else {
81  for (unsigned int i = __from; i <= std::min(__to, arrsize-1); ++i) {
82  outbuf[i] = inbuf[i];
83  }
84  }
85  }
86 }
std::vector< Buffer * > out
Vector of output arrays.
Definition: filter.h:76
Fawkes library namespace.
LaserCircleSectorDataFilter(const std::string filter_name, unsigned int from, unsigned int to, unsigned int data_size, std::vector< LaserDataFilter::Buffer *> &in)
Constructor.
void filter()
Filter the incoming data.
void reset_outbuf(Buffer *b)
Resets all readings in outbuf to NaN.
Definition: filter.cpp:186
unsigned int out_data_size
Number of entries in output arrays.
Definition: filter.h:73
std::vector< Buffer * > in
Vector of input arrays.
Definition: filter.h:75
unsigned int in_data_size
Number of entries in input arrays.
Definition: filter.h:74
Laser data filter.
Definition: filter.h:32