Java Code Examples for mpicbg.models.Point#squareDistance()

The following examples show how to use mpicbg.models.Point#squareDistance() . 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: SquareDistance.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
@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;		
}
 
Example 2
Source File: NonLinearTransformMode.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void mousePressed( final MouseEvent me, final int x_p, final int y_p, final double magnification )
{
	/* find if clicked on a point */
	p_clicked = null;
	double min = Double.MAX_VALUE;
	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 )
		{
			p_clicked = p;
			min = sd;
		}
	}

	if ( me.isShiftDown() )
	{
		if ( null == p_clicked )
		{
			/* add one */
			try
			{
				if ( points.size() > 0 )
				{
					/*
					 * Create a pseudo-invertible (TransformMesh) for the screen.
					 */
					final CoordinateTransform mlst = createCT();
					final SimilarityModel2D toWorld = new SimilarityModel2D();
					toWorld.set( 1.0 / magnification, 0, srcRect.x, srcRect.y );
					final SimilarityModel2D toScreen = toWorld.createInverse();

					final mpicbg.models.CoordinateTransformList< mpicbg.models.CoordinateTransform > ctl = new mpicbg.models.CoordinateTransformList< mpicbg.models.CoordinateTransform >();
					ctl.add( toWorld );
					ctl.add( mlst );
					ctl.add( toScreen );

					final CoordinateTransformMesh ctm = new CoordinateTransformMesh(
							ctl,
							32,
							( int )Math.ceil( srcRect.width * magnification ),
							( int )Math.ceil( srcRect.height * magnification ) );

					final double[] l = mouse.getL();
					toScreen.applyInPlace( l );
					ctm.applyInverseInPlace( l );
					toWorld.applyInPlace( l );
				}
				points.add( mouse );
				p_clicked = mouse;
			}
			catch ( final Exception e )
			{
				Utils.log( "Could not add point" );
				e.printStackTrace();
			}
		}
		else if ( Utils.isControlDown( me ) )
		{
			// remove it
			points.remove(p_clicked);
		 	p_clicked = null;
		}
	}
}