use of imagingbook.pub.geometry.basic.Pnt2d in project imagingbook-common by imagingbook.
the class HoughLineTest method test0.
@Test
public void test0() {
// example from CV lecture notes
Pnt2d xRef = PntInt.from(90, 60);
AlgebraicLine h12 = AlgebraicLine.from(p1, p2);
HoughLine L12 = new HoughLine(h12, xRef.getX(), xRef.getY(), 0);
Assert.assertEquals(0.0, L12.getDistance(p1), 1E-6);
Assert.assertEquals(0.0, L12.getDistance(p2), 1E-6);
}
use of imagingbook.pub.geometry.basic.Pnt2d in project imagingbook-common by imagingbook.
the class HessianLineTest method test3.
@Test
public void test3() {
HessianLine l12 = HessianLine.fromPoints(p1, p2);
Pnt2d x0 = l12.getClosestLinePoint(p3);
// x0 is actually ON the line
Assert.assertEquals(0.0, l12.getDistance(x0), 1E-6);
// distance (p3,x0) is shortest
Assert.assertEquals(p3.distance(x0), Math.abs(l12.getDistance(p3)), 1E-6);
}
use of imagingbook.pub.geometry.basic.Pnt2d in project imagingbook-common by imagingbook.
the class RoiUtils method getPolygonPointsInts.
/**
* Retrieves the outline of the specified ROI as an
* array of {@link Pnt2d} points with {@code int}
* coordinates. Note that unless the ROI is of type
* {@link PolygonRoi} or {@link PointRoi} only the corner points of the
* bounding box are returned.
* Interpolated contour points are returned for a instance of {@link OvalRoi}.
*
* @param roi the ROI
* @return the ROI's polygon coordinates
*/
public static Pnt2d[] getPolygonPointsInts(Roi roi) {
Polygon pgn = roi.getPolygon();
Pnt2d[] pts = new Pnt2d[pgn.npoints];
for (int i = 0; i < pgn.npoints; i++) {
pts[i] = Pnt2d.PntInt.from(pgn.xpoints[i], pgn.ypoints[i]);
}
return pts;
}
use of imagingbook.pub.geometry.basic.Pnt2d in project imagingbook-common by imagingbook.
the class Utils method makeOuterTriangle.
/**
* Creates a 2D triangle that is sufficiently large to be used as
* an outer triangle for the Delaunay triangulation of the given
* point set.
* @param points the 2D point set
* @return a triangle as an array of 3 points
*/
public static Pnt2d[] makeOuterTriangle(Collection<? extends Pnt2d> points) {
double xmin = Double.POSITIVE_INFINITY;
double xmax = Double.NEGATIVE_INFINITY;
double ymin = xmin;
double ymax = xmax;
for (Pnt2d p : points) {
double x = p.getX();
double y = p.getY();
xmin = Math.min(x, xmin);
xmax = Math.max(x, xmax);
ymin = Math.min(y, ymin);
ymax = Math.max(y, ymax);
}
return makeOuterTriangle(xmin, xmax, ymin, ymax);
}
use of imagingbook.pub.geometry.basic.Pnt2d in project imagingbook-common by imagingbook.
the class FourierDescriptorFromPolygon method getRoiPoints.
static Pnt2d[] getRoiPoints(Roi roi) {
Polygon poly = roi.getPolygon();
int[] xp = poly.xpoints;
int[] yp = poly.ypoints;
// copy vertices for all non-zero-length polygon segments:
List<Pnt2d> points = new ArrayList<>(xp.length);
points.add(PntInt.from(xp[0], yp[0]));
int last = 0;
for (int i = 1; i < xp.length; i++) {
if (xp[last] != xp[i] || yp[last] != yp[i]) {
points.add(PntInt.from(xp[i], yp[i]));
last = i;
}
}
// remove last point if the closing segment has zero length:
if (xp[last] == xp[0] && yp[last] == yp[0]) {
points.remove(last);
}
return points.toArray(new Pnt2d[0]);
}
Aggregations