Search in sources :

Example 66 with ArrayUtil

use of mcib3d.utils.ArrayUtil in project mcib3d-core by mcib3d.

the class TrackThreshold method computeAssociation.

private ArrayList<ObjectTrack> computeAssociation(ArrayList<ObjectTrack> frame1, ArrayList<ObjectTrack> frame2, ArrayList<ObjectTrack> allFrames, ImageHandler labels2) {
    HashMap<Integer, ObjectTrack> hashObjectsT2 = new HashMap<Integer, ObjectTrack>();
    for (ObjectTrack objectTrack : frame2) {
        hashObjectsT2.put(objectTrack.getObject3D().getValue(), objectTrack);
    }
    // create association
    ArrayList<ObjectTrack> newListTrack = new ArrayList<ObjectTrack>();
    for (ObjectTrack obt : frame1) {
        // IJ.log("testing asso " + obt + " " + obt.getObject3D());
        ArrayUtil list = obt.getObject3D().listValues(labels2, 0);
        // no association
        if (list.isEmpty()) {
        } else {
            list = list.distinctValues();
            // association 1<->1
            if (list.size() == 1) {
                ObjectTrack child = hashObjectsT2.get((int) list.getValue(0));
                if ((child != null) && (obt.volume > child.volume)) {
                    // was >
                    // IJ.log("adding one child " + obt + " " + child);
                    obt.addChild(child);
                    child.setParent(obt);
                    allFrames.add(child);
                    // test
                    newListTrack.add(child);
                    frame2.remove(child);
                    obt.setObject3D(null);
                }
                if ((child != null) && (obt.volume == child.volume)) {
                    // IJ.log("adding same volume " + obt + " " + child);
                    newListTrack.add(obt);
                    frame2.remove(child);
                    treeSet.remove(child);
                }
            } else // association 1<->n
            if (list.size() > 1) {
                for (int i = 0; i < list.size(); i++) {
                    ObjectTrack child = hashObjectsT2.get((int) list.getValue(i));
                    if ((child != null)) {
                        // IJ.log("adding two child " + obt + " " + child);
                        obt.addChild(child);
                        child.setParent(obt);
                        newListTrack.add(child);
                        allFrames.add(child);
                        frame2.remove(child);
                        obt.setObject3D(null);
                    }
                }
            }
        }
    }
    // add all new objects from T2
    for (ObjectTrack objectTrack : frame2) allFrames.add(objectTrack);
    newListTrack.addAll(frame2);
    return newListTrack;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayUtil(mcib3d.utils.ArrayUtil)

Aggregations

ArrayUtil (mcib3d.utils.ArrayUtil)66 ArrayList (java.util.ArrayList)9 Iterator (java.util.Iterator)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Voxel3D (mcib3d.geom.Voxel3D)2 Voxel3DComparable (mcib3d.geom.Voxel3DComparable)2 RoiManager (ij.plugin.frame.RoiManager)1 HashMap (java.util.HashMap)1 Random (java.util.Random)1 Point3D (mcib3d.geom.Point3D)1 Vector3D (mcib3d.geom.Vector3D)1 ImageInt (mcib3d.image3d.ImageInt)1