use of imagingbook.pub.geometry.basic.Pnt2d in project imagingbook-common by imagingbook.
the class PolygonSampler method samplePolygonUniformly.
/**
* Samples the closed polygon path specified by V at M
* equi-distant positions.
* @param V the vertices of the (closed) polygon.
* @param M the number of sample points.
* @return the sample points as an array of Point objects.
*/
public Pnt2d[] samplePolygonUniformly(Pnt2d[] V, int M) {
int N = V.length;
// constant segment length in Q
double Delta = pathLength(V) / M;
// distribute N points along polygon path P
Pnt2d[] S = new Pnt2d[M];
// S[0] = (Point) V[0].clone(); // q_0 = p_0 (duplicate p_0)
// q_0 = p_0 (duplicate p_0)
S[0] = PntDouble.from(V[0]);
// lower index of segment (i,i+1) in P
int i = 0;
// index of next point to be added to Q
int j = 1;
// lower boundary of current path segment in P
double alpha = 0;
// path position of next point to be added to Q
double beta = Delta;
// for all M segments in P do:
while (i < N && j < M) {
Pnt2d vA = V[i];
Pnt2d vB = V[(i + 1) % N];
double delta = vA.distance(vB);
// handle segment (i,i+1) with path boundaries (a,a+d), knowing a < b
while (beta <= alpha + delta && j < M) {
// a < b <= a+d
S[j] = interpolate(vA, vB, (beta - alpha) / delta);
j = j + 1;
beta = beta + Delta;
}
alpha = alpha + delta;
i = i + 1;
}
return S;
}
use of imagingbook.pub.geometry.basic.Pnt2d in project imagingbook-common by imagingbook.
the class RoiUtils method getPolygonPointsFloat.
/**
* 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[] getPolygonPointsFloat(Roi roi) {
FloatPolygon pgn = roi.getFloatPolygon();
Pnt2d[] pts = new Pnt2d[pgn.npoints];
for (int i = 0; i < pgn.npoints; i++) {
pts[i] = Pnt2d.PntDouble.from(pgn.xpoints[i], pgn.ypoints[i]);
}
return pts;
}
use of imagingbook.pub.geometry.basic.Pnt2d in project imagingbook-common by imagingbook.
the class ImageMapper method map.
// ---------------------------------------------------------------------
/**
* Transforms the source image to the target image using this geometric
* mapping and the specified pixel interpolation method.
* The two images are passed as instances of {@link ImageAccessor}.
* Note that source and target reference different images!
* The geometric mapping is supposed to be INVERTED, i.e. transforming
* target to source image coordinates!
*
* @param sourceAcc accessor to the source image
* @param targetAcc accessor to the target image
*/
public void map(ImageAccessor sourceAcc, ImageAccessor targetAcc) {
if (targetAcc.getProcessor() == sourceAcc.getProcessor()) {
throw new IllegalArgumentException("Source and target image must not be the same!");
}
// this always IS an inverse mapping!!
Mapping2D invMap = mapping;
ImageProcessor target = targetAcc.getProcessor();
final int w = target.getWidth();
final int h = target.getHeight();
for (int v = 0; v < h; v++) {
for (int u = 0; u < w; u++) {
Pnt2d sourcePt = invMap.applyTo(PntInt.from(u, v));
float[] val = sourceAcc.getPix(sourcePt.getX(), sourcePt.getY());
targetAcc.setPix(u, v, val);
}
}
}
use of imagingbook.pub.geometry.basic.Pnt2d in project imagingbook-common by imagingbook.
the class AlgebraicLineTest method test2.
@Test
public void test2() {
AlgebraicLine l12 = AlgebraicLine.from(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 Translation2DTest method testFromPoints.
@Test
public void testFromPoints() {
Pnt2d p = Pnt2d.from(3.5, -17);
Pnt2d q = Pnt2d.from(-5, 7.1);
Translation2D m = Translation2D.fromPoints(p, q);
Pnt2d pp = m.applyTo(p);
Assert.assertArrayEquals(q.toDoubleArray(), pp.toDoubleArray(), 1E-6);
}
Aggregations