00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "common.h"
00019 #include "PatchMatrix.h"
00020
00021 using namespace Marsyas;
00022
00023
00024
00025
00026 PatchMatrix::PatchMatrix(mrs_string name):MarSystem("PatchMatrix", name)
00027 {
00028
00029
00030
00031
00032
00033
00034
00035 addControls();
00036 use_consts_=false;
00037 use_weights_=false;
00038 }
00039
00040 PatchMatrix::PatchMatrix(const PatchMatrix& a) : MarSystem(a)
00041 {
00042
00043
00044
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
00067 addctrl("mrs_realvec/consts", realvec(), ctrl_consts_);
00068 addctrl("mrs_realvec/weights", realvec(), ctrl_weights_);
00069
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
00091
00092
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