Commit 14a65eff authored by flechsig's avatar flechsig
Browse files

recoverered WFI functionality- working

parent 57a8a18e
// Time-stamp: <14 Mar 19 11:02:32 flechsig>
// Time-stamp: <14 Mar 19 12:41:16 flechsig>
/*
* NDPluginXGI.cpp
*
......@@ -218,18 +218,21 @@ void NDPluginXGI::processCallbacks(NDArray *pArray)
// waveform_advanced();
break;
case 2:
#ifdef DEBUG
printf("Algorithm == %d --> call evaluf()\n", algorithm);
#endif
this->XGIconfig.direction= COLDIR;
evaluf(&image, &this->XGIconfig, &output);
break;
printf("Algorithm == %d not yet implemented\n", algorithm);
break;
case 3:
#ifdef DEBUG
printf("Algorithm == %d --> call evalfft2d()\n", algorithm);
#endif
evalfft2d(&image, &this->XGIconfig, &output);
break;
case 4:
#ifdef DEBUG
printf("Algorithm == %d --> call evaluf()\n", algorithm);
#endif
this->XGIconfig.direction= COLDIR;
evaluf(&image, &this->XGIconfig, &output);
break;
case 5:
#ifdef DEBUG
printf("Algorithm == %d --> call evaluf()\n", algorithm);
......@@ -377,7 +380,9 @@ NDArray *NDPluginXGI::matrixToNDArray(const Matrix *matrix)
if (matrix->data == NULL) // UF it fails in case the matrix is not allocated
{
std::cerr << "error: matrixToNDArray: matrix == NULL" << std::endl;
#ifdef DEBUG
std::cerr << "info: matrixToNDArray: matrix == NULL" << std::endl;
#endif
return NULL;
}
......
// File : /afs/psi.ch/user/f/flechsig/git/WFI/src/algorithms.cpp
// Date : <11 Feb 19 10:02:46 flechsig>
// Time-stamp: <14 Mar 19 11:04:50 flechsig>
// Time-stamp: <14 Mar 19 14:00:41 flechsig>
// Author : Flechsig Uwe, uwe.flechsig&#64;psi.&#99;&#104;
#include <iostream>
......@@ -115,8 +115,24 @@ void evalfft2d(Matrix *put_in, struct ConfigStruct *cstp, struct Xgi_out *put_ou
put_out->dphi_wrap.data[idxc]= pha; // fill wrap
}
put_out->dphi_wrap.copy(&put_out->dphi_unwrap); // cp wrap to unwrap
unwrap_phase(put_out->dphi_unwrap.data, rows, cols); // call Herra
switch (cstp->outputs)
{
case 1:
autorange(put_out->amp.data, rows, cols, cstp->logscale);
break;
case 2:
put_out->dphi_wrap.copy(&put_out->amp);
autorange(put_out->amp.data, rows, cols, cstp->logscale);
break;
case 3:
put_out->dphi_wrap.copy(&put_out->amp); // overwrite amp whith phase
unwrap_phase(put_out->amp.data, rows, cols); // call Herra
autorange(put_out->amp.data, rows, cols, cstp->logscale);
break;
default:
put_out->dphi_wrap.copy(&put_out->dphi_unwrap); // cp wrap to unwrap
unwrap_phase(put_out->dphi_unwrap.data, rows, cols); // call Herra
}
fftw_destroy_plan(p1); // clean up
fftw_free(in);
......@@ -146,7 +162,7 @@ void evalfft_ifft_2d(Matrix *put_in, struct ConfigStruct *cstp, struct Xgi_out *
put_in->copy(&put_out->dphi_wrap);
rows= put_in->height;
cols= put_in->width;
data= put_out->amp.data; // Array address= 1
data= put_out->amp.data; // Array address= 1
idxmax= rows* cols;
......@@ -183,9 +199,25 @@ void evalfft_ifft_2d(Matrix *put_in, struct ConfigStruct *cstp, struct Xgi_out *
put_out->dphi_wrap.data[idxc]= pha;
}
put_out->dphi_wrap.copy(&put_out->dphi_unwrap);
unwrap_phase(put_out->dphi_unwrap.data, rows, cols); // call Herra
switch (cstp->outputs)
{
case 1:
autorange(put_out->amp.data, rows, cols, cstp->logscale);
break;
case 2:
put_out->dphi_wrap.copy(&put_out->amp);
autorange(put_out->amp.data, rows, cols, cstp->logscale);
break;
case 3:
put_out->dphi_wrap.copy(&put_out->amp); // overwrite amp whith phase
unwrap_phase(put_out->amp.data, rows, cols); // call Herra
autorange(put_out->amp.data, rows, cols, cstp->logscale);
break;
default:
put_out->dphi_wrap.copy(&put_out->dphi_unwrap); // cp wrap to unwrap
unwrap_phase(put_out->dphi_unwrap.data, rows, cols); // call Herra
}
fftw_destroy_plan(p1);
fftw_destroy_plan(p2);
fftw_free(in);
......@@ -211,7 +243,6 @@ void evaluf(Matrix *put_in, struct ConfigStruct *cstp, struct Xgi_out *put_out)
put_in->copy(&put_out->amp); // copy input to output in field amp, address= 1
put_in->copy(&put_out->dphi_wrap);
rows= put_in->height;
cols= put_in->width;
data= put_out->amp.data; // Array address= 1
......@@ -292,6 +323,17 @@ void evaluf(Matrix *put_in, struct ConfigStruct *cstp, struct Xgi_out *put_out)
put_out->roc= (fabs(m) > DBL_MIN)
? 1/m : 0; // formula just a guess
switch (cstp->outputs)
{
case 2:
put_out->dphi_wrap.copy(&put_out->amp);
break;
case 3:
put_out->dphi_unwrap.copy(&put_out->amp); // overwrite amp whith phase
break;
}
cout << "return from evaluf" << endl;
} // end evaluf()
......@@ -328,29 +370,29 @@ void evaluf_zp(Matrix *put_in, struct ConfigStruct *cstp, struct Xgi_out *put_ou
autorange(data, rows, cols, cstp->logscale); // logscale
break;
case 2: // fft(-1)
hanning(data, rows, cols, cstp->direction); // hanning filter
eval1d_zp(data, rows, cols, cstp, put_out); // fft stuff
hanning(data, rows, cols, cstp->direction); // hanning filter
eval1d_zp(data, rows, cols, cstp, put_out); // fft stuff
autorange(data, rows, cols, cstp->logscale); // logscale
overlay(data, rows, cols, cstp->center, cstp->width, (double)val4overlay, cstp->direction); // add a overlay
break;
case 3: // filter
hanning(data, rows, cols, cstp->direction); // hanning filter
eval1d_zp(data, rows, cols, cstp, put_out); // fft stuff
eval1d_zp(data, rows, cols, cstp, put_out); // fft stuff
autorange(data, rows, cols, cstp->logscale);
break;
case 4: // shift
hanning(data, rows, cols, cstp->direction); // hanning filter
eval1d_zp(data, rows, cols, cstp, put_out); // fft stuff
eval1d_zp(data, rows, cols, cstp, put_out); // fft stuff
autorange(data, rows, cols, cstp->logscale);
break;
case 5: // FFT(1)
hanning(data, rows, cols, cstp->direction); // hanning filter
eval1d_zp(data, rows, cols, cstp, put_out);// fft stuff
eval1d_zp(data, rows, cols, cstp, put_out); // fft stuff
autorange(data, rows, cols, cstp->logscale);
break;
case 6: // no scaling
hanning(data, rows, cols, cstp->direction); // hanning filter
eval1d_zp(data, rows, cols, cstp, put_out); // fft stuff
eval1d_zp(data, rows, cols, cstp, put_out); // fft stuff
break;
default:
cout << "error: undefined minor mode, minor= " << cstp->minor << endl;
......@@ -391,8 +433,17 @@ void evaluf_zp(Matrix *put_in, struct ConfigStruct *cstp, struct Xgi_out *put_ou
put_out->roc= (fabs(m) > DBL_MIN)
? 1/m : 0; // formula just a guess
cout << "return from evaluf" << endl;
switch (cstp->outputs)
{
case 2:
put_out->dphi_wrap.copy(&put_out->amp);
break;
case 3:
put_out->dphi_unwrap.copy(&put_out->amp); // overwrite amp whith phase
break;
}
cout << "return from evaluf_zp" << endl;
} // end evaluf_zp()
// makes a 1d fft, default is cols plus other treatment
......@@ -402,19 +453,12 @@ void eval1d(double *data, int rows, int cols, struct ConfigStruct *cs, struct Xg
fftw_plan p1, p2;
size_t arrsize;
int row, col, idxc;
int rowdir, minor, outphase, center, width;
rowdir= cs->direction;
minor= cs->minor;
outphase= cs->outputs;
center= cs->center;
width= cs->width;
#ifdef DEBUG
cout << "eval1d called" << endl;
#endif
if (rowdir)
if (cs->direction) // rowdir
{
arrsize= sizeof(fftw_complex) * rows;
in = (fftw_complex*) fftw_malloc(arrsize);
......@@ -433,19 +477,19 @@ void eval1d(double *data, int rows, int cols, struct ConfigStruct *cs, struct Xg
fftw_execute(p1); // forward fft(-1)
fftshift1d(out, rows);
switch (minor) // go ahead with filter etc
switch (cs->minor) // go ahead with filter etc
{
case 2:
break;
case 3:
filter1d(out, rows, 0, center, width); // do not move center
filter1d(out, rows, 0, cs->center, cs->width); // do not move center
break;
case 4:
filter1d(out, rows, 1, center, width); // do move center
filter1d(out, rows, 1, cs->center, cs->width); // do move center
break;
case 5:
case 6:
filter1d(out, rows, 1, center, width);
filter1d(out, rows, 1, cs->center, cs->width);
memcpy(in, out, arrsize);
fftw_execute(p2);
break;
......@@ -456,13 +500,12 @@ void eval1d(double *data, int rows, int cols, struct ConfigStruct *cs, struct Xg
exit(-1);
}
if (outphase)
//put_out->dphi_wrap.data
for (row= 0; row < rows; row++)
put_out->dphi_wrap.data[col+ row* cols]= atan2(out[row][1], out[row][0]);
else // amplitude
for (row= 0; row < rows; row++)
data[col+ row* cols]= sqrt(pow(out[row][0], 2)+ pow(out[row][1], 2));
for (row= 0; row < rows; row++)
{
idxc= col+ row* cols;
put_out->dphi_wrap.data[idxc]= atan2(out[row][1], out[row][0]);
data[idxc]= sqrt(pow(out[row][0], 2)+ pow(out[row][1], 2));
}
} // colloop
fftw_destroy_plan(p1);
fftw_destroy_plan(p2);
......@@ -488,19 +531,19 @@ void eval1d(double *data, int rows, int cols, struct ConfigStruct *cs, struct Xg
fftw_execute(p1); // forward fft(-1)
fftshift1d(out, cols);
switch (minor) // go ahead with filter etc
switch (cs->minor) // go ahead with filter etc
{
case 2:
break;
case 3:
filter1d(out, cols, 0, center, width); // do not move center
filter1d(out, cols, 0, cs->center, cs->width); // do not move center
break;
case 4:
filter1d(out, cols, 1, center, width); // do move center
filter1d(out, cols, 1, cs->center, cs->width); // do move center
break;
case 5:
case 6:
filter1d(out, cols, 1, center, width);
filter1d(out, cols, 1, cs->center, cs->width);
memcpy(in, out, arrsize);
fftw_execute(p2);
break;
......@@ -511,12 +554,12 @@ void eval1d(double *data, int rows, int cols, struct ConfigStruct *cs, struct Xg
exit(-1);
}
if (outphase)
for (col= 0; col < cols; col++)
put_out->dphi_wrap.data[col+ row* cols]= atan2(out[col][1], out[col][0]);
else // amplitude
for (col= 0; col < cols; col++)
data[col+ row* cols]= sqrt(pow(out[col][0], 2)+ pow(out[col][1], 2));
for (col= 0; col < cols; col++)
{
idxc= col+ row* cols;
put_out->dphi_wrap.data[idxc]= atan2(out[col][1], out[col][0]);
data[idxc]= sqrt(pow(out[col][0], 2)+ pow(out[col][1], 2));
}
} // rowloop
fftw_destroy_plan(p1);
fftw_destroy_plan(p2);
......@@ -524,10 +567,18 @@ void eval1d(double *data, int rows, int cols, struct ConfigStruct *cs, struct Xg
fftw_free(out);
} // else cols
if (outphase > 1)
switch (cs->outputs)
{
put_out->dphi_wrap.copy(&put_out->dphi_unwrap);
unwrap_phase(put_out->dphi_unwrap.data, rows, cols);
case 2:
put_out->dphi_wrap.copy(&put_out->amp);
break;
case 3:
put_out->dphi_wrap.copy(&put_out->amp);
unwrap_phase(put_out->amp.data, rows, cols); // call Herra
break;
default:
put_out->dphi_wrap.copy(&put_out->dphi_unwrap);
unwrap_phase(put_out->dphi_unwrap.data, rows, cols);
}
} // end eval1d
......@@ -539,20 +590,16 @@ void eval1d_zp(double *data, int rows, int cols, struct ConfigStruct *cs, struct
fftw_complex *in, *out;
fftw_plan p1, p2;
size_t arrsize;
int row, col, i, i0, len0, imax, fftlen[8]= {64, 128, 256, 512, 1024, 2048, 4096, 8192};
int rowdir, minor, outphase, center, width;
int row, col, i, i0, len0, imax, idxc, fftlen[8]= {64, 128, 256, 512, 1024, 2048, 4096, 8192};
#ifdef DEBUG
cout << "eval1d_zp called" << endl;
#endif
rowdir= cs->direction;
minor= cs->minor;
outphase= cs->outputs;
center= cs->center;
width=cs->width;
len0= (rowdir) ? rows : cols;
len0= (cs->direction) ? rows : cols;
i= 0;
while ((i < 8) && (fftlen[i] < len0)) i++;
imax= (i < 6) ? fftlen[i+ cs->zeropadding] : fftlen[7];
......@@ -565,7 +612,7 @@ void eval1d_zp(double *data, int rows, int cols, struct ConfigStruct *cs, struct
p1 = fftw_plan_dft_1d(imax, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
p2 = fftw_plan_dft_1d(imax, in, out, FFTW_BACKWARD, FFTW_ESTIMATE);
if (rowdir)
if (cs->direction)
{
for (col= 0; col< cols; col++)
{
......@@ -575,19 +622,19 @@ void eval1d_zp(double *data, int rows, int cols, struct ConfigStruct *cs, struct
fftw_execute(p1); // forward fft(-1)
fftshift1d(out, imax);
switch (minor) // go ahead with filter etc
switch (cs->minor) // go ahead with filter etc
{
case 2:
break;
case 3:
filter1d(out, imax, 0, (i0+ center), width); // do not move center
filter1d(out, imax, 0, (i0+ cs->center), cs->width); // do not move center
break;
case 4:
filter1d(out, imax, 1, (i0+ center), width); // do move center
filter1d(out, imax, 1, (i0+ cs->center), cs->width); // do move center
break;
case 5:
case 6:
filter1d(out, imax, 1, (i0+ center), width);
filter1d(out, imax, 1, (i0+ cs->center), cs->width);
memcpy(in, out, arrsize);
fftw_execute(p2);
break;
......@@ -597,12 +644,13 @@ void eval1d_zp(double *data, int rows, int cols, struct ConfigStruct *cs, struct
cout << "error - unexpected minor - exit(-1)" << endl;
exit(-1);
}
if (outphase)
for (i= 0; i< len0; i++)
put_out->dphi_wrap.data[col+ i* cols]= atan2(out[i+ i0][1], out[i+ i0][0]);
else // amplitude
for (i= 0; i< len0; i++)
data[col+ i* cols]= sqrt(pow(out[i+ i0][0], 2)+ pow(out[i+ i0][1], 2));
{
idxc= col+ i* cols;
put_out->dphi_wrap.data[idxc]= atan2(out[i+ i0][1], out[i+ i0][0]);
data[idxc]= sqrt(pow(out[i+ i0][0], 2)+ pow(out[i+ i0][1], 2));
}
} // colloop
} // end rows
else // cols
......@@ -615,19 +663,19 @@ void eval1d_zp(double *data, int rows, int cols, struct ConfigStruct *cs, struct
fftw_execute(p1); // forward fft(-1)
fftshift1d(out, imax);
switch (minor) // go ahead with filter etc
switch (cs->minor) // go ahead with filter etc
{
case 2:
break;
case 3:
filter1d(out, imax, 0, (i0+ center), width); // do not move center
filter1d(out, imax, 0, (i0+ cs->center), cs->width); // do not move center
break;
case 4:
filter1d(out, imax, 1, (i0 + center), width); // do move center
filter1d(out, imax, 1, (i0 + cs->center), cs->width); // do move center
break;
case 5:
case 6:
filter1d(out, imax, 1, (i0+ center), width);
filter1d(out, imax, 1, (i0+ cs->center), cs->width);
memcpy(in, out, arrsize);
fftw_execute(p2);
break;
......@@ -637,12 +685,13 @@ void eval1d_zp(double *data, int rows, int cols, struct ConfigStruct *cs, struct
cout << "error - unexpected minor - exit(-1)" << endl;
exit(-1);
}
if (outphase)
for (i= 0; i< len0; i++)
put_out->dphi_wrap.data[i+ row* cols]= atan2(out[i+ i0][1], out[i+ i0][0]);
else // amplitude
for (i= 0; i< len0; i++)
data[i+ row* cols]= sqrt(pow(out[i+ i0][0], 2)+ pow(out[i+ i0][1], 2));
{
idxc= i+ row* cols;
put_out->dphi_wrap.data[idxc]= atan2(out[i+ i0][1], out[i+ i0][0]);
data[idxc]= sqrt(pow(out[i+ i0][0], 2)+ pow(out[i+ i0][1], 2));
}
} // rowloop
} // else cols
......@@ -650,10 +699,18 @@ void eval1d_zp(double *data, int rows, int cols, struct ConfigStruct *cs, struct
fftw_destroy_plan(p2);
fftw_free(in);
fftw_free(out);
if (outphase > 1)
switch (cs->outputs)
{
put_out->dphi_wrap.copy(&put_out->dphi_unwrap);
unwrap_phase(put_out->dphi_unwrap.data, rows, cols);
case 2:
put_out->dphi_wrap.copy(&put_out->amp);
break;
case 3:
put_out->dphi_wrap.copy(&put_out->amp);
unwrap_phase(put_out->amp.data, rows, cols); // call Herra
break;
default:
put_out->dphi_wrap.copy(&put_out->dphi_unwrap);
unwrap_phase(put_out->dphi_unwrap.data, rows, cols);
}
} // end eval1d_zp
......@@ -855,8 +912,7 @@ void myoverlay(Matrix *put_in, struct ConfigStruct *cstp, struct Xgi_out *put_ou
int row, col, row0= 80, col0= 10, row1, col1, row2, col2, height= 20, width= 10, val= 255;
FLOATING *data;
int rows, cols;
Matrix *m = NULL;
#define UINT16_OUT
#ifdef UINT16_OUT
val= 0xFFFF; // 65535
......@@ -864,17 +920,10 @@ void myoverlay(Matrix *put_in, struct ConfigStruct *cstp, struct Xgi_out *put_ou
rows= put_in->height;
cols= put_in->width;
switch (cstp->outputs)
{
case 0: m= &put_out->amp; break;
case 1: m= &put_out->dphi_wrap; break;
case 2: m= &put_out->dphi_unwrap; break;
}
put_in->copy(&put_out->amp); // copy input to output in field amp, address= 1
data= put_out->amp.data; // Array address= 1
put_in->copy(m); // copy input to output in field amp, address= 1
data= m->data; // Array address= 1
cout << "put myoverlay to OutPhase @ (row, col, val) " << row0 << ", " << col0 << ", " << val << endl;
cout << "put myoverlay @ (row, col, val) " << row0 << ", " << col0 << ", " << val << endl;
row0= rows- row0; // plot at bottom
......@@ -883,7 +932,7 @@ void myoverlay(Matrix *put_in, struct ConfigStruct *cstp, struct Xgi_out *put_ou
col1= col0+ width;
col2= col0+ 2* width;
for (row=row0; row< row1; row++) // vertical lines
for (row=row0; row< row1; row++) // vertical lines
{
data[col0+ row* cols]= val;
data[col1+ row* cols]= val;
......@@ -902,6 +951,9 @@ void myoverlay(Matrix *put_in, struct ConfigStruct *cstp, struct Xgi_out *put_ou
data[col+ 2* width+ (row0+ 1)* cols]= val;
data[col+ 2* width+ (row2+ 1)* cols]= val;
}
put_out->amp.copy(&put_out->dphi_wrap); // export all arrays
put_out->amp.copy(&put_out->dphi_unwrap);
} // end myoverlay
// overlay lines at the filter values in the data array
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment