code
stringlengths 67
466k
| docstring
stringlengths 1
13.2k
|
---|---|
public int convexHullSize() {
int ans = 0;
Iterator<Vector3> it = this.getConvexHullVerticesIterator();
while (it.hasNext()) {
ans++;
it.next();
}
return ans;
} | compute the number of vertices in the convex hull. <br />
NOTE: has a 'bug-like' behavor: <br />
in cases of colinear - not on a asix parallel rectangle,
colinear points are reported
@return the number of vertices in the convex hull. |
public Triangle find(Vector3 p) {
// If triangulation has a spatial index try to use it as the starting triangle
Triangle searchTriangle = startTriangle;
/*if(gridIndex != null) {
Triangle indexTriangle = gridIndex.findCellTriangleOf(p);
if(indexTriangle != null)
searchTriangle = indexTriangle;
}*/
// Search for the point's triangle starting from searchTriangle
return find(searchTriangle, p);
} | finds the triangle the query point falls in, note if out-side of this
triangulation a half plane triangle will be returned (see contains), the
search has expected time of O(n^0.5), and it starts form a fixed triangle
(this.startTriangle),
@param p
query point
@return the triangle that point p is in. |
public Triangle find(Vector3 p, Triangle start) {
if (start == null)
start = this.startTriangle;
Triangle T = find(start, p);
return T;
} | finds the triangle the query point falls in, note if out-side of this
triangulation a half plane triangle will be returned (see contains). the
search starts from the the start triangle
@param p
query point
@param start
the triangle the search starts at.
@return the triangle that point p is in.. |
private static Triangle findnext1(Vector3 p, Triangle v) {
if (!v.abnext.halfplane && PointLineTest.pointLineTest(v.a, v.b, p) == PointLinePosition.RIGHT)
return v.abnext;
if (!v.bcnext.halfplane && PointLineTest.pointLineTest(v.b, v.c, p) == PointLinePosition.RIGHT)
return v.bcnext;
if (!v.canext.halfplane && PointLineTest.pointLineTest(v.c, v.a, p) == PointLinePosition.RIGHT)
return v.canext;
if (PointLineTest.pointLineTest(v.a, v.b, p) == PointLinePosition.RIGHT)
return v.abnext;
if (PointLineTest.pointLineTest(v.b, v.c, p) == PointLinePosition.RIGHT)
return v.bcnext;
if (PointLineTest.pointLineTest(v.c, v.a, p) == PointLinePosition.RIGHT)
return v.canext;
return null;
} | /*
assumes v is NOT an halfplane!
returns the next triangle for find. |
private static Triangle findnext2(Vector3 p, Triangle v) {
if (v.abnext != null && !v.abnext.halfplane)
return v.abnext;
if (v.bcnext != null && !v.bcnext.halfplane)
return v.bcnext;
if (v.canext != null && !v.canext.halfplane)
return v.canext;
return null;
} | assumes v is an halfplane! - returns another (none halfplane) triangle |
private List<Triangle> findConnectedTriangles(Vector3 point) {
// Getting one of the neigh
Triangle triangle = find(point);
// Validating find results.
if (!triangle.isCorner(point)) {
System.err.println("findConnectedTriangles: Could not find connected vertices since the first found triangle doesn't" +
" share the given point.");
return null;
}
return findTriangleNeighborhood(triangle, point);
} | /*
Receives a point and returns all the points of the triangles that
shares point as a corner (Connected vertices to this point).
By Doron Ganel & Eyal Roth |
public List<Triangle> findTriangleNeighborhood(Triangle firstTriangle, Vector3 point) {
List<Triangle> triangles = new ArrayList<Triangle>(30);
triangles.add(firstTriangle);
Triangle prevTriangle = null;
Triangle currentTriangle = firstTriangle;
Triangle nextTriangle = currentTriangle.nextNeighbor(point, prevTriangle);
while (!nextTriangle.equals(firstTriangle)) {
//the point is on the perimeter
if(nextTriangle.isHalfplane()) {
return null;
}
triangles.add(nextTriangle);
prevTriangle = currentTriangle;
currentTriangle = nextTriangle;
nextTriangle = currentTriangle.nextNeighbor(point, prevTriangle);
}
return triangles;
} | changed to public by Udi |
private Iterator<Vector3> getConvexHullVerticesIterator() {
List<Vector3> ans = new ArrayList<Vector3>();
Triangle curr = this.startTriangleHull;
boolean cont = true;
double x0 = bbMin.x, x1 = bbMax.x;
double y0 = bbMin.y, y1 = bbMax.y;
boolean sx, sy;
while (cont) {
sx = curr.p1().x == x0 || curr.p1().x == x1;
sy = curr.p1().y == y0 || curr.p1().y == y1;
if ((sx && sy) || (!sx && !sy)) {
ans.add(curr.p1());
}
if (curr.bcnext != null && curr.bcnext.halfplane)
curr = curr.bcnext;
if (curr == this.startTriangleHull)
cont = false;
}
return ans.iterator();
} | returns an iterator to the set of all the points on the XY-convex hull
@return iterator to the set of all the points on the XY-convex hull. |
public List<Triangle> triangulate(List<Vector3> points) {
init(points.size());
Set<Vector3> vertices = new TreeSet<Vector3>(new PointComparator());
bbMin = new Vector3(points.get(0));
bbMax = new Vector3(points.get(0));
//Insert Points
for (Vector3 point:points) {
this.insertPoint(vertices, point);
}
List<Triangle> triangles = null;
if (modCount != modCount2 && vertices.size() > 2) {
triangles = generateTriangles();
}
return triangles;
} | Triangulate given points.
Note: duplicated points are ignored.
@param points
@return list of triangles |
public static double[] Normalize(int[] values){
int sum = 0;
for (int i = 0; i < values.length; i++) {
sum += values[i];
}
double[] norm = new double[values.length];
for (int i = 0; i < norm.length; i++) {
norm[i] = values[i] / (double)sum;
}
return norm;
} | Normalize histogram.
@param values Values.
@return Normalized histogram. |
private void update(){
int i, n = values.length;
max = 0;
min = n;
total = 0;
int maxVal = -Integer.MAX_VALUE;
int minVal = Integer.MAX_VALUE;
// calculate min and max
for ( i = 0; i < n; i++ )
{
if ( values[i] != 0 )
{
// max
if ( i > max )
max = i;
// min
if ( i < min )
min = i;
maxVal = Math.max(maxVal, values[i]);
minVal = Math.min(minVal, values[i]);
total += values[i];
}
}
double k = (maxVal - minVal) / (double)bins;
int[] h = new int[bins];
for (int j = 0; j < values.length; j++) {
double _min = minVal;
double _max = _min + k;
//First interval.
if(values[j] >= _min && values[j] <= _max)
h[0]++;
_min += k;
_max += k;
//Others interval.
for (int l = 1; l < bins; l++) {
if(values[j] > _min && values[j] <= _max)
h[l]++;
_min += k;
_max += k;
}
}
this.values = h;
mean = HistogramStatistics.Mean( values );
stdDev = HistogramStatistics.StdDev( values, mean );
median = HistogramStatistics.Median( values );
mode = HistogramStatistics.Mode(values);
entropy = HistogramStatistics.Entropy(values);
} | Update histogram. |
public double[] Normalize(){
double[] h = new double[values.length];
for (int i = 0; i < h.length; i++) {
h[i] = values[i] / (double)total;
}
return h;
} | Normalize histogram.
@return Normalized histogram. |
public RotateOperation angle(double angle) {
this.angle = angle;
// Calculate cos and sin with negative angle
double angleRad = -angle * Math.PI / 180;
angleCos = Math.cos(angleRad);
angleSin = Math.sin(angleRad);
return this;
} | Set Angle.
@param angle Angle [0..360]. |
public RotateOperation fillColor(int red, int green, int blue) {
this.fillRed = red;
this.fillGreen = green;
this.fillBlue = blue;
return this;
} | Set Fill color.
@param red Red channel's value.
@param green Green channel's value.
@param blue Blue channel's value. |
@Parameters
public static final Collection<Object[]> getParameters() {
return Arrays.asList(
new Object[] {
(Function<ListenerStore, ? extends EventProvider>) store -> new AWTEventProvider(store, true),
(Supplier<ListenerStore>) () -> PerformanceListenerStore.create().synchronizedView()
},
new Object[] {
(Function<ListenerStore, ? extends EventProvider>) store -> new AWTEventProvider(store, false),
(Supplier<ListenerStore>) () -> PriorityListenerStore.create().synchronizedView()
},
new Object[] {
(Function<ListenerStore, ? extends EventProvider>) store -> new StatisticsEventProvider<>(new AWTEventProvider(store, true)),
(Supplier<ListenerStore>) () -> PriorityListenerStore.create().synchronizedView()
},
new Object[] {
(Function<ListenerStore, ? extends EventProvider>) store -> new StatisticsEventProvider<>(new AWTEventProvider(store, true)),
(Supplier<ListenerStore>) () -> PriorityListenerStore.create().synchronizedView()
}
);
} | Parameterizes the test instances.
@return Collection of parameters for the constructor of
{@link EventProviderTestBase}. |
public void removePoint(int index) {
int numKnots = x.length;
if (numKnots <= 2)
return;
float[] nx = new float[numKnots - 1];
float[] ny = new float[numKnots - 1];
int j = 0;
for (int i = 0; i < numKnots - 1; i++) {
if (i == index)
j++;
nx[i] = x[j];
ny[i] = y[j];
j++;
}
x = nx;
y = ny;
} | Remove point
@param index Index. |
public int[] makeLut() {
int numKnots = x.length;
float[] nx = new float[numKnots + 2];
float[] ny = new float[numKnots + 2];
System.arraycopy(x, 0, nx, 1, numKnots);
System.arraycopy(y, 0, ny, 1, numKnots);
nx[0] = nx[1];
ny[0] = ny[1];
nx[numKnots + 1] = nx[numKnots];
ny[numKnots + 1] = ny[numKnots];
int[] table = new int[256];
for (int i = 0; i < 1024; i++) {
float f = i / 1024.0f;
int x = (int) (255 * Curve.Spline(f, nx.length, nx) + 0.5f);
int y = (int) (255 * Curve.Spline(f, nx.length, ny) + 0.5f);
x = x > 255 ? 255 : x;
x = x < 0 ? 0 : x;
y = y > 255 ? 255 : y;
y = y < 0 ? 0 : y;
table[x] = y;
}
return table;
} | Create LUT.
@return LUT. |
public static float Spline(float x, int numKnots, float[] knots) {
int span;
int numSpans = numKnots - 3;
float k0, k1, k2, k3;
float c0, c1, c2, c3;
if (numSpans < 1)
throw new IllegalArgumentException("Too few knots in spline");
x = x > 1 ? 1 : x;
x = x < 0 ? 0 : x;
x *= numSpans;
span = (int) x;
if (span > numKnots - 4)
span = numKnots - 4;
x -= span;
k0 = knots[span];
k1 = knots[span + 1];
k2 = knots[span + 2];
k3 = knots[span + 3];
c3 = -0.5f * k0 + 1.5f * k1 + -1.5f * k2 + 0.5f * k3;
c2 = 1f * k0 + -2.5f * k1 + 2f * k2 + -0.5f * k3;
c1 = -0.5f * k0 + 0f * k1 + 0.5f * k2 + 0f * k3;
c0 = 0f * k0 + 1f * k1 + 0f * k2 + 0f * k3;
return ((c3 * x + c2) * x + c1) * x + c0;
} | compute a Catmull-Rom spline.
@param x the input parameter
@param numKnots the number of knots in the spline
@param knots the array of knots
@return the spline value |
public static float Spline(float x, int numKnots, int[] xknots, int[] yknots) {
int span;
int numSpans = numKnots - 3;
float k0, k1, k2, k3;
float c0, c1, c2, c3;
if (numSpans < 1)
throw new IllegalArgumentException("Too few knots in spline");
for (span = 0; span < numSpans; span++)
if (xknots[span + 1] > x)
break;
if (span > numKnots - 3)
span = numKnots - 3;
float t = (float) (x - xknots[span]) / (xknots[span + 1] - xknots[span]);
span--;
if (span < 0) {
span = 0;
t = 0;
}
k0 = yknots[span];
k1 = yknots[span + 1];
k2 = yknots[span + 2];
k3 = yknots[span + 3];
c3 = -0.5f * k0 + 1.5f * k1 + -1.5f * k2 + 0.5f * k3;
c2 = 1f * k0 + -2.5f * k1 + 2f * k2 + -0.5f * k3;
c1 = -0.5f * k0 + 0f * k1 + 0.5f * k2 + 0f * k3;
c0 = 0f * k0 + 1f * k1 + 0f * k2 + 0f * k3;
return ((c3 * t + c2) * t + c1) * t + c0;
} | compute a Catmull-Rom spline, but with variable knot spacing.
@param x the input parameter
@param numKnots the number of knots in the spline
@param xknots the array of knot x values
@param yknots the array of knot y values
@return the spline value |
public static Predicate<Event<?, ?>> withListenerClass(
Class<? extends Listener> cls) {
if (cls == null) {
throw new IllegalArgumentException("cls is null");
}
return event -> event.getListenerClass() == cls;
} | Creates a predicate that matches events for the given listener class.
@param cls The listener class to check for.
@return The predicate. |
public static float fieldOfView(float focalLength, float sensorWidth) {
double fov = 2 * Math.atan(.5 * sensorWidth / focalLength);
return (float) Math.toDegrees(fov);
} | Calculate the FOV of camera, using focalLength and sensorWidth
@param focalLength
@param sensorWidth
@return FOV |
public boolean IsOverlapping(DoubleRange range) {
return ((isInside(range.min)) || (isInside(range.max)) ||
(range.isInside(min)) || (range.isInside(max)));
} | Check if the specified range overlaps with the range.
@param range DoubleRange.
@return True if the range overlaps with the range, otherwise returns false. |
private static int[] gammaLUT(double gammaValue) {
int[] gammaLUT = new int[256];
for (int i = 0; i < gammaLUT.length; i++) {
gammaLUT[i] = (int) (255 * (Math.pow((double) i / (double) 255, gammaValue)));
}
return gammaLUT;
} | Create the gamma correction lookup table |
public boolean IsOverlapping(FloatRange range) {
return ((isInside(range.min)) || (isInside(range.max)) ||
(range.isInside(min)) || (range.isInside(max)));
} | Check if the specified range overlaps with the range.
@param range FloatRange.
@return True if the range overlaps with the range, otherwise returns false. |
public static double Log(double a, double b) {
return Gamma.Log(a) + Gamma.Log(b) - Gamma.Log(a + b);
} | Natural logarithm of the Beta function.
@param a Value.
@param b Value.
@return Result. |
public static double Incomplete(double a, double b, double x) {
double aa, bb, t, xx, xc, w, y;
boolean flag;
if (a <= 0.0) {
try {
throw new IllegalArgumentException(" 'a' Lower limit must be greater than zero.");
} catch (Exception e) {
e.printStackTrace();
}
}
if (b <= 0.0) {
try {
throw new IllegalArgumentException(" 'b' Upper limit must be greater than zero.");
} catch (Exception e) {
e.printStackTrace();
}
}
if ((x <= 0.0) || (x >= 1.0)) {
if (x == 0.0) return 0.0;
if (x == 1.0) return 1.0;
try {
throw new IllegalArgumentException(" 'x' Value must be between 0 and 1.");
} catch (Exception e) {
e.printStackTrace();
}
}
flag = false;
if ((b * x) <= 1.0 && x <= 0.95) {
t = PowerSeries(a, b, x);
return t;
}
w = 1.0 - x;
if (x > (a / (a + b))) {
flag = true;
aa = b;
bb = a;
xc = x;
xx = w;
} else {
aa = a;
bb = b;
xc = w;
xx = x;
}
if (flag && (bb * xx) <= 1.0 && xx <= 0.95) {
t = PowerSeries(aa, bb, xx);
if (t <= Constants.DoubleEpsilon) t = 1.0 - Constants.DoubleEpsilon;
else t = 1.0 - t;
return t;
}
y = xx * (aa + bb - 2.0) - (aa - 1.0);
if (y < 0.0)
w = Incbcf(aa, bb, xx);
else
w = Incbd(aa, bb, xx) / xc;
y = aa * Math.log(xx);
t = bb * Math.log(xc);
if ((aa + bb) < Gamma.GammaMax && Math.abs(y) < Constants.LogMax && Math.abs(t) < Constants.LogMax) {
t = Math.pow(xc, bb);
t *= Math.pow(xx, aa);
t /= aa;
t *= w;
t *= Gamma.Function(aa + bb) / (Gamma.Function(aa) * Gamma.Function(bb));
if (flag) {
if (t <= Constants.DoubleEpsilon) t = 1.0 - Constants.DoubleEpsilon;
else t = 1.0 - t;
}
return t;
}
y += t + Gamma.Log(aa + bb) - Gamma.Log(aa) - Gamma.Log(bb);
y += Math.log(w / aa);
if (y < Constants.LogMin)
t = 0.0;
else
t = Math.exp(y);
if (flag) {
if (t <= Constants.DoubleEpsilon) t = 1.0 - Constants.DoubleEpsilon;
else t = 1.0 - t;
}
return t;
} | Incomplete (regularized) Beta function Ix(a, b).
@param a Value.
@param b Value.
@param x Value.
@return Result. |
public static double Incbcf(double a, double b, double x) {
double xk, pk, pkm1, pkm2, qk, qkm1, qkm2;
double k1, k2, k3, k4, k5, k6, k7, k8;
double r, t, ans, thresh;
int n;
double big = 4.503599627370496e15;
double biginv = 2.22044604925031308085e-16;
k1 = a;
k2 = a + b;
k3 = a;
k4 = a + 1.0;
k5 = 1.0;
k6 = b - 1.0;
k7 = k4;
k8 = a + 2.0;
pkm2 = 0.0;
qkm2 = 1.0;
pkm1 = 1.0;
qkm1 = 1.0;
ans = 1.0;
r = 1.0;
n = 0;
thresh = 3.0 * Constants.DoubleEpsilon;
do {
xk = -(x * k1 * k2) / (k3 * k4);
pk = pkm1 + pkm2 * xk;
qk = qkm1 + qkm2 * xk;
pkm2 = pkm1;
pkm1 = pk;
qkm2 = qkm1;
qkm1 = qk;
xk = (x * k5 * k6) / (k7 * k8);
pk = pkm1 + pkm2 * xk;
qk = qkm1 + qkm2 * xk;
pkm2 = pkm1;
pkm1 = pk;
qkm2 = qkm1;
qkm1 = qk;
if (qk != 0) r = pk / qk;
if (r != 0) {
t = Math.abs((ans - r) / r);
ans = r;
} else
t = 1.0;
if (t < thresh) return ans;
k1 += 1.0;
k2 += 1.0;
k3 += 2.0;
k4 += 2.0;
k5 += 1.0;
k6 -= 1.0;
k7 += 2.0;
k8 += 2.0;
if ((Math.abs(qk) + Math.abs(pk)) > big) {
pkm2 *= biginv;
pkm1 *= biginv;
qkm2 *= biginv;
qkm1 *= biginv;
}
if ((Math.abs(qk) < biginv) || (Math.abs(pk) < biginv)) {
pkm2 *= big;
pkm1 *= big;
qkm2 *= big;
qkm1 *= big;
}
} while (++n < 300);
return ans;
} | Continued fraction expansion #1 for incomplete beta integral.
@param a Value.
@param b Value.
@param x Value.
@return Result. |
public static double PowerSeries(double a, double b, double x) {
double s, t, u, v, n, t1, z, ai;
ai = 1.0 / a;
u = (1.0 - b) * x;
v = u / (a + 1.0);
t1 = v;
t = u;
n = 2.0;
s = 0.0;
z = Constants.DoubleEpsilon * ai;
while (Math.abs(v) > z) {
u = (n - b) * x / n;
t *= u;
v = t / (a + n);
s += v;
n += 1.0;
}
s += t1;
s += ai;
u = a * Math.log(x);
if ((a + b) < Gamma.GammaMax && Math.abs(u) < Constants.LogMax) {
t = Gamma.Function(a + b) / (Gamma.Function(a) * Gamma.Function(b));
s = s * t * Math.pow(x, a);
} else {
t = Gamma.Log(a + b) - Gamma.Log(a) - Gamma.Log(b) + u + Math.log(s);
if (t < Constants.LogMin) s = 0.0;
else s = Math.exp(t);
}
return s;
} | Power series for incomplete beta integral. Use when b*x is small and x not too close to 1.
@param a Value.
@param b Value.
@param x Value.
@return Result. |
public static <L extends Listener, E extends Event<?, L>> boolean checkPrevent(
EventStack eventStack, E event, BiConsumer<L, E> bc, ExceptionCallback ec) {
// check if any of the currently dispatched events marked the target
// listener class to be prevented.
final Optional<SequentialEvent<?, ?>> cause = eventStack.preventDispatch(
event.getListenerClass());
if (cause.isPresent()) {
event.setPrevented(true);
cause.get().addSuppressedEvent(
new SuppressedEventImpl<L, E>(event, ec, bc));
return true;
}
return false;
} | Checks whether the given Event should be prevented according to the given
event stack. If so, the event's {@link Event#isPrevented() isPrevented}
property is set to <code>true</code> and a new {@link SuppressedEvent} is
added to the <em>preventing</em> event.
@param <L> Type of the listener.
@param <E> Type of the event.
@param eventStack The event stack.
@param event The Event to check whether it is prevented.
@param bc Function to delegate the event to the specific callback method
of the listener.
@param ec Callback to be notified when any of the listeners throws an
exception.
@return Whether the event should be prevented. |
@Override
protected <T> List<T> createListenerList(int sizeHint) {
if (this.optimized) {
return new CopyOnWriteArrayList<>();
}
return super.createListenerList(sizeHint);
} | {@inheritDoc}
<p>
After {@link #optimizeGet()} has been called, this method will return
instances of {@link CopyOnWriteArrayList}.
</p> |
public static void DFT(ComplexNumber[] data, Direction direction) {
int n = data.length;
ComplexNumber[] c = new ComplexNumber[n];
// for each destination element
for (int i = 0; i < n; i++) {
c[i] = new ComplexNumber(0, 0);
double sumRe = 0;
double sumIm = 0;
double phim = 2 * Math.PI * i / n;
// sum source elements
for (int j = 0; j < n; j++) {
double gRe = data[j].real;
double gIm = data[j].imaginary;
double cosw = Math.cos(phim * j);
double sinw = Math.sin(phim * j);
if (direction == Direction.Backward)
sinw = -sinw;
sumRe += (gRe * cosw + data[j].imaginary * sinw);
sumIm += (gIm * cosw - data[j].real * sinw);
}
c[i] = new ComplexNumber(sumRe, sumIm);
}
if (direction == Direction.Backward) {
for (int i = 0; i < c.length; i++) {
data[i].real = c[i].real / n;
data[i].imaginary = c[i].imaginary / n;
}
} else {
for (int i = 0; i < c.length; i++) {
data[i].real = c[i].real;
data[i].imaginary = c[i].imaginary;
}
}
} | 1-D Discrete Fourier Transform.
@param data Data to transform.
@param direction Transformation direction. |
public static void DFT2(ComplexNumber[][] data, Direction direction) {
int n = data.length;
int m = data[0].length;
ComplexNumber[] row = new ComplexNumber[Math.max(m, n)];
for (int i = 0; i < n; i++) {
// copy row
for (int j = 0; j < n; j++)
row[j] = data[i][j];
// transform it
FourierTransform.DFT(row, direction);
// copy back
for (int j = 0; j < n; j++)
data[i][j] = row[j];
}
// process columns
ComplexNumber[] col = new ComplexNumber[n];
for (int j = 0; j < n; j++) {
// copy column
for (int i = 0; i < n; i++)
col[i] = data[i][j];
// transform it
FourierTransform.DFT(col, direction);
// copy back
for (int i = 0; i < n; i++)
data[i][j] = col[i];
}
} | 2-D Discrete Fourier Transform.
@param data Data to transform.
@param direction Transformation direction. |
public static void FFT(ComplexNumber[] data, Direction direction) {
double[] real = ComplexNumber.getReal(data);
double[] img = ComplexNumber.getImaginary(data);
if (direction == Direction.Forward)
FFT(real, img);
else
FFT(img, real);
if (direction == Direction.Forward) {
for (int i = 0; i < real.length; i++) {
data[i] = new ComplexNumber(real[i], img[i]);
}
} else {
int n = real.length;
for (int i = 0; i < n; i++) {
data[i] = new ComplexNumber(real[i] / n, img[i] / n);
}
}
} | 1-D Fast Fourier Transform.
@param data Data to transform.
@param direction Transformation direction. |
public static void FFT2(ComplexNumber[][] data, Direction direction) {
int n = data.length;
int m = data[0].length;
//ComplexNumber[] row = new ComplexNumber[m];//Math.max(m, n)];
for (int i = 0; i < n; i++) {
// copy row
//for ( int j = 0; j < m; j++ )
//row[j] = data[i][j];
ComplexNumber[] row = data[i];
// transform it
FourierTransform.FFT(row, direction);
// copy back
for (int j = 0; j < m; j++)
data[i][j] = row[j];
}
// process columns
ComplexNumber[] col = new ComplexNumber[n];
for (int j = 0; j < m; j++) {
// copy column
for (int i = 0; i < n; i++)
col[i] = data[i][j];
// transform it
FourierTransform.FFT(col, direction);
// copy back
for (int i = 0; i < n; i++)
data[i][j] = col[i];
}
} | 2-D Fast Fourier Transform.
@param data Data to transform.
@param direction Transformation direction. |
private static void FFT(double[] real, double[] imag) {
int n = real.length;
if (n == 0) {
return;
} else if ((n & (n - 1)) == 0) // Is power of 2
transformRadix2(real, imag);
else // More complicated algorithm for arbitrary sizes
transformBluestein(real, imag);
} | /*
Computes the discrete Fourier transform (DFT) of the given complex vector, storing the result back into the vector.
The vector can have any length. This is a wrapper function. |
private static void transformRadix2(double[] real, double[] imag) {
int n = real.length;
int levels = 31 - Integer.numberOfLeadingZeros(n); // Equal to floor(log2(n))
// if (1 << levels != n)
// throw new IllegalArgumentException("Length is not a power of 2");
double[] cosTable = new double[n / 2];
double[] sinTable = new double[n / 2];
for (int i = 0; i < n / 2; i++) {
cosTable[i] = Math.cos(2 * Math.PI * i / n);
sinTable[i] = Math.sin(2 * Math.PI * i / n);
}
// Bit-reversed addressing permutation
for (int i = 0; i < n; i++) {
int j = Integer.reverse(i) >>> (32 - levels);
if (j > i) {
double temp = real[i];
real[i] = real[j];
real[j] = temp;
temp = imag[i];
imag[i] = imag[j];
imag[j] = temp;
}
}
// Cooley-Tukey decimation-in-time radix-2 FFT
for (int size = 2; size <= n; size *= 2) {
int halfsize = size / 2;
int tablestep = n / size;
for (int i = 0; i < n; i += size) {
for (int j = i, k = 0; j < i + halfsize; j++, k += tablestep) {
double tpre = real[j + halfsize] * cosTable[k] + imag[j + halfsize] * sinTable[k];
double tpim = -real[j + halfsize] * sinTable[k] + imag[j + halfsize] * cosTable[k];
real[j + halfsize] = real[j] - tpre;
imag[j + halfsize] = imag[j] - tpim;
real[j] += tpre;
imag[j] += tpim;
}
}
// Prevent overflow in 'size *= 2'
if (size == n)
break;
}
} | /*
Computes the discrete Fourier transform (DFT) of the given complex vector, storing the result back into the vector.
The vector's length must be a power of 2. Uses the Cooley-Tukey decimation-in-time radix-2 algorithm. |
private static void transformBluestein(double[] real, double[] imag) {
int n = real.length;
int m = Integer.highestOneBit(n * 2 + 1) << 1;
// Trignometric tables
double[] cosTable = new double[n];
double[] sinTable = new double[n];
for (int i = 0; i < n; i++) {
int j = (int) ((long) i * i % (n * 2)); // This is more accurate than j = i * i
cosTable[i] = Math.cos(Math.PI * j / n);
sinTable[i] = Math.sin(Math.PI * j / n);
}
// Temporary vectors and preprocessing
double[] areal = new double[m];
double[] aimag = new double[m];
for (int i = 0; i < n; i++) {
areal[i] = real[i] * cosTable[i] + imag[i] * sinTable[i];
aimag[i] = -real[i] * sinTable[i] + imag[i] * cosTable[i];
}
double[] breal = new double[m];
double[] bimag = new double[m];
breal[0] = cosTable[0];
bimag[0] = sinTable[0];
for (int i = 1; i < n; i++) {
breal[i] = breal[m - i] = cosTable[i];
bimag[i] = bimag[m - i] = sinTable[i];
}
// Convolution
double[] creal = new double[m];
double[] cimag = new double[m];
convolve(areal, aimag, breal, bimag, creal, cimag);
// Postprocessing
for (int i = 0; i < n; i++) {
real[i] = creal[i] * cosTable[i] + cimag[i] * sinTable[i];
imag[i] = -creal[i] * sinTable[i] + cimag[i] * cosTable[i];
}
} | /*
Computes the discrete Fourier transform (DFT) of the given complex vector, storing the result back into the vector.
The vector can have any length. This requires the convolution function, which in turn requires the radix-2 FFT function.
Uses Bluestein's chirp z-transform algorithm. |
private static void convolve(double[] x, double[] y, double[] out) {
// if (x.length != y.length || x.length != out.length)
// throw new IllegalArgumentException("Mismatched lengths");
int n = x.length;
convolve(x, new double[n], y, new double[n], out, new double[n]);
} | /*
Computes the circular convolution of the given real vectors. Each vector's length must be the same. |
private static void convolve(double[] xreal, double[] ximag, double[] yreal, double[] yimag, double[] outreal, double[] outimag) {
// if (xreal.length != ximag.length || xreal.length != yreal.length || yreal.length != yimag.length || xreal.length != outreal.length || outreal.length != outimag.length)
// throw new IllegalArgumentException("Mismatched lengths");
int n = xreal.length;
FFT(xreal, ximag);
FFT(yreal, yimag);
for (int i = 0; i < n; i++) {
double temp = xreal[i] * yreal[i] - ximag[i] * yimag[i];
ximag[i] = ximag[i] * yreal[i] + xreal[i] * yimag[i];
xreal[i] = temp;
}
inverseTransform(xreal, ximag);
// Scaling (because this FFT implementation omits it)
for (int i = 0; i < n; i++) {
outreal[i] = xreal[i] / n;
outimag[i] = ximag[i] / n;
}
} | /*
Computes the circular convolution of the given complex vectors. Each vector's length must be the same. |
public static void FFTShift1D(double[] x, Direction direction) {
if (x.length == 1)
return;
double[] temp = x.clone();
int move = x.length / 2;
if (direction == Direction.Forward) {
int c = 0;
for (int i = x.length - move; i < x.length; i++)
x[c++] = temp[i];
for (int i = 0; i < x.length - move; i++)
x[c++] = temp[i];
} else {
int c = 0;
for (int i = move; i < x.length; i++)
x[c++] = temp[i];
for (int i = 0; i < move; i++)
x[c++] = temp[i];
}
} | Shift zero-frequency component to center of spectrum.
@param x Data.
@param direction Transformation direction. |
public static void FFTShift2D(double[][] x, Direction direction) {
FFTShift2D(x, direction, 1);
FFTShift2D(x, direction, 2);
} | Shift zero-frequency component to center of spectrum.
@param x Data.
@param direction Direction. |
public static <E> void FFTShift2D(E[][] x, Direction direction, int dimension) {
//Create a copy
E[][] temp = (E[][]) new Object[x.length][x[0].length];
for (int i = 0; i < x.length; i++) {
for (int j = 0; j < x[0].length; j++) {
temp[i][j] = x[i][j];
}
}
if (direction == Direction.Forward) {
//Perform fftshift in the first dimension
if (dimension == 1) {
int move = temp.length / 2;
for (int i = 0; i < move; i++) {
for (int j = 0; j < x[0].length; j++) {
x[i][j] = temp[temp.length - move + i][j];
}
}
for (int i = move; i < x.length; i++) {
for (int j = 0; j < x[0].length; j++) {
x[i][j] = temp[i - move][j];
}
}
}
//Perform fftshift in the second dimension
if (dimension == 2) {
for (int i = 0; i < x.length; i++) {
FFTShift1D(x[i], Direction.Forward);
}
}
} else {
if (dimension == 1) {
int move = temp.length / 2;
for (int i = 0; i < x.length - move; i++) {
for (int j = 0; j < x[0].length; j++) {
x[i][j] = temp[move + i][j];
}
}
for (int i = 0; i < move; i++) {
for (int j = 0; j < x[0].length; j++) {
x[x.length - move + i][j] = temp[i][j];
}
}
}
if (dimension == 2) {
for (int i = 0; i < x.length; i++) {
FFTShift1D(x[i], Direction.Backward);
}
}
}
} | Shift zero-frequency component to center of spectrum.
@param x Data.
@param direction Direction.
@param dimension Dimension. |
public ImageSource BFS(int startI, int startJ, /*String imageName*/ImageSource originalImage) {
LinkedList<Vector2i> queue = new LinkedList<>();
//=============================================================================
int gapX = 30;
int gapY = 30;
MatrixSource letter = new MatrixSource(letterWidth, letterHeight);
//BufferedImage letter = new BufferedImage(letterWidth, letterHeight, BufferedImage.TYPE_BYTE_BINARY);
int alpha = originalImage.getA(startI, startJ);
int white = ColorHelper.getARGB(255, 255, 255, alpha);
int black = ColorHelper.getARGB(0, 0, 0, alpha);
for (int j = 0; j < letterHeight; j++) {
for (int i = 0; i < letterWidth; i++) {
letter.setRGB(i, j, white);
}
}
//=============================================================================
int count = 0;
Vector2i positions = new Vector2i(startI, startJ);
visited[startI][startJ] = true;
queue.addLast(positions);
while (!queue.isEmpty()) {
Vector2i pos = queue.removeFirst();
int x = pos.getX();
int y = pos.getY();
visited[x][y] = true;
//set black pixel to letter image===================================
int posX = startI - x + gapX;
int posY = startJ - y + gapY;
count++;
if(posX>=originalImage.getWidth() || posY>=originalImage.getHeight()) {
continue;
} else {
letter.setRGB(posX, posY, black);
/*try {
letter.setRGB(posX, posY, black);
} catch (Exception e) {
e.printStackTrace();
System.out.println("posX " + posX);
System.out.println("posY " + posY);
System.out.println("letterWidth " + letter.getWidth());
System.out.println("letterHeight " + letter.getHeight());
throw e;
}*/
}
//==================================================================
for (int i = x - 1; i <= x + 1; i++) {
for (int j = y - 1; j <= y + 1; j++) {
if (i >= 0 && j >= 0 && i < originalImage.getWidth() && j < originalImage.getHeight()) {
if (!visited[i][j]) {
int color = originalImage.getGray(i, j);
if (color < 10) {
visited[i][j] = true;
Vector2i tmpPos = new Vector2i(i, j);
queue.addLast(tmpPos);
}
}
}
} //i
} //j
}
System.out.println("count = " + count);
//save letter===========================================================
if (count < 3) {
return letter;
}
/*try {
saveToFile(letter, imageName);
//
} catch (IOException ex) {
ex.printStackTrace();
}*/
return letter;
} | Breadth first search |
public FloatPoint Add(FloatPoint point1, FloatPoint point2) {
FloatPoint result = new FloatPoint(point1);
result.Add(point2);
return result;
} | Adds values of two points.
@param point1 FloatPoint.
@param point2 FloatPoint.
@return A new FloatPoint with the add operation. |
public FloatPoint Subtract(FloatPoint point1, FloatPoint point2) {
FloatPoint result = new FloatPoint(point1);
result.Subtract(point2);
return result;
} | Subtracts values of two points.
@param point1 FloatPoint.
@param point2 FloatPoint.
@return A new FloatPoint with the subtract operation. |
public FloatPoint Multiply(FloatPoint point1, FloatPoint point2) {
FloatPoint result = new FloatPoint(point1);
result.Multiply(point2);
return result;
} | Multiply values of two points.
@param point1 FloatPoint.
@param point2 FloatPoint.
@return A new FloatPoint with the multiplication operation. |
public FloatPoint Divide(FloatPoint point1, FloatPoint point2) {
FloatPoint result = new FloatPoint(point1);
result.Divide(point2);
return result;
} | Divide values of two points.
@param point1 FloatPoint.
@param point2 FloatPoint.
@return A new FloatPoint with the division operation. |
@Override
public ImageSource apply(ImageSource fastBitmap) {
Convolution c = new Convolution(kernel);
return c.apply(fastBitmap);
} | Apply filter to a FastBitmap. |
public void setCurve(Curve curveRed, Curve curveGreen, Curve curveBlue) {
this.curveRed = curveRed;
this.curveGreen = curveGreen;
this.curveBlue = curveBlue;
} | Set curves.
@param curveRed Red curve.
@param curveGreen Green curve.
@param curveBlue Blue curve. |
public List<Point2D> apply(PointFeature feature) {
List<Point2D> points = feature.getPoints();
if (points.size() < 4) {
return points;
}
Point2D pointOnHull = points.get(getIndexOfLeftMostPoint(points)); // leftmost point in shape
List<Point2D> hull = new ArrayList<Point2D>();
int i = 0;
Point2D endpoint = points.get(0); // initial endpoint for a candidate edge on the hull
do {
hull.add(pointOnHull);
endpoint = points.get(0);
for (int j = 1; j < points.size(); j++) {
if (endpoint == pointOnHull || isLeftOfLine(points.get(j), hull.get(i), endpoint)) {
endpoint = points.get(j); // found greater left turn, update endpoint
}
}
i++;
pointOnHull = endpoint;
} while (endpoint != hull.get(0));
/* i is now equal to the number of points of the hull.
* need to make correctly sized hull array now.
*/
List<Point2D> hullToReturn = new ArrayList<Point2D>();
for (int k = 0; k < i; k++) {
hullToReturn.add(hull.get(k));
}
return hullToReturn;
} | calculates the convex hull of the specified array of points.
<br>
the array of points has to be of dimensions [n][2], <br>
which means that a point can be obtained like this: <br>
<code> double[] point = array[i]; </code><br>
and coordinates like this: <br>
<code> x= array[i][0] and y= array[i][1] </code>
@param points in double[][]
@return double[][] with points of the convex hull |
public void publish(int qos, String payload) throws ArtikCloudMqttException {
MqttMessage mqttMessage = new MqttMessage(payload.getBytes());
mqttMessage.setQos(qos);
// System.out.println("****** Thread: " + Thread.currentThread().getName()+ "; MqttSession publishing : "+ "topic: " + publishTopic +"; payload: " + payload);
try {
mqttClient.publish(publishMessageTopicPath, mqttMessage, String.valueOf(OperationMode.PUBLISH), operationListener);
} catch (MqttException e) {
throw new ArtikCloudMqttException(e);
}
} | @param qos Quality of Service (0, 1, or 2) used for publishing a message to ARTIK Cloud
@param payload the payload of the published message
@throws ArtikCloudMqttException |
public void setFactor(int factor) {
this.factor = factor = Math.max(-127, Math.min(127, factor));
if (factor > 1) {
baseFilter.setInRed(new IntRange(factor, 255 - factor));
baseFilter.setInGreen(new IntRange(factor, 255 - factor));
baseFilter.setInBlue(new IntRange(factor, 255 - factor));
baseFilter.setInGray(new IntRange(factor, 255 - factor));
baseFilter.setOutRed(new IntRange(0, 255));
baseFilter.setOutGreen(new IntRange(0, 255));
baseFilter.setOutBlue(new IntRange(0, 255));
baseFilter.setOutGray(new IntRange(0, 255));
} else {
baseFilter.setInRed(new IntRange(-factor, 255 + factor));
baseFilter.setInGreen(new IntRange(-factor, 255 + factor));
baseFilter.setInBlue(new IntRange(-factor, 255 + factor));
baseFilter.setInGray(new IntRange(-factor, 255 + factor));
baseFilter.setOutRed(new IntRange(0, 255));
baseFilter.setOutGreen(new IntRange(0, 255));
baseFilter.setOutBlue(new IntRange(0, 255));
baseFilter.setOutGray(new IntRange(0, 255));
}
} | Set Contrast adjusting factor, [-127, 127].
@param factor Contrast factor. |
@Override
public ImageSource apply(ImageSource input) {
final int[][] pixelMatrix = new int[3][3];
int w = input.getWidth();
int h = input.getHeight();
int[][] output = new int[h][w];
for (int j = 1; j < h - 1; j++) {
for (int i = 1; i < w - 1; i++) {
pixelMatrix[0][0] = input.getR(i - 1, j - 1);
pixelMatrix[0][1] = input.getRGB(i - 1, j);
pixelMatrix[0][2] = input.getRGB(i - 1, j + 1);
pixelMatrix[1][0] = input.getRGB(i, j - 1);
pixelMatrix[1][2] = input.getRGB(i, j + 1);
pixelMatrix[2][0] = input.getRGB(i + 1, j - 1);
pixelMatrix[2][1] = input.getRGB(i + 1, j);
pixelMatrix[2][2] = input.getRGB(i + 1, j + 1);
int edge = (int) convolution(pixelMatrix);
int rgb = (edge << 16 | edge << 8 | edge);
output[j][i] = rgb;
}
}
MatrixSource source = new MatrixSource(output);
return source;
} | Expects a height mat as input
@param input - A grayscale height map
@return edges |
public <L extends Listener> void pushEvent(Event<?, L> event) {
synchronized (this.stack) {
this.stack.push(event);
}
} | Pushes the event onto the event stack. This action must be performed
immediately before the event is being dispatched. Additionally, after the
event has been dispatched, it has to be {@link #popEvent(Event) popped}
off the stack again.
@param <L> Type of the listener.
@param event The event which will be dispatched.
@see #popEvent(Event) |
public <L extends Listener> void popEvent(Event<?, L> expected) {
synchronized (this.stack) {
final Event<?, ?> actual = this.stack.pop();
if (actual != expected) {
throw new IllegalStateException(String.format(
"Unbalanced pop: expected '%s' but encountered '%s'",
expected.getListenerClass(), actual));
}
}
} | Pops the top event off the current event stack. This action has to be
performed immediately after the event has been dispatched to all
listeners.
@param <L> Type of the listener.
@param expected The Event which is expected at the top of the stack.
@see #pushEvent(Event) |
public ExportRequestResponse exportRequest(ExportRequestInfo exportRequestInfo) throws ApiException {
ApiResponse<ExportRequestResponse> resp = exportRequestWithHttpInfo(exportRequestInfo);
return resp.getData();
} | Create Export Request
Export normalized messages. The following input combinations are supported:<br/><table><tr><th>Combination</th><th>Parameters</th><th>Description</th></tr><tr><td>Get by users</td><td>uids</td><td>Search by a list of User IDs. For each user in the list, the current authenticated user must have read access over the specified user.</td></tr><tr><td>Get by devices</td><td>sdids</td><td>Search by Source Device IDs.</td></tr><tr><td>Get by device types</td><td>uids,sdtids</td><td>Search by list of Source Device Type IDs for the given list of users.</td></tr><tr><td>Get by trial</td><td>trialId</td><td>Search by Trial ID.</td></tr><tr><td>Get by combination of parameters</td><td>uids,sdids,sdtids</td><td>Search by list of Source Device IDs. Each Device ID must belong to a Source Device Type ID and a User ID.</td></tr><tr><td>Common</td><td>startDate,endDate,order,format,url,csvHeaders</td><td>Parameters that can be used with the above combinations.</td></tr></table>
@param exportRequestInfo ExportRequest object that is passed in the body (required)
@return ExportRequestResponse
@throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body |
public ApiResponse<ExportRequestResponse> exportRequestWithHttpInfo(ExportRequestInfo exportRequestInfo) throws ApiException {
com.squareup.okhttp.Call call = exportRequestValidateBeforeCall(exportRequestInfo, null, null);
Type localVarReturnType = new TypeToken<ExportRequestResponse>(){}.getType();
return apiClient.execute(call, localVarReturnType);
} | Create Export Request
Export normalized messages. The following input combinations are supported:<br/><table><tr><th>Combination</th><th>Parameters</th><th>Description</th></tr><tr><td>Get by users</td><td>uids</td><td>Search by a list of User IDs. For each user in the list, the current authenticated user must have read access over the specified user.</td></tr><tr><td>Get by devices</td><td>sdids</td><td>Search by Source Device IDs.</td></tr><tr><td>Get by device types</td><td>uids,sdtids</td><td>Search by list of Source Device Type IDs for the given list of users.</td></tr><tr><td>Get by trial</td><td>trialId</td><td>Search by Trial ID.</td></tr><tr><td>Get by combination of parameters</td><td>uids,sdids,sdtids</td><td>Search by list of Source Device IDs. Each Device ID must belong to a Source Device Type ID and a User ID.</td></tr><tr><td>Common</td><td>startDate,endDate,order,format,url,csvHeaders</td><td>Parameters that can be used with the above combinations.</td></tr></table>
@param exportRequestInfo ExportRequest object that is passed in the body (required)
@return ApiResponse<ExportRequestResponse>
@throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body |
public com.squareup.okhttp.Call exportRequestAsync(ExportRequestInfo exportRequestInfo, final ApiCallback<ExportRequestResponse> callback) throws ApiException {
ProgressResponseBody.ProgressListener progressListener = null;
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
if (callback != null) {
progressListener = new ProgressResponseBody.ProgressListener() {
@Override
public void update(long bytesRead, long contentLength, boolean done) {
callback.onDownloadProgress(bytesRead, contentLength, done);
}
};
progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
@Override
public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
callback.onUploadProgress(bytesWritten, contentLength, done);
}
};
}
com.squareup.okhttp.Call call = exportRequestValidateBeforeCall(exportRequestInfo, progressListener, progressRequestListener);
Type localVarReturnType = new TypeToken<ExportRequestResponse>(){}.getType();
apiClient.executeAsync(call, localVarReturnType, callback);
return call;
} | Create Export Request (asynchronously)
Export normalized messages. The following input combinations are supported:<br/><table><tr><th>Combination</th><th>Parameters</th><th>Description</th></tr><tr><td>Get by users</td><td>uids</td><td>Search by a list of User IDs. For each user in the list, the current authenticated user must have read access over the specified user.</td></tr><tr><td>Get by devices</td><td>sdids</td><td>Search by Source Device IDs.</td></tr><tr><td>Get by device types</td><td>uids,sdtids</td><td>Search by list of Source Device Type IDs for the given list of users.</td></tr><tr><td>Get by trial</td><td>trialId</td><td>Search by Trial ID.</td></tr><tr><td>Get by combination of parameters</td><td>uids,sdids,sdtids</td><td>Search by list of Source Device IDs. Each Device ID must belong to a Source Device Type ID and a User ID.</td></tr><tr><td>Common</td><td>startDate,endDate,order,format,url,csvHeaders</td><td>Parameters that can be used with the above combinations.</td></tr></table>
@param exportRequestInfo ExportRequest object that is passed in the body (required)
@param callback The callback to be executed when the API call finishes
@return The request call
@throws ApiException If fail to process the API call, e.g. serializing the request body object |
public ExportHistoryResponse getExportHistory(String trialId, Integer count, Integer offset) throws ApiException {
ApiResponse<ExportHistoryResponse> resp = getExportHistoryWithHttpInfo(trialId, count, offset);
return resp.getData();
} | Get Export History
Get the history of export requests.
@param trialId Filter by trialId. (optional)
@param count Pagination count. (optional)
@param offset Pagination offset. (optional)
@return ExportHistoryResponse
@throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body |
public ApiResponse<ExportHistoryResponse> getExportHistoryWithHttpInfo(String trialId, Integer count, Integer offset) throws ApiException {
com.squareup.okhttp.Call call = getExportHistoryValidateBeforeCall(trialId, count, offset, null, null);
Type localVarReturnType = new TypeToken<ExportHistoryResponse>(){}.getType();
return apiClient.execute(call, localVarReturnType);
} | Get Export History
Get the history of export requests.
@param trialId Filter by trialId. (optional)
@param count Pagination count. (optional)
@param offset Pagination offset. (optional)
@return ApiResponse<ExportHistoryResponse>
@throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body |
public String getExportResult(String exportId) throws ApiException {
ApiResponse<String> resp = getExportResultWithHttpInfo(exportId);
return resp.getData();
} | Get Export Result
Retrieve result of the export query in tgz format. The tar file may contain one or more files with the results.
@param exportId Export ID of the export query. (required)
@return String
@throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body |
public ApiResponse<String> getExportResultWithHttpInfo(String exportId) throws ApiException {
com.squareup.okhttp.Call call = getExportResultValidateBeforeCall(exportId, null, null);
Type localVarReturnType = new TypeToken<String>(){}.getType();
return apiClient.execute(call, localVarReturnType);
} | Get Export Result
Retrieve result of the export query in tgz format. The tar file may contain one or more files with the results.
@param exportId Export ID of the export query. (required)
@return ApiResponse<String>
@throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body |
protected void modify(Transaction t) {
try {
this.lock.writeLock().lock();
t.perform();
} finally {
this.lock.writeLock().unlock();
}
} | Executes the given transaction within the context of a write lock.
@param t The transaction to execute. |
protected <E> E read(Supplier<E> sup) {
try {
this.lock.readLock().lock();
return sup.get();
} finally {
this.lock.readLock().unlock();
}
} | Executes the given supplier within the context of a read lock.
@param <E> The result type.
@param sup The supplier.
@return The result of {@link Supplier#get()}. |
protected void setOffsetAndLength(long offset, int length) throws IOException {
this.offset = offset;
this.length = length;
this.position = 0;
if (subStream.position() != offset) {
subStream.seek(offset);
}
} | This should be called from a subclass constructor, if offset or length
are unknown at a time when SubIIMInputStream constructor is called. This
method shouldn't be called more than once.
@param offset
byte offset
@param length
byte length
@throws IOException
if underlying stream can't be read |
public static double J0(double x) {
double ax;
if ((ax = Math.abs(x)) < 8.0) {
double y = x * x;
double ans1 = 57568490574.0 + y * (-13362590354.0 + y * (651619640.7
+ y * (-11214424.18 + y * (77392.33017 + y * (-184.9052456)))));
double ans2 = 57568490411.0 + y * (1029532985.0 + y * (9494680.718
+ y * (59272.64853 + y * (267.8532712 + y * 1.0))));
return ans1 / ans2;
} else {
double z = 8.0 / ax;
double y = z * z;
double xx = ax - 0.785398164;
double ans1 = 1.0 + y * (-0.1098628627e-2 + y * (0.2734510407e-4
+ y * (-0.2073370639e-5 + y * 0.2093887211e-6)));
double ans2 = -0.1562499995e-1 + y * (0.1430488765e-3
+ y * (-0.6911147651e-5 + y * (0.7621095161e-6
- y * 0.934935152e-7)));
return Math.sqrt(0.636619772 / ax) *
(Math.cos(xx) * ans1 - z * Math.sin(xx) * ans2);
}
} | Bessel function of order 0.
@param x Value.
@return J0 value. |
public static double J(int n, double x) {
int j, m;
double ax, bj, bjm, bjp, sum, tox, ans;
boolean jsum;
double ACC = 40.0;
double BIGNO = 1.0e+10;
double BIGNI = 1.0e-10;
if (n == 0) return J0(x);
if (n == 1) return J(x);
ax = Math.abs(x);
if (ax == 0.0) return 0.0;
else if (ax > (double) n) {
tox = 2.0 / ax;
bjm = J0(ax);
bj = J(ax);
for (j = 1; j < n; j++) {
bjp = j * tox * bj - bjm;
bjm = bj;
bj = bjp;
}
ans = bj;
} else {
tox = 2.0 / ax;
m = 2 * ((n + (int) Math.sqrt(ACC * n)) / 2);
jsum = false;
bjp = ans = sum = 0.0;
bj = 1.0;
for (j = m; j > 0; j--) {
bjm = j * tox * bj - bjp;
bjp = bj;
bj = bjm;
if (Math.abs(bj) > BIGNO) {
bj *= BIGNI;
bjp *= BIGNI;
ans *= BIGNI;
sum *= BIGNI;
}
if (jsum) sum += bj;
jsum = !jsum;
if (j == n) ans = bjp;
}
sum = 2.0 * sum - bj;
ans /= sum;
}
return x < 0.0 && n % 2 == 1 ? -ans : ans;
} | Bessel function of order n.
@param n Order.
@param x Value.
@return J value. |
public static double Y0(double x) {
if (x < 8.0) {
double y = x * x;
double ans1 = -2957821389.0 + y * (7062834065.0 + y * (-512359803.6
+ y * (10879881.29 + y * (-86327.92757 + y * 228.4622733))));
double ans2 = 40076544269.0 + y * (745249964.8 + y * (7189466.438
+ y * (47447.26470 + y * (226.1030244 + y * 1.0))));
return (ans1 / ans2) + 0.636619772 * J0(x) * Math.log(x);
} else {
double z = 8.0 / x;
double y = z * z;
double xx = x - 0.785398164;
double ans1 = 1.0 + y * (-0.1098628627e-2 + y * (0.2734510407e-4
+ y * (-0.2073370639e-5 + y * 0.2093887211e-6)));
double ans2 = -0.1562499995e-1 + y * (0.1430488765e-3
+ y * (-0.6911147651e-5 + y * (0.7621095161e-6
+ y * (-0.934945152e-7))));
return Math.sqrt(0.636619772 / x) *
(Math.sin(xx) * ans1 + z * Math.cos(xx) * ans2);
}
} | Bessel function of the second kind, of order 0.
@param x Value.
@return Y0 value. |
public static double Y(double x) {
if (x < 8.0) {
double y = x * x;
double ans1 = x * (-0.4900604943e13 + y * (0.1275274390e13
+ y * (-0.5153438139e11 + y * (0.7349264551e9
+ y * (-0.4237922726e7 + y * 0.8511937935e4)))));
double ans2 = 0.2499580570e14 + y * (0.4244419664e12
+ y * (0.3733650367e10 + y * (0.2245904002e8
+ y * (0.1020426050e6 + y * (0.3549632885e3 + y)))));
return (ans1 / ans2) + 0.636619772 * (J(x) * Math.log(x) - 1.0 / x);
} else {
double z = 8.0 / x;
double y = z * z;
double xx = x - 2.356194491;
double ans1 = 1.0 + y * (0.183105e-2 + y * (-0.3516396496e-4
+ y * (0.2457520174e-5 + y * (-0.240337019e-6))));
double ans2 = 0.04687499995 + y * (-0.2002690873e-3
+ y * (0.8449199096e-5 + y * (-0.88228987e-6
+ y * 0.105787412e-6)));
return Math.sqrt(0.636619772 / x) *
(Math.sin(xx) * ans1 + z * Math.cos(xx) * ans2);
}
} | Bessel function of the second kind, of order 1.
@param x Value.
@return Y value. |
public static double Y(int n, double x) {
double by, bym, byp, tox;
if (n == 0) return Y0(x);
if (n == 1) return Y(x);
tox = 2.0 / x;
by = Y(x);
bym = Y0(x);
for (int j = 1; j < n; j++) {
byp = j * tox * by - bym;
bym = by;
by = byp;
}
return by;
} | Bessel function of the second kind, of order n.
@param n Order.
@param x Value.
@return Y value. |
public static double I0(double x) {
double ans;
double ax = Math.abs(x);
if (ax < 3.75) {
double y = x / 3.75;
y = y * y;
ans = 1.0 + y * (3.5156229 + y * (3.0899424 + y * (1.2067492
+ y * (0.2659732 + y * (0.360768e-1 + y * 0.45813e-2)))));
} else {
double y = 3.75 / ax;
ans = (Math.exp(ax) / Math.sqrt(ax)) * (0.39894228 + y * (0.1328592e-1
+ y * (0.225319e-2 + y * (-0.157565e-2 + y * (0.916281e-2
+ y * (-0.2057706e-1 + y * (0.2635537e-1 + y * (-0.1647633e-1
+ y * 0.392377e-2))))))));
}
return ans;
} | Bessel function of the first kind, of order 0.
@param x Value.
@return I0 value. |
public static double I(int n, double x) {
if (n < 0)
throw new IllegalArgumentException("the variable n out of range.");
else if (n == 0)
return I0(x);
else if (n == 1)
return I(x);
if (x == 0.0)
return 0.0;
double ACC = 40.0;
double BIGNO = 1.0e+10;
double BIGNI = 1.0e-10;
double tox = 2.0 / Math.abs(x);
double bip = 0, ans = 0.0;
double bi = 1.0;
for (int j = 2 * (n + (int) Math.sqrt(ACC * n)); j > 0; j--) {
double bim = bip + j * tox * bi;
bip = bi;
bi = bim;
if (Math.abs(bi) > BIGNO) {
ans *= BIGNI;
bi *= BIGNI;
bip *= BIGNI;
}
if (j == n)
ans = bip;
}
ans *= I0(x) / bi;
return x < 0.0 && n % 2 == 1 ? -ans : ans;
} | Bessel function of the first kind, of order n.
@param n Order.
@param x Value.
@return I value. |
public double[][] solve(double[][] B) {
if (B.length != n) {
throw new IllegalArgumentException("Matrix row dimensions must agree.");
}
if (!isspd) {
throw new RuntimeException("Matrix is not symmetric positive definite.");
}
// Copy right hand side.
double[][] X = Matrix.Copy(B);
int nx = B[0].length;
// Solve L*Y = B;
for (int k = 0; k < n; k++) {
for (int j = 0; j < nx; j++) {
for (int i = 0; i < k; i++) {
X[k][j] -= X[i][j] * L[k][i];
}
X[k][j] /= L[k][k];
}
}
// Solve L'*X = Y;
for (int k = n - 1; k >= 0; k--) {
for (int j = 0; j < nx; j++) {
for (int i = k + 1; i < n; i++) {
X[k][j] -= X[i][j] * L[i][k];
}
X[k][j] /= L[k][k];
}
}
return Matrix.SubMatrix(X, n, nx);
} | Solve A*X = B
@param B A Matrix with as many rows as A and any number of columns.
@return X so that L*L'*X = B
@throws IllegalArgumentException Matrix row dimensions must agree.
@throws RuntimeException Matrix is not symmetric positive definite. |
@Override
public ImageSource apply(ImageSource input) {
int w = input.getWidth();
int h = input.getHeight();
MatrixSource output = new MatrixSource(input);
Vector3 n = new Vector3(0, 0, 1);
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
if (x < border || x == w - border || y < border || y == h - border) {
output.setRGB(x, y, VectorHelper.Z_NORMAL);
continue;
}
float s0 = input.getR(x - 1, y + 1);
float s1 = input.getR(x, y + 1);
float s2 = input.getR(x + 1, y + 1);
float s3 = input.getR(x - 1, y);
float s5 = input.getR(x + 1, y);
float s6 = input.getR(x - 1, y - 1);
float s7 = input.getR(x, y - 1);
float s8 = input.getR(x + 1, y - 1);
float nx = -(s2 - s0 + 2 * (s5 - s3) + s8 - s6);
float ny = -(s6 - s0 + 2 * (s7 - s1) + s8 - s2);
n.set(nx, ny, scale);
n.nor();
int rgb = VectorHelper.vectorToColor(n);
output.setRGB(x, y, rgb);
}
}
return new MatrixSource(output);
} | Sobel method to generate bump map from a height map
@param input - A height map
@return bump map |
public boolean IsOverlapping(IntRange range) {
return ((isInside(range.min)) || (isInside(range.max)) ||
(range.isInside(min)) || (range.isInside(max)));
} | Check if the specified range overlaps with the range.
@param range IntRange.
@return True if the range overlaps with the range, otherwise returns false. |
@Deprecated
public static TraceContextHolder wrap(TraceContext traceContext) {
return (traceContext != null) ? new TraceContextHolder(traceContext) : TraceContextHolder.EMPTY;
} | Used by TracedParallelBatch where its used to wrap a TraceContext and puts it in the
registry for the forked execution. This is marked deprecated as we prefer not to
expose details of the RatpackCurrentTraceContext implementation.
@param traceContext a trace context.
@return a holder for the trace context, which can be put into the registry. |
public static double Sinc(double x) {
return Math.sin(Math.PI * x) / (Math.PI * x);
} | Sinc function.
@param x Value.
@return Sinc of the value. |
public static float Angle(float x, float y) {
if (y >= 0) {
if (x >= 0)
return (float) Math.atan(y / x);
return (float) (Math.PI - Math.atan(-y / x));
} else {
if (x >= 0)
return (float) (2 * Math.PI - Math.atan(-y / x));
return (float) (Math.PI + Math.atan(y / x));
}
} | Gets the angle formed by the vector [x,y].
@param x X axis coordinate.
@param y Y axis coordinate.
@return Angle formed by the vector. |
public static double Clamp(double x, DoubleRange range) {
return Clamp(x, range.getMin(), range.getMax());
} | Clamp values.
@param x Value.
@param range Range.
@return Value. |
public static int Clamp(int x, IntRange range) {
return Clamp(x, range.getMin(), range.getMax());
} | Clamp values.
@param x Value.
@param range Range.
@return Value. |
public static float Clamp(float x, FloatRange range) {
return Clamp(x, range.getMin(), range.getMax());
} | Clamp values.
@param x Value.
@param range Range.
@return Value. |
public static double Clamp(double x, double min, double max) {
if (x < min)
return min;
if (x > max)
return max;
return x;
} | Clamp values.
@param x Value.
@param min Minimum value.
@param max Maximum value.
@return Value. |
public static int Mod(int x, int m) {
if (m < 0) m = -m;
int r = x % m;
return r < 0 ? r + m : r;
} | Gets the proper modulus operation.
@param x Integer.
@param m Modulo.
@return Modulus. |
public static int NextPowerOf2(int x) {
--x;
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
return ++x;
} | Returns the next power of 2 after the input value x.
@param x Input value x.
@return Returns the next power of 2 after the input value x. |
public static int Scale(IntRange from, IntRange to, int x) {
if (from.length() == 0) return 0;
return (int) ((to.length()) * (x - from.getMin()) / from.length() + to.getMin());
} | Converts the value x (which is measured in the scale 'from') to another value measured in the scale 'to'.
@param from Scale from.
@param to Scale to.
@param x Value.
@return Result. |
public static double Scale(DoubleRange from, DoubleRange to, int x) {
if (from.length() == 0) return 0;
return ((to.length()) * (x - from.getMin()) / from.length() + to.getMin());
} | Converts the value x (which is measured in the scale 'from') to another value measured in the scale 'to'.
@param from Scale from.
@param to Scale to.
@param x Value.
@return Result. |
public static float Scale(FloatRange from, FloatRange to, int x) {
if (from.length() == 0) return 0;
return (float) ((to.length()) * (x - from.getMin()) / from.length() + to.getMin());
} | Converts the value x (which is measured in the scale 'from') to another value measured in the scale 'to'.
@param from Scale from.
@param to Scale to.
@param x Value.
@return Result. |
public static double Scale(double fromMin, double fromMax, double toMin, double toMax, double x) {
if (fromMax - fromMin == 0) return 0;
return (toMax - toMin) * (x - fromMin) / (fromMax - fromMin) + toMin;
} | Converts the value x (which is measured in the scale 'from') to another value measured in the scale 'to'.
@param fromMin Scale min from.
@param fromMax Scale max from.
@param toMin Scale min to.
@param toMax Scale max to.
@param x Value.
@return Result. |
public static float Sum(float[] data) {
float sum = 0;
for (int i = 0; i < data.length; i++) {
sum += data[i];
}
return sum;
} | Sum of the elements.
@param data Data.
@return Sum(data). |
public static double TruncatedPower(double value, double degree) {
double x = Math.pow(value, degree);
return (x > 0) ? x : 0.0;
} | Truncated power function.
@param value Value.
@param degree Degree.
@return Result. |
public static int[] Unique(int[] values) {
HashSet<Integer> lst = new HashSet<Integer>();
for (int i = 0; i < values.length; i++) {
lst.add(values[i]);
}
int[] v = new int[lst.size()];
Iterator<Integer> it = lst.iterator();
for (int i = 0; i < v.length; i++) {
v[i] = it.next();
}
return v;
} | Get unique values form the array.
@param values Array of values.
@return Unique values. |
public static double Hypotenuse(double a, double b) {
double r = 0.0;
double absA = Math.abs(a);
double absB = Math.abs(b);
if (absA > absB) {
r = b / a;
r = absA * Math.sqrt(1 + r * r);
} else if (b != 0) {
r = a / b;
r = absB * Math.sqrt(1 + r * r);
}
return r;
} | Hypotenuse calculus without overflow/underflow.
@param a First value.
@param b Second value.
@return The hypotenuse Sqrt(a^2 + b^2). |
public void setT(int t) {
this.t = Math.min((radius * 2 + 1) * (radius * 2 + 1) / 2, Math.max(0, t));
} | Set trimmed value.
@param t Trimmed value. |
public static double Sin(double x, int nTerms) {
if (nTerms < 2) return x;
if (nTerms == 2) {
return x - (x * x * x) / 6D;
} else {
double mult = x * x * x;
double fact = 6;
double sign = 1;
int factS = 5;
double result = x - mult / fact;
for (int i = 3; i <= nTerms; i++) {
mult *= x * x;
fact *= factS * (factS - 1);
factS += 2;
result += sign * (mult / fact);
sign *= -1;
}
return result;
}
} | compute Sin using Taylor Series.
@param x An angle, in radians.
@param nTerms Number of terms.
@return Result. |
public static double Sinh(double x, int nTerms) {
if (nTerms < 2) return x;
if (nTerms == 2) {
return x + (x * x * x) / 6D;
} else {
double mult = x * x * x;
double fact = 6;
int factS = 5;
double result = x + mult / fact;
for (int i = 3; i <= nTerms; i++) {
mult *= x * x;
fact *= factS * (factS - 1);
factS += 2;
result += mult / fact;
}
return result;
}
} | compute Sinh using Taylor Series.
@param x An angle, in radians.
@param nTerms Number of terms.
@return Result. |
public static double Cosh(double x, int nTerms) {
if (nTerms < 2) return x;
if (nTerms == 2) {
return 1 + (x * x) / 2D;
} else {
double mult = x * x;
double fact = 2;
int factS = 4;
double result = 1 + mult / fact;
for (int i = 3; i <= nTerms; i++) {
mult *= x * x;
fact *= factS * (factS - 1);
factS += 2;
result += mult / fact;
}
return result;
}
} | compute Cosh using Taylor Series.
@param x An angle, in radians.
@param nTerms Number of terms.
@return Result. |
public static double Exp(double x, int nTerms) {
if (nTerms < 2) return 1 + x;
if (nTerms == 2) {
return 1 + x + (x * x) / 2;
} else {
double mult = x * x;
double fact = 2;
double result = 1 + x + mult / fact;
for (int i = 3; i <= nTerms; i++) {
mult *= x;
fact *= i;
result += mult / fact;
}
return result;
}
} | compute Exp using Taylor Series.
@param x An angle, in radians.
@param nTerms Number of terms.
@return Result. |
public WhitelistEnvelope deleteVdid(String dtid, String vdid) throws ApiException {
ApiResponse<WhitelistEnvelope> resp = deleteVdidWithHttpInfo(dtid, vdid);
return resp.getData();
} | Delete a vdid from the devicetype whitelist.
Delete a vdid from the devicetype whitelist.
@param dtid Device Type ID. (required)
@param vdid Vendor Device ID. (required)
@return WhitelistEnvelope
@throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body |
public WhitelistEnvelope deleteWhitelistCertificate(String dtid, String cid) throws ApiException {
ApiResponse<WhitelistEnvelope> resp = deleteWhitelistCertificateWithHttpInfo(dtid, cid);
return resp.getData();
} | Delete a whitelist certificate associated with a devicetype.
Delete a whitelist certificate associated with a devicetype.
@param dtid Device Type ID. (required)
@param cid Certificate ID. (required)
@return WhitelistEnvelope
@throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body |
public ApiResponse<WhitelistEnvelope> deleteWhitelistCertificateWithHttpInfo(String dtid, String cid) throws ApiException {
com.squareup.okhttp.Call call = deleteWhitelistCertificateValidateBeforeCall(dtid, cid, null, null);
Type localVarReturnType = new TypeToken<WhitelistEnvelope>(){}.getType();
return apiClient.execute(call, localVarReturnType);
} | Delete a whitelist certificate associated with a devicetype.
Delete a whitelist certificate associated with a devicetype.
@param dtid Device Type ID. (required)
@param cid Certificate ID. (required)
@return ApiResponse<WhitelistEnvelope>
@throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.