net.imglib2.RealPoint Java Examples
The following examples show how to use
net.imglib2.RealPoint.
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: 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 #2
Source File: ConsensusWarpFieldBuilder.java From render with GNU General Public License v2.0 | 6 votes |
private void mapCellsToPoints(final Map<Integer, List<RealPoint>> cellToPointsMap, final RealCursor<ARGBType> cursor) { List<RealPoint> pointList; while (cursor.hasNext()) { cursor.fwd(); final double x = cursor.getDoublePosition(0) * pixelsPerColumn; final double y = cursor.getDoublePosition(1) * pixelsPerRow; final int row = (int) ((y / height) * rowCount); final int column = (int) ((x / width) * columnCount); final int gridIndex = (row * rowCount) + column; pointList = cellToPointsMap.get(gridIndex); if (pointList == null) { pointList = new ArrayList<>(); cellToPointsMap.put(gridIndex, pointList); } pointList.add(new RealPoint(x, y)); } }
Example #3
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 #4
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 #5
Source File: Geom3DUtils.java From paintera with GNU General Public License v2.0 | 6 votes |
/** * Returns a 4D vector [a,b,c,d] that defines a 3D plane in the following way: ax+by+cz+d=0. * * The normal vector of the plane is calculated by taking the cross-product of the two vectors within the plane * formed between 3 points that are passed as parameters: P1->P2 and P1->P3. * * @param p1 * @param p2 * @param p3 * @return */ public static Vec4d createPlane(final RealPoint p1, final RealPoint p2, final RealPoint p3) { // p1 -> p2 final Vec3d p12 = new Vec3d( p2.getDoublePosition(0) - p1.getDoublePosition(0), p2.getDoublePosition(1) - p1.getDoublePosition(1), p2.getDoublePosition(2) - p1.getDoublePosition(2)); // p1 -> p3 final Vec3d p13 = new Vec3d( p3.getDoublePosition(0) - p1.getDoublePosition(0), p3.getDoublePosition(1) - p1.getDoublePosition(1), p3.getDoublePosition(2) - p1.getDoublePosition(2)); final Vec3d normal = new Vec3d(); normal.cross(p12, p13); normal.normalize(); // plug the coordinates of any given point in the plane into the plane equation to find the last component of the equation final double d = -normal.dot(new Vec3d(p1.getDoublePosition(0), p1.getDoublePosition(1), p1.getDoublePosition(2))); return new Vec4d(normal.x, normal.y, normal.z, d); }
Example #6
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 #7
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 #8
Source File: DerivedMatchGroup.java From render with GNU General Public License v2.0 | 6 votes |
private List<Integer> getSetIndexesForPoints(final RealPointSampleList<ARGBType> largestSetIndexSamples, final List<RealPoint> otherSetPoints) { final List<Integer> setIndexList = new ArrayList<>(); final KDTree<ARGBType> kdTree = new KDTree<>(largestSetIndexSamples); final NearestNeighborSearch<ARGBType> nnSearchSamples = new NearestNeighborSearchOnKDTree<>(kdTree); Sampler<ARGBType> sampler; ARGBType sampleItem; int nnSetIndex; for (final RealPoint otherPoint : otherSetPoints) { nnSearchSamples.search(otherPoint); sampler = nnSearchSamples.getSampler(); sampleItem = sampler.get(); nnSetIndex = sampleItem.get(); setIndexList.add(nnSetIndex); } return setIndexList; }
Example #9
Source File: DefaultDetectJunctions.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
private void filterJunctions(List<RealPoint> list) { // filter out all vaguely similar junction points. for (int i = 0; i < list.size() - 1; i++) { ArrayList<RealPoint> similars = new ArrayList<>(); similars.add(list.get(i)); list.remove(i); for (int j = 0; j < list.size(); j++) { if (areClose(list.get(j), similars)) { similars.add(list.get(j)); list.remove(j); j--; } } if (list.size() > 0) list.add(i, averagePoints(similars)); else list.add(averagePoints(similars)); } }
Example #10
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 #11
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 #12
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 #13
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 #14
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 #15
Source File: ShapeInterpolationMode.java From paintera with GNU General Public License v2.0 | 5 votes |
private D getDataValue(final double x, final double y) { final RealPoint sourcePos = getSourceCoordinates(x, y); final int time = activeViewer.getState().getTimepoint(); final int level = MASK_SCALE_LEVEL; final RandomAccessibleInterval<D> data = source.getDataSource(time, level); final RandomAccess<D> dataAccess = data.randomAccess(); for (int d = 0; d < sourcePos.numDimensions(); ++d) dataAccess.setPosition(Math.round(sourcePos.getDoublePosition(d)), d); return dataAccess.get(); }
Example #16
Source File: AbstractFeatureTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
protected static Polygon2D getPolygon() { final List<RealPoint> vertices = new ArrayList<>(); try { Files.lines(Paths.get(AbstractFeatureTest.class.getResource("2d_geometric_features_polygon.txt").toURI())) .forEach(l -> { String[] coord = l.split(" "); RealPoint v = new RealPoint(new double[]{ Double.parseDouble(coord[0]), Double.parseDouble(coord[1])}); vertices.add(v); }); } catch (IOException | URISyntaxException exc) { exc.printStackTrace(); } return new DefaultWritablePolygon2D(vertices); }
Example #17
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 #18
Source File: ShapeInterpolationMode.java From paintera with GNU General Public License v2.0 | 5 votes |
private UnsignedLongType getMaskValue(final double x, final double y) { final RealPoint sourcePos = getSourceCoordinates(x, y); final RandomAccess<UnsignedLongType> maskAccess = Views.extendValue(mask.mask, new UnsignedLongType(Label.OUTSIDE)).randomAccess(); for (int d = 0; d < sourcePos.numDimensions(); ++d) maskAccess.setPosition(Math.round(sourcePos.getDoublePosition(d)), d); return maskAccess.get(); }
Example #19
Source File: ShapeInterpolationMode.java From paintera with GNU General Public License v2.0 | 5 votes |
private RealPoint getSourceCoordinates(final double x, final double y) { final AffineTransform3D maskTransform = getMaskTransform(); final RealPoint sourcePos = new RealPoint(maskTransform.numDimensions()); activeViewer.displayToSourceCoordinates(x, y, maskTransform, sourcePos); return sourcePos; }
Example #20
Source File: DefaultDetectJunctions.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
private RealPoint averagePoints(ArrayList<RealPoint> list) { double[] pos = { 0, 0 }; for (RealPoint p : list) { pos[0] += p.getDoublePosition(0); pos[1] += p.getDoublePosition(1); } pos[0] /= list.size(); pos[1] /= list.size(); return new RealPoint(pos); }
Example #21
Source File: CoordinateDisplayListener.java From paintera with GNU General Public License v2.0 | 5 votes |
public CoordinateDisplayListener( final ViewerPanelFX viewer, final Consumer<RealPoint> submitViewerCoordinate, final Consumer<RealPoint> submitWorldCoordinate) { super(); this.viewer = viewer; this.submitViewerCoordinate = submitViewerCoordinate; this.submitWorldCoordinate = submitWorldCoordinate; }
Example #22
Source File: ConsensusWarpFieldBuilderTest.java From render with GNU General Public License v2.0 | 5 votes |
@Test public void testBuild() throws Exception { final List<List<PointMatch>> consensusSets = CanvasFeatureMatcherTest.findAndValidateFoldTestConsensusSets(); final int consensusGridResolution = 16; final ConsensusWarpFieldBuilder consensusWarpFieldBuilder = new ConsensusWarpFieldBuilder(963.0, 1024.0, consensusGridResolution, consensusGridResolution); int setNumber = 0; for (final List<PointMatch> pointMatchList : consensusSets) { final List<RealPoint> pointList = pointMatchList.stream() .map(pointMatch -> new RealPoint(pointMatch.getP1().getL())) .collect(Collectors.toList()); final AffineModel2D alignmentModel = new AffineModel2D(); alignmentModel.set(1.0, 0.0, 0.0, 1.0, (setNumber * 100), (setNumber * 100)); consensusWarpFieldBuilder.addConsensusSetData(alignmentModel, pointList); setNumber++; } LOG.info("Consensus Grid is ...\n\n{}\n", consensusWarpFieldBuilder.toIndexGridString()); Assert.assertEquals("invalid number of consensus sets left in grid after nearest neighbor analysis", 3, consensusWarpFieldBuilder.getNumberOfConsensusSetsInGrid()); final AffineWarpFieldTransform affineWarpFieldTransform = new AffineWarpFieldTransform(new double[] {0.0, 0.0}, consensusWarpFieldBuilder.build()); LOG.info("Warp Field Data String is {}", affineWarpFieldTransform.toDataString()); }
Example #23
Source File: Matches.java From render with GNU General Public License v2.0 | 5 votes |
private static List<RealPoint> buildPointList(final double[][] locations) { final double[] xLocations = locations[0]; final double[] yLocations = locations[1]; final List<RealPoint> pointList = new ArrayList<>(xLocations.length); for (int i = 0; i < xLocations.length; i++) { pointList.add(new RealPoint(xLocations[i], yLocations[i])); } return pointList; }
Example #24
Source File: DerivedMatchGroup.java From render with GNU General Public License v2.0 | 5 votes |
public void addMatch(final RealPoint p, final RealPoint q, final double w) { pList.add(p); qList.add(q); wList.add(w); }
Example #25
Source File: DerivedMatchGroup.java From render with GNU General Public License v2.0 | 5 votes |
private static double[][] buildLocationArray(final List<RealPoint> pointList) { final double[][] locations = new double[2][pointList.size()]; final double[] xLocations = locations[0]; final double[] yLocations = locations[1]; int i = 0; for (final RealPoint point : pointList) { xLocations[i] = point.getDoublePosition(0); yLocations[i] = point.getDoublePosition(1); i++; } return locations; }
Example #26
Source File: CoordinateDisplayListener.java From paintera with GNU General Public License v2.0 | 5 votes |
public void update(final double x, final double y) { this.x = x; this.y = y; final RealPoint p = new RealPoint(x, y); this.submitViewerCoordinate.accept(p); synchronized (viewer) { updateWorldCoordinates(); } }
Example #27
Source File: DerivedMatchGroup.java From render with GNU General Public License v2.0 | 5 votes |
private Map<String, List<RealPoint>> mapCanvasIdsToPointLists(final List<CanvasMatches> consensusSetPairsList) { final Map<String, List<RealPoint>> idToPointList = new LinkedHashMap<>(); // HACK: order matters String canvasId; List<RealPoint> pointList; for (final CanvasMatches pair : consensusSetPairsList) { final boolean isP = groupId.equals(pair.getpGroupId()); canvasId = isP ? pair.getpId() : pair.getqId(); pointList = isP ? pair.getMatches().getPList() : pair.getMatches().getQList(); idToPointList.put(canvasId, pointList); } return idToPointList; }
Example #28
Source File: DerivedMatchGroup.java From render with GNU General Public License v2.0 | 5 votes |
private void buildSamplesForLargestSet(final List<CanvasMatches> largestSetPairList, final RealPointSampleList<ARGBType> largestSetIndexSamples, final List<String> largestSetCanvasIds) { final Map<String, List<RealPoint>> idToPointList = mapCanvasIdsToPointLists(largestSetPairList); for (final String canvasId : idToPointList.keySet()) { final ARGBType canvasIdIndex = new ARGBType(largestSetCanvasIds.size()); largestSetCanvasIds.add(canvasId); for (final RealPoint realPoint : idToPointList.get(canvasId)) { largestSetIndexSamples.add(realPoint, canvasIdIndex); } } }
Example #29
Source File: FractalSpimDataGenerator.java From BigStitcher with GNU General Public License v2.0 | 5 votes |
/** * create SpimData containing Views at each Interval * @param intervals list of intervals * @return generated SpimData */ public SpimData generateSpimData(final 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 generateSpimData( intervals, mins ); }
Example #30
Source File: SegmentNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod(op = net.imagej.ops.segment.detectJunctions.DefaultDetectJunctions.class) public List<RealPoint> detectJunctions(final List<? extends WritablePolyline> lines) { @SuppressWarnings("unchecked") final List<RealPoint> result = (List<RealPoint>) ops().run( Ops.Segment.DetectJunctions.class, lines); return result; }