net.imglib2.RealLocalizable Java Examples
The following examples show how to use
net.imglib2.RealLocalizable.
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: 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 #2
Source File: N5.java From sciview with BSD 2-Clause "Simplified" License | 6 votes |
public static List<RealLocalizable> openPoints(N5Reader n5, String pointDataset) throws IOException { List<RealLocalizable> points = new ArrayList<>(); // Now load vertices RandomAccessibleInterval<DoubleType> vRai = N5Utils.open(n5, pointDataset); RandomAccess<DoubleType> vAccess = vRai.randomAccess(); long[] pos = new long[2]; for( pos[0] = 0; pos[0] < vRai.dimension(0); pos[0]++ ) { double[] vert = new double[(int) vRai.dimension(1)]; for( pos[1] = 0; pos[1] < (int) vRai.dimension(1); pos[1]++ ) { vAccess.setPosition(pos); vert[(int) pos[1]] = vAccess.get().get(); } points.add(new RealPoint(vert)); } return points; }
Example #3
Source File: Utils.java From sciview with BSD 2-Clause "Simplified" License | 6 votes |
public static void writeXYZ(File xyzFile, List<RealLocalizable> points) throws IOException { BufferedWriter w = new BufferedWriter( new FileWriter(xyzFile) ); if( points.isEmpty() ) return; int numDim = points.get(0).numDimensions(); double[] pos = new double[numDim]; for( RealLocalizable v : points ) { for( int d = 0; d < numDim; d++ ) { if( d > 0 ) w.write(", "); w.write("" + v.getDoublePosition(d)); } w.write("\n"); } w.close(); }
Example #4
Source File: N5Test.java From sciview with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void writeReadRealLocalizableListTest() throws IOException { Path tmp = Files.createTempDirectory(null); tmp.toFile().deleteOnExit(); N5FSWriter n5w = new N5FSWriter(tmp.toAbsolutePath().toString()); N5FSReader n5r = new N5FSReader(tmp.toAbsolutePath().toString()); int numPoints = 100; int numDimensions = 17; Random rng = new Random(171717); List<RealLocalizable> points = new ArrayList<>(); for( int k = 0; k < numPoints; k++ ) { double[] pos = new double[numDimensions]; for( int d = 0; d < numDimensions; d++ ) { pos[d] = rng.nextDouble(); } points.add(new RealPoint(pos)); } N5.save(points, n5w, "testPoints", new int[]{10000,17}, new GzipCompression()); List<RealLocalizable> resultPoints = N5.openPoints(n5r, "testPoints"); assertPointsEqual(points, resultPoints); }
Example #5
Source File: DefaultElongation.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void compute(final Polygon2D input, final DoubleType output) { final List<? extends RealLocalizable> minBB = GeomUtils.vertices( minimumBoundingBoxFunc.calculate(input)); final RealLocalizable p1 = minBB.get(0); final RealLocalizable p2 = minBB.get(1); final RealLocalizable p3 = minBB.get(2); double width = Math.sqrt(Math.pow(p1.getDoublePosition(0) - p2 .getDoublePosition(0), 2) + Math.pow(p1.getDoublePosition(1) - p2 .getDoublePosition(1), 2)); double length = Math.sqrt(Math.pow(p2.getDoublePosition(0) - p3 .getDoublePosition(0), 2) + Math.pow(p2.getDoublePosition(1) - p3 .getDoublePosition(1), 2)); if (width > length) { final double tmp = width; width = length; length = tmp; } output.set(1d - (width / length)); }
Example #6
Source File: DefaultCenterOfGravity.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Override public RealLocalizable calculate(final IterableInterval<T> input) { final int numDimensions = input.numDimensions(); final double[] output = new double[numDimensions]; final double[] intensityValues = new double[numDimensions]; final Cursor<T> c = input.localizingCursor(); while (c.hasNext()) { c.fwd(); for (int i = 0; i < output.length; i++) { output[i] += c.getDoublePosition(i) * c.get().getRealDouble(); intensityValues[i] += c.get().getRealDouble(); } } for (int i = 0; i < output.length; i++) { output[i] = output[i] / intensityValues[i]; } return new RealPoint(output); }
Example #7
Source File: PolygonFeatureTests.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void labelRegionToPolygonConverter() { // ground truth computed with matlab final LabelRegionToPolygonConverter c = new LabelRegionToPolygonConverter(); c.setContext(ops.context()); final Polygon2D test = c.convert(ROI, Polygon2D.class); final List<? extends RealLocalizable> expected = GeomUtils.vertices(contour); final List<? extends RealLocalizable> received = GeomUtils.vertices(test); assertEquals("Number of polygon points differs.", expected.size(), received.size()); for (int i = 0; i < contour.numVertices(); i++) { assertEquals("Polygon point " + i + " differs in x-coordinate.", expected.get(i).getDoublePosition(0), received.get(i).getDoublePosition(0), EPSILON); assertEquals("Polygon point " + i + " differs in y-coordinate.", expected.get(i).getDoublePosition(1), received.get(i).getDoublePosition(1), EPSILON); } }
Example #8
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 #9
Source File: DefaultPerimeterLength.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void compute(final Polygon2D input, final DoubleType output) { double perimeter = 0; final List<? extends RealLocalizable> vertices = GeomUtils.vertices(input); final int size = vertices.size(); for (int i = 0; i < size; i++) { final int nexti = (i + 1) % size; final double dx2 = vertices.get(nexti).getDoublePosition(0) - vertices.get(i).getDoublePosition(0); final double dy2 = vertices.get(nexti).getDoublePosition(1) - vertices.get(i).getDoublePosition(1); perimeter += Math.sqrt(dx2 * dx2 + dy2 * dy2); } output.set(perimeter); }
Example #10
Source File: OrthoSliceMeshFX.java From paintera with GNU General Public License v2.0 | 6 votes |
private static void setCoords2D( final int col, final int row, final RealLocalizable min, final RealLocalizable max, final RealPositionable target) { final int[] pos = new int[] {col, row}; for (int d = 0; d < 2; ++d) { switch (pos[d]) { case 0: target.setPosition(min.getDoublePosition(d), d); break; case 1: target.setPosition((min.getDoublePosition(d) + max.getDoublePosition(d)) / 2, d); break; case 2: target.setPosition(max.getDoublePosition(d), d); break; } } }
Example #11
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 #12
Source File: OrthoSliceMeshFX.java From paintera with GNU General Public License v2.0 | 6 votes |
public void setTexCoords(final RealLocalizable texCoordMin, final RealLocalizable texCoordMax) { final List<RealPoint> texCoordsPoints = calculateTexCoords(texCoordMin, texCoordMax); for (int row = 0; row < 2; ++row) { for (int col = 0; col < 2; ++col) { final MeshView meshView = meshViews.get(2 * row + col); if (meshView == null) continue; final TriangleMesh mesh = (TriangleMesh) meshView.getMesh(); mesh.getTexCoords().clear(); final int[] pointIndices = getPointIndicesForQuadrant(row, col); for (final int ptIndex : pointIndices) { texCoordsPoints.get(ptIndex).localize(buf2D); mesh.getTexCoords().addAll(buf2D); } } } }
Example #13
Source File: PolygonFeatureTests.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void smallesEnclosingRectangle() { // ground truth verified with matlab final List<? extends RealLocalizable> received = GeomUtils.vertices( ((Polygon2D) ops.run(DefaultSmallestEnclosingRectangle.class, contour))); final RealPoint[] expected = new RealPoint[] { new RealPoint(37.229184188393, -0.006307821699), new RealPoint(-14.757779646762, 27.800672834315), new RealPoint(31.725820016821, 114.704793944491), new RealPoint(83.712783851976, 86.897813288478) }; assertEquals("Number of polygon points differs.", expected.length, received.size()); for (int i = 0; i < expected.length; i++) { assertEquals("Polygon point " + i + " differs in x-coordinate.", expected[i].getDoublePosition(0), received.get(i).getDoublePosition(0), EPSILON); assertEquals("Polygon point " + i + " differs in y-coordinate.", expected[i].getDoublePosition(1), received.get(i).getDoublePosition(1), EPSILON); } }
Example #14
Source File: CentroidII.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Override public RealLocalizable calculate(final IterableInterval<?> input) { int numDimensions = input.numDimensions(); double[] output = new double[numDimensions]; Cursor<?> c = input.localizingCursor(); double[] pos = new double[numDimensions]; while (c.hasNext()) { c.fwd(); c.localize(pos); for (int i = 0; i < output.length; i++) { output[i] += pos[i]; } } for (int i = 0; i < output.length; i++) { output[i] = output[i] / input.size(); } return new RealPoint(output); }
Example #15
Source File: FloodFill.java From paintera with GNU General Public License v2.0 | 6 votes |
private static <P extends RealLocalizable & RealPositionable> P setCoordinates( final double x, final double y, final P location, final ViewerPanelFX viewer, final AffineTransform3D labelTransform) { location.setPosition(x, 0); location.setPosition(y, 1); location.setPosition(0, 2); viewer.displayToGlobalCoordinates(location); labelTransform.applyInverse(location, location); return location; }
Example #16
Source File: PolygonFeatureTests.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void convexHull2D() { // ground truth computed with matlab final Polygon2D test = (Polygon2D) ops.run(DefaultConvexHull2D.class, contour); final List<? extends RealLocalizable> received = GeomUtils.vertices(test); final RealPoint[] expected = new RealPoint[] { new RealPoint(1, 30), new RealPoint(2, 29), new RealPoint(26, 6), new RealPoint(31, 6), new RealPoint(42, 9), new RealPoint(49, 22), new RealPoint(72, 65), new RealPoint(78, 77), new RealPoint(48, 106), new RealPoint(42, 109), new RealPoint(34, 109), new RealPoint(28, 106), new RealPoint(26, 104), new RealPoint(23, 98) }; assertEquals("Number of polygon points differs.", expected.length, received.size()); for (int i = 0; i < expected.length; i++) { assertEquals("Polygon point " + i + " differs in x-coordinate.", expected[i].getDoublePosition(0), received.get(i).getDoublePosition(0), EPSILON); assertEquals("Polygon point " + i + " differs in y-coordinate.", expected[i].getDoublePosition(1), received.get(i).getDoublePosition(1), EPSILON); } }
Example #17
Source File: FloodFillTransformedPlane.java From paintera with GNU General Public License v2.0 | 6 votes |
public static void fill( final AffineTransform3D localToWorld, final double[] min, final double[] max, final double zRangePos, final double zRangeNeg, final RandomAccess<? extends BooleanType<?>> relevantBackgroundAccess, final RandomAccess<? extends IntegerType<?>> localAccess, final RealLocalizable seedWorld, final long fillLabel) { new FloodFillTransformedPlane(localToWorld, min[0], min[1], max[0], max[1], zRangePos, zRangeNeg).fill( relevantBackgroundAccess, localAccess, seedWorld, fillLabel ); }
Example #18
Source File: RestrictPainting.java From paintera with GNU General Public License v2.0 | 6 votes |
private static <P extends RealLocalizable & RealPositionable> P setCoordinates( final double x, final double y, final P location, final ViewerPanelFX viewer, final AffineTransform3D labelTransform) { location.setPosition(x, 0); location.setPosition(y, 1); location.setPosition(0, 2); viewer.displayToGlobalCoordinates(location); labelTransform.applyInverse(location, location); return location; }
Example #19
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 #20
Source File: InterestPointOverlay.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
@Override public void drawOverlays( final Graphics g ) { final Graphics2D graphics = ( Graphics2D ) g; final int t = viewer.getState().getCurrentTimepoint(); final double[] lPos = new double[ 3 ]; final double[] gPos = new double[ 3 ]; final AffineTransform3D transform = new AffineTransform3D(); for ( final InterestPointSource pointSource : interestPointSources ) { pointSource.getLocalToGlobalTransform( t, transform ); transform.preConcatenate( viewerTransform ); for ( final RealLocalizable p : pointSource.getLocalCoordinates( t ) ) { p.localize( lPos ); transform.apply( lPos, gPos ); final double size = getPointSize( gPos ); final int x = ( int ) ( gPos[ 0 ] - 0.5 * size ); final int y = ( int ) ( gPos[ 1 ] - 0.5 * size ); final int w = ( int ) size; graphics.setColor( getColor( gPos ) ); graphics.fillOval( x, y, w, w ); } } }
Example #21
Source File: ViewerPanelFX.java From paintera with GNU General Public License v2.0 | 5 votes |
/** * Set {@code pos} to the display coordinates (x,y,0)<sup>T</sup> transformed into the source coordinate system. * * @param pos * is set to the source coordinates at display (x,y,0)<sup>T</sup>. */ public <P extends RealLocalizable & RealPositionable> void displayToSourceCoordinates( final double x, final double y, final AffineTransform3D sourceTransform, final P pos) { pos.setPosition(x, 0); pos.setPosition(y, 1); pos.setPosition(0, 2); displayToGlobalCoordinates(pos); sourceTransform.applyInverse(pos, pos); }
Example #22
Source File: FractalSpimDataGenerator.java From BigStitcher with GNU General Public License v2.0 | 5 votes |
public static List< RealLocalizable > getTileMins(List<Interval> intervals) { final List<RealLocalizable> mins = new ArrayList<>(); for(Interval iv : intervals) { RealPoint min = new RealPoint( iv.numDimensions() ); iv.min( min ); mins.add( min ); } return mins; }
Example #23
Source File: DefaultFeretsAngle.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void compute(final Pair<RealLocalizable, RealLocalizable> input, final DoubleType output) { final RealLocalizable p1 = input.getA(); final RealLocalizable p2 = input.getB(); final double degree = Math.atan2(p2.getDoublePosition(1) - p1.getDoublePosition(1), p2.getDoublePosition(0) - p1.getDoublePosition(0)) * (180.0 / Math.PI); output.set(degree % 180); }
Example #24
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 #25
Source File: PolygonFeatureTests.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void boundingBox() { // ground truth verified with matlab final List<? extends RealLocalizable> received = GeomUtils.vertices( ((Polygon2D) ops.run(DefaultBoundingBox.class, contour))); final RealPoint[] expected = new RealPoint[] { new RealPoint(1, 6), new RealPoint(1, 109), new RealPoint(78, 109), new RealPoint(78, 6) }; assertEquals("Number of polygon points differs.", expected.length, received.size()); for (int i = 0; i < expected.length; i++) { assertEquals("Polygon point " + i + " differs in x-coordinate.", expected[i].getDoublePosition(0), received.get(i).getDoublePosition(0), EPSILON); assertEquals("Polygon point " + i + " differs in y-coordinate.", expected[i].getDoublePosition(1), received.get(i).getDoublePosition(1), EPSILON); } }
Example #26
Source File: GeomNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod(op = net.imagej.ops.geom.geom2d.DefaultMaximumFeret.class) public Pair<RealLocalizable, RealLocalizable> maximumFeret(final Polygon2D in) { @SuppressWarnings("unchecked") final Pair<RealLocalizable, RealLocalizable> result = (Pair<RealLocalizable, RealLocalizable>) ops().run(net.imagej.ops.geom.geom2d.DefaultMaximumFeret.class, in); return result; }
Example #27
Source File: DefaultFeretsDiameter.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void compute(final Pair<RealLocalizable, RealLocalizable> input, final DoubleType output) { final RealLocalizable p1 = input.getA(); final RealLocalizable p2 = input.getB(); output.set(Math.hypot(p1.getDoublePosition(0) - p2.getDoublePosition(0), p1.getDoublePosition(1) - p2.getDoublePosition(1))); }
Example #28
Source File: PolygonFeatureTests.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void contour() { // ground truth computed with matlab final Polygon2D test = (Polygon2D) ops.run(DefaultContour.class, ROI, true); final List<? extends RealLocalizable> expected = GeomUtils.vertices(contour); final List<? extends RealLocalizable> received = GeomUtils.vertices(test); assertEquals("Number of polygon points differs.", expected.size(), received.size()); for (int i = 0; i < contour.numVertices(); i++) { assertEquals("Polygon point " + i + " differs in x-coordinate.", expected.get(i).getDoublePosition(0), received.get(i).getDoublePosition(0), EPSILON); assertEquals("Polygon point " + i + " differs in y-coordinate.", expected.get(i).getDoublePosition(1), received.get(i).getDoublePosition(1), EPSILON); } }
Example #29
Source File: DefaultMinorMajorAxis.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
/** * Calculates moments for {@link Polygon2D} * * @param points * vertices of polygon in counter clockwise order. * @return moments m00, n20, n11 and n02 * @see "On Calculation of Arbitrary Moments of Polygon2Ds, Carsten Steger, October 1996" */ private double[] getMoments(final Polygon2D input, final List<RealLocalizable> points) { // calculate normalized moment double m00 = 0; double m01 = 0; double m02 = 0; double m10 = 0; double m11 = 0; double m20 = 0; for (int i = 1; i < points.size(); i++) { double a = getX(input, i - 1) * getY(input, i) - getX(input, i) * getY(input, i - 1); m00 += a; m10 += a * (getX(input, i - 1) + getX(input, i)); m01 += a * (getY(input, i - 1) + getY(input, i)); m20 += a * (Math.pow(getX(input, i - 1), 2) + getX(input, i - 1) * getX(input, i) + Math.pow(getX(input, i), 2)); m11 += a * (2 * getX(input, i - 1) * getY(input, i - 1) + getX(input, i - 1) * getY(input, i) + getX(input, i) * getY(input, i - 1) + 2 * getX(input, i) * getY(input, i)); m02 += a * (Math.pow(getY(input, i - 1), 2) + getY(input, i - 1) * getY(input, i) + Math.pow(getY(input, i), 2)); } m00 /= 2d; m01 /= 6 * m00; m02 /= 12d * m00; m10 /= 6d * m00; m11 /= 24d * m00; m20 /= 12d * m00; // calculate central moments double n20 = m20 - Math.pow(m10, 2); double n11 = m11 - m10 * m01; double n02 = m02 - Math.pow(m01, 2); return new double[] { m00, n20, n11, n02 }; }
Example #30
Source File: DefaultMaximumFeret.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Override public Pair<RealLocalizable, RealLocalizable> calculate(Polygon2D input) { final List<? extends RealLocalizable> points = GeomUtils.vertices(function .calculate(input)); double distance = Double.NEGATIVE_INFINITY; RealLocalizable p0 = points.get(0); RealLocalizable p1 = points.get(0); for (int i = 0; i < points.size(); i++) { for (int j = i + 2; j < points.size(); j++) { final RealLocalizable tmpP0 = points.get(i); final RealLocalizable tmpP1 = points.get(j); final double tmp = Math.sqrt(Math.pow(tmpP0.getDoublePosition(0) - tmpP1 .getDoublePosition(0), 2) + Math.pow(tmpP0.getDoublePosition(1) - tmpP1.getDoublePosition(1), 2)); if (tmp > distance) { distance = tmp; p0 = tmpP0; p1 = tmpP1; } } } return new ValuePair<>(p0, p1); }