View Javadoc
1   package com.github.celldynamics.quimp.filesystem;
2   
3   import java.util.ArrayList;
4   
5   import org.slf4j.Logger;
6   import org.slf4j.LoggerFactory;
7   
8   import com.github.celldynamics.quimp.OutlineHandler;
9   
10  /**
11   * Represent collection of OutlineHandlers for cells.
12   * 
13   * <p>This class is used as storage of OutlineHandlers (results of continuous segmentation) in
14   * {@link com.github.celldynamics.quimp.filesystem.DataContainer}.
15   * 
16   * @author p.baniukiewicz
17   *
18   */
19  public class OutlinesCollection implements IQuimpSerialize {
20  
21    /**
22     * The Constant LOGGER.
23     */
24    static final Logger LOGGER = LoggerFactory.getLogger(OutlinesCollection.class.getName());
25    /**
26     * Contain {@link OutlineHandler} objects.
27     * 
28     * <p>Each object ({@link OutlineHandler} represents segmented cell (outline) between frame
29     * <it>f1</it> and <it>f2</it> but only if segmentation process run continuously between these
30     * frames. Outlines are returned by of ECMM module and they are almost the same as Snakes but
31     * may differ in node order or number.
32     * 
33     */
34    public ArrayList<OutlineHandler> oHs;
35  
36    /**
37     * Instantiates a new outlines collection.
38     *
39     * @param size the size
40     */
41    public OutlinesCollection(int size) {
42      oHs = new ArrayList<>(size);
43    }
44  
45    /**
46     * Instantiates a new outlines collection.
47     */
48    public OutlinesCollection() {
49      oHs = new ArrayList<>();
50    }
51  
52    /**
53     * Prepare Outlines for serialization. Build arrays from Outline objects stored in
54     * OutlineHandlers
55     */
56    @Override
57    public void beforeSerialize() {
58      if (oHs != null) {
59        for (OutlineHandler oh : oHs) {
60          oh.beforeSerialize();
61        }
62      }
63    }
64  
65    /**
66     * Rebuild every Outline from temporary array.
67     */
68    @Override
69    public void afterSerialize() throws Exception {
70      if (oHs != null) {
71        for (OutlineHandler oh : oHs) {
72          oh.afterSerialize();
73        }
74      }
75    }
76  }