/** * 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()); }
/** * 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; }
public float[][] grid(Sampling s1, Sampling s2) { int n1 = s1.getCount(); int n2 = s2.getCount(); double d1 = s1.getDelta(); double d2 = s2.getDelta(); double f1 = s1.getFirst(); double f2 = s2.getFirst(); double l1 = s1.getLast(); double l2 = s2.getLast(); f1 -= 0.5*d1; l1 += 0.5*d1; f2 -= 0.5*d2; l2 += 0.5*d2; float[][] g = new float[n2][n1]; float[][] c = new float[n2][n1]; for (int i=0; i<_n; ++i) { double x1 = _x1[i]; double x2 = _x2[i]; if (f1<=x1 && x1<=l1 && f2<=x2 && x2<=l2) { int i1 = s1.indexOfNearest(x1); int i2 = s2.indexOfNearest(x2); g[i2][i1] += _f[i]; c[i2][i1] += 1.0f; } } for (int i2=0; i2<n2; ++i2) { for (int i1=0; i1<n1; ++i1) { g[i2][i1] = (c[i2][i1]>0.0f)?g[i2][i1]/c[i2][i1]:_fnull; } } return g; }
/** * 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; } }
double dx = _sx.getDelta(); double fx = _sx.getFirst(); double lx = _sx.getLast();
double xl = _sx.getLast(); double xmin = min(xf,xl); double xmax = max(xf,xl);