Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * min_merge.cpp - Laser min merge data filter 00004 * 00005 * Created: Wed Mar 16 21:46:36 2011 00006 * Copyright 2006-2011 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Library General Public License for more details. 00019 * 00020 * Read the full text in the LICENSE.GPL file in the doc directory. 00021 */ 00022 00023 #include "min_merge.h" 00024 00025 #include <core/exception.h> 00026 #include <cstring> 00027 00028 /** @class LaserMinMergeDataFilter "min_merge.h" 00029 * Merge multiple laser data arrays into one. 00030 * For each value in the output array takes the minimum value of all input 00031 * arrays. 00032 * @author Tim Niemueller 00033 */ 00034 00035 /** Constructor. 00036 * @param in_data_size number of entries input value arrays 00037 * @param in vector of input arrays 00038 */ 00039 LaserMinMergeDataFilter::LaserMinMergeDataFilter(unsigned int in_data_size, 00040 std::vector<LaserDataFilter::Buffer *> &in) 00041 : LaserDataFilter(in_data_size, in, 1) 00042 { 00043 } 00044 00045 00046 void 00047 LaserMinMergeDataFilter::filter() 00048 { 00049 const unsigned int vecsize = in.size(); 00050 if (vecsize == 0) return; 00051 00052 out[0]->frame = in[0]->frame; 00053 00054 copy_to_outbuf(out[0], in[0]); 00055 float *outbuf = out[0]->values; 00056 00057 for (unsigned int a = 1; a < vecsize; ++a) { 00058 if (in[a]->frame != out[0]->frame) { 00059 throw fawkes::Exception("MinMerge frame mismatch: two frames with different frame IDs " 00060 "(first has %s but input buffer %u has %s)", 00061 out[0]->frame.c_str(), a, in[a]->frame.c_str()); 00062 } 00063 float *inbuf = in[a]->values; 00064 for (unsigned int i = 0; i < (const unsigned int)out_data_size; ++i) { 00065 if ( (outbuf[i] == 0) || ((inbuf[i] != 0) && (inbuf[i] < outbuf[i])) ) { 00066 outbuf[i] = inbuf[i]; 00067 } 00068 } 00069 } 00070 }