View Javadoc
1   package com.github.celldynamics.quimp.plugin.qanalysis;
2   
3   import org.slf4j.Logger;
4   import org.slf4j.LoggerFactory;
5   
6   import com.github.celldynamics.quimp.QColor;
7   import com.github.celldynamics.quimp.utils.QuimPArrayUtils;
8   
9   /**
10   * Hold fluorescence map for given channel together with indexed colors.
11   * 
12   * @author rtyson
13   */
14  
15  public class FluoMap {
16  
17    /**
18     * The Constant LOGGER.
19     */
20    static final Logger LOGGER = LoggerFactory.getLogger(FluoMap.class.getName());
21    /**
22     * Number of frames. Part of QCONF.
23     */
24    private int T;
25    /**
26     * Horizontal resolution (points of outline). Part of QCONF.
27     */
28    private int res;
29    /**
30     * Fluorescence channel kept in this object. Part of QCONF.
31     */
32    private int channel;
33    /**
34     * Fluorescence map [time points][outline points]. Part of QCONF.
35     */
36    private double[][] map;
37    /**
38     * Colors for intensities stored in map.
39     * 
40     * <p>1D array is mapped to map[tt][p] as pN = (tt * res) + p;
41     * Part of QCONF.
42     */
43    byte[] fluColor;
44    /**
45     * If no data switch false. Part of QCONF.
46     */
47    boolean enabled;
48  
49    /**
50     * Copy constructor.
51     * 
52     * @param src source object
53     */
54    public FluoMapynamics/quimp/plugin/qanalysis/FluoMap.html#FluoMap">FluoMap(final FluoMap src) {
55      this.T = src.T;
56      this.res = src.res;
57      this.channel = src.channel;
58      this.map = QuimPArrayUtils.copy2darray(src.map, null);
59      this.fluColor = new byte[src.fluColor.length];
60      System.arraycopy(src.fluColor, 0, this.fluColor, 0, src.fluColor.length);
61      this.enabled = src.enabled;
62    }
63  
64    /**
65     * Constructor.
66     * 
67     * @param t number of time points
68     * @param r resolution
69     * @param i channel
70     */
71    public FluoMap(int t, int r, int i) {
72      T = t;
73      res = r;
74      channel = i;
75      enabled = true;
76      map = new double[T][res];
77      fluColor = new byte[T * res];
78    }
79  
80    /**
81     * Enables this map.
82     * 
83     * @param b status
84     */
85    public void setEnabled(boolean b) {
86      enabled = b;
87    }
88  
89    /**
90     * Check if enabled.
91     * 
92     * @return true if enabled
93     */
94    public boolean isEnabled() {
95      return enabled;
96    }
97  
98    /**
99     * Put value to fluoromap calculating correct color.
100    * 
101    * @param t time
102    * @param p membrane pixel
103    * @param pn linear index for <tt>fluColor</tt>
104    * @param intensity fluoroscence intensity to store at <tt>map</tt>
105    * @param max value to scale to colors
106    * @see #recalculateColorScale(double)
107    */
108   public void fill(int t, int p, int pn, double intensity, double max) {
109     map[t][p] = intensity;
110     fluColor[pn] = (byte) QColor.bwScale(intensity, 256, max, 0); // don't bother scaling
111   }
112 
113   /**
114    * Recalculate colors for <tt>map</tt> array.
115    * 
116    * @param max Value to scale to colors. Usually it is maximum of map.
117    * @see #fill(int, int, int, double, double)
118    */
119   public void recalculateColorScale(double max) {
120     LOGGER.debug("Recalculate fluColor, max=" + max + " enabled state:" + isEnabled());
121     if (!isEnabled()) {
122       return; // do not if not enabled (e.g. not initialized)
123     }
124     int pn;
125     double intensity;
126     for (int r = 0; r < res; r++) {
127       for (int t = 0; t < T; t++) {
128         pn = t * res + r;
129         intensity = map[t][r];
130         fluColor[pn] = (byte) QColor.bwScale(intensity, 256, max, 0);
131       }
132     }
133 
134   }
135 
136   /**
137    * getColours.
138    * 
139    * @return fluColor
140    */
141   public byte[] getColours() {
142     return fluColor;
143   }
144 
145   /**
146    * getMap.
147    * 
148    * @return map
149    */
150   public double[][] getMap() {
151     return map;
152   }
153 
154   /**
155    * getChannel.
156    * 
157    * @return the channel
158    */
159   public int getChannel() {
160     return channel;
161   }
162 
163   /**
164    * Set new fluorescence map calculating also adequate colorscale. Set this map enabled.
165    * 
166    * @param map the map to set
167    */
168   public void setMap(double[][] map) {
169     this.map = map;
170     recalculateColorScale(QuimPArrayUtils.array2dMax(map));
171     setEnabled(true);
172     T = map.length;
173     res = map[0].length;
174   }
175 }