20 cwoVect2(T tx, T ty){ x = tx; y = ty; };
21 void Show(){ std::cout <<
"(" << x <<
"," << y <<
")" << std::endl; }
114 cwoVect2<T> operator()(
const T t1,
const T t2)
const {
137 void SetThreads(
int N);
138 void Crop(
CWO *src,
CWO *dst,
int x1,
int y1,
int Sx,
int Sy);
141 template<
class T> T& Expand(T &src, T &dst)
143 long long int sNx = src.
GetNx();
144 long long int sNy = src.GetNy();
145 long long int dNx = dst.GetNx();
146 long long int dNy = dst.GetNy();
150 dst.SetCtx(src.GetCtx());
151 dst.SetSize(dNx, dNy);
154 p_src, 0, 0, sNx, sNy,
155 p_dst, abs((dNx - sNx) / 2), abs((dNy - sNy) / 2), dNx, dNy,
174 void Resize(
CWO *src,
CWO *dst,
float scale_x,
float scale_y,
int flag);
177 CWO* DiffractAngular(
CWO *src,
CWO *dst,
float z);
178 CWO* DiffractARSSFresnel(
CWO *src,
CWO *dst,
float z);
180 template<
class T> T& DiffractAngular(T &src, T &dst,
float z){
182 dst.SetCtx(src.GetCtx());
183 long long int Nx = src.GetNx();
184 long long int Ny = src.GetNy();
187 dst.__FFT(p_src, p_dst, CWO_C2C);
188 dst.__AngularProp(p_dst, CWO_PROP_MUL_FFT_SHIFT);
189 dst.__IFFT(p_dst, p_dst);
190 dst.__Mul(p_dst, cwo::MakeCplx(1.0f / (Nx*Ny), 0), p_dst);
194 template<
class T> T& DiffractARSSFresnel(T &src, T &dst,
float z){
196 dst.SetCtx(src.GetCtx());
198 long long int Nx = src.GetNx();
199 long long int Ny = src.GetNx();
203 double wl = src.GetWaveLength();
204 double spx = src.GetSrcPx();
205 double spy = src.GetSrcPy();
206 double dpx = src.GetDstPx();
207 double dpy = src.GetDstPy();
208 double ox = src.GetSrcOx() + src.GetDstOx();
209 double oy = src.GetSrcOy() + src.GetDstOy();
210 double sx1 = spx / dpx;
211 double sy1 = spy / dpy;
212 double sx2 = dpx / spx;
213 double sy2 = dpy / spy;
215 int cz1x = (int)fabs((wl*fabs(z) / dpx - fabs(2 * sx1*ox)) / (2 * fabs(1 - sx1)*dpx));
216 int cz1y = (int)fabs((wl*fabs(z) / dpy - fabs(2 * sy1*oy)) / (2 * fabs(1 - sy1)*dpy));
217 int u1x = (int)fabs((wl*fabs(z) / dpx - fabs(2 * sx1*ox)) / (2 * (sx1*sx1 - sx1)*dpx));
218 int u1y = (int)fabs((wl*fabs(z) / dpy - fabs(2 * sy1*oy)) / (2 * (sy1*sy1 - sy1)*dpy));
219 int h1x = (int)(wl*fabs(z) / (2 * sx1*dpx*dpx));
220 int h1y = (int)(wl*fabs(z) / (2 * sy1*dpy*dpy));
222 int cz2x = (int)fabs((wl*fabs(z) / spx - fabs(2 * sx2*ox)) / (2 * (sx2*sx2 - sx2)*spx));
223 int cz2y = (int)fabs((wl*fabs(z) / spy - fabs(2 * sy2*oy)) / (2 * (sy2*sy2 - sy2)*spy));
224 int u2x = (int)fabs((wl*fabs(z) / spx - fabs(2 * sx2*ox)) / (2 * fabs(1 - sx2)*spx));
225 int u2y = (int)fabs((wl*fabs(z) / spy - fabs(2 * sy2*oy)) / (2 * fabs(1 - sy2)*spy));
226 int h2x = (int)(wl*fabs(z) / (2 * sx2*spx*spx));
227 int h2y = (int)(wl*fabs(z) / (2 * sy2*spy*spy));
229 src.__ARSSFresnelAperture(p_src);
230 src.__FFT(p_src, p_src, CWO_C2C);
232 src.__ARSSFresnelProp(p_dst);
233 src.__FFTShift(p_dst);
234 src.__RectFillOutside(
235 p_dst, Nx / 2 - h1x, Ny / 2 - h1y,
236 h1x * 2, h1y * 2, cwo::MakeCplx(0, 0));
237 src.__FFTShift(p_dst);
238 src.__FFT(p_dst, p_dst, CWO_C2C);
240 src.__Mul(p_src, p_dst, p_dst);
241 src.__IFFT(p_dst, p_dst);
242 src.__ARSSFresnelCoeff(p_dst);
245 dst.Rect(dst.GetNx() / 4, dst.GetNy() / 4, dst.GetNx() / 2, dst.GetNy() / 2, cwo::MakeCplx(0, 0), CWO_FILL_OUTSIDE);
251 template<
class T> T& Diffract(T &src, T &dst,
float z,
int type =
CWO_ANGULAR){
253 case CWO_ANGULAR: DiffractAngular(src, dst, z);
break;
271 std::string ExtractFileName(
const std::string &path);
272 std::string ExtractPath(
const std::string &path);
273 std::string ExtractExt(
const std::string &path);
298 void AffineRotX(
float *affine_mat,
float deg);
304 void AffineRotY(
float *affine_mat,
float deg);
310 void AffineRotZ(
float *affine_mat,
float deg);
313 inline cwoComplex MakeCplx(
float re,
float im){
cwoComplex tmp; CWO_RE(tmp) = re; CWO_IM(tmp) = im;
return tmp; };
314 inline cwoFloat2 MakeFloat2(
float x,
float y){
cwoFloat2 tmp; tmp.x = x; tmp.y = y;
return tmp; };
315 inline cwoFloat3 MakeFloat3(
float x,
float y,
float z){
cwoFloat3 tmp; tmp.x = x; tmp.y = y; tmp.z = z;
return tmp; };
344 long long int rnd_seed;
361 virtual void*
__Malloc(
size_t size);
362 virtual void __Free(
void **a);
363 virtual void __Memcpy(
void *dst,
void *src,
size_t size);
364 virtual void __Memset(
void *p,
int c,
size_t size);
367 virtual void __Expand(
368 void *src,
int sx,
int sy,
int srcNx,
int srcNy,
369 void *dst,
int dx,
int dy,
int dstNx,
int dstNy,
372 virtual void __ExpandMirror(
377 virtual void __ShiftedFresnelAperture(
cwoComplex *a);
378 virtual void __ShiftedFresnelProp(
cwoComplex *a);
379 virtual void __ShiftedFresnelCoeff(
cwoComplex *a);
381 virtual void __ARSSFresnelAperture(
cwoComplex *a);
382 virtual void __ARSSFresnelProp(
cwoComplex *a);
383 virtual void __ARSSFresnelCoeff(
cwoComplex *a);
385 virtual void __FresnelConvProp(
cwoComplex *a);
386 virtual void __FresnelConvCoeff(
cwoComplex *a,
float const_val=1.0f);
390 virtual void __AngularProp(
cwoComplex *a,
int flag);
391 void __AngularLim(
float *fx_c,
float *fx_w,
float *fy_c,
float *fy_w);
396 virtual void __FresnelFourierProp(
cwoComplex *a);
397 virtual void __FresnelFourierCoeff(
cwoComplex *a);
399 virtual void __FresnelDblAperture(
cwoComplex *a,
float z1);
400 virtual void __FresnelDblFourierDomain(
cwoComplex *a,
float z1,
float z2,
cwoInt4 *zp);
401 virtual void __FresnelDblCoeff(
cwoComplex *a,
float z1,
float z2);
403 virtual void __FFT(
void *src,
void *dst,
int type);
404 virtual void __IFFT(
void *src,
void *dst);
405 virtual void __FFTShift(
void *src);
436 virtual void __Real2Complex(
float *src,
cwoComplex *dst);
437 virtual void __Phase2Complex(
float *src,
cwoComplex *dst);
439 virtual void __Polar(
float *amp,
float *ph,
cwoComplex *c);
447 virtual void __FloatToChar(
char *dst,
float *src,
int N);
448 virtual void __CharToFloat(
float *dst,
char *src,
int N);
450 void FromChar(
const char *src,
int Nx,
int Ny);
451 void FromFloat(
const float *src,
int Nx,
int Ny);
454 void SetSize(
int Nx,
int Ny);
455 void SetPropDist(
float z);
494 CWO& operator=(
float a);
518 #ifdef __NOW_DEBUGGIBNG_OPERATOR
519 template<
class T>
friend CWO operator+(
CWO&
const lhs, T&
const rhs){ printf(
"ope1 + \n");
CWO nrv = lhs; nrv += rhs;
return nrv; };
520 template<
class T>
friend CWO&& operator+(
CWO&& lhs, T&
const rhs){ printf(
"ope2 + \n"); lhs += rhs;
return std::move(lhs); };
521 template<
class T>
friend CWO&& operator+(
const CWO& lhs, T&& rhs){ printf(
"ope3 + \n"); rhs += lhs;
return std::move(rhs); };
522 template<
class T>
friend CWO&& operator+(
CWO&& lhs, T&& rhs){ printf(
"ope4 + \n"); lhs += std::move(rhs);
return std::move(lhs); };
524 template<
class T>
friend CWO operator-(
CWO&
const lhs, T&
const rhs){ printf(
"ope1 - \n");
CWO nrv = lhs; nrv -= rhs;
return nrv; };
525 template<
class T>
friend CWO&& operator-(
CWO&& lhs, T&
const rhs){ printf(
"ope2 - \n"); lhs -= rhs;
return std::move(lhs); };
526 template<
class T>
friend CWO&& operator-(
const T& lhs,
CWO&& rhs){ printf(
"ope3 - \n"); rhs -= lhs;
return std::move(rhs); };
527 template<
class T>
friend CWO&& operator-(
CWO&& lhs, T&& rhs){ printf(
"ope4 - \n"); lhs -= std::move(rhs);
return std::move(lhs); };
529 template<
class T>
friend CWO operator*(
CWO&
const lhs, T&
const rhs){ printf(
"ope1 * \n");
CWO nrv = lhs; nrv *= rhs;
return nrv; };
530 template<
class T>
friend CWO&& operator*(
CWO&& lhs, T&
const rhs){ printf(
"ope2 * \n"); lhs *= rhs;
return std::move(lhs); };
531 template<
class T>
friend CWO&& operator*(
const T& lhs,
CWO&& rhs){ printf(
"ope3 * \n"); rhs *= lhs;
return std::move(rhs); };
532 template<
class T>
friend CWO&& operator*(
CWO&& lhs, T&& rhs){ printf(
"ope4 * \n"); lhs *= std::move(rhs);
return std::move(lhs); };
534 template<
class T>
friend CWO operator/(
CWO&
const lhs, T&
const rhs){ printf(
"ope1 / \n");
CWO nrv = lhs; nrv /= rhs;
return nrv; };
535 template<
class T>
friend CWO&& operator/(
CWO&& lhs, T&
const rhs){ printf(
"ope2 / \n"); lhs /= rhs;
return std::move(lhs); };
536 template<
class T>
friend CWO&& operator/(
const T& lhs,
CWO&& rhs){ printf(
"ope3 / \n"); rhs /= lhs;
return std::move(rhs); };
537 template<
class T>
friend CWO&& operator/(
CWO&& lhs, T&& rhs){ printf(
"ope4 / \n"); lhs /= std::move(rhs);
return std::move(lhs); };
539 template<
class T=CWO> T operator+(T &a) {
542 assert(tmp.GetBuffer() !=
nullptr);
544 __Add(
GetBuffer(), a.GetBuffer(), tmp.GetBuffer());
547 template<
class T=CWO> T operator+(
float a) {
550 assert(tmp.GetBuffer() !=
nullptr);
553 CWO_RE(cplx) = a; CWO_IM(cplx) = 0.0f;
554 __Add(
GetBuffer(), cplx, tmp.GetBuffer());
557 template<
class T=CWO> T operator+(
const cwoComplex &a) {
560 assert(tmp.GetBuffer() !=
nullptr);
565 template<
class T>
friend CWO operator+(
const T &a,
CWO& c) {
CWO tmp = c; tmp += a;
return tmp; };
567 template<
class T = CWO> T operator-(T &a) {
570 assert(tmp.GetBuffer() !=
nullptr);
572 __Sub(
GetBuffer(), a.GetBuffer(), tmp.GetBuffer());
575 template<
class T = CWO> T operator-(
float a) {
578 assert(tmp.GetBuffer() !=
nullptr);
581 CWO_RE(cplx) = a; CWO_IM(cplx) = 0.0f;
582 __Sub(
GetBuffer(), cplx, tmp.GetBuffer());
585 template<
class T = CWO> T operator-(
const cwoComplex &a) {
588 assert(tmp.GetBuffer() !=
nullptr);
593 template<
class T>
friend CWO operator-(
const T &a,
CWO& c) {
CWO tmp(c.
GetNx(),c.
GetNy()); tmp = a; tmp -= c;
return tmp; };
595 template<
class T = CWO> T operator*(T &a) {
598 assert(tmp.GetBuffer() !=
nullptr);
600 __Mul(
GetBuffer(), a.GetBuffer(), tmp.GetBuffer());
603 template<
class T = CWO> T operator*(
float a) {
606 assert(tmp.GetBuffer() !=
nullptr);
609 CWO_RE(cplx) = a; CWO_IM(cplx) = 0.0f;
610 __Mul(
GetBuffer(), cplx, tmp.GetBuffer());
613 template<
class T = CWO> T operator*(
const cwoComplex &a) {
616 assert(tmp.GetBuffer() !=
nullptr);
621 template<
class T>
friend CWO operator*(
const T &a,
CWO& c) {
CWO tmp = c; tmp *= a;
return tmp; };
623 template<
class T = CWO> T operator/(T &a) {
626 assert(tmp.GetBuffer() !=
nullptr);
628 __Div(
GetBuffer(), a.GetBuffer(), tmp.GetBuffer());
631 template<
class T = CWO> T operator/(
float a) {
634 assert(tmp.GetBuffer() !=
nullptr);
637 CWO_RE(cplx) = a; CWO_IM(cplx) = 0.0f;
638 __Div(
GetBuffer(), cplx, tmp.GetBuffer());
641 template<
class T = CWO> T operator/(
const cwoComplex &a) {
644 assert(tmp.GetBuffer() !=
nullptr);
649 template<
class T>
friend CWO operator/(
const T &a,
CWO& c) {
674 CWO& operator+=(
CWO&
const a);
675 CWO& operator+=(
float a);
678 CWO& operator-=(
float a);
681 CWO& operator*=(
float a);
684 CWO& operator/=(
float a);
716 int Create(
int Nx,
int Ny=1);
778 ctx.calc_type = type;
955 return ctx.wave_length;
1152 int x =
GetNx() / 2;
1153 int y =
GetNx() / 2;
1154 return cwo::MakeVect2(x,y);
1169 int r = (int)(fabs(z)*asin(wl / (2.0*p)) / p);
1197 int CheckExt(
const char* fname,
const char* ext);
1216 int Load(
const std::string& fname_amp,
const std::string& fname_pha,
int c =
CWO_GREY);
1228 int Save(
const std::string& fname,
int bmp_8_24 = 24);
1229 int Save(
const std::string& fname,
CWO *r,
CWO *g =
nullptr,
CWO *b =
nullptr);
1231 int SaveMonosToColor(
const std::string& fname,
const std::string& r_name,
const std::string& g_name,
const std::string& b_name);
1232 int SaveAsImage(
const std::string& fname,
float i1,
float i2,
float o1,
float o2,
int flag =
CWO_SAVE_AS_RE,
int bmp_8_24 = 24);
1233 int SaveAsImage(
const std::string& fname,
int flag =
CWO_SAVE_AS_RE,
int bmp_8_24 = 24);
1234 virtual int SaveAsImage(
cwoComplex *p,
int Nx,
int Ny,
const std::string& fname,
int flag =
CWO_SAVE_AS_RE,
int bmp_8_24 = 24);
1237 int SaveLineAsText(
const std::string& fname,
int flag);
1238 int SaveLineAsText(
const std::string& fname,
int flag,
int x1,
int y1,
int x2,
int y2);
1256 int CmpCtx(cwoCtx &a, cwoCtx &b);
1280 void SetDfrExpand(
int flag = 0);
1285 void Diffract(
float d,
int type,
CWO *tmp_buf);
1286 void Diffract(
int type,
CWO *kernel[]);
1290 void DiffractFourier(
float d,
int type,
cwoInt4 *zp=NULL);
1291 void DiffractDirect(
float d,
CWO *snumap,
CWO *dnumap);
1307 void DiffractDepth(
float z,
float dz,
int num,
1308 const char* path,
const char *name,
const char *ext,
int type=
CWO_ANGULAR);
1311 void AngularProp(
CWO *a);
1312 void ShiftedAngularProp(
CWO *a);
1314 void FresnelConvProp(
CWO *a);
1315 void FresnelConvCoeff(
CWO *a);
1317 void ShiftedFresnelProp(
CWO *a);
1318 void ShiftedFresnelAperture(
CWO *a);
1319 void ShiftedFresnelCoeff(
CWO *a);
1321 void ARSSFresnelProp(
CWO *a);
1322 void ARSSFresnelAperture(
CWO *a);
1323 void ARSSFresnelCoeff(
CWO *a);
1325 void FresnelFourierProp(
CWO *a);
1326 void FresnelFourierCoeff(
CWO *a);
1328 void FresnelDblAperture(
CWO *a,
float z1);
1329 void FresnelDblFourierDomain(
CWO *a,
float z1,
float z2,
cwoInt4 *zp);
1330 void FresnelDblCoeff(
CWO *a,
float z1,
float z2);
1332 void FresnelDupProp(
CWO *a,
float M);
1335 void PreDiffract(
float z,
int type,
CWO *a[]);
1337 void ReleaseTmpBuffer();
1339 void FresnelCoeff(
float z1,
float z2,
float wl1,
float wl2);
1344 float fresnel_c(
float x);
1345 float fresnel_s(
float x);
1347 float z,
int x1,
int y1,
int x2,
int y2);
1356 virtual void __AddSphericalWave(
cwoComplex *p,
float x,
float y,
float z,
float px,
float py,
float a,
float ph=0.0f);
1357 virtual void __MulSphericalWave(
cwoComplex *p,
float x,
float y,
float z,
float px,
float py,
float a);
1379 void AddSphericalWave(
float x,
float y,
float z,
float px,
float py,
float a,
float ph=1.0f);
1401 void MulSphericalWave(
float x,
float y,
float z,
float px,
float py,
float a=1.0f);
1427 void AddApproxSphWave(
float x,
float y,
float z,
float a=1.0f);
1428 void AddApproxSphWave(
float x,
float y,
float z,
float px,
float py,
float a=1.0f);
1429 void AddApproxSphWave(
float x,
float y,
float phi,
float zx,
float zy,
float px,
float py,
float a=1.0f);
1443 void MulApproxSphWave(
float x,
float y,
float z,
float a=1.0f);
1444 void MulApproxSphWave(
float x,
float y,
float z,
float px,
float py,
float a=1.0f);
1445 void MulApproxSphWave(
float x,
float y,
float phi,
float zx,
float zy,
float px,
float py,
float a=1.0f);
1456 void AddPlanarWave(
float kx,
float ky,
float px,
float py,
float a=1.0f);
1475 void MulPlanarWave(
float kx,
float ky,
float px,
float py,
float a=1.0f);
1540 void Phase(
float offset=0.0f);
1569 void Arg(
float scale=1.0f,
float offset=0.0f);
1598 void Arg2Cplx(
float scale=1.0,
float offset=0.0);
1628 void Quant(
float alpha);
1630 void ToDouble(
double *a);
1631 void FromDouble(
double *a);
1657 void SetPixel(
int x,
int y,
float a);
1658 void SetPixel(
const cwoVect2<int> &v,
float a){ SetPixel(v.x, v.y, a); };
1659 void SetPixel(
int x,
int y,
float amp,
float ph);
1660 void SetPixel(
const cwoVect2<int> &v,
float amp,
float ph){ SetPixel(v.x, v.y, amp, ph); };
1663 void SetPixel(
int x,
int y,
CWO &a);
1668 void AddPixel(
int x,
int y,
CWO &a);
1671 void MulPixel(
int x,
int y,
float a);
1672 void MulPixel(
const cwoVect2<int> &v,
float a){ MulPixel(v.x, v.y, a); };
1676 void GetPixel(
int x,
int y,
float &a);
1677 void GetPixel(
const cwoVect2<int> &v,
float &a){ GetPixel(v.x, v.y, a); };
1682 void GetPixel(
int x,
int y,
CWO &a);
1685 void GetLineH(
int n,
int N,
CWO &a);
1686 void GetLineV(
int m,
int N,
CWO &a);
1687 void GetLine(
int m1,
int n1,
int m2,
int n2,
CWO &a);
1688 void SetLineH(
int n,
CWO &a);
1689 void SetLineV(
int m,
CWO &a);
1690 void SetLine(
int m1,
int n1,
int m2,
int n2,
CWO &a);
1692 virtual void __Copy(
1693 cwoComplex *src,
int x1,
int y1,
int sNx,
int sNy,
1694 cwoComplex *dst,
int x2,
int y2,
int dNx,
int dNy,
1697 void Copy(
CWO &a,
int x1,
int y1,
int x2,
int y2,
int Sx,
int Sy);
1700 void Clear(
int c=0);
1703 template <
class T>
void FlipH(T *a);
1704 template <
class T>
void FlipV(T *a);
1705 void Flip(
int mode=0);
1707 void Crop(
int x1,
int y1,
int Sx,
int Sy);
1709 void Crop(
int x1,
int y1,
int Sx,
int Sy,
CWO &a);
1712 void ShiftX(
int s,
int flag=0);
1713 void ShiftY(
int s,
int flag=0);
1718 void JoinH(
CWO &a);
1719 void JoinV(
CWO &a);
1728 void Rect(
int m,
int n,
int Sx,
int Sy,
cwoComplex &a,
int flag=CWO_FILL_INSIDE);
1731 Rect(v.x, v.y, s.x, s.y, a, flag);
1742 void Circ(
int m,
int n,
int r,
cwoComplex &a,
int flag=CWO_FILL_INSIDE);
1745 Circ(v.x, v.y, r, a, flag);
1773 void Convolve(
CWO &a,
float *ker,
int Sx,
int Sy);
1775 void ConvolveFFT(
CWO *a,
CWO *b,
CWO *c);
1778 virtual void Expand(
int Nx,
int Ny);
1779 void ExpandMirror();
1780 void ExpandTwice(
CWO *src);
1781 void ExpandHalf(
CWO *dst);
1819 int ScaleReal(
float i1,
float i2,
float o1,
float o2);
1821 virtual int __ScaleReal(
float i1,
float i2,
float o1,
float o2);
1841 int ScaleCplx(
float i1,
float i2,
float o1,
float o2);
1843 virtual int __ScaleCplx(
float i1,
float i2,
float o1,
float o2);
1862 long long int GetRandSeed();
1874 virtual void __RandPhase(
cwoComplex *a,
float max,
float min);
1875 virtual void __MulRandPhase(
cwoComplex *a,
float max,
float min);
1877 virtual void RandReal(
float max = 1.0f,
float min = 0.0f);
1878 void RandPhase(
float max=CWO_PI,
float min=-CWO_PI);
1879 void SetRandPhase(
float max=CWO_PI,
float min=-CWO_PI);
1880 void MulRandPhase(
float max=CWO_PI,
float min=-CWO_PI);
1888 void __WindowCos(
cwoComplex *a,
int m,
int n,
int W,
int Wa);
1897 void __WindowFlatCosCirc(
cwoComplex *p,
int L,
int L0,
float k);
1924 virtual void __ResizeNearest(
1928 virtual void __ResizeLinear(
1932 virtual void __ResizeCubic(
1936 virtual void __ResizeLanczos(
1940 virtual void __ResizeNearestScale(
cwoComplex *p_src,
cwoComplex *p_dst,
float scale_x,
float scale_y);
1941 virtual void __ResizeLinearScale(
cwoComplex *p_src,
cwoComplex *p_dst,
float scale_x,
float scale_y);
1942 virtual void __ResizeCubicScale(
cwoComplex *p_src,
cwoComplex *p_dst,
float scale_x,
float scale_y);
1943 virtual void __ResizeLanczosScale(
cwoComplex *p_src,
cwoComplex *p_dst,
float scale_x,
float scale_y);
1947 void AddNoiseWhite(
float max=1.0);
1948 void MulNoiseWhite(
float max=1.0);
1949 void AddNoiseGaussian(
float mu,
float sigma);
1950 void MulNoiseGaussian(
float mu,
float sigma);
1980 void Rotate(
float deg);
1982 virtual void AffineAngularSpectrum(
float *mat_affine,
float px,
float py,
int flag=
CWO_INTER_LINEAR);
1984 AffineAngularSpectrum(mat_affine, pitch.x, pitch.y, flag);
1987 virtual void ErrorDiffusion(
CWO *a =
nullptr,
int flag =
CWO_ED_FS);
1988 virtual void ErrorDiffusionSegmented(
CWO *output,
int flag =
CWO_ED_FS);
1991 void RGB2YCbCr(
CWO *rgb,
CWO *ycbcr);
1992 void YCbCr2RGB(
CWO *rgb,
CWO *ycbcr);
2001 void FourierShift(
float m,
float n);
2003 int FFT(
int flag=0);
2006 int FFT(
int dx,
int dy,
int flag = 0);
2007 virtual void FFTShift(
int dx,
int dy);
2019 void NUFFT1(
CWO *map,
int R=2,
int Msp=12);
2020 void NUFFT2(
CWO *map,
int R=2,
int Msp=12);
2022 void ConvertSamplingMap(
int type);
2023 void SamplingMapScaleOnly(
int Nx,
int Ny,
float R,
float sgn);
2026 virtual void Log(
float base=10.0f,
float eps=1.0f);
2028 virtual void Gamma(
float g);
2029 virtual void Threshold(
float max,
float min=0.0);
2030 virtual void Threshold(
float max_th,
float max_val,
float min_th,
float min_val);
2031 void ThresholdAmp(
float max_amp,
float min_amp);
2032 void ThresholdToZero(
float th);
2033 void ThresholdAbsToZero(
float th);
2034 void ThresholdHist(
float var);
2035 virtual void Binary(
float th=0.0,
float max=1.0,
float min=0.0);
2037 virtual void __PickupFloat(
float *src,
float *pix_p,
float pix);
2065 unsigned int Count(
float a);
2066 unsigned int CountNonZero();
2079 float Average(
int m,
int n,
int Sx,
int Sy);
2087 float Variance(
int m,
int n,
int Sx,
int Sy);
2093 float StdDev(
int m,
int n,
int Sx,
int Sy);
2097 virtual void __MaxMin(
cwoComplex *a,
float *max,
float *min,
int *max_x =
nullptr,
int *max_y =
nullptr,
int *min_x =
nullptr,
int *min_y =
nullptr);
2103 float Max(
int *m=NULL,
int *n=NULL);
2108 float Min(
int *m = NULL,
int *n = NULL);
2127 int MaxMin(
float *max,
float *min,
int *max_x =
nullptr,
int *max_y =
nullptr,
int *min_x =
nullptr,
int *min_y =
nullptr);
2186 virtual float MSE(
CWO &ref);
2224 float SpeckleContrast(
int m,
int n,
int Sx,
int Sy);
2233 CWO LaplacianPhase();
2234 void PoisonSolverFFT();
2235 void PhaseUnwrap(
int type=0);
2244 virtual cwoObjPoint* GetPointBuffer(){
return nullptr; };
2245 virtual int GetPointNum(){
return 0;};
2246 virtual void SetPointNum(
int num){};
2247 virtual void ScalePoint(
float lim){};
2253 virtual void __PLS_Huygens(
float ph=0.0f){};
2254 virtual void __PLS_Fresnel(
float ph=0.0f){};
2255 virtual void __PLS_CGH_Fresnel(
float ph=0.0f){};
2305 inline cwoComplex cwoCplxPolar(
float amp,
float ph)
2308 CWO_RE(tmp)=amp*cos(ph);
2309 CWO_IM(tmp)=amp*sin(ph);
2313 inline cwoComplex cwoCplxCart(
float r,
float i)
2324 double arg = atan2(CWO_IM(a), CWO_RE(a));
2325 if (arg < 0.0f) arg += CWO_2PI;
2326 if (arg >= CWO_2PI) arg -= CWO_2PI;
2331 char* cwoFname(
const char *arg, ...);
2347 cwoVect(
float tx,
float ty,
float tz) {
2348 x = tx; y = ty; z = tz;
2351 void Set(
float tx,
float ty,
float tz){
2352 x = tx; y = ty; z = tz;
2389 if(a == 0.0f)
return *
this;
2418 if(a == 0.0f)
return *
this;
2426 double tx = (double)x;
2427 double ty = (double)y;
2428 double tz = (double)z;
2429 return (
float)sqrt(tx*tx + ty*ty + tz*tz);
2445 return (x*a.x+y*a.y+z*a.z);
2450 double x1, y1, z1, x2, y2, z2;
2457 vec.x = (
float)(y1 * z2 - z1 * y2);
2458 vec.y = (float)(z1 * x2 - x1 * z2);
2459 vec.z = (float)(x1 * y2 - y1 * x2);
2516 void MakeWRPTbl(
float z,
int Nz,
float pz,
float wl,
float px,
float py);
2548 template<
typename T>
2552 T cwo_r, cwo_g, cwob;
2561 T* GetCWOR(){
return &cwo_r; };
2562 T* GetCWOG(){
return &cwo_g; };
2563 T* GetCWOB(){
return &cwo_b; };
2569 template<
typename T>
2575 float threshold_hist_val;
2580 std::string out_path;
2581 std::string out_name;
2585 wavelength = 633e-9;
2586 gaze_point.x = 0.0f;
2587 gaze_point.y = 0.0f;
2588 gaze_point.z = 0.0f;
2595 threshold_hist_val = 5.0f;
2598 pupil_radius = 2e-3;
2603 out_name =
"view_z=%02d_y=%02d_x=%02d.jpg";
2606 void SetWaveLength(
float wl){
2609 float GetWaveLength(){
2636 void SetThresholdHist(
const float hist){
2637 threshold_hist_val = hist;
2639 void SetOutImageSize(
const int Nx,
const int Ny){
2643 int GetOutImageNx(){
2646 int GetOutImageNy(){
2650 float GetThresholdHist(){
2651 return threshold_hist_val;
2654 void SetPupilRadius(
const float r){
2657 float GetPupilRadius(){
2658 return pupil_radius;
2660 void SetTypeSrcToEye(
const int type){
2661 type_holo_eye = type;
2663 void SetTypeEyeToGaze(
const int type){
2664 type_eye_gaze = type;
2666 int GetTypeSrcToEye(){
2667 return type_holo_eye;
2669 int GetTypeEyeToGaze(){
2670 return type_eye_gaze;
2673 void SetOutPath(
const std::string &path){
2676 void SetOutName(
const std::string &name){
2679 std::string &GetOutPath(){
2682 std::string &GetOutName(){
2702 dst->SetSrcOffset(0, 0);
2703 dst->SetDstOffset(ep.x - sp.x, ep.y - sp.y);
2706 dst->SetSrcPitch(p_src);
2707 dst->SetDstPitch(p_eye);
2709 dst->Diffract(ep.z, GetTypeSrcToEye());
2712 float pr = GetPupilRadius();
2713 int pri = (int)(pr / p_eye.x);
2715 printf(
"pupil_r %f pupil_r(int) %d\n", pr, pri);
2717 dst->Circ(dst->GetNx() / 2, dst->GetNy() / 2, pri, cwoCplxCart(0, 0), CWO_FILL_OUTSIDE);
2736 double vx = ep.x - gp.x;
2737 double vy = ep.y - gp.y;
2738 double vz = ep.z - gp.z;
2739 double R = sqrt(vx*vx + vy*vy + vz*vz);
2741 dst->SetOffset(0, 0);
2742 dst->SetDstOffset(-vx, -vy);
2743 dst->SetSrcPitch(p_eye);
2744 dst->SetDstPitch(p_dst);
2745 dst->Diffract(abs(vz), GetTypeEyeToGaze());
2747 double radx = atan(vx / vz);
2748 double rady = atan(vy / vz);
2749 double wn = (double)dst->GetWaveNum();
2752 dst->SetOffset(0, 0);
2753 dst->SetPitch(p_eye);
2754 cwo::AffineRotY(aff, CWO_DEG(+radx));
2756 dst->Expand(dst->GetNx() * 2, dst->GetNy() * 2);
2757 dst->DiffractAffine(aff);
2758 dst->Expand(dst->GetNx() / 2, dst->GetNy() / 2);
2775 double vx = ep.x - gp.x;
2776 double vy = ep.y - gp.y;
2777 double vz = ep.z - gp.z;
2778 double R = sqrt(vx*vx + vy*vy + vz*vz);
2780 double px = src->GetPx();
2781 double py = src->GetPy();
2785 double radx = atan(vx / vz);
2786 double rady = atan(vy / vz);
2787 double wn = (double)dst->GetWaveNum();
2791 dst->SetSrcOffset(0, 0);
2792 dst->SetDstOffset(ep.x - sp.x, ep.y - sp.y);
2793 dst->SetSrcPitch(px, py);
2794 dst->SetDstPitch(px, py);
2796 dst->Diffract(ep.z, GetTypeSrcToEye());
2802 float pr = GetPupilRadius();
2803 int pri = (int)(pr / dst->GetPx());
2804 printf(
"pupil_r %f pupil_r(int) %d\n", pr, pri);
2805 dst->Circ(dst->GetNx() / 2, dst->GetNy() / 2, pri, cwoCplxCart(0, 0), CWO_FILL_OUTSIDE);
2808 dst->SetOffset(0, 0);
2809 dst->SetPitch(px, py);
2810 cwo::AffineRotY(aff, CWO_DEG(+radx));
2813 dst->SetOffset(0, 0);
2814 dst->SetDstOffset(-vx, -vy);
2815 dst->Diffract(abs(vz), GetTypeEyeToGaze());
2822 T *src,
const float dx,
const float dy,
2823 const int Nvx,
const int Nvy = 1,
char *fname_out =
nullptr)
2830 for (
int i = 0; i<Nvy; ++i){
2831 for (
int j = 0; j<Nvx; ++j){
2835 Eye(src, tmp, cur_eye_pos, cur_gaz_pos, cur_src_pos);
2839 int srcNx = src->GetNx();
2840 int srcNy = src->GetNy();
2841 int outNx = GetOutImageNx();
2842 int outNy = GetOutImageNy();
2844 if (srcNx != outNx || srcNy != outNy) tmp->Resize(outNx, outNy);
2848 float th = GetThresholdHist();
2849 if (th >= 0.0f) tmp->ThresholdHist(th);
2850 if (fname_out ==
nullptr)
2851 tmp->SaveAsImage(cwoFname(
"z:\\view_y=%02d_x=%02d.jpg", i, j));
2853 tmp->SaveAsImage(cwoFname(fname_out, i));
2855 cur_eye_pos.x += dx;
2859 cur_eye_pos.x = tmp.x;
2860 cur_eye_pos.y += dy;
2872 char *fname_in,
const float dx,
const float dy,
2873 const int Nvx,
const int Nvy = 1,
char *fname_out =
nullptr)
2878 T *tmp2 = (T*)
new T;
2883 for (
int i = 0; i<Nvy; ++i){
2884 for (
int j = 0; j < Nvx; ++j){
2888 FILE *fp = fopen(fname_in,
"r");
2889 double src_pos_x, src_pos_y;
2893 while (fscanf(fp,
"%lf %lf %s", &src_pos_x, &src_pos_y, fname) != EOF){
2896 src->SetPitch(1e-6);
2898 cur_src_pos.x = src_pos_x;
2899 cur_src_pos.y = src_pos_y;
2901 printf(
"%e %e %s \n", src_pos_x, src_pos_y, fname);
2903 Eye(src, tmp2, cur_eye_pos, cur_gaz_pos, cur_src_pos);
2905 if (tmp->GetNx() != src->GetNx() || tmp->GetNy() != src->GetNy()){
2906 tmp->Create(src->GetNx(), src->GetNy());
2917 int srcNx = src->GetNx();
2918 int srcNy = src->GetNy();
2919 int outNx = GetOutImageNx();
2920 int outNy = GetOutImageNy();
2922 if (srcNx != outNx || srcNy != outNy)
2923 tmp->Resize(outNx, outNy);
2927 float th = GetThresholdHist();
2928 if (th >= 0.0f) tmp->ThresholdHist(th);
2929 if (fname_out ==
nullptr)
2930 tmp->SaveAsImage(cwoFname(
"z:\\view_y=%02d_x=%02d.jpg", i, j));
2932 tmp->SaveAsImage(cwoFname(fname_out, i));
2934 cur_eye_pos.x += dx;
2938 cur_eye_pos.x = tmp.x;
2939 cur_eye_pos.y += dy;
2952 const std::string &fname_in,
2959 T *tmp2 = (T*)
new T;
2971 for (
int k = 0; k < Nvz; ++k){
2972 for (
int i = 0; i < Nvy; ++i){
2973 for (
int j = 0; j < Nvx; ++j){
2977 FILE *fp = fopen(fname_in.c_str(),
"r");
2979 double src_pos_x, src_pos_y;
2983 while (fscanf(fp,
"%lf %lf %s", &src_pos_x, &src_pos_y, fname) != EOF){
2986 cur_src_pos.x = src_pos_x;
2987 cur_src_pos.y = src_pos_y;
2989 printf(
"%e %e %s \n", src_pos_x, src_pos_y, fname);
2991 src->SetWaveLength(GetWaveLength());
2992 tmp->SetWaveLength(GetWaveLength());
2993 tmp2->SetWaveLength(GetWaveLength());
2995 SrcToEye(src, tmp2, cur_src_pos, cur_eye_pos, p_src, p_eye);
2997 if (tmp->GetNx() != src->GetNx() || tmp->GetNy() != src->GetNy()){
2998 tmp->Create(src->GetNx(), src->GetNy());
3006 EyeToDst(src, tmp, cur_eye_pos, cur_gaz_pos, p_eye, p_dst);
3008 int srcNx = src->GetNx();
3009 int srcNy = src->GetNy();
3010 int outNx = GetOutImageNx();
3011 int outNy = GetOutImageNy();
3013 if (srcNx != outNx || srcNy != outNy)
3014 tmp->Resize(outNx, outNy);
3018 float th = GetThresholdHist();
3019 if (th >= 0.0f) tmp->ThresholdHist(th);
3026 tmp->SaveAsImage(cwoFname((GetOutPath() + GetOutName()).c_str(), k, i, j));
3029 cur_eye_pos.x += eye_dv.x;
3030 cur_gaz_pos.x += gaz_dv.x;
3034 tmp_flt3 = GetEyePoint();
3035 cur_eye_pos.x = tmp_flt3.x;
3036 cur_eye_pos.y += eye_dv.y;
3038 tmp_flt3 = GetGazePoint();
3039 cur_gaz_pos.x = tmp_flt3.x;
3040 cur_gaz_pos.y += gaz_dv.y;
3044 tmp_flt3 = GetEyePoint();
3045 cur_eye_pos.x = tmp_flt3.x;
3046 cur_eye_pos.y = tmp_flt3.y;
3047 cur_eye_pos.z += eye_dv.z;
3049 tmp_flt3 = GetGazePoint();
3050 cur_gaz_pos.x = tmp_flt3.x;
3051 cur_gaz_pos.y = tmp_flt3.y;
3052 cur_gaz_pos.z += gaz_dv.z;
3062 void Divide(
const std::string &fname_in,
int Nx,
int Ny,
float px,
float py){
3069 c_org->
Load(fname_in);
3070 int org_Nx = c_org->
GetNx();
3071 int org_Ny = c_org->
GetNy();
3073 int new_Nx = int(ceil((
float)org_Nx/Nx)*Nx);
3074 int new_Ny = int(ceil((
float)org_Ny/Ny)*Ny);
3077 c_org->Expand(new_Nx, new_Ny);
3081 std::string fname_out =
"../../data/wide_reconst/hol_div_%02d%02d.cwo";
3082 std::string fname_txt =
"../../data/wide_reconst/div_out.txt";
3085 FILE *fp = fopen(fname_txt.c_str(),
"wt");
3087 for (
int i = 0; i < new_Ny; i += Ny){
3088 for (
int j = 0; j < new_Nx; j += Nx){
3089 c_org->GetPixel(j, i, *c_new);
3091 int idx_x = int((
float)j / Nx);
3092 int idx_y = int((
float)i / Ny);
3094 std::string name = cwoFname(fname_out.c_str(), idx_y, idx_x);
3096 c_new->SaveAsImage(name+
".jpg");
3098 float center_x = CWO_X(((j - new_Nx / 2) + Nx / 2)*px);
3099 float center_y = CWO_Y(((i - new_Ny / 2) + Ny / 2)*py);
3102 std::to_string(center_x) +
" " + std::to_string(center_y) +
" " + name +
"\n";
3104 fwrite(txt.c_str(),1, strlen(txt.c_str()), fp);