static PointListConnections loadConnections() { final PointListConnections plc = new PointListConnections(); plc.addConnection(0, 1); plc.addConnection(1, 2); plc.addConnection(1, 4); plc.addConnection(1, 9); plc.addConnection(4, 3); plc.addConnection(9, 10); plc.addConnection(0, 5); plc.addConnection(0, 8); plc.addConnection(5, 6); plc.addConnection(8, 7); return plc; }
/** * Calculate a normal line for a given vertex. * * @param idx * the vertex index * @param pointList * the {@link PointList} in which to search/ * @param scale * The scaling to apply to the line; a scale of 1.0 will lead to * a line that is 2.0 units long (1.0 either side of the vertex). * @return the normal line. */ public Line2d calculateNormalLine(int idx, PointList pointList, float scale) { return calculateNormalLine(pointList.points.get(idx), pointList, scale); }
/** * @param conns * @return calls {@link PointListConnections#getLines(PointList)} with this */ public List<Line2d> getLines(PointListConnections conns) { return conns.getLines(this); }
@Override protected void updateNextFrame(FImage frame) { frame.fill(0f); final PointList newShape = pdm.generateNewShape(a.nextValue()); final PointList tfShape = newShape.transform(TransformUtilities.translateMatrix(300, 300).times( TransformUtilities.scaleMatrix(150, 150))); final List<Line2d> lines = connections.getLines(tfShape); frame.drawLines(lines, 1, 1f); for (final Point2d pt : tfShape) { final Line2d normal = connections.calculateNormalLine(pt, tfShape, 10f); if (normal != null) { frame.drawLine(normal, 1, 0.5f); } } } });
public static void main(String[] args) { final List<IndependentPair<PointList, FImage>> data = generateData(10); final PointListConnections connections = new PointListConnections(); connections.addConnection(0, 1); connections.addConnection(1, 2); connections.addConnection(2, 0); rgb.drawLines(connections.getLines(shape), 1, RGBColour.RED); rgb.drawLines(connections.getLines(res.shape), 1, RGBColour.GREEN);
/** * Add a connection between two points in the given {@link PointList}. * * @param pl * the {@link PointList} * @param from * the first point * @param to * the second point */ public void addConnection(PointList pl, Point2d from, Point2d to) { addConnection(pl.points.indexOf(from), pl.points.indexOf(to)); }
/** * Calculate the normal vector at a given vertex. * * @param pt * the vertex. * @param pointList * the {@link PointList} in which to search. * @return the unit normal vector of the vertex. */ public Point2dImpl calculateNormal(Point2d pt, PointList pointList) { return calculateNormal(pointList.points.indexOf(pt), pointList); }
/** * Get the points connected to the given point. * * @param pt * The target point. * @param pl * The {@link PointList} in whioch to search. * @return the connected points. */ public Point2d[] getConnections(Point2d pt, PointList pl) { final int[] conns = getConnections(pl.points.indexOf(pt)); final Point2d[] pts = new Point2d[conns.length]; for (int i = 0; i < conns.length; i++) { pts[i] = pl.points.get(conns[i]); } return pts; }
@Override protected void updateNextFrame(FImage frame) { frame.fill(0f); final PointList newShape = pdm.generateNewShape(a.nextValue()); final PointList tfShape = newShape.transform(TransformUtilities.translateMatrix(300, 300).times( TransformUtilities.scaleMatrix(150, 150))); final List<Line2d> lines = connections.getLines(tfShape); frame.drawLines(lines, 1, 1f); for (final Point2d pt : tfShape) { final Line2d normal = connections.calculateNormalLine(pt, tfShape, 10f); if (normal != null) { frame.drawLine(normal, 1, 0.5f); } } } });
public static void main(String[] args) { final List<IndependentPair<PointList, FImage>> data = generateData(10); final PointListConnections connections = new PointListConnections(); connections.addConnection(0, 1); connections.addConnection(1, 2); connections.addConnection(2, 0); rgb.drawLines(connections.getLines(shape), 1, RGBColour.RED); rgb.drawLines(connections.getLines(res.shape), 1, RGBColour.GREEN);
/** * Add a connection between the two end points of the given line in the * given {@link PointList}. * * @param pl * the {@link PointList} * @param line * the line */ public void addConnection(PointList pl, Line2d line) { addConnection(pl.points.indexOf(line.begin), pl.points.indexOf(line.end)); }
/** * Calculate a normal line for a given vertex. * * @param pt * the vertex * @param pointList * the {@link PointList} in which to search/ * @param scale * The scaling to apply to the line; a scale of 1.0 will lead to * a line that is 2.0 units long (1.0 either side of the vertex). * @return the normal line. */ public Line2d calculateNormalLine(Point2d pt, PointList pointList, float scale) { final Point2dImpl normal = calculateNormal(pointList.points.indexOf(pt), pointList); if (normal == null) return null; final float nx = normal.x; final float ny = normal.y; final Point2dImpl start = new Point2dImpl((nx * scale) + pt.getX(), (ny * scale) + pt.getY()); final Point2dImpl end = new Point2dImpl(-(nx * scale) + pt.getX(), -(ny * scale) + pt.getY()); return new Line2d(start, end); }
final int[] conns = getConnections(id);
static PointListConnections loadConnections() { final PointListConnections plc = new PointListConnections(); plc.addConnection(0, 1); plc.addConnection(1, 2); plc.addConnection(1, 4); plc.addConnection(1, 9); plc.addConnection(4, 3); plc.addConnection(9, 10); plc.addConnection(0, 5); plc.addConnection(0, 8); plc.addConnection(5, 6); plc.addConnection(8, 7); return plc; }
frame.drawLines(connections.getLines(shape), 1, RGBColour.RED); final Line2d normal = connections.calculateNormalLine(pt, shape, scale * shapeScale); if (normal != null) frame.drawLine(normal, 1, RGBColour.BLUE);
@Override public void updateModel(FImage image, Point2d point, PointList pointList) { float lineScale = normalLength * pointList.computeIntrinsicScale(); Line2d line = connections.calculateNormalLine(point, pointList, lineScale); model.updateModel(image, line); }
@Override protected void updateNextFrame(MBFImage frame) { frame.drawImage(img.toRGB(), 0, 0); frame.drawLines(conns.getLines(shape), 1, RGBColour.BLUE); final IterationResult next = asm.performIteration(img, shape); shape = next.shape; // frame.drawPoint(pt, RGBColour.RED, 3); // Point2d newpt = // ((NormalLandmarkModel)asm.getLandmarkModels()[idx]).updatePosition(img, // pt, shape).first; // pt.setX(newpt.getX()); // pt.setY(newpt.getY()); } });
private PointListConnections readAMPTSConnections(File connFile) throws IOException { final BufferedReader br = new BufferedReader(new FileReader(connFile)); final PointListConnections plc = new PointListConnections(); String line; while ((line = br.readLine()) != null) { if (!line.trim().startsWith("indices")) continue; final String[] data = line.trim().replace("indices(", "").replace(")", "").split(","); final boolean isOpen = (br.readLine().contains("open_boundary")); int prev = Integer.parseInt(data[0]); for (int i = 1; i < data.length; i++) { final int next = Integer.parseInt(data[i]); plc.addConnection(prev, next); prev = next; } if (!isOpen) { plc.addConnection(Integer.parseInt(data[data.length - 1]), Integer.parseInt(data[0])); } } br.close(); return plc; }
frame.drawLines(connections.getLines(shape), 1, RGBColour.RED); final Line2d normal = connections.calculateNormalLine(pt, shape, scale * shapeScale); if (normal != null) frame.drawLine(normal, 1, RGBColour.BLUE);
@Override public void updateModel(FImage image, Point2d point, PointList pointList) { float lineScale = normalLength * pointList.computeIntrinsicScale(); Line2d line = connections.calculateNormalLine(point, pointList, lineScale); model.updateModel(image, line); }