28 template <
class A,
class B,
class C>
30 int ly,
int ify,
const B& y,
31 int lz,
int ifz, C& z)
33 int ilx=ifx+lx-1,ily=ify+ly-1,ilz=ifz+lz-1,i,j,jlow,jhigh;
36 for ( i=ifz; i<=ilz; ++i )
39 if ( jlow < ifx ) jlow = ifx;
42 if ( jhigh > ilx ) jhigh = ilx;
44 for ( j=jlow,sum=0.0; j<=jhigh; ++j )
47 sum += x[j-ifx]*y[i-j-ify];
55 template <
class A,
class B,
class C>
57 int ly,
int ify,
const B& y,
58 int lz,
int ifz, C& z)
60 int ilx=ifx+lx-1,ily=ify+ly-1,ilz=ifz+lz-1,i,j,jlow,jhigh;
63 for ( i=ifz; i<=ilz; ++i )
66 if ( jlow < ifx ) jlow = ifx;
69 if ( jhigh > ilx ) jhigh = ilx;
71 for ( j=jlow,sum=0.0; j<=jhigh; ++j )
72 sum += x[j-ifx]*y[i-j-ify];
83 template <
class A,
class B>
84 inline float similarity(
const A& a,
const B& b,
int sz,
bool normalize=
false,
85 int firstposa=0,
int firstposb=0 )
88 double sqdist = 0, sq1 = 0, sq2 = 0;
90 double meana =
mUdf(
double), stddeva =
mUdf(
double);
91 double meanb =
mUdf(
double), stddevb =
mUdf(
double);
95 if ( sz==1 ) normalize =
false;
99 for (
int idx=0; idx<sz; idx++ )
101 asum += a[firstposa+idx];
102 bsum += b[firstposb+idx];
110 for (
int idx=0; idx<sz; idx++ )
112 const double adiff = a[firstposa+idx]-meana;
113 const double bdiff = b[firstposb+idx]-meanb;
126 int curposa = firstposa;
127 int curposb = firstposb;
129 for (
int idx=0; idx<sz; idx++ )
131 val1 = normalize ? (float) ( (a[curposa]-meana)/stddeva ) : a[curposa];
132 val2 = normalize ? (float) ( (b[curposb]-meanb)/stddevb ) : b[curposb];
138 sqdist += (val1-
val2) * (val1-val2);
158 float x1,
float x2,
float dist,
int sz,
bool normalize );
177 float& res,
float targetval = 0,
float tol=1e-5);
199 float x2,
float tol = 1e-5);
202 template <
class A,
class B>
inline 204 B& output,
int nrsamples )
206 for (
int idx=0; idx<nrsamples; idx++ )
208 const float sampleval = samplevals[idx];
229 template <
class A,
class B,
class C>
231 int ly,
int ify,
const B& y,
232 int lz,
int ifz, C& z)
236 for (
int i=0,j=lx-1; i<lx; ++i,--j)
246 for (
int idx=0; idx<sz; idx++ )
247 out[idx] = in[sz-1-idx];
251 for (
int idx=0; idx<sz/2; idx++ )
253 tmparr[idx] = in[idx];
254 int opsamp = sz-1-idx;
255 in[idx] = in[opsamp];
256 in[opsamp] = tmparr[idx];
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:287
double LanczosKernel(int size, double x)
#define mGlobal(module)
Definition: commondefs.h:163
#define mIsZero(x, eps)
Definition: commondefs.h:53
void GenericConvolve(int lx, int ifx, const A &x, int ly, int ify, const B &y, int lz, int ifz, C &z)
Definition: genericnumer.h:29
Mathematical function.
Definition: mathfunc.h:61
void genericCrossCorrelation(int lx, int ifx, const A &x, int ly, int ify, const B &y, int lz, int ifz, C &z)
Definition: genericnumer.h:230
float findExtreme(const FloatMathFunction &, bool minima, float x1, float x2, float tol=1e-5)
const T val2
Definition: arrayndalgo.h:1699
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:272
float similarity(const A &a, const B &b, int sz, bool normalize=false, int firstposa=0, int firstposb=0)
Definition: genericnumer.h:84
float findValueInAperture(const FloatMathFunction &, float startx, const Interval< float > &aperture, float dx, float target=0, float tol=1e-5)
#define mAllocVarLenArr(type, varnm, __size)
Definition: varlenarray.h:54
#define mDefEps
Definition: commondefs.h:58
void reverseArray(A *in, int sz, A *out=0)
Definition: genericnumer.h:243
bool findValue(const FloatMathFunction &, float x1, float x2, float &res, float targetval=0, float tol=1e-5)
void GenericConvolveNoUdf(int lx, int ifx, const A &x, int ly, int ify, const B &y, int lz, int ifz, C &z)
Definition: genericnumer.h:56
#define mAllocLargeVarLenArr(type, varnm, __size)
Definition: varlenarray.h:31
const T val1
Definition: arrayndalgo.h:1699
bool isUdf(const T &t)
Definition: undefval.h:243
virtual RT getValue(PT) const =0
void reSample(const FloatMathFunction &input, const A &samplevals, B &output, int nrsamples)
Definition: genericnumer.h:203
float semblance(const ObjectSet< float > &signals, const Interval< int > &)