Skip to content
Snippets Groups Projects
Commit 77895c20 authored by Christophe Palmann's avatar Christophe Palmann
Browse files

ENH: bandmathx (operators)

parent c60cb20a
No related branches found
No related tags found
No related merge requests found
......@@ -63,6 +63,7 @@ public:
m_MuParserX.DefineFun(new cat);
m_MuParserX.DefineOprt(new ElementWiseDivision);
m_MuParserX.DefineOprt(new ElementWiseMultiplication);
m_MuParserX.DefineOprt(new ElementWisePower);
m_MuParserX.DefineFun(new mean);
m_MuParserX.DefineFun(new var);
m_MuParserX.DefineFun(new median);
......
......@@ -30,6 +30,7 @@ void bands::Eval(mup::ptr_val_type &ret, const mup::ptr_val_type *a_pArg, int a_
{
assert(a_iArgc==2);
assert(a_pArg[0]->GetType()=='m');
assert(a_pArg[1]->GetType()=='m');
// Get the argument from the argument input vector
......@@ -53,6 +54,8 @@ void bands::Eval(mup::ptr_val_type &ret, const mup::ptr_val_type *a_pArg, int a_
void conv::Eval(mup::ptr_val_type &ret, const mup::ptr_val_type *a_pArg, int a_iArgc)
{
assert(a_pArg[0]->GetType()=='m');
// Get the argument from the argument input vector
mup::matrix_type m1 = a_pArg[0]->GetArray();
......@@ -95,6 +98,9 @@ void conv::Eval(mup::ptr_val_type &ret, const mup::ptr_val_type *a_pArg, int a_i
void ElementWiseDivision::Eval(mup::ptr_val_type &ret, const mup::ptr_val_type *a_pArg, int)
{
assert(a_pArg[0]->GetType()=='m');
assert(a_pArg[1]->GetType()=='m');
const mup::matrix_type a = a_pArg[0]->GetArray();
const mup::matrix_type b = a_pArg[1]->GetArray();
......@@ -102,6 +108,17 @@ void ElementWiseDivision::Eval(mup::ptr_val_type &ret, const mup::ptr_val_type *
int nbrows = a.GetRows();
int nbcols = a.GetCols();
int nbrows2 = b.GetRows();
int nbcols2 = b.GetCols();
if ( (nbrows != nbrows2) || (nbcols != nbcols2) )
{
mup::ErrorContext err;
err.Errc = mup::ecMATRIX_DIMENSION_MISMATCH;
err.Ident = GetIdent();
throw mup::ParserError(err);
}
mup::matrix_type res(nbrows,nbcols,0.);
for (int k=0; k<nbcols; ++k)
......@@ -119,12 +136,27 @@ void ElementWiseDivision::Eval(mup::ptr_val_type &ret, const mup::ptr_val_type *
void ElementWiseMultiplication::Eval(mup::ptr_val_type &ret, const mup::ptr_val_type *a_pArg, int)
{
assert(a_pArg[0]->GetType()=='m');
assert(a_pArg[1]->GetType()=='m');
const mup::matrix_type a = a_pArg[0]->GetArray();
const mup::matrix_type b = a_pArg[1]->GetArray();
int nbrows = a.GetRows();
int nbcols = a.GetCols();
int nbrows2 = b.GetRows();
int nbcols2 = b.GetCols();
if ( (nbrows != nbrows2) || (nbcols != nbcols2) )
{
mup::ErrorContext err;
err.Errc = mup::ecMATRIX_DIMENSION_MISMATCH;
err.Ident = GetIdent();
throw mup::ParserError(err);
}
mup::matrix_type res(nbrows,nbcols,0.);
for (int k=0; k<nbcols; ++k)
......@@ -136,11 +168,37 @@ void ElementWiseMultiplication::Eval(mup::ptr_val_type &ret, const mup::ptr_val_
}
void ElementWisePower::Eval(mup::ptr_val_type &ret, const mup::ptr_val_type *a_pArg, int a_iArgc)
{
assert(a_iArgc==2);
assert(a_pArg[0]->GetType()=='m');
// Get the argument from the argument input vector
const mup::matrix_type a = a_pArg[0]->GetArray();
const double pw = a_pArg[1]->GetFloat();
int nbrows = a.GetRows();
int nbcols = a.GetCols();
mup::matrix_type res(nbrows,nbcols,0.);
for (int k=0; k<nbcols; ++k)
for (int p=0; p<nbrows; ++p)
{
assert(a.At(p,k).GetFloat() >= 0 );
res.At(p,k) = vcl_pow(a.At(p,k).GetFloat(),pw);
}
// The return value is passed by writing it to the reference ret
*ret = res;
}
void ndvi::Eval(mup::ptr_val_type &ret, const mup::ptr_val_type *a_pArg, int a_iArgc)
{
// Get the argument from the argument input vector
mup::float_type r = a_pArg[0]->GetFloat();
mup::float_type niri = a_pArg[1]->GetFloat();
......@@ -475,6 +533,7 @@ void vmax::Eval(mup::ptr_val_type &ret, const mup::ptr_val_type *a_pArg, int a_i
}
//--------------------------------------------------------------------------------------------------------//
void vcos::Eval(mup::ptr_val_type &ret, const mup::ptr_val_type *a_pArg, int a_iArgc)
{
......@@ -699,6 +758,5 @@ void vsqrt::Eval(mup::ptr_val_type &ret, const mup::ptr_val_type *a_pArg, int a_
*ret = res;
}
}//end namespace otb
......@@ -107,6 +107,26 @@ class ElementWiseMultiplication : public mup::IOprtBin
};
class ElementWisePower : public mup::IOprtBin
{
public:
ElementWisePower():IOprtBin(_T("pow"), (int) mup::prPOW, mup::oaRIGHT)
{}
virtual void Eval(mup::ptr_val_type &ret, const mup::ptr_val_type *a_pArg, int a_iArgc);
const mup::char_type* GetDesc() const
{
return _T("pow - Power for noncomplex vectors & matrices");
}
virtual mup::IToken* Clone() const
{
return new ElementWisePower(*this);
}
};
class ndvi : public mup::ICallback
{
public:
......@@ -246,7 +266,6 @@ public:
}
};
//--------------------------------------------------------------------------------------------------------//
class vcos : public mup::ICallback
{
......@@ -467,6 +486,7 @@ public:
}
};
}//end namespace otb
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment