@Override final public Point createPoint( final double[] l ) { return new Point( l ); } };
/** * Apply a {@link CoordinateTransform} to {@link #p1} with a given amount, * update distance. * * @param t * @param amount */ public void apply( final CoordinateTransform t, final double amount ) { p1.apply( t, strength * amount ); }
/** Returns the index of the closest point, with accuracy depending on magnification. */ synchronized public int find(final double x_p, final double y_p, final double mag) { int index = -1; double d = 10 / mag; if (d < 2) d = 2; double min_dist = Integer.MAX_VALUE; int i = 0; final Point ref = new Point(new double[]{x_p, y_p}); for (final Point p : points) { final double dist = Point.distance(ref, p); if (dist <= d && dist <= min_dist) { min_dist = dist; index = i; } i++; } return index; }
/** * Check if a {@link CoordinateTransform} is the identity transform with * respect to a set of {@link Point Points} and a given tolerance. * * @param t * @param points * @param tolerance * @return */ static public boolean isIdentity( final CoordinateTransform t, final Iterable< Point > points, final double tolerance ) { final double t2 = tolerance * tolerance; for ( final Point p : points ) { p.apply( t ); if ( p.squareDistance() > t2 ) return false; } return true; } }
@Override final protected void setHandles() { final int[] x = new int[]{ imp.getWidth() / 4, 3 * imp.getWidth() / 4 }; final int[] y = new int[]{ imp.getHeight() / 2, imp.getHeight() / 2 }; p = new Point[]{ new Point( new double[]{ x[ 0 ], y[ 0 ] } ), new Point( new double[]{ x[ 1 ], y[ 1 ] } ) }; q = new Point[]{ p[ 0 ].clone(), p[ 1 ].clone() }; m.add( new PointMatch( p[ 0 ], q[ 0 ] ) ); m.add( new PointMatch( p[ 1 ], q[ 1 ] ) ); handles = new PointRoi( x, y, 2 ); imp.setRoi( handles ); }
public static void main( String[] args ) throws NotEnoughDataPointsException { Point p1 = new Point( new double[]{ 10, 20 } ); Point p2 = new Point( new double[]{ 100, 200 } ); TranslationModel2D m = new TranslationModel2D(); ArrayList< PointMatch > list = new ArrayList< PointMatch >(); list.add( new PointMatch( p1, p2 ) ); m.fit( list ); System.out.println( m ); p1.apply( m ); System.out.println( Util.printCoordinates( p1.getL() ) ); System.out.println( Util.printCoordinates( p1.getW() ) ); System.out.println( Util.printCoordinates( p2.getL() ) ); System.out.println( Util.printCoordinates( p2.getW() ) ); } }
final Point p1 = new Point( p2.getW().clone() ); w[ 1 ] = weigh( Point.squareDistance( vertex.getP1(), p2 ), alpha );
@Override final protected void updateHandles( final int x, final int y ) { final double[] l = hooks.get( targetIndex ).getW(); l[ 0 ] = x; l[ 1 ] = y; }
p1 = new Point( new double[] { x, y, z }, new double[] { xR, yR, zR } ); addCross( imp, x, y ); radius1 = Point.distance( p1, new Point( new double[] { xR, yR, zR } ) ); addCircle( imp, (int)Math.round( p1.getL()[ 0 ] ), (int)Math.round( p1.getL()[ 1 ] ), radius1 / imp.getCalibration().getX( 1 ) ); p2 = new Point( new double[] { x, y, z }, new double[] { xR, yR, zR } ); addCross( imp, x, y ); radius2 = Point.distance( p2, new Point( new double[] { xR, yR, zR } ) ); addCircle( imp, (int)Math.round( p2.getL()[ 0 ] ), (int)Math.round( p2.getL()[ 1 ] ), radius2 / imp.getCalibration().getX( 1 ) ); removeColoredOverlays( imp2, 1, select ); addCorrespondence( new ExtendedPointMatch( p1.clone(), p2.clone(), (float)radius1 / (float)imp.getCalibration().getX( 1 ), radius1, (float)radius2 / (float)imp.getCalibration().getX( 1 ), radius2 ) ); p1 = p2 = null; radius1 = radius2 = 0;
static public final class ReferenceData { /** Patch id vs transform */ final Map<Long,Patch.TransformProperties> tp; /** A map of Displayable vs a map of Layer id vs list of Patch ids in that Layer that lay under the Patch, sorted by stack index. */ final Map<Displayable,Map<Long,TreeMap<Integer,Long>>> underlying; /** A list of the Layer ids form which at least one Patch was used to determine a transform of part of a VectorData instance. I.e. the visited layers. */ final Set<Long> src_layer_lids_used; ReferenceData(final Map<Long,Patch.TransformProperties> tp, final Map<Displayable,Map<Long,TreeMap<Integer,Long>>> underlying, final Set<Long> src_layer_lids_used) { this.tp = tp; this.underlying = underlying; this.src_layer_lids_used = src_layer_lids_used; } }
protected void addSimplePoints( final ArrayList<Point> points1, final ArrayList<Point> points2 ) { points1.add( new Point( new double[]{ 0, 0, 0 } ) ); points1.add( new Point( new double[]{ 0, 0, 1.1f } ) ); points1.add( new Point( new double[]{ 0, 1.2f, 0 } ) ); points1.add( new Point( new double[]{ 1.3f, 0, 0 } ) ); points1.add( new Point( new double[]{ 1.3f, 1.4f, 0 } ) ); final Point offset = new Point( new double[]{ 1, 2, 3 } ); for ( final Iterator<Point> i = points1.iterator(); i.hasNext(); ) { final Point p2 = new Point( i.next().getL().clone() ); add( p2, offset ); points2.add( p2 ); } points1.add( new Point( new double[]{ 0.1f, 0.1f ,0.1f } ) ); }
final Point mouse = new Point( new double[]{ x_p, y_p } ); final double a = 64.0 / magnification / magnification; for ( final Point p : points ) final double sd = Point.squareDistance( p, mouse ); if ( sd < min && sd < a ) ( int )Math.ceil( srcRect.height * magnification ) ); final double[] l = mouse.getL(); toScreen.applyInPlace( l ); ctm.applyInverseInPlace( l );
@Override final protected void addHandle( final int x, final int y ) { final double[] l = new double[]{ x, y }; synchronized ( mesh ) { final InvertibleCoordinateTransform ict = ( InvertibleCoordinateTransform )mesh.findClosest( l ).getModel(); try { ict.applyInverseInPlace( l ); final Point here = new Point( l ); final Point there = new Point( l ); hooks.add( here ); here.apply( ict ); mesh.addMatchWeightedByDistance( new PointMatch( there, here, 10f ), alpha ); } catch ( final NoninvertibleModelException e ){ e.printStackTrace(); } } }
@Override public float distanceTo( final PointNode other ) { return (float)Point.distance( this, other ); }
@Override public double getSimilarity( final ArrayList<PointMatch> matches ) { final int numDimensions = matches.get( 0 ).getP1().getL().length; double difference = 0; for ( final PointMatch match : matches ) difference += Point.distance( match.getP1(), match.getP2() ); return difference / (double)numDimensions; } }
@Override public double getSimilarity( final ArrayList<PointMatch> matches ) { final int numDimensions = matches.get( 0 ).getP1().getL().length; double difference = 0; for ( final PointMatch match : matches ) difference += Point.squareDistance( match.getP1(), match.getP2() ); return difference / (double)numDimensions; } }
public VirtualPointNode( final P p ) { this.useW = true; this.p = p; this.numDimensions = p.getL().length; }
final public static void cloneTargetPoints( final Collection< PointMatch > matches, final Collection< Point > targetPoints ) { for ( final PointMatch m : matches ) targetPoints.add( m.getP2().clone() ); }
/** * Estimate the Euclidean distance of local and world coordinates. * * @return square distance */ public double distance() { return Math.sqrt( squareDistance() ); }