/** * Gets the value of the center of the first bin for this histogram. * @return the value of the center of the first bin. */ public double getBinFirst() { return _sbin.getFirst(); }
/** * Determines whether the specified value is in the bounds of this sampling. * A value is in bounds if in the range [first,last] defined by the first * and last sample values. * @param x the value. * @return true, if in bounds; false, otherwise. */ public boolean isInBounds(double x) { return getFirst()<=x && x<=getLast(); }
/** * Sets bounds for this interpolator using specified samplings. * Values interpolated within the bounding box of these samplings * are never null, even when the interpolation point (x1,x2) * lies outside that box. * <p> * If gradients are to be computed (not specified explicitly), it is best * to set bounds by calling this method before computing gradients. * @param s1 sampling of x1. * @param s2 sampling of x2. */ public void setBounds(Sampling s1, Sampling s2) { setBounds((float)s1.getFirst(),(float)s1.getLast(), (float)s2.getFirst(),(float)s2.getLast()); }
/** * Constructs a box constraint with specified samplings and min sizes. * Constrains object vertices to lie on the sampling grid. * @param sx sampling of x coordinate * @param sy sampling of y coordinate * @param sz sampling of z coordinate * @param dxmin minimum size in x dimension. * @param dymin minimum size in y dimension. * @param dzmin minimum size in z dimension. */ public BoxConstraint( Sampling sx, Sampling sy, Sampling sz, double dxmin, double dymin, double dzmin) { _xmin = sx.getFirst(); _ymin = sy.getFirst(); _zmin = sz.getFirst(); _xmax = sx.getLast(); _ymax = sy.getLast(); _zmax = sz.getLast(); _dxmin = dxmin; _dymin = dymin; _dzmin = dzmin; _sx = sx; _sy = sy; _sz = sz; _sampled = true; }
/** * Sets bounds for this interpolator using specified samplings. * Values interpolated within the bounding box of these samplings * are never null, even when the interpolation point (x1,x2,x3) * lies outside that box. * <p> * If gradients are to be computed (not specified explicitly), it is best * to set bounds by calling this method before computing gradients. * @param s1 sampling of x1. * @param s2 sampling of x2. * @param s3 sampling of x3. */ public void setBounds(Sampling s1, Sampling s2, Sampling s3) { setBounds((float)s1.getFirst(),(float)s1.getLast(), (float)s2.getFirst(),(float)s2.getLast(), (float)s3.getFirst(),(float)s3.getLast()); }
private void phase(int sign1, int sign2, int sign3, float[][][] f) { double fx1 = _sx1.getFirst(); double fx2 = _sx2.getFirst(); double fx3 = _sx3.getFirst(); if (fx1==0.0 && fx2==0.0 && fx3==0.0) return; int nk1 = (_complex)?_nfft1:_nfft1/2+1; int nk2 = _nfft2; int nk3 = _nfft3; double dp1 = sign1*2.0*PI*_sk1.getDelta()*fx1; double dp2 = sign2*2.0*PI*_sk2.getDelta()*fx2; double dp3 = sign3*2.0*PI*_sk3.getDelta()*fx3; for (int i3=0; i3<nk3; ++i3) { for (int i2=0; i2<nk2; ++i2) { double p23 = i2*dp2+i3*dp3; float[] f32 = f[i3][i2]; for (int i1=0,ir=0,ii=1; i1<nk1; ++i1,ir+=2,ii+=2) { float p = (float)(i1*dp1+p23); float cosp = cos(p); float sinp = sin(p); float fr = f32[ir]; float fi = f32[ii]; f32[ir] = fr*cosp-fi*sinp; f32[ii] = fi*cosp+fr*sinp; } } } } }
private void phase(int sign1, int sign2, float[][] f) { double fx1 = _sx1.getFirst(); double fx2 = _sx2.getFirst(); if (fx1==0.0 && fx2==0.0) return; int nk1 = (_complex)?_nfft1:_nfft1/2+1; int nk2 = _nfft2; double dp1 = sign1*2.0*PI*_sk1.getDelta()*fx1; double dp2 = sign2*2.0*PI*_sk2.getDelta()*fx2; for (int i2=0; i2<nk2; ++i2) { double p2 = i2*dp2; float[] f2 = f[i2]; for (int i1=0,ir=0,ii=1; i1<nk1; ++i1,ir+=2,ii+=2) { float p = (float)(i1*dp1+p2); float cosp = cos(p); float sinp = sin(p); float fr = f2[ir]; float fi = f2[ii]; f2[ir] = fr*cosp-fi*sinp; f2[ii] = fi*cosp+fr*sinp; } } } private void phase(float[][][] f) {
/** * Determines whether the specified value is in the bounds of this sampling, * which is assumed to be uniform. A value is in bounds if in the range * [first-0.5*delta,last+0.5*delta] defined by the first and last sample * values and the sampling interval delta. In effect, this method extends * the bounds of this sampling by one-half sample when testing the value. * @param x the value. * @return true, if in bounds; false, otherwise. */ public boolean isInBoundsExtended(double x) { Check.state(isUniform(),"sampling is uniform"); double dhalf = 0.5*_d; return getFirst()-dhalf<=x && x<=getLast()+dhalf; }
private void phase(int sign1, float[] f) { double fx = _sx1.getFirst(); if (fx==0.0) return; int nk = (_complex)?_nfft1:_nfft1/2+1; double dp = sign1*2.0*PI*_sk1.getDelta()*fx; for (int i=0,ir=0,ii=1; i<nk; ++i,ir+=2,ii+=2) { float p = (float)(i*dp); float cosp = cos(p); float sinp = sin(p); float fr = f[ir]; float fi = f[ii]; f[ir] = fr*cosp-fi*sinp; f[ii] = fi*cosp+fr*sinp; } } private void phase(float[][] f) {
/** * Returns a sampled linear (ramp) function. * The function values are fv+dv*(s-f), for s = f, f+d, ..., f+d*(n-1), * where n, d, and f are the sampling count, delta, and first value. * @param fv the first function value. * @param dv the function value delta. * @param s the sampling. * @return the function. */ public static Real1 ramp(double fv, double dv, Sampling s) { int n = s.getCount(); double d = s.getDelta(); double f = s.getFirst(); return new Real1(s, rampfloat((float)(fv-f*dv),(float)(d*dv),n)); }
/** * Interpolates one real value y(x). * @param sxu sampling of input samples. * @param yu input array of uniformly sampled values y(x). * @param xi value x at which to interpolate. * @return interpolated value y(x). */ public float interpolate(Sampling sxu, float[] yu, double xi) { Check.argument(sxu.isUniform(),"input sampling is uniform"); return interpolate(sxu.getCount(),sxu.getDelta(),sxu.getFirst(),yu,xi); }
/** * Interpolates one real value y(x). * @param sxu sampling of input samples. * @param yu input array of uniformly sampled values y(x). * @param xi value x at which to interpolate. * @return interpolated value y(x). */ public float interpolate(Sampling sxu, float[] yu, double xi) { Check.argument(sxu.isUniform(),"input sampling is uniform"); return interpolate(sxu.getCount(),sxu.getDelta(),sxu.getFirst(),yu,xi); }
/** * Interpolates one real value y(x1,x2). * @param sx1u sampling of input x in 1st dimension. * @param sx2u sampling of input x in 2nd dimension. * @param yu input array of sampled values y(x). * @param x1i 1st coordinate of x at which to interpolate. * @param x2i 2nd coordinate of x at which to interpolate. * @return interpolated value y(x). */ public float interpolate( Sampling sx1u, Sampling sx2u, float[][] yu, double x1i, double x2i) { Check.argument(sx1u.isUniform(),"input sampling of x1 is uniform"); Check.argument(sx2u.isUniform(),"input sampling of x2 is uniform"); return interpolate( sx1u.getCount(),sx1u.getDelta(),sx1u.getFirst(), sx2u.getCount(),sx2u.getDelta(),sx2u.getFirst(), yu,x1i,x2i); }
/** * Interpolates one real value y(x1,x2). * @param sx1u sampling of input x in 1st dimension. * @param sx2u sampling of input x in 2nd dimension. * @param yu input array of sampled values y(x). * @param x1i 1st coordinate of x at which to interpolate. * @param x2i 2nd coordinate of x at which to interpolate. * @return interpolated value y(x). */ public float interpolate( Sampling sx1u, Sampling sx2u, float[][] yu, double x1i, double x2i) { Check.argument(sx1u.isUniform(),"input sampling of x1 is uniform"); Check.argument(sx2u.isUniform(),"input sampling of x2 is uniform"); return interpolate( sx1u.getCount(),sx1u.getDelta(),sx1u.getFirst(), sx2u.getCount(),sx2u.getDelta(),sx2u.getFirst(), yu,x1i,x2i); }
/** * Interpolates one real value y(x1,x2,x3). * @param sx1u sampling of input x in 1st dimension. * @param sx2u sampling of input x in 2nd dimension. * @param sx3u sampling of input x in 3rd dimension. * @param yu input array of sampled values y(x). * @param x1i 1st coordinate of x at which to interpolate. * @param x2i 2nd coordinate of x at which to interpolate. * @param x3i 3rd coordinate of x at which to interpolate. * @return interpolated value y(x). */ public float interpolate( Sampling sx1u, Sampling sx2u, Sampling sx3u, float[][][] yu, double x1i, double x2i, double x3i) { Check.argument(sx1u.isUniform(),"input sampling of x1 is uniform"); Check.argument(sx2u.isUniform(),"input sampling of x2 is uniform"); Check.argument(sx3u.isUniform(),"input sampling of x3 is uniform"); return interpolate( sx1u.getCount(),sx1u.getDelta(),sx1u.getFirst(), sx2u.getCount(),sx2u.getDelta(),sx2u.getFirst(), sx3u.getCount(),sx3u.getDelta(),sx3u.getFirst(), yu,x1i,x2i,x3i); }
/** * Interpolates multiple real values y(x). * @param sxu sampling of input samples. * @param yu input array of uniformly sampled values y(x). * @param sxi sampling of output samples. * @param yi output array of interpolated values y(x). */ public void interpolate( Sampling sxu, float[] yu, Sampling sxi, float[] yi) { Check.argument(sxu.isUniform(),"input sampling is uniform"); if (sxi.isUniform()) { interpolate(sxu.getCount(),sxu.getDelta(),sxu.getFirst(),yu, sxi.getCount(),sxi.getDelta(),sxi.getFirst(),yi); } else { int nxu = sxu.getCount(); int nxi = sxi.getCount(); double xscale = 1.0/sxu.getDelta(); double xshift = _lsinc-sxu.getFirst()*xscale; int nxum = nxu-_lsinc; for (int ixi=0; ixi<nxi; ++ixi) { double xi = sxi.getValue(ixi); yi[ixi] = interpolate(xscale,xshift,nxum,nxu,yu,xi); } } }
/** * Interpolates multiple real values y(x). * @param sxu sampling of input samples. * @param yu input array of uniformly sampled values y(x). * @param sxi sampling of output samples. * @param yi output array of interpolated values y(x). */ public void interpolate( Sampling sxu, float[] yu, Sampling sxi, float[] yi) { Check.argument(sxu.isUniform(),"input sampling is uniform"); if (sxi.isUniform()) { interpolate(sxu.getCount(),sxu.getDelta(),sxu.getFirst(),yu, sxi.getCount(),sxi.getDelta(),sxi.getFirst(),yi); } else { int nxu = sxu.getCount(); int nxi = sxi.getCount(); double xscale = 1.0/sxu.getDelta(); double xshift = _lsinc-sxu.getFirst()*xscale; int nxum = nxu-_lsinc; for (int ixi=0; ixi<nxi; ++ixi) { double xi = sxi.getValue(ixi); yi[ixi] = interpolate(xscale,xshift,nxum,nxu,yu,xi); } } }
/** * Interpolates one real value y(x1,x2,x3). * @param sx1u sampling of input x in 1st dimension. * @param sx2u sampling of input x in 2nd dimension. * @param sx3u sampling of input x in 3rd dimension. * @param yu input array of sampled values y(x). * @param x1i 1st coordinate of x at which to interpolate. * @param x2i 2nd coordinate of x at which to interpolate. * @param x3i 3rd coordinate of x at which to interpolate. * @return interpolated value y(x). */ public float interpolate( Sampling sx1u, Sampling sx2u, Sampling sx3u, float[][][] yu, double x1i, double x2i, double x3i) { Check.argument(sx1u.isUniform(),"input sampling of x1 is uniform"); Check.argument(sx2u.isUniform(),"input sampling of x2 is uniform"); Check.argument(sx3u.isUniform(),"input sampling of x3 is uniform"); return interpolate( sx1u.getCount(),sx1u.getDelta(),sx1u.getFirst(), sx2u.getCount(),sx2u.getDelta(),sx2u.getFirst(), sx3u.getCount(),sx3u.getDelta(),sx3u.getFirst(), yu,x1i,x2i,x3i); }
/** * Determines whether this sampling is equivalent to the specified sampling. * Two samplings are equivalent if each of their sample values differs by * no more than the sampling tolerance. * @param s the sampling to compare to this sampling. * @return true, if equivalent; false, otherwise. */ public boolean isEquivalentTo(Sampling s) { Sampling t = this; if (t.isUniform()!=s.isUniform()) return false; if (t.isUniform()) { if (t.getCount()!=s.getCount()) return false; double tiny = tinyWith(s); double tf = t.getFirst(); double tl = t.getLast(); double sf = s.getFirst(); double sl = s.getLast(); return almostEqual(tf,sf,tiny) && almostEqual(tl,sl,tiny); } else { double tiny = tinyWith(s); for (int i=0; i<_n; ++i) { if (!almostEqual(_v[i],s.value(i),tiny)) return false; } return true; } }