#include "segyops.hh" // mutefun = 0, t \le 0; mutefun = 1, t \ge 1 float mutefun(float t) { t = MIN(1.0f,MAX(t,0.0f)); return 3*t*t-2*t*t*t; } // returns true if a < x < b, sets fac=hermite cubic, // else returns false and fac=1 int taperfun(int lr, float a, float b, float x, float & fac) { if (x<=a) { if (lr==0) { fac*=0.0f; return 0; } else { fac*=1.0f; return 1; } } else if (x>=b) { if (lr==0) { fac*=1.0f; return 1; } else { fac*=0.0f; return 0; } } else { if (lr==0) fac*=mutefun((x-a)/(b-a)); else fac*=mutefun((b-x)/(b-a)); return 0; } } float cosfun(float t){ return 0.5 - cos(M_PI * t)/2.0f; } float cosfun2(float t){ return 0.5 + cos(M_PI * t)/2.0f; } // precondition for all of these FOs: input, output have same geom namespace TSOpt { using RVL::LocalDataContainer; using RVL::RVLException; void conv(int shift, int nout, int nin, int nker, float * restrict out, const float * restrict in, const float * restrict ker, float scal ) { int start; int stop; for (int i=0; i= i - min(i+outbeg-kerbeg,inend)+inbeg+outbeg-inbeg-kerbeg >= i+outbeg-kerbeg - min(i+outbeg-kerbeg,inend) >=0 sim k <= kerend-kerbeg in terms of start and length nout = outend-outbeg+1 : outend = nout+outbeg-1 nin = inend-inbeg+1 : inend = nin +inbeg -1 nker = kerend-kerbeg+1 : kerend = nker+kerbeg-1 so: 0 <= i < nout max(i+outbeg-nker-kerbeg+1,inbeg)-inbeg <= j < min(i+outbeg-kerbeg,nin+inbeg-1)-inbeg+1 max(i+outbeg-kerbeg-inbeg+1-nker,0) <= j < min(i+outbeg-kerbeg-inbeg+1,nin) */ void SEGYConvolve::operator()(LocalDataContainer & x, LocalDataContainer const & y, LocalDataContainer const & z) { try { segytrace & cpout = dynamic_cast(x); segy & trout = cpout.getMetadata(); segytrace const & cpin = dynamic_cast(y); segy const & trin = cpin.getMetadata(); segytrace const & cpker = dynamic_cast(z); segy const & trker = cpker.getMetadata(); Value val; float dt; int nin; int nout; int nker; int inbeg; int outbeg; int kerbeg; string dtstr="dt"; string nsstr="ns"; string rtstr="delrt"; gethdval(&trout, (char*)(dtstr.c_str()), &val); dt=vtof(hdtype((char*)(dtstr.c_str())), val); gethdval(&trin, (char*)(nsstr.c_str()), &val); nin=vtoi(hdtype(nsstr.c_str()), val); gethdval(&trin, (char*)(rtstr.c_str()), &val); inbeg=int(0.01 + vtof(hdtype(rtstr.c_str()), val)/dt); gethdval(&trout, (char*)(nsstr.c_str()), &val); nout=vtoi(hdtype(nsstr.c_str()), val); gethdval(&trout, (char*)(rtstr.c_str()), &val); outbeg=int(0.01 + vtof(hdtype(rtstr.c_str()), val)/dt); gethdval(&trker, (char*)(nsstr.c_str()), &val); nker=vtoi(hdtype(nsstr.c_str()), val); gethdval(&trker, (char*)(rtstr.c_str()), &val); kerbeg=int(0.01 + vtof(hdtype(rtstr.c_str()), val)/dt); if (adj==0) { int ishift=outbeg-inbeg-kerbeg; conv(ishift,nout,nin,nker, trout.data,trin.data,trker.data); } else { int ishift=inbeg-kerbeg-outbeg; corr(ishift,nout,nin,nker, trout.data,trin.data,trker.data); } } catch (bad_cast) { RVLException e; e<<"ERROR: SEGYConvolve::operator()\n"; e<<" at least one input not segytrace type\n"; throw e; } } void SEGYTaper::operator()(LocalDataContainer & x, LocalDataContainer const & y) { try { segytrace & cpout = dynamic_cast(x); segy & trout = cpout.getMetadata(); segytrace const & cpin = dynamic_cast(y); segy const & trin = cpin.getMetadata(); Value val; float fac=1.0f; int dontdoit = 1; // fetch coordinates for each taper axis float xcoord; std::string tmp = "scalco"; gethdval(&trout,(char *)(tmp.c_str()),&val); float scalco = vtof(hdtype("scalco"),val); for (int i=0; i 0) { xcoord *= scalco; } if (scalco < 0) { xcoord /= -scalco; } dontdoit*=taperfun(0,tap[i].t[0],tap[i].t[1],xcoord,fac); // returns 1 if x to r of t[1] dontdoit*=taperfun(1,tap[i].t[2],tap[i].t[3],xcoord,fac); // returns 1 if x to l of t[2] // cerr<<"xcoord="< & x, LocalDataContainer const & y) { try { segytrace & cpout = dynamic_cast(x); segytrace const & cpin = dynamic_cast(y); segy & trout = cpout.getMetadata(); segy const & trin = cpin.getMetadata(); Value val; float gx; float x; float dt; float t0; float wm; int nt; string name="ns"; gethdval(&trin,(char *)(name.c_str()),&val); nt=vtoi(hdtype((char *)(name.c_str())),val); name="dt"; gethdval(&trin,(char *)(name.c_str()),&val); dt=0.001*vtof(hdtype((char *)(name.c_str())),val); name="delrt"; gethdval(&trin,(char *)(name.c_str()),&val); t0=vtof(hdtype((char *)(name.c_str())),val); name="gx"; gethdval(&trin,(char *)(name.c_str()),&val); gx = vtof(hdtype((char *)(name.c_str())),val); name="sx"; gethdval(&trin,(char *)(name.c_str()),&val); x = gx - vtof(hdtype((char *)(name.c_str())),val); // adjust mute so that w=0 works if (mute_type) { wm = MAX(dt/s,w); float wtmp = mutefun((gx - s)/wm) * mutefun((tm - gx)/wm); for (int i=0;i & x, LocalDataContainer const & y) { try { segytrace & cpout = dynamic_cast(x); segytrace const & cpin = dynamic_cast(y); segy & trout = cpout.getMetadata(); segy const & trin = cpin.getMetadata(); Value val; float gx; float sx; float x; float dt; float t0; float wm; float wt; int nt; string name="ns"; gethdval(&trin,(char *)(name.c_str()),&val); nt=vtoi(hdtype((char *)(name.c_str())),val); name="dt"; gethdval(&trin,(char *)(name.c_str()),&val); dt=0.001*vtof(hdtype((char *)(name.c_str())),val); name="delrt"; gethdval(&trin,(char *)(name.c_str()),&val); t0=vtof(hdtype((char *)(name.c_str())),val); name="gx"; gethdval(&trin,(char *)(name.c_str()),&val); gx = vtof(hdtype((char *)(name.c_str())),val); name="sx"; gethdval(&trin,(char *)(name.c_str()),&val); sx = vtof(hdtype((char *)(name.c_str())),val); x = gx - sx; int itw = (int) (tw/dt + 0.1); itw = MAX(1,itw); float sxt_wt = 1.0f; wt = MAX(1.0,sx_width); if (sx < sx_min) sxt_wt = cosfun2((sx_min-sx)/wt); if (sx > sx_max) sxt_wt = cosfun2((sx-sx_max)/wt); //cerr << " sxt_wt = " << sxt_wt << endl; // adjust mute so that w=0 works if (mute_type) { wm = MAX(dt/s,w); float wtmp = mutefun((gx - s)/wm) * mutefun((tm - gx)/wm); wtmp = wtmp * sxt_wt; wt=MAX(1.0,width); float wttmp=1.0; if (taper_type){ // offset if (x < taper_min) wttmp = cosfun2((taper_min-x)/wt); else if (x > taper_max) wttmp = cosfun2((x - taper_max)/wt); #pragma ivdep for (int i=0;i taper_max) wttmp = cosfun2((gx - taper_max)/wt); #pragma ivdep for (int i=0;i taper_max) wttmp = cosfun2((x - taper_max)/wt); wttmp = wttmp * sxt_wt; #pragma ivdep for (int i=0;i taper_max) wttmp = cosfun2((gx - taper_max)/wt); wttmp = wttmp * sxt_wt; #pragma ivdep for (int i=0;i & x, LocalDataContainer const & y) { try { segytrace & cpout = dynamic_cast(x); segytrace const & cpin = dynamic_cast(y); segy & trout = cpout.getMetadata(); segy const & trin = cpin.getMetadata(); Value val; float dt; int nt; string name="ns"; gethdval(&trin,(char *)(name.c_str()),&val); nt=vtoi(hdtype((char *)(name.c_str())),val); gethdval(&trout,(char *)(name.c_str()),&val); if (nt != vtoi(hdtype((char *)(name.c_str())),val)) { RVLException e; e<<"Error: SEGYFwdInt::operator()\n"; e<<"input, output incompatible\n"; throw e; } name="dt"; gethdval(&trin,(char *)(name.c_str()),&val); dt=0.001*vtof(hdtype((char *)(name.c_str())),val); memcpy(trout.data,trin.data,nt*sizeof(float)); trout.data[0]=0.0f; for (int j=0;j & x, LocalDataContainer const & y) { try { segytrace & cpout = dynamic_cast(x); segytrace const & cpin = dynamic_cast(y); segy & trout = cpout.getMetadata(); segy const & trin = cpin.getMetadata(); Value val; float dt; int nt; string name="ns"; gethdval(&trin,(char *)(name.c_str()),&val); nt=vtoi(hdtype((char *)(name.c_str())),val); gethdval(&trout,(char *)(name.c_str()),&val); if (nt != vtoi(hdtype((char *)(name.c_str())),val)) { RVLException e; e<<"Error: SEGYAdjInt::operator()\n"; e<<"input, output incompatible\n"; throw e; } name="dt"; gethdval(&trin,(char *)(name.c_str()),&val); dt=0.001*vtof(hdtype((char *)(name.c_str())),val); memcpy(trout.data,trin.data,nt*sizeof(float)); trout.data[nt-1]=0.0f; for (int j=0;j-1;i--) trout.data[i] = trout.data[i+1]+trin.data[i+1]*dt; } } catch (bad_cast) { RVLException e; e<<"Error: SEGYAdjInt::operator()\n"; e<<"input LDC not segytrace\n"; throw e; } } }