View Javadoc
1   package com.github.celldynamics.quimp.plugin.protanalysis;
2   
3   import java.awt.Point;
4   import java.awt.Polygon;
5   import java.awt.geom.Point2D;
6   import java.util.ArrayList;
7   import java.util.Collection;
8   import java.util.Iterator;
9   
10  import org.slf4j.Logger;
11  import org.slf4j.LoggerFactory;
12  
13  /**
14   * Hold one track line with additional parameters.
15   * 
16   * <p>In general x coordinate stands for frame and y for index.
17   * 
18   * @author p.baniukiewicz
19   * @see TrackMapAnalyser#trackMaxima(com.github.celldynamics.quimp.plugin.qanalysis.STmap, double,
20   *      MaximaFinder)
21   */
22  class Track extends ArrayList<Point> {
23    private static final long serialVersionUID = 8928704797702167155L;
24    static final Logger LOGGER = LoggerFactory.getLogger(Track.class.getName());
25  
26    /**
27     * Types of tracking lines.
28     * 
29     * @author p.baniukiewicz
30     *
31     */
32    public static enum TrackType {
33      BACKWARD, FORWARD, OTHER
34    }
35  
36    /**
37     * ID of tracking line. Every line in TrackCollection has different id.
38     */
39    private int id;
40    /**
41     * Parents (Ids) of this track.
42     */
43    private Point parents;
44    /**
45     * Type of track. OTHER is reserved for virtual tracks created from merging points.
46     */
47    TrackType type;
48  
49    public Track() {
50      super();
51      id = -1;
52      parents = null;
53    }
54  
55    public Track(int id, Point parents) {
56      this();
57      this.id = id;
58      this.parents = parents;
59    }
60  
61    public Track(Collection<? extends Point> c) {
62      super(c);
63      id = -1;
64      parents = null;
65    }
66  
67    public Track(Collection<? extends Point> c, int id, Point parents) {
68      this(c);
69      this.id = id;
70      this.parents = parents;
71    }
72  
73    /**
74     * Not in use due to similar structure as Track(int, Point).
75     * 
76     * @param initialCapacity initialCapacity
77     */
78    @SuppressWarnings("unused")
79    private Track(int initialCapacity) {
80      super(initialCapacity);
81      id = -1;
82      parents = null;
83    }
84  
85    /**
86     * Return track as polygon.
87     * 
88     * @return This Track as polygon.
89     */
90    public Polygon asPolygon() {
91      Iterator<Point> it = iterator();
92      Polygon ret = new Polygon();
93      while (it.hasNext()) {
94        Point p = it.next();
95        ret.addPoint(p.x, p.y);
96      }
97      return ret;
98    }
99  
100   /**
101    * Get xy coordinates of Track point according to xy maps.
102    * 
103    * @param index order of Track point
104    * @param xmap x-coordinates map compatible with
105    *        {@link com.github.celldynamics.quimp.plugin.qanalysis.STmap}
106    * @param ymap y-coordinates map compatible with
107    *        {@link com.github.celldynamics.quimp.plugin.qanalysis.STmap}
108    * @return Screen coordinates of Track point.
109    */
110   public Point2D.Double getXY(int index, double[][] xmap, double[][] ymap) {
111     Point p = get(index);
112     return new Point2D.Double(xmap[p.x][p.y], ymap[p.x][p.y]);
113   }
114 
115   /**
116    * Return frame for given index of Track point.
117    * 
118    * <p>Resolves correct mapping between coordinates.
119    * 
120    * @param index index of point
121    * @return Frame of this point
122    */
123   public int getFrame(int index) {
124     return get(index).x;
125   }
126 
127   /**
128    * Return outline index for given index of Track point.
129    * 
130    * <p>Resolves correct mapping between coordinates.
131    * 
132    * @param index index of point
133    * @return Outline index of this point
134    */
135   public int getOutline(int index) {
136     return get(index).y;
137   }
138 
139 }