Skip to content
Snippets Groups Projects
Commit 39e0e64f authored by Mark Winter's avatar Mark Winter
Browse files

Always reference count tracks and hulls in integrity check even if there are...

Always reference count tracks and hulls in integrity check even if there are errors in the family or track.
parent 3a970b19
No related branches found
No related tags found
No related merge requests found
...@@ -257,7 +257,25 @@ bool checkFamilySizes(mwIndex familyID) ...@@ -257,7 +257,25 @@ bool checkFamilySizes(mwIndex familyID)
return true; return true;
} }
bool checkTrackFamilyReferences(mwIndex familyID, std::vector<int>& trackRefCount) void addTrackFamilyReference(mwIndex familyID, std::vector<std::vector<int>>& trackRefCount)
{
mxArray* tracks = mxGetField(gCellFamilies, C_IDX(familyID), "tracks");
mwSize numTracks = mxGetNumberOfElements(tracks);
double* trackData = mxGetPr(tracks);
for ( mwSize i=0; i < numTracks; ++i )
{
mwIndex matTrackID = (mwIndex) trackData[i];
if ( MATLAB_IDX(matTrackID) >= mxGetNumberOfElements(gCellTracks) || (MATLAB_IDX(matTrackID) < 0) )
continue;
trackRefCount[MATLAB_IDX(matTrackID)].push_back(familyID+1);
}
}
bool checkTrackFamilyReferences(mwIndex familyID)
{ {
mxArray* rootTrackID = mxGetField(gCellFamilies, C_IDX(familyID), "rootTrackID"); mxArray* rootTrackID = mxGetField(gCellFamilies, C_IDX(familyID), "rootTrackID");
mxArray* tracks = mxGetField(gCellFamilies, C_IDX(familyID), "tracks"); mxArray* tracks = mxGetField(gCellFamilies, C_IDX(familyID), "tracks");
...@@ -281,8 +299,6 @@ bool checkTrackFamilyReferences(mwIndex familyID, std::vector<int>& trackRefCoun ...@@ -281,8 +299,6 @@ bool checkTrackFamilyReferences(mwIndex familyID, std::vector<int>& trackRefCoun
return false; return false;
} }
++trackRefCount[MATLAB_IDX(matTrackID)];
if ( gTrackErrors.count(MATLAB_IDX(matTrackID)) > 0 ) if ( gTrackErrors.count(MATLAB_IDX(matTrackID)) > 0 )
{ {
//char errMsg[errBufSize]; //char errMsg[errBufSize];
...@@ -581,7 +597,27 @@ int findTrackID(mwIndex matHullID) ...@@ -581,7 +597,27 @@ int findTrackID(mwIndex matHullID)
return -1; return -1;
} }
bool checkHullReferences(mwIndex trackID, std::vector<int>& hullRefCount) void addHullReference(mwIndex trackID, std::vector<std::vector<int>>& hullRefCount)
{
mxArray* trackHulls = mxGetField(gCellTracks, C_IDX(trackID), "hulls");
mwSize numHulls = mxGetNumberOfElements(trackHulls);
double* hullData = mxGetPr(trackHulls);
for ( mwIndex i=0; i < numHulls; ++i )
{
mwIndex matHullID = (mwIndex) hullData[i];
if ( matHullID == 0 )
continue;
if ( MATLAB_IDX(matHullID) >= mxGetNumberOfElements(gCellHulls) || (MATLAB_IDX(matHullID) < 0) )
continue;
hullRefCount[MATLAB_IDX(matHullID)].push_back(trackID+1);
}
}
bool checkHullReferences(mwIndex trackID)
{ {
mxArray* trackHulls = mxGetField(gCellTracks, C_IDX(trackID), "hulls"); mxArray* trackHulls = mxGetField(gCellTracks, C_IDX(trackID), "hulls");
...@@ -607,8 +643,6 @@ bool checkHullReferences(mwIndex trackID, std::vector<int>& hullRefCount) ...@@ -607,8 +643,6 @@ bool checkHullReferences(mwIndex trackID, std::vector<int>& hullRefCount)
continue; continue;
} }
++hullRefCount[MATLAB_IDX(matHullID)];
if ( gHullErrors.count(MATLAB_IDX(matHullID)) > 0 ) if ( gHullErrors.count(MATLAB_IDX(matHullID)) > 0 )
{ {
//gTrackErrors.insert(tErrorPair(C_IDX(trackID), "Track hull list references broken hulls")); //gTrackErrors.insert(tErrorPair(C_IDX(trackID), "Track hull list references broken hulls"));
...@@ -693,12 +727,18 @@ bool verifyStructureElements() ...@@ -693,12 +727,18 @@ bool verifyStructureElements()
continue; continue;
} }
std::vector<int> familyTrackRefCount; std::vector<std::vector<int>> familyTrackRefCount;
familyTrackRefCount.resize(mxGetNumberOfElements(gCellTracks)); familyTrackRefCount.resize(mxGetNumberOfElements(gCellTracks));
// TODO: Verify that all tracks referenced in families are actually
// connected in the tree heirarchy, this isn't detected right now!
// Verify family->track references // Verify family->track references
for ( mwIndex i=0; i < numFamilies; ++i ) for ( mwIndex i=0; i < numFamilies; ++i )
{ {
// Always add references to ref count
addTrackFamilyReference(i, familyTrackRefCount);
// Ignore families for which we've already discovered errors // Ignore families for which we've already discovered errors
if ( gFamilyErrors.count(i) > 0 ) if ( gFamilyErrors.count(i) > 0 )
continue; continue;
...@@ -708,27 +748,38 @@ bool verifyStructureElements() ...@@ -708,27 +748,38 @@ bool verifyStructureElements()
if ( mxGetNumberOfElements(startTime) == 0 ) if ( mxGetNumberOfElements(startTime) == 0 )
continue; continue;
if ( !checkTrackFamilyReferences(i, familyTrackRefCount) ) // Verify correctness of references
if ( !checkTrackFamilyReferences(i) )
continue; continue;
} }
// Verify that all tracks referenced by CellFamilies are referenced no more than once // Verify that all tracks referenced by CellFamilies are referenced no more than once
for ( size_t i=0; i < familyTrackRefCount.size(); ++i ) for ( size_t i=0; i < familyTrackRefCount.size(); ++i )
{ {
if ( familyTrackRefCount[i] > 1 ) if ( familyTrackRefCount[i].size() > 1 )
{ {
char errMsg[errBufSize]; char errMsg[errBufSize];
sprintf(errMsg, "Track referenced %d (>1) times by families", familyTrackRefCount[i]); char refList[200];
sprintf(refList, "%d", familyTrackRefCount[i][0]);
for ( size_t j=1; j < familyTrackRefCount[i].size(); ++j )
sprintf(refList, "%s %d", refList, familyTrackRefCount[i][j]);
sprintf(errMsg, "Track referenced %d times by families [%s]", familyTrackRefCount[i].size(), refList);
gTrackErrors.insert(tErrorPair(C_IDX(i), errMsg)); gTrackErrors.insert(tErrorPair(C_IDX(i), errMsg));
} }
} }
std::vector<int> trackHullRefCount; std::vector<std::vector<int>> trackHullRefCount;
trackHullRefCount.resize(mxGetNumberOfElements(gCellHulls)); trackHullRefCount.resize(mxGetNumberOfElements(gCellHulls));
// Verify track references // Verify track references
for ( mwIndex i=0; i < numTracks; ++i ) for ( mwIndex i=0; i < numTracks; ++i )
{ {
// Always add references to ref count
addHullReference(i, trackHullRefCount);
// Ignore tracks for which we've already discovered errors // Ignore tracks for which we've already discovered errors
if ( gTrackErrors.count(i) > 0 ) if ( gTrackErrors.count(i) > 0 )
continue; continue;
...@@ -754,7 +805,7 @@ bool verifyStructureElements() ...@@ -754,7 +805,7 @@ bool verifyStructureElements()
continue; continue;
} }
if ( !checkHullReferences(i, trackHullRefCount) ) if ( !checkHullReferences(i) )
continue; continue;
} }
...@@ -762,10 +813,17 @@ bool verifyStructureElements() ...@@ -762,10 +813,17 @@ bool verifyStructureElements()
// Verify that all hulls referenced by CellTracks are referenced no more than once // Verify that all hulls referenced by CellTracks are referenced no more than once
for ( size_t i=0; i < trackHullRefCount.size(); ++i ) for ( size_t i=0; i < trackHullRefCount.size(); ++i )
{ {
if ( trackHullRefCount[i] > 1 ) if ( trackHullRefCount[i].size() > 1 )
{ {
char errMsg[errBufSize]; char errMsg[errBufSize];
sprintf(errMsg, "Hull referenced %d (>1) times by tracks", trackHullRefCount[i]); char refList[200];
sprintf(refList, "%d", trackHullRefCount[i][0]);
for ( size_t j=1; j < trackHullRefCount[i].size(); ++j )
sprintf(refList, "%s %d", refList, trackHullRefCount[i][j]);
sprintf(errMsg, "Hull referenced %d times by tracks [%s]", trackHullRefCount[i].size(), refList);
gHullErrors.insert(tErrorPair(C_IDX(i), errMsg)); gHullErrors.insert(tErrorPair(C_IDX(i), errMsg));
} }
} }
...@@ -787,7 +845,7 @@ bool verifyStructureElements() ...@@ -787,7 +845,7 @@ bool verifyStructureElements()
continue; continue;
} }
if ( trackHullRefCount[i] == 1 ) if ( trackHullRefCount[i].size() >= 1 )
continue; continue;
if ( trackID < 0 ) if ( trackID < 0 )
...@@ -802,12 +860,11 @@ bool verifyStructureElements() ...@@ -802,12 +860,11 @@ bool verifyStructureElements()
continue; continue;
} }
// Reuse these for HashedCells ref count std::vector<int> hashTrackRefCount;
for ( size_t i=0; i < familyTrackRefCount.size(); ++i ) std::vector<int> hashHullRefCount;
familyTrackRefCount[i] = 0;
for ( size_t i=0; i < trackHullRefCount.size(); ++i ) hashTrackRefCount.resize(mxGetNumberOfElements(gCellTracks));
trackHullRefCount[i] = 0; hashHullRefCount.resize(mxGetNumberOfElements(gCellHulls));
for ( mwIndex i=0; i < numFrames; ++i ) for ( mwIndex i=0; i < numFrames; ++i )
{ {
...@@ -841,8 +898,8 @@ bool verifyStructureElements() ...@@ -841,8 +898,8 @@ bool verifyStructureElements()
continue; continue;
} }
++familyTrackRefCount[MATLAB_IDX(matHashTrack)]; ++hashTrackRefCount[MATLAB_IDX(matHashTrack)];
++trackHullRefCount[MATLAB_IDX(matHashHull)]; ++hashHullRefCount[MATLAB_IDX(matHashHull)];
mxArray* trackStartTime = mxGetField(gCellTracks, MATLAB_IDX(matHashTrack), "startTime"); mxArray* trackStartTime = mxGetField(gCellTracks, MATLAB_IDX(matHashTrack), "startTime");
if ( mxGetNumberOfElements(trackStartTime) == 0 ) if ( mxGetNumberOfElements(trackStartTime) == 0 )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment