Marsyas  0.6.0-alpha
/usr/src/RPM/BUILD/marsyas-0.6.0/src/marsyas/marsystems/PatchMatrix.cpp
Go to the documentation of this file.
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 #include "../common_source.h"
00019 #include "PatchMatrix.h"
00020 
00021 using namespace Marsyas;
00022 
00023 
00024 //#define MTLB_DBG_LOG
00025 
00026 PatchMatrix::PatchMatrix(mrs_string name):MarSystem("PatchMatrix", name)
00027 {
00028   //Add any specific controls needed by PatchMatrix
00029   //(default controls all MarSystems should have
00030   //were already added by MarSystem::addControl(),
00031   //called by :MarSystem(name) constructor).
00032   //If no specific controls are needed by a MarSystem
00033   //there is no need to implement and call this addControl()
00034   //method (see for e.g. Rms.cpp)
00035   addControls();
00036   use_consts_=false;
00037   use_weights_=false;
00038 }
00039 
00040 PatchMatrix::PatchMatrix(const PatchMatrix& a) : MarSystem(a)
00041 {
00042   // For any MarControlPtr in a MarSystem
00043   // it is necessary to perform this getctrl
00044   // in the copy constructor in order for cloning to work
00045   ctrl_weights_ = getctrl("mrs_realvec/weights");
00046   ctrl_consts_ = getctrl("mrs_realvec/consts");
00047 
00048   use_consts_=a.use_consts_;
00049   use_weights_=a.use_weights_;
00050 }
00051 
00052 PatchMatrix::~PatchMatrix()
00053 {
00054 
00055 }
00056 
00057 MarSystem*
00058 PatchMatrix::clone() const
00059 {
00060   return new PatchMatrix(*this);
00061 }
00062 
00063 void
00064 PatchMatrix::addControls()
00065 {
00066   //Add specific controls needed by this MarSystem.
00067   addctrl("mrs_realvec/consts", realvec(), ctrl_consts_);
00068   addctrl("mrs_realvec/weights", realvec(), ctrl_weights_);
00069   //setControlState("mrs_realvec/consts",true);
00070   setControlState("mrs_realvec/weights",true);
00071 }
00072 
00073 void
00074 PatchMatrix::myUpdate(MarControlPtr sender)
00075 {
00076 
00077   MarSystem::myUpdate(sender);
00078 
00079   if(ctrl_weights_->to<mrs_realvec>().getSize()!=0)
00080   {
00081     use_weights_=true;
00082     ctrl_onObservations_->setValue(ctrl_weights_->to<mrs_realvec>().getRows(),NOUPDATE);
00083   }
00084 }
00085 
00086 
00087 void
00088 PatchMatrix::myProcess(realvec& in, realvec& out)
00089 {
00090   //get a local copy of the current PatchMatrix control's values
00091   //(they will be used for this entire processing, even if it's
00092   //changed by a different thread)
00093   mrs_realvec PatchMatrixValue = ctrl_weights_->to<mrs_realvec>();
00094   mrs_realvec patchConstValues = ctrl_consts_->to<mrs_realvec>();
00095 
00096   if(PatchMatrixValue.getSize()!=0) use_weights_=true;
00097   if(patchConstValues.getSize()!=0) use_consts_=true;
00098 
00099 
00100 #ifdef MARSYAS_MATLAB
00101 #ifdef MTLB_DBG_LOG
00102   MATLAB_PUT(in, "in");
00103   MATLAB_EVAL("figure(11),plot(in'),axis('tight'),grid on");
00104 #endif
00105 #endif
00106 
00107   if (use_weights_)
00108   {
00109     mrs_realvec::matrixMulti(PatchMatrixValue,in,out);
00110   }
00111 
00112   if (use_consts_)
00113   {
00114     out += patchConstValues;
00115   }
00116 
00117 #ifdef MARSYAS_MATLAB
00118 #ifdef MTLB_DBG_LOG
00119   MATLAB_PUT(out, "out");
00120   MATLAB_EVAL("figure(12),plot(out'),axis('tight'),grid on");
00121 #endif
00122 #endif
00123 
00124 }
00125 
00126 
00127 
00128 
00129 
00130 
00131 
00132