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;
}
Aggregations