Skip to content

Commit

Permalink
Merge branch 'feature/T1_long_array' into feature/manual_tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
davhel committed Apr 21, 2017
2 parents 77950fa + 8ecfcdf commit c8b7e93
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 30 deletions.
21 changes: 12 additions & 9 deletions CellGraph/src/headless/DetectT1Transition.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static void main(String[] args){

System.out.println("\nAnalyzing the cell edges..");
EdgeTracking edgeTracking = new EdgeTracking(stGraph, 0);
HashMap<Long, boolean[]> tracked_edges = edgeTracking.trackEdges();
HashMap<Long, Long[]> tracked_edges = edgeTracking.trackEdges();

//saveStableEdgesToCSV(stGraph, tracked_edges);

Expand All @@ -65,10 +65,10 @@ public static void main(String[] args){
* @param tracked_edges a Map containing a boolean presence array for every edgeID for every frame
*/
public static void saveStableEdgesToCSV(SpatioTemporalGraph stGraph,
HashMap<Long, boolean[]> tracked_edges) {
HashMap<Long, Long[]> tracked_edges) {
StringBuilder builder = new StringBuilder();
for(long track_code:tracked_edges.keySet()){
boolean[] edge_track = tracked_edges.get(track_code);
Long[] edge_track = tracked_edges.get(track_code);

if(hasStableTrack(edge_track)){
int[] cell_ids = Edge.getCodePair(track_code);
Expand Down Expand Up @@ -106,9 +106,9 @@ public static void saveStableEdgesToCSV(SpatioTemporalGraph stGraph,
CsvWriter.writeOutBuilder(builder, main_output_file);
}

public static boolean hasStableTrack(boolean[] edge_track){
for(boolean tracked_in_frame_i: edge_track)
if(!tracked_in_frame_i)
public static boolean hasStableTrack(Long[] edge_track){
for(Long tracked_in_frame_i: edge_track)
if(tracked_in_frame_i == null)
return false;

return true;
Expand All @@ -129,7 +129,7 @@ public static boolean hasStableTrack(boolean[] edge_track){
public static ArrayList<T1Transition> findTransitions(
SpatioTemporalGraph stGraph,
HashMap<Node, PolygonalCellTile> cell_tiles,
HashMap<Long, boolean[]> tracked_edges,
HashMap<Long, Long[]> tracked_edges,
int minimalTransitionLength,
int minimalOldEdgeSurvivalLength,
int starting_frame
Expand All @@ -142,7 +142,7 @@ public static ArrayList<T1Transition> findTransitions(

edge_loop:
for(long track_code:tracked_edges.keySet()){
boolean[] edge_track = tracked_edges.get(track_code);
Long[] edge_track = tracked_edges.get(track_code);

if(!hasStableTrack(edge_track)){
//determine whether a persistent Edge Change occurred
Expand Down Expand Up @@ -186,7 +186,7 @@ public static ArrayList<T1Transition> findTransitions(
else if(stGraph.getFrame(0).hasTrackID(track_id))
if(stGraph.getFrame(0).getNode(track_id).hasObservedDivision()){
divisions_with_transitions.add(transition);
continue edge_loop;
//continue edge_loop;
}
}

Expand All @@ -213,6 +213,9 @@ else if(stGraph.getFrame(0).hasTrackID(track_id))
}

}

for(T1Transition t1: divisions_with_transitions)
System.out.println("T1wDivision:\n"+t1.toString());

return stable_transitions;
}
Expand Down
26 changes: 20 additions & 6 deletions CellGraph/src/plugins/davhelle/cellgraph/misc/T1Transition.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import plugins.davhelle.cellgraph.graphs.FrameGraph;
import plugins.davhelle.cellgraph.graphs.SpatioTemporalGraph;
import plugins.davhelle.cellgraph.nodes.Edge;
import plugins.davhelle.cellgraph.nodes.Node;

import com.vividsolutions.jts.geom.Geometry;
Expand Down Expand Up @@ -33,7 +34,7 @@ public class T1Transition {
* presence or absence of the old
* edge
*/
boolean[] lostEdgeTrack;
Long[] lostEdgeTrack;

/**
* Store when the first stable transition
Expand Down Expand Up @@ -65,7 +66,7 @@ public class T1Transition {
* @param pair track ids of parent nodes
* @param edge_track presence array for each time point in the stGraph
*/
public T1Transition(SpatioTemporalGraph stGraph, int[] pair, boolean[] edge_track, int starting_frame) {
public T1Transition(SpatioTemporalGraph stGraph, int[] pair, Long[] edge_track, int starting_frame) {

this.stGraph = stGraph;
this.lostEdgeTrack = edge_track;
Expand All @@ -91,7 +92,7 @@ public T1Transition(SpatioTemporalGraph stGraph, int[] pair, boolean[] edge_trac
private int findFirstMissingFrameNo(){

for(int i=0; i<lostEdgeTrack.length; i++)
if(!lostEdgeTrack[i])
if(lostEdgeTrack[i] == null)
return i + startingFrame;

return -1;
Expand All @@ -107,7 +108,7 @@ private int computeTransitionLength(){
//compute the transition vector, i.e. length of every transition
int[] transition_vector = new int[lostEdgeTrack.length];
for(int i=detectionTimePoint - startingFrame; i<lostEdgeTrack.length; i++)
if(!lostEdgeTrack[i]){
if(lostEdgeTrack[i] == null){
transition_vector[i] = transition_vector[i-1] + 1;
transition_vector[i-1] = 0;
}
Expand Down Expand Up @@ -200,7 +201,16 @@ public int getOldEdgeSurvivalLength() {
* @return true if the transition occurs on the border
*/
public boolean onBoundary(){
FrameGraph previous_frame = stGraph.getFrame(detectionTimePoint - 1);

int previous_frame_no = detectionTimePoint - 1;

FrameGraph previous_frame = stGraph.getFrame(previous_frame_no);

// get the actual tracking code from the array
int[] loserNodes = Edge.getCodePair(lostEdgeTrack[previous_frame_no - startingFrame]);

assert previous_frame.hasTrackID(loserNodes[0]): "Looser node not found in previous frame";
assert previous_frame.hasTrackID(loserNodes[1]): "Looser node not found in previous frame";

Node l1 = previous_frame.getNode(loserNodes[0]);
Node l2 = previous_frame.getNode(loserNodes[1]);
Expand All @@ -218,7 +228,11 @@ public boolean onBoundary(){
*/
public void findSideGain(HashMap<Node, PolygonalCellTile> cell_tiles) {

FrameGraph previous_frame = stGraph.getFrame(detectionTimePoint - 1);
int previous_frame_no = detectionTimePoint - 1;
FrameGraph previous_frame = stGraph.getFrame(previous_frame_no);

// get the actual tracking code from the array
int[] loserNodes = Edge.getCodePair(lostEdgeTrack[previous_frame_no - startingFrame]);

assert previous_frame.hasTrackID(loserNodes[0]): "Looser node not found in previous frame";
assert previous_frame.hasTrackID(loserNodes[1]): "Looser node not found in previous frame";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public TransitionOverlay(SpatioTemporalGraph stGraph, CellOverlay plugin) {
//TODO move createPolygonalTiles to PolygonalCellTile class
HashMap<Node, PolygonalCellTile> cell_tiles = PolygonalCellTileGenerator.createPolygonalTiles(stGraph,plugin);
EdgeTracking edgeTracking = new EdgeTracking(stGraph, plugin.varT1StartingFrame.getValue());
HashMap<Long, boolean[]> tracked_edges = edgeTracking.trackEdges(plugin);
HashMap<Long, Long[]> tracked_edges = edgeTracking.trackEdges(plugin);

plugin.getUI().setProgressBarMessage("Analyzing Transitions..");
this.transitions = DetectT1Transition.findTransitions(
Expand Down
95 changes: 81 additions & 14 deletions CellGraph/src/plugins/davhelle/cellgraph/tracking/EdgeTracking.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
public class EdgeTracking {

HashMap<Long, boolean[]> tracked_edges;
HashMap<Long, Long[]> tracked_edges;
SpatioTemporalGraph stGraph;
int starting_frame_no;

Expand All @@ -37,7 +37,7 @@ public class EdgeTracking {
* @param startingFrameNo the frame at which to start the tracking
*/
public EdgeTracking(SpatioTemporalGraph stGraph, int startingFrameNo){
tracked_edges = new HashMap<Long,boolean[]>();
tracked_edges = new HashMap<Long,Long[]>();
this.stGraph = stGraph;
this.starting_frame_no = startingFrameNo;
}
Expand All @@ -49,7 +49,7 @@ public EdgeTracking(SpatioTemporalGraph stGraph, int startingFrameNo){
* tells if the edge is present or not at the corresponding time point. The key of the map is
* the cantor paring of the edges vertex ids.
*/
public HashMap<Long, boolean[]> trackEdges(){
public HashMap<Long, Long[]> trackEdges(){

initializeTrackedEdges();
for(int i=1; i<stGraph.size(); i++)
Expand All @@ -66,7 +66,7 @@ public HashMap<Long, boolean[]> trackEdges(){
* tells if the edge is present or not at the corresponding time point. The key of the map is
* the cantor paring of the edges vertex ids.
*/
public HashMap<Long, boolean[]> trackEdges(CellOverlay plugin) {
public HashMap<Long, Long[]> trackEdges(CellOverlay plugin) {

plugin.getUI().setProgressBarMessage("Tracking Edges..");
plugin.getUI().setProgressBarValue(0.0);
Expand All @@ -88,8 +88,8 @@ private void initializeTrackedEdges() {
for(Edge e: first_frame.edgeSet())
if(e.canBeTracked(first_frame)){
long track_code = e.getPairCode(first_frame);
tracked_edges.put(track_code, new boolean[stGraph.size() - starting_frame_no]);
tracked_edges.get(track_code)[0] = true;
tracked_edges.put(track_code, new Long[stGraph.size() - starting_frame_no]);
tracked_edges.get(track_code)[0] = track_code;
}
}

Expand All @@ -115,23 +115,62 @@ private void analyzeFrame(int i) {
*/
private void trackEdgesInFrame(FrameGraph frame_i) {

for(Edge e: frame_i.edgeSet())
for(Edge e: frame_i.edgeSet()){
if(e.canBeTracked(frame_i)){
long edge_track_code = e.getPairCode(frame_i);

if(tracked_edges.containsKey(edge_track_code)){

boolean[] oldArray = tracked_edges.get(edge_track_code);
Long[] oldArray = tracked_edges.get(edge_track_code);

int correctedFrameNo = frame_i.getFrameNo() - starting_frame_no;
if(oldArray.length < correctedFrameNo )
continue;
else
tracked_edges.get(edge_track_code)[correctedFrameNo] = true;
tracked_edges.get(edge_track_code)[correctedFrameNo] = edge_track_code;

}else {

//did source or target divide? => changing the ids
Node target = frame_i.getEdgeTarget(e);
Node source = frame_i.getEdgeSource(e);

Long old_track_code = null;

int source_id = source.getTrackID();
int target_id = target.getTrackID();

//1. Both cells divide
if(target.hasObservedDivision() && source.hasObservedDivision())
old_track_code = Edge.computePairCode(
target.getDivision().getMother().getTrackID(),
source.getDivision().getMother().getTrackID());
else if(target.hasObservedDivision()) {
old_track_code = Edge.computePairCode(
target.getDivision().getMother().getTrackID(),
source_id);
} else if(source.hasObservedDivision()) // only source divides
old_track_code = Edge.computePairCode(
target_id,
source.getDivision().getMother().getTrackID());

if(old_track_code != null){
if (tracked_edges.containsKey(old_track_code)){
Long[] oldArray = tracked_edges.get(old_track_code);

int correctedFrameNo = frame_i.getFrameNo() - starting_frame_no;
if(oldArray.length < correctedFrameNo )
continue;
else
tracked_edges.get(old_track_code)[correctedFrameNo] = edge_track_code;

}
}
}
}
}
}
}


/**
* Eliminates the edges that are not found because
Expand All @@ -156,20 +195,48 @@ private void removeUntrackedEdges(

for(long track_code:tracked_edges.keySet()){

int a = Edge.getCodePair(track_code)[0];
int b = Edge.getCodePair(track_code)[1];

// skip edge arrays that have been resized
boolean[] oldArray = tracked_edges.get(track_code);
Long[] oldArray = tracked_edges.get(track_code);
if(oldArray.length < i_adjusted )
continue;

for(int track_id: Edge.getCodePair(track_code)) //Edge tuple (v1,v2)
Long edge_code_i = oldArray[i_adjusted];
if(edge_code_i == null){
//find the last time frame at which the edge was seen
for(int i=1; i <= i_adjusted; i++){
edge_code_i = oldArray[i_adjusted - i];
if(edge_code_i != null)
break;
}

if(edge_code_i == null){
System.out.printf("Null code for %d [%d,%d] @ %d\n",
track_code, a, b, i_adjusted - 1);
}
}

for(int track_id: Edge.getCodePair(edge_code_i)) //Edge tuple (v1,v2)
if(!frame_i.hasTrackID(track_id)){ // vertex is missing

// check previous frames whether cell is on the boundary
assert frame_pre.hasTrackID(track_id): String.format(
"Missing cell %d at frame %d",track_id, preNo_adjusted + starting_frame_no);
Node pre = frame_pre.getNode(track_id);

if(pre.onBoundary())
if(pre == null){
//try to rescue
FrameGraph frame0 = stGraph.getFrame(starting_frame_no);
pre = frame0.getNode(track_id);
}

if(pre.hasObservedElimination())
to_resize.add(track_code);
else if(pre.hasObservedDivision())
to_resize.add(track_code);
else if(pre.onBoundary())
to_resize.add(track_code);
else
to_eliminate.add(track_code);
Expand All @@ -180,7 +247,7 @@ private void removeUntrackedEdges(

// re-scale boolean array in case the cell just went out from the boundary
for(long track_code:to_resize){
boolean[] oldArray = tracked_edges.get(track_code);
Long[] oldArray = tracked_edges.get(track_code);
tracked_edges.put(track_code, Arrays.copyOfRange(oldArray, 0, preNo_adjusted));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,12 @@ private void division_recognition(Stack<Node> unmarried_brides, Stack<Node> unma
Node brother2 = bestBrotherCandidate.getNode();
Node mother = brother2.getPrevious();

if (mother.getFirst().onBoundary() && brother1.onBoundary() && brother2.onBoundary()){
System.out.printf("Frame %d: Suppressed division detection on boundary @ [%.0f,%.0f]\n",
time_point,untracked.getCentroid().getX(),untracked.getCentroid().getY());
continue;
}

//Geometry acronyms
//TODO extend use downwards
Geometry b1 = brother1.getGeometry();
Expand Down

0 comments on commit c8b7e93

Please sign in to comment.