newNamedPoints = NamedPointSet.forImage(imp); } catch( NamedPointSet.PointsFileException e ) { return false; points=new NamedPointSet(); for (i = newNamedPoints.listIterator();i.hasNext();) { NamedPointWorld current = i.next(); boolean foundName = false; ListIterator<NamedPointWorld> j; for(j=points.listIterator();j.hasNext();) { NamedPointWorld p = j.next(); if (current.getName().equals(p.getName())) { points.add(current);
public static NamedPointSet fromFile( File f, ImagePlus imagePlus, String imageFilename ) throws PointsFileException { try { return fromBufferedReader( new BufferedReader( new FileReader(f) ), imagePlus, imageFilename ); } catch( FileNotFoundException e ) { throw new PointsFileException( "Couldn't find the file: "+f.getAbsolutePath() ); } }
public static NamedPointSet fromFile( File f ) throws PointsFileException { return fromFile( f, null, null ); }
public NamedPointSet transformPointsWith( OrderedTransformations o ) { NamedPointSet result = new NamedPointSet(); Iterator i0; for( i0 = pointsWorld.listIterator(); i0.hasNext(); ) { NamedPointWorld p = (NamedPointWorld)i0.next(); NamedPointWorld transformed = p.transformWith(o); result.add( transformed ); } return result; }
public boolean equals( NamedPointSet other ) { Set< String > thisNames = getNamesAsSet(); Set< String > otherNames = other.getNamesAsSet(); if( ! thisNames.equals( otherNames ) ) return false; double epsilon = 0.00001; for( String name : thisNames ) { NamedPointWorld thisNPW = get( name ); NamedPointWorld otherNPW = other.get( name ); if( thisNPW.set != otherNPW.set ) return false; if( thisNPW.set ) { if( Math.abs( thisNPW.x - otherNPW.x ) > epsilon ) return false; if( Math.abs( thisNPW.y - otherNPW.y ) > epsilon ) return false; if( Math.abs( thisNPW.z - otherNPW.z ) > epsilon ) return false; } } return true; }
public static double evaluateFastMatrix( FastMatrix fm, NamedPointSet from, NamedPointSet to ) { if( from.size() != to.size() ) { throw new RuntimeException("In evaluateFastMatrix, 'from' (size "+from.size()+") and 'to' (size "+to.size()+") must be equal"); } double sumDistances = 0; int n = from.size(); for( int i = 0; i < n; ++i ) { NamedPointWorld fromPoint = from.get( i ); NamedPointWorld toPoint = to.get( i ); if( ! fromPoint.name.equals(toPoint.name) ) throw new RuntimeException("In evaluateFastMatrix, point index "+i+" has a name mismatch: fromPoint = "+fromPoint+", toPoint = "+toPoint); fm.apply( fromPoint.x, fromPoint.y, fromPoint.z ); double xdiff = fm.x - toPoint.x; double ydiff = fm.y - toPoint.y; double zdiff = fm.z - toPoint.z; sumDistances += Math.sqrt( xdiff * xdiff + ydiff * ydiff + zdiff * zdiff ); } return sumDistances / n; }
boolean foundExistingPointsFile = loadAtStart(); if( ! foundExistingPointsFile ) { points = new NamedPointSet(); if( templateImageFile != null && templateImageFile.exists() ) { try { templatePoints = NamedPointSet.forImage( templateImageFilename ); } catch( NamedPointSet.PointsFileException e ) { IJ.error("Couldn't load points file for template image. The error was: " + e ); points.addNewPoint(); } else { String [] templatePointNames = templatePoints.getPointNames(); for( String name : templatePointNames ) points.add( new NamedPointWorld(name) );
public static FastMatrix bestBetweenPoints( NamedPointSet points0, ImagePlus image0, NamedPointSet points1, ImagePlus image1 ) { ArrayList<String> commonPointNames = points0.namesSharedWith( points1, true ); NamedPointSet fromCommon = new NamedPointSet(); NamedPointSet toCommon = new NamedPointSet(); toCommon.add( points0.get( name ) ); fromCommon.add( points1.get( name ) ); fromCommon.get(choice[0]), fromCommon.get(choice[1]), fromCommon.get(choice[2]), fromCommon.get(choice[3]), toCommon.get(choice[0]), toCommon.get(choice[1]), toCommon.get(choice[2]), toCommon.get(choice[3]) ); Point3d [] to = new Point3d[4]; for( int i = 0; i < 4; ++i ) { NamedPointWorld npw1 = fromCommon.get(choice[i]); NamedPointWorld npw0 = toCommon.get(choice[i]); from[i] = npw1.toPoint3d(); to[i] = npw0.toPoint3d();
points = NamedPointSet.forImage(imp); } catch( NamedPointSet.PointsFileException e ) { IJ.error("Couldn't load points file for image '"+imp.getTitle()+"': " + e ) ; ArrayList<String> namesInCommon = points.namesSharedWith(templatePoints,true); NamedPointWorld guessedPoint = points.get( name ); if( ! points.savePointsFile( outputPointsFilename ) ) { IJ.error( "Saving the points file to: " + outputPointsFilename );
public static NamedPointSet forImage( String imageFilename ) throws PointsFileException { return forImage( null, imageFilename ); }
synchronized public NamedPointWorld addNewPoint( ) { int i = pointsWorld.size(); boolean nameTaken = true; String newName = null; while( nameTaken ) { newName = "Named Point (" + i + ")"; nameTaken = get( newName ) != null; ++ i; } NamedPointWorld toAdd = new NamedPointWorld( newName ); pointsWorld.add( toAdd ); return toAdd; }
void addNewPoint() { NamedPointWorld npw = points.addNewPoint(); dialog.recreatePointsPanel(); dialog.pack(); }
void rename(int i) { NamedPointWorld npw = points.get(i); GenericDialog gd = new GenericDialog( "Rename Point" ); gd.addStringField( "Rename point to:", npw.getName() ); gd.showDialog(); if( gd.wasCanceled() ) return; String newName = gd.getNextString(); boolean result = points.renamePointTo( i, newName ); if( result ) { dialog.markButtons[i].setLabel( newName ); dialog.pack(); } else { IJ.error("Couldn't rename point: there already is one called \"" + newName + "\"" ); } }
public static NamedPointSet fromString( String s ) { return fromString( s ); }
boolean fineTune( NamedPointWorld p ) { int index = points.getIndexOfPoint( p.getName() ); return fineTune( p, index ); }
StringReader reader=new StringReader(s); InputSource inputSource=new InputSource(reader); NamedPointSet nps = new NamedPointSet(); Handler h = new Handler(nps); parser.parse( inputSource, h ); NamedPointSet nps = new NamedPointSet(); Pattern emptyPattern = Pattern.compile("^ *$"); Pattern numberPattern = Pattern.compile( "[eE0-9\\.\\-]+" ); double y = Double.parseDouble( yString ); double z = Double.parseDouble( zString ); nps.add( new NamedPointWorld( name, x, y, z ) ); } else { nps.add( new NamedPointWorld( name ) ); NamedPointSet nps = new NamedPointSet(); Pattern p_data = Pattern.compile("^\"(.*)\": *"+ nps.add( new NamedPointWorld( m_data.group(1), Double.parseDouble(m_data.group(2)) * xSpacing, Double.parseDouble(m_data.group(3)) * ySpacing, Double.parseDouble(m_data.group(4)) * zSpacing) ); } else if (m_name_no_data.matches()) { nps.add( new NamedPointWorld( m_name_no_data.group(1) ) ); } else if (m_comment.matches()) { continue;
public ImagePlus register() { NamedPointSet points0 = null; NamedPointSet points1 = null; try { points0 = NamedPointSet.forImage(sourceImages[0]); } catch( NamedPointSet.PointsFileException e ) { throw new RuntimeException( "No corresponding .points file found "+ "for image: \""+sourceImages[0].getTitle()+"\"" ); } try { points1 = NamedPointSet.forImage(sourceImages[1]); } catch( NamedPointSet.PointsFileException e ) { throw new RuntimeException( "No corresponding .points file found "+ "for image: \""+sourceImages[1].getTitle()+"\"" ); } return register( points0, points1 ); }
public void add(NamedPointWorld namedPointWorld) { synchronized (this) { String name = namedPointWorld.getName(); NamedPointWorld existing = get( name ); if( existing != null ) throw new RuntimeException( "Trying to add a point of name '" + name + "', but this NamedPointSet already has one." ); pointsWorld.add( namedPointWorld ); } }