Fixed potential threading issue with Swing and the Layer panels when
[trakem2.git] / mpi / fruitfly / registration / PointMatch.java
blob85465c822b170491c2ed62f7c855d08f5c352295
1 package mpi.fruitfly.registration;
3 import java.util.ArrayList;
4 import java.util.Collection;
6 public class PointMatch
8 final private Point p1;
9 final public Point getP1() { return p1; }
11 final private Point p2;
12 final public Point getP2() { return p2; }
14 private float weight;
15 final public float getWeight(){ return weight; }
16 final public void setWeight( float weight ){ this.weight = weight; }
18 private float distance;
19 final public float getDistance(){ return distance; }
21 public PointMatch(
22 Point p1,
23 Point p2,
24 float weight )
26 this.p1 = p1;
27 this.p2 = p2;
29 this.weight = weight;
31 distance = Point.distance( p1, p2 );
34 public PointMatch(
35 Point p1,
36 Point p2 )
38 this.p1 = p1;
39 this.p2 = p2;
41 weight = 1.0f;
43 distance = Point.distance( p1, p2 );
46 /**
47 * apply a model to p1, update distance
49 * @param model
51 final public void apply( Model model )
53 p1.apply( model );
54 distance = Point.distance( p1, p2 );
57 /**
58 * convert from Matches, weight is 1.0
60 * @param matches
61 * @return
63 final public static ArrayList< PointMatch > fromMatches( Collection< Match > matches )
65 ArrayList< PointMatch > list = new ArrayList< PointMatch >();
66 for ( Match match : matches )
68 list.add(
69 new PointMatch(
70 new Point( match.p1 ),
71 new Point( match.p2 ) ) );
73 return list;
76 /**
77 * convert to Matches using the world coordinates, weight gets lost
79 * @param matches
80 * @return
82 final public static ArrayList< Match > toMatches( Collection< PointMatch > matches )
84 ArrayList< Match > list = new ArrayList< Match >();
85 for ( PointMatch match : matches )
87 list.add(
88 new Match(
89 match.p1.getW(),
90 match.p2.getW() ) );
92 return list;
95 final public static ArrayList< Match > toLocalMatches( Collection< PointMatch > matches )
97 ArrayList< Match > list = new ArrayList< Match >();
98 for ( PointMatch match : matches )
100 list.add(
101 new Match(
102 match.p2.getW(),
103 match.p1.getL() ) );
105 return list;
109 * flip symmetrically, weight remains unchanged
111 * @param matches
112 * @return
114 final public static ArrayList< PointMatch > flip( Collection< PointMatch > matches )
116 ArrayList< PointMatch > list = new ArrayList< PointMatch >();
117 for ( PointMatch match : matches )
119 list.add(
120 new PointMatch(
121 match.p2,
122 match.p1,
123 match.weight ) );
125 return list;