Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 1998-2006 George Tzanetakis <gtzan@cs.uvic.ca> 00003 ** 00004 ** This program is free software; you can redistribute it and/or modify 00005 ** it under the terms of the GNU General Public License as published by 00006 ** the Free Software Foundation; either version 2 of the License, or 00007 ** (at your option) any later version. 00008 ** 00009 ** This program is distributed in the hope that it will be useful, 00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 ** GNU General Public License for more details. 00013 ** 00014 ** You should have received a copy of the GNU General Public License 00015 ** along with this program; if not, write to the Free Software 00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 00020 #include "Centroid.h" 00021 #include "../common_source.h" 00022 00023 using std::ostringstream; 00024 using namespace Marsyas; 00025 00026 Centroid::Centroid(mrs_string name):MarSystem("Centroid", name) 00027 { 00028 m0_ = 0.0; 00029 m1_ = 0.0; 00030 } 00031 00032 Centroid::~Centroid() 00033 { 00034 } 00035 00036 MarSystem* 00037 Centroid::clone() const 00038 { 00039 return new Centroid(*this); 00040 } 00041 00042 void 00043 Centroid::myUpdate(MarControlPtr sender) 00044 { 00045 (void) sender; //suppress warning of unused parameter(s) 00046 00047 MRSDIAG("Centroid.cpp - Centroid:myUpdate"); 00048 ctrl_onSamples_->setValue(ctrl_inSamples_, NOUPDATE); 00049 ctrl_onObservations_->setValue((mrs_natural)1, NOUPDATE); 00050 ctrl_osrate_->setValue(ctrl_israte_, NOUPDATE); 00051 ctrl_onObsNames_->setValue("Centroid_" + ctrl_inObsNames_->to<mrs_string>() , NOUPDATE); 00052 } 00053 00054 void 00055 Centroid::myProcess(realvec& in, realvec& out) 00056 { 00057 mrs_natural o,t; 00058 // computer centroid of observations for each time sample 00059 // using zero and first-order moments 00060 for (t = 0; t < inSamples_; t++) 00061 { 00062 m0_ = 0.0; 00063 m1_ = 0.0; 00064 for (o=0; o < inObservations_; o++) 00065 { 00066 m1_ += o * in(o,t); 00067 m0_ += in(o,t); 00068 } 00069 if (m0_ != 0.0) 00070 out(0,t) = (m1_ / m0_) / inObservations_; 00071 else 00072 out(0,t) = 0.5; 00073 } 00074 00075 }