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 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 ); } }
public Point3d[] getPoint3DArrayForNames( String [] names ) { Point3d [] result = new Point3d[names.length]; for( int i = 0; i < names.length; ++i ) { NamedPointWorld np = get(names[i]); if( np == null ) return null; else result[i] = new Point3d( np.x, np.y, np.z ); } return result; }
synchronized public boolean renamePointTo( int i, String newName ) { NamedPointWorld existing = get( newName ); if( existing == null ) { pointsWorld.get(i).setName( newName ); return true; } else { return false; } }
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; }
boolean fineTune( int i ) { NamedPointWorld p = points.get(i); if (p == null) { IJ.error("You must have set a point in order to fine-tune it."); return false; } return fineTune( p ); }
public void useFineTuneResult( RegistrationResult r ) { if( r != null ) { NamedPointWorld point = points.get( indexOfPointBeingFineTuned ); point.x = r.point_would_be_moved_to_x; point.y = r.point_would_be_moved_to_y; point.z = r.point_would_be_moved_to_z; point.set = true; System.out.println("Got a result, changed point to: "+point); unsaved = true; if( dialog != null ) { dialog.setCoordinateLabel( indexOfPointBeingFineTuned, point.x, point.y, point.z ); dialog.pack(); } } progressWindow = null; }
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; }
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();
System.out.println("Point is now: "+points.get( indexOfPointBeingFineTuned ).toString()); fineTuning = false;
void delete(int i) { String name = points.get(i).getName(); YesNoCancelDialog d = new YesNoCancelDialog( IJ.getInstance(), "Really delete?", "Do you really want to delete the point \""+name+"\"?" ); if( d.yesPressed() ) { points.delete(i); dialog.recreatePointsPanel(); dialog.pack(); } }
dialog.pack(); NamedPointWorld point = points.get(i); point.set( xWorld, yWorld, zWorld );
NamedPointWorld guessedPoint = points.get( name );
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 + "\"" ); } }