Commit fe63cc2c authored by Andrew Cohen's avatar Andrew Cohen

setTrackID and patch use tblFamilies with null child2

parent 1e2f5fdd
......@@ -40,7 +40,7 @@ function updateManualEdit(lDB,cellID,time,trackID,userID,fnCallback)
lDB.all(sqlCmd,function(err,rows) {
if (err)
console.error('updateManualEdit: '+err);
var cellID_src=-1;
var cellID_src=cellID;
if (rows.length>0){
// find the closest smaller time
var iClosest=-1;
......@@ -60,13 +60,18 @@ function updateManualEdit(lDB,cellID,time,trackID,userID,fnCallback)
sqlCmd='INSERT OR REPLACE INTO tblManualEdits(cellID_src,cellID_dst,dateTime,userID) VALUES ('+cellID_src+
','+cellID+',datetime("now","localtime"),"'+userID+'")';
lDB.run(sqlCmd, function(){
if (undefined!==fnCallback)
fnCallback();
// finally, put the trackID change into tblFamilies
sqlCmd='INSERT OR REPLACE INTO tblFamilies values('+cellID_src+','+cellID+',null)';
lDB.run(sqlCmd,function(){
if (undefined!==fnCallback)
fnCallback();
})
});
});
})
});
} // updateManualEditTable
} // updateManualEditTable
// helper for changeTrackID
function setTrackID(lDB,cellID,trackID)
......@@ -163,6 +168,8 @@ function changeTrackID(lDB, leverCommand, fnCallback)
replaceTrackID=rows[0].cellID;
}
setTrackIDForward(lDB,newTrackID,oldTrackID,replaceTrackID,time);
if (undefined===user)
user='Electron User';
updateManualEdit(lDB,cellID,time,newTrackID,user,function(){
......@@ -615,7 +622,7 @@ function recurseGetFileList(leverFolder)
if ('.LEVER' === path.extname(flist[f])) {
leverFileNames.push(fname);
}
else if (''===path.extname(fname) && fs.lstatSync(fname).isDirectory()) {
else if (''===path.extname(fname) && fs.statSync(fname).isDirectory()) {
// see if the fname folder is an image folder for a .lever file in this folder, save some recursing
for (var j=0;j<flist.length;j++){
var bSkip=false;
......
......@@ -189,15 +189,16 @@ double getHullDistance(int hull1, int hull2)
} //getHullDistance
// we have a track connection in tblManualEdits. Write that back to the db right meow.
int OverRideTrackID(Hull *pNewHull, int cellID_src)
int OverRideTrackID(Hull *pNewHull, int cellID_parent,int cellID_child1,int cellID_child2)
{
int rc;
memset(gszSqlCmd, 0, 1024);
sprintf(gszSqlCmd, "Update tblCells set trackID = (select trackID from tblCells where cellID = %d) where cellID = %d",
cellID_src, pNewHull->get_cellID());
cellID_parent, pNewHull->get_cellID());
rc = dbExec(gszSqlCmd, NULL, NULL, "OverRideTrackID");
gOverRideTrackIDs[cellID_src]=pNewHull->get_cellID();
gOverRideTrackIDs[cellID_parent]=pNewHull->get_cellID();
return rc;
} // OverRideTrackID
......@@ -207,7 +208,8 @@ int OverRideTrackID(Hull *pNewHull, int cellID_src)
// it also stashes a pointer to newhull in the hashedhulls slot for the time frame
static int getCellsCallback(void *pvnull, int argc, char **argv, char **azColName) {
int i;
int nscan, cellID = 0, trackID = -1, time = -1, nOverRide = -1, nParent=-1;
int nscan, cellID = 0, trackID = -1, time = -1;
int nChild1 = -1,nChild2 = -1,nParent = -1;
int area=0;
float centroid[3] = { 0, 0, 0 };
Hull newHull;
......@@ -233,9 +235,14 @@ static int getCellsCallback(void *pvnull, int argc, char **argv, char **azColNam
else if (0 == strcmp(azColName[i], "area")) {
area = atoi(argv[i]);;
}
else if (0 == strcmp(azColName[i], "cellID_override")) {
else if (0 == strcmp(azColName[i], "cellID_child1")) {
if (NULL != argv[i]) {
nChild1 = atoi(argv[i]);
}
}
else if (0 == strcmp(azColName[i], "cellID_child2")) {
if (NULL != argv[i]) {
nOverRide = atoi(argv[i]);
nChild2 = atoi(argv[i]);
}
}
else if (0 == strcmp(azColName[i], "cellID_parent")) {
......@@ -253,11 +260,11 @@ static int getCellsCallback(void *pvnull, int argc, char **argv, char **azColNam
newHull.set_time(time);
newHull.setNumPixels(area);
newHull.setParent(nParent);
newHull.setOverride(nOverRide);
newHull.setOverride(nChild2);
// if not mitotic, and there's a track override, set the override
if ( (nParent<0) && (nOverRide >= 0)) {
if (nParent>=0) {
// else if there's a manual edit, we set its trackID to the overrideID
OverRideTrackID(&newHull, nOverRide);
OverRideTrackID(&newHull, nParent,nChild1, nChild2);
}
newHull.init_trackID(trackID);
......@@ -282,9 +289,8 @@ int readCells(int t, cmdElement * pcmd)
memset(gszSqlCmd, 0, 1024);
sprintf(gszSqlCmd, "SELECT cellID, trackID, time, centroid, area, tblManualEdits.cellID_src as cellID_override, cellID_parent from tblCells "
"LEFT JOIN tblManualEdits ON tblManualEdits.cellID_dst = cellID "
"LEFT JOIN tblFamilies ON tblFamilies.cellID_child1 = cellID OR tblFamilies.cellID_child2 = cellID "
sprintf(gszSqlCmd, "SELECT cellID, trackID, time, centroid, area, cellID_parent, cellID_child1, cellID_child2 from tblCells "
"LEFT JOIN tblFamilies ON cellID_child1 = cellID OR cellID_child2 = cellID "
"WHERE time BETWEEN %d AND %d", t - gWindowSize, t + gWindowSize);
rc = dbExec(gszSqlCmd, getCellsCallback, NULL, "getCells");
......@@ -327,7 +333,8 @@ int ResetTrackIDs(int time)
memset(gszSqlCmd, 0, 1024);
// add
time = time + 1; // db time is 1 based, matdb time is 0 based. add 1 here.
sprintf(gszSqlCmd, "Update tblCells set trackID = cellID where time= %d", time);
sprintf(gszSqlCmd, "Update tblCells set trackID = cellID where time= %d and cellID not in "
" (select cellID_child1 from tblFamilies where cellID_child2=null)", time);
rc = dbExec(gszSqlCmd, NULL, NULL, "ResetTrackIDs");
return rc;
......@@ -358,8 +365,9 @@ int goTrack(cmdElement * pcmd)
}
else {
gWindowSize = WINDOW_SIZE_DEFAULT;
// ResetTrackIDs(t + 1);
//
}
ResetTrackIDs(t + 1);
// put database into write mode -- we turn this off below after we finish tracking and update the command to indicate we're done
SetTransactionDB("BEGIN");
trackHulls(t);
......
function resegPatch(conn,tReseg,CONSTANTS)
% patch 1->2 scenarios
% object A (on extFamily) at time t has first choice object B at t+1.
% first, undo any patches that originate in frame tReseg-1 or tReseg-2
cmd=['delete from tblFamilies where rowid in (select tblFamilies.rowid from tblCells '...
' inner join tblFamilies on cellID_parent=cellID where cellID_child2 IS NULL and time='...
num2str(tReseg-1) ' or time=' num2str(tReseg-2) ...
' and cellID_parent not in (select cellID_src from tblManualEdits))'];
exec(conn,cmd);
% object A at time t has first choice object B at t+1.
% Object B is untracked. Object B's second choice is A. then patch A->B
% tracks that end in the previous frame
cmd=['select * from (select max(time) as t1,cellID,trackID from tblCells group by trackID) where t1='...
num2str(tReseg-1) ' or t1=' num2str(tReseg-2)];
num2str(tReseg-1) ' or t1=' num2str(tReseg-2)...
' and cellID not in (select cellID_src from tblManualEdits)'];
q=fetch(conn,cmd);
if isempty(q)
return
......@@ -13,7 +22,8 @@ end
srcTracks=cell2mat(q);
% tracks that start in this frame
cmd=['select cellID,time from tblCells where cellID=trackID and time>='...
num2str(tReseg-5) ' and time<=' num2str(tReseg+1)];
num2str(tReseg-5) ' and time<=' num2str(tReseg+1) ...
' and cellID not in (select cellID_dst from tblManualEdits)'];
q=fetch(conn,cmd);
if isempty(q)
return
......@@ -61,6 +71,11 @@ for i=1:size(srcTracks,1)
cmd=['update tblCells set TrackID=' num2str(tidSrc) ' where trackID=' num2str(tidDst)...
' and time>=' num2str(tReseg)];
exec(conn,cmd);
% write the patch into the tblFamilies
cmd=['insert into tblFamilies values(' num2str(cidSrc) ',' num2str(cidDst) ...
',null)'];
exec(conn,cmd);
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment