Java Code Examples for net.imglib2.RealLocalizable#getDoublePosition()
The following examples show how to use
net.imglib2.RealLocalizable#getDoublePosition() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultFeretsDiameterForAngle.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void compute(Polygon2D input, DoubleType output) { final List<? extends RealLocalizable> points = GeomUtils.vertices(function .calculate(input)); final double angleRad = -angle * Math.PI / 180.0; double minX = Double.POSITIVE_INFINITY; double maxX = Double.NEGATIVE_INFINITY; for (RealLocalizable p : points) { final double tmpX = p.getDoublePosition(0) * Math.cos(angleRad) - p .getDoublePosition(1) * Math.sin(angleRad); minX = tmpX < minX ? tmpX : minX; maxX = tmpX > maxX ? tmpX : maxX; } output.set(Math.abs(maxX - minX)); }
Example 2
Source File: DefaultSmallestEnclosingRectangle.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
/** * Rotates the given Polygon2D consisting of a list of RealPoints by the * given angle about the given center. * * @param inPoly A Polygon2D consisting of a list of RealPoint RealPoints * @param angle the rotation angle * @param center the rotation center * @return a rotated polygon */ private Polygon2D rotate(final Polygon2D inPoly, final double angle, final RealLocalizable center) { List<RealLocalizable> out = new ArrayList<>(); for (RealLocalizable RealPoint : GeomUtils.vertices(inPoly)) { // double angleInRadians = Math.toRadians(angleInDegrees); double cosTheta = Math.cos(angle); double sinTheta = Math.sin(angle); double x = cosTheta * (RealPoint.getDoublePosition(0) - center .getDoublePosition(0)) - sinTheta * (RealPoint.getDoublePosition(1) - center.getDoublePosition(1)) + center.getDoublePosition(0); double y = sinTheta * (RealPoint.getDoublePosition(0) - center .getDoublePosition(0)) + cosTheta * (RealPoint.getDoublePosition(1) - center.getDoublePosition(1)) + center.getDoublePosition(1); out.add(new RealPoint(x, y)); } return new DefaultWritablePolygon2D(out); }
Example 3
Source File: DefaultSizePolygon.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void compute(Polygon2D input, DoubleType output) { double sum = 0; final int numVertices = input.numVertices(); for (int i = 0; i < numVertices; i++) { final RealLocalizable p0 = input.vertex(i); final RealLocalizable p1 = input.vertex((i + 1) % numVertices); final double p0_x = p0.getDoublePosition(0); final double p0_y = p0.getDoublePosition(1); final double p1_x = p1.getDoublePosition(0); final double p1_y = p1.getDoublePosition(1); sum += p0_x * p1_y - p0_y * p1_x; } output.set(Math.abs(sum) / 2d); }
Example 4
Source File: DefaultInertiaTensor3DMesh.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Override public RealMatrix calculate(final Mesh input) { final RealLocalizable cent = centroid.calculate(input); final double originX = cent.getDoublePosition(0); final double originY = cent.getDoublePosition(1); final double originZ = cent.getDoublePosition(2); BlockRealMatrix tensor = new BlockRealMatrix(3, 3); for (final Triangle triangle : input.triangles()) { final double x1 = triangle.v0x() - originX; final double y1 = triangle.v0y() - originY; final double z1 = triangle.v0z() - originZ; final double x2 = triangle.v1x() - originX; final double y2 = triangle.v1y() - originY; final double z2 = triangle.v1z() - originZ; final double x3 = triangle.v2x() - originX; final double y3 = triangle.v2y() - originY; final double z3 = triangle.v2z() - originZ; tensor = tensor.add(// tetrahedronInertiaTensor(x1, y1, z1, x2, y2, z2, x3, y3, z3)); } return tensor; }
Example 5
Source File: CentroidPolygon.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Override public RealLocalizable calculate(final Polygon2D input) { double area = sizeFunc.calculate(input).get(); double cx = 0; double cy = 0; for (int i = 0; i < input.numVertices(); i++) { RealLocalizable p0 = input.vertex(i); RealLocalizable p1 = input.vertex((i + 1) % input.numVertices()); double p0_x = p0.getDoublePosition(0); double p0_y = p0.getDoublePosition(1); double p1_x = p1.getDoublePosition(0); double p1_y = p1.getDoublePosition(1); cx += (p0_x + p1_x) * (p0_x * p1_y - p1_x * p0_y); cy += (p0_y + p1_y) * (p0_x * p1_y - p1_x * p0_y); } return new RealPoint(cx / (area * 6), cy / (area * 6)); }
Example 6
Source File: AffineWarp.java From BigStitcher with GNU General Public License v2.0 | 5 votes |
@Override public double partial( final RealLocalizable pos, final int d, final int param ) { final int i = param / ( n + 1 ); if ( i != d ) return 0.0; final int j = param - i * ( n + 1 ); return j == n ? 1.0 : pos.getDoublePosition( j ); }
Example 7
Source File: RigidWarp3D.java From BigStitcher with GNU General Public License v2.0 | 5 votes |
@Override public double partial(RealLocalizable pos, int d, int param) { // we evaluate at p1,...,p3 = (1,0,0,0) (identity as quat) // translational part of Jacobian = I if ( param > 3 ) return ( param - 4 ) == d ? 1.0 : 0.0; final int c = lut[d][param]; // set Quat derivatives according to LUT above (*2) return c == 0 ? 0 : ( c < 0 ? -2 * pos.getDoublePosition( -c - 1 ) : 2 * pos.getDoublePosition( c - 1 ) ); }
Example 8
Source File: RigidWarp2D.java From BigStitcher with GNU General Public License v2.0 | 5 votes |
@Override public double partial(RealLocalizable pos, int d, int param) { if (param == 0) return (d == 0 ? -1.0 : 1.0) * pos.getDoublePosition( (d + 1) % 2 ); else return d == param-1 ? 1.0 : 0.0; }
Example 9
Source File: DefaultBoundingBox.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Override public Polygon2D calculate(final Polygon2D input) { double min_x = Double.POSITIVE_INFINITY; double max_x = Double.NEGATIVE_INFINITY; double min_y = Double.POSITIVE_INFINITY; double max_y = Double.NEGATIVE_INFINITY; for (final RealLocalizable rl : GeomUtils.vertices(input)) { if (rl.getDoublePosition(0) < min_x) { min_x = rl.getDoublePosition(0); } if (rl.getDoublePosition(0) > max_x) { max_x = rl.getDoublePosition(0); } if (rl.getDoublePosition(1) < min_y) { min_y = rl.getDoublePosition(1); } if (rl.getDoublePosition(1) > max_y) { max_y = rl.getDoublePosition(1); } } final List<RealLocalizable> bounds = new ArrayList<>(); bounds.add(new RealPoint(min_x, min_y)); bounds.add(new RealPoint(min_x, max_y)); bounds.add(new RealPoint(max_x, max_y)); bounds.add(new RealPoint(max_x, min_y)); return new DefaultWritablePolygon2D(bounds); }
Example 10
Source File: DefaultVoxelization3D.java From imagej-ops with BSD 2-Clause "Simplified" License | 4 votes |
@Override public RandomAccessibleInterval<BitType> calculate(Mesh input) { Img<BitType> outImg = ops.create().img(new FinalInterval(width, height, depth), new BitType()); Vertices verts = input.vertices(); RealPoint minPoint = new RealPoint(verts.iterator().next()); RealPoint maxPoint = new RealPoint(verts.iterator().next()); for (RealLocalizable v : verts) { if (v.getDoublePosition(0) < minPoint.getDoublePosition(0)) minPoint.setPosition(v.getDoublePosition(0), 0); if (v.getDoublePosition(1) < minPoint.getDoublePosition(1)) minPoint.setPosition(v.getDoublePosition(1), 1); if (v.getDoublePosition(2) < minPoint.getDoublePosition(2)) minPoint.setPosition(v.getDoublePosition(2), 2); if (v.getDoublePosition(0) > maxPoint.getDoublePosition(0)) maxPoint.setPosition(v.getDoublePosition(0), 0); if (v.getDoublePosition(1) > maxPoint.getDoublePosition(1)) maxPoint.setPosition(v.getDoublePosition(1), 1); if (v.getDoublePosition(2) > maxPoint.getDoublePosition(2)) maxPoint.setPosition(v.getDoublePosition(2), 2); } RealPoint dimPoint = new RealPoint((maxPoint.getDoublePosition(0) - minPoint.getDoublePosition(0)), (maxPoint.getDoublePosition(1) - minPoint.getDoublePosition(1)), (maxPoint.getDoublePosition(2) - minPoint.getDoublePosition(2))); double[] stepSizes = new double[3]; stepSizes[0] = dimPoint.getDoublePosition(0) / width; stepSizes[1] = dimPoint.getDoublePosition(1) / height; stepSizes[2] = dimPoint.getDoublePosition(2) / depth; double[] voxelHalfsize = new double[3]; for (int k = 0; k < stepSizes.length; k++) voxelHalfsize[k] = stepSizes[k] / 2.0; for (final Triangle tri : input.triangles()) { final Vector3D v1 = new Vector3D(tri.v0x(), tri.v0y(), tri.v0z()); final Vector3D v2 = new Vector3D(tri.v1x(), tri.v1y(), tri.v1z()); final Vector3D v3 = new Vector3D(tri.v2x(), tri.v2y(), tri.v2z()); double[] minSubBoundary = new double[] { Math.min(Math.min(v1.getX(), v2.getX()), v3.getX()) - minPoint.getDoublePosition(0), Math.min(Math.min(v1.getY(), v2.getY()), v3.getY()) - minPoint.getDoublePosition(1), Math.min(Math.min(v1.getZ(), v2.getZ()), v3.getZ()) - minPoint.getDoublePosition(2) }; double[] maxSubBoundary = new double[] { Math.max(Math.max(v1.getX(), v2.getX()), v3.getX()) - minPoint.getDoublePosition(0), Math.max(Math.max(v1.getY(), v2.getY()), v3.getY()) - minPoint.getDoublePosition(1), Math.max(Math.max(v1.getZ(), v2.getZ()), v3.getZ()) - minPoint.getDoublePosition(2) }; RandomAccess<BitType> ra = outImg.randomAccess();// Should use the // interval // implementation // for speed long[] indices = new long[3]; for (indices[0] = (long) Math.floor(minSubBoundary[0] / stepSizes[0]); indices[0] < Math .floor(maxSubBoundary[0] / stepSizes[0]); indices[0]++) { for (indices[1] = (long) Math.floor(minSubBoundary[1] / stepSizes[1]); indices[1] < Math .floor(maxSubBoundary[1] / stepSizes[1]); indices[1]++) { for (indices[2] = (long) Math.floor(minSubBoundary[2] / stepSizes[2]); indices[2] < Math .floor(maxSubBoundary[2] / stepSizes[2]); indices[2]++) { ra.setPosition(indices); if (!ra.get().get())// Don't check if voxel is already // filled { double[] voxelCenter = new double[3]; for (int k = 0; k < 3; k++) voxelCenter[k] = indices[k] * stepSizes[k] + voxelHalfsize[k]; if (triBoxOverlap(voxelCenter, voxelHalfsize, v1, v2, v3) == 1) { ra.get().set(true); } } } } } } return outImg; }
Example 11
Source File: DefaultConvexHull2D.java From imagej-ops with BSD 2-Clause "Simplified" License | 3 votes |
/** * 2D cross product of OA and OB vectors, i.e. z-component of ir 3D cross * product. Returns a positive value, if OAB makes a counter-clockwise turn, * negative for clockwise turn, and zero if RealPoints are collinear. * * @param o first RealPoint * @param a second RealPoint * @param b third RealPoint * @return Returns a positive value, if OAB makes a counter-clockwise wturn, * negative for clockwise turn, and zero if RealPoints are collinear. */ private double ccw(final RealLocalizable o, final RealLocalizable a, final RealLocalizable b) { return (a.getDoublePosition(0) - o.getDoublePosition(0)) * (b .getDoublePosition(1) - o.getDoublePosition(1)) - (a.getDoublePosition( 1) - o.getDoublePosition(1)) * (b.getDoublePosition(0) - o .getDoublePosition(0)); }