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

Used some struct wrappers for static compile-time verification of valid CellID vs. HullIdx usage

parent 89e315f3
Branches
No related tags found
No related merge requests found
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include "../matdb/matdb.h" #include "../matdb/matdb.h"
std::vector<Hull> gHulls; std::vector<Hull> gHulls;
std::vector<std::set<int> > gHashedHulls; std::vector<std::set<HullIdx>> gHashedHulls;
void Hull::clear() void Hull::clear()
{ {
...@@ -33,7 +33,7 @@ void Hull::clear() ...@@ -33,7 +33,7 @@ void Hull::clear()
COM.y = UNSET_VAR; COM.y = UNSET_VAR;
COM.z = UNSET_VAR; COM.z = UNSET_VAR;
trackID = UNSET_VAR; trackID = UNSET_VAR;
cellID = UNSET_VAR; cellID = wrapID(UNSET_VAR);
} }
...@@ -61,11 +61,11 @@ void Hull::set_COM(float * com) ...@@ -61,11 +61,11 @@ void Hull::set_COM(float * com)
COM.z = com[2]; COM.z = com[2];
} }
void Hull::set_trackID(int cellID_src) void Hull::set_trackID(CellID cellID_src)
{ {
// nOverride means the cell is either a mitotic child, or a patch recipient // nOverride means the cell is either a mitotic child, or a patch recipient
// read from tblFamilies in matdb.getCellsCallback() // read from tblFamilies in matdb.getCellsCallback()
if ((this->nOverRide > 0)) { if ( !invalidID(this->nOverRide) ) {
#ifdef _DEBUG #ifdef _DEBUG
char buffer[1024]; char buffer[1024];
sprintf(buffer, "set_trackID: overriding for cellID = %d trackID = %d\n",this->cellID,this->nOverRide); sprintf(buffer, "set_trackID: overriding for cellID = %d trackID = %d\n",this->cellID,this->nOverRide);
...@@ -74,6 +74,6 @@ void Hull::set_trackID(int cellID_src) ...@@ -74,6 +74,6 @@ void Hull::set_trackID(int cellID_src)
return; return;
} }
SetDBTrackID(cellID_src, this->cellID); SetDBTrackID(unwrapID(cellID_src), unwrapID(this->cellID));
} // set_trackID } // set_trackID
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#ifndef HULL_H #ifndef HULL_H
#define HULL_H #define HULL_H
#include "../matdb/cidtypes.h"
#include "Utility.h" #include "Utility.h"
#include <vector> #include <vector>
#include <set> #include <set>
...@@ -40,41 +42,41 @@ public: ...@@ -40,41 +42,41 @@ public:
Vec<float> get_COM(){return COM;} Vec<float> get_COM(){return COM;}
size_t get_Volume(){return volume;} size_t get_Volume(){return volume;}
unsigned int get_trackID(){return trackID;} unsigned int get_trackID(){return trackID;}
unsigned int get_cellID() { return cellID; } CellID get_cellID() { return cellID; }
int get_parent() { CellID get_parent() {
if (cellID == nParent) if (cellID == nParent)
return cellID; return cellID;
//else; //else;
return -1; return wrapID(-1);
} }
//setters //setters
void set_COM(float * com); void set_COM(float * com);
void set_time(unsigned int time) { this->time = time; } void set_time(unsigned int time) { this->time = time; }
// set will update in the database // set will update in the database
void set_trackID(int label); void set_trackID(CellID label);
// init updates without writing to database (e.g. on load) // init updates without writing to database (e.g. on load)
void init_trackID(int label) { this->trackID = label; } void init_trackID(int label) { this->trackID = label; }
void set_cellID(int label) { this->cellID = label; } void set_cellID(CellID label) { this->cellID = label; }
void setNumPixels(size_t numPixels) { this->volume = numPixels; } void setNumPixels(size_t numPixels) { this->volume = numPixels; }
void setOverride(int nOverRide) { this->nOverRide = nOverRide; } void setOverride(CellID nOverRide) { this->nOverRide = nOverRide; }
void setParent(int nParent) { this->nParent = nParent; } void setParent(CellID nParent) { this->nParent = nParent; }
// void clearTrack(){track=UNSET_VAR;} // void clearTrack(){track=UNSET_VAR;}
private: private:
unsigned int time; unsigned int time;
Vec<float> COM; Vec<float> COM;
int trackID; int trackID;
unsigned int cellID; CellID cellID;
size_t volume; size_t volume;
int nOverRide; CellID nOverRide;
int nParent; CellID nParent;
void clear(); void clear();
}; };
extern std::vector<Hull> gHulls; extern std::vector<Hull> gHulls;
extern std::vector<std::set<int> > gHashedHulls; extern std::vector<std::set<HullIdx>> gHashedHulls;
#endif #endif
\ No newline at end of file
...@@ -32,31 +32,31 @@ ...@@ -32,31 +32,31 @@
#define SIGN(x) (((x) >= 0.0) ? (1.0) : (-1.0) ) #define SIGN(x) (((x) >= 0.0) ? (1.0) : (-1.0) )
double calcCCDist(threadDB* thread_db, int startCellIdx, int nextCellIdx) double calcCCDist(threadDB* thread_db, CellID startCellID, CellID nextCellID)
{ {
// TODO: MRW - I don't think we need to look backwards with the tracker anymore! // TODO: MRW - I don't think we need to look backwards with the tracker anymore!
int startHullIdx = getHullIdx(startCellIdx); HullIdx startHullIdx = getHullIdx(startCellID);
int nextHullIdx = getHullIdx(nextCellIdx); HullIdx nextHullIdx = getHullIdx(nextCellID);
if ( gHulls[startHullIdx].get_time() > gHulls[nextHullIdx].get_time() ) if ( gHulls[unwrapIdx(startHullIdx)].get_time() > gHulls[unwrapIdx(nextHullIdx)].get_time() )
std::swap(startHullIdx, nextHullIdx); std::swap(startCellID,nextCellID);
return gTrackerData.getDistance(thread_db, startHullIdx, nextHullIdx); return gTrackerData.getDistance(thread_db, startCellID, nextCellID);
} }
double calcFullCellDist(threadDB* thread_db, int startCellIdx, int nextCellIdx) double calcFullCellDist(threadDB* thread_db, CellID startCellID, CellID nextCellID)
{ {
double cdist = calcCCDist(thread_db, startCellIdx, nextCellIdx); double cdist = calcCCDist(thread_db, startCellID, nextCellID);
if (cdist == dbltype::infinity()) if (cdist == dbltype::infinity())
return dbltype::infinity(); return dbltype::infinity();
int startHullIdx = getHullIdx(startCellIdx); HullIdx startHullIdx = getHullIdx(startCellID);
int nextHullIdx = getHullIdx(nextCellIdx); HullIdx nextHullIdx = getHullIdx(nextCellID);
int startCellSize = gHulls[startHullIdx].get_Volume(); int startCellSize = gHulls[unwrapIdx(startHullIdx)].get_Volume();
int nextCellSize = gHulls[nextHullIdx].get_Volume(); int nextCellSize = gHulls[unwrapIdx(nextHullIdx)].get_Volume();
int nmax = MAX(startCellSize, nextCellSize); int nmax = MAX(startCellSize, nextCellSize);
int nmin = MIN(startCellSize, nextCellSize); int nmin = MIN(startCellSize, nextCellSize);
......
...@@ -33,8 +33,8 @@ void updateGInEdges(CSourcePath& path) ...@@ -33,8 +33,8 @@ void updateGInEdges(CSourcePath& path)
int srcIdx = path.src_index(); int srcIdx = path.src_index();
int startGIdx = path.indices[srcIdx]; CellID startGIdx = path.indices[srcIdx];
int nextGIdx = path.indices[srcIdx + 1]; CellID nextGIdx = path.indices[srcIdx + 1];
if (gTrackerData.connectIn[nextGIdx].count(startGIdx) == 0) if (gTrackerData.connectIn[nextGIdx].count(startGIdx) == 0)
{ {
...@@ -49,7 +49,7 @@ void updateGInEdges(CSourcePath& path) ...@@ -49,7 +49,7 @@ void updateGInEdges(CSourcePath& path)
} }
} }
int addBestPath(threadDB* thread_db, CSourcePath& path, int bestGIdx) CellID addBestPath(threadDB* thread_db, CSourcePath& path, CellID bestGIdx)
{ {
if ( path.length() < 1 ) if ( path.length() < 1 )
return bestGIdx; return bestGIdx;
...@@ -63,14 +63,14 @@ int addBestPath(threadDB* thread_db, CSourcePath& path, int bestGIdx) ...@@ -63,14 +63,14 @@ int addBestPath(threadDB* thread_db, CSourcePath& path, int bestGIdx)
int srcIdx = path.src_index(); int srcIdx = path.src_index();
int startGIdx = path.indices[srcIdx]; CellID startGIdx = path.indices[srcIdx];
int nextGIdx = path.indices[srcIdx+1]; CellID nextGIdx = path.indices[srcIdx+1];
// Update global outgoing edges // Update global outgoing edges
updateGInEdges(path); updateGInEdges(path);
// Return new bestGIdx if new path is better than current best // Return new bestGIdx if new path is better than current best
if ( (bestGIdx < 0) || (newPathCost < gTrackerData.connectIn[nextGIdx].at(bestGIdx)->cost) ) if ( invalidID(bestGIdx) || (newPathCost < gTrackerData.connectIn[nextGIdx].at(bestGIdx)->cost) )
{ {
bestGIdx = startGIdx; bestGIdx = startGIdx;
} }
...@@ -79,7 +79,7 @@ int addBestPath(threadDB* thread_db, CSourcePath& path, int bestGIdx) ...@@ -79,7 +79,7 @@ int addBestPath(threadDB* thread_db, CSourcePath& path, int bestGIdx)
} }
// Simple inline function to return a new path with appended node at end // Simple inline function to return a new path with appended node at end
inline CSourcePath path_append_back(const CSourcePath& inPath, int idx) inline CSourcePath path_append_back(const CSourcePath& inPath, CellID idx)
{ {
CSourcePath np(inPath); CSourcePath np(inPath);
np.push_back(idx); np.push_back(idx);
...@@ -88,7 +88,7 @@ inline CSourcePath path_append_back(const CSourcePath& inPath, int idx) ...@@ -88,7 +88,7 @@ inline CSourcePath path_append_back(const CSourcePath& inPath, int idx)
} }
// Simple inline function to return a new path with appended node at start // Simple inline function to return a new path with appended node at start
inline CSourcePath path_append_front(const CSourcePath& inPath, int idx) inline CSourcePath path_append_front(const CSourcePath& inPath, CellID idx)
{ {
CSourcePath np(inPath); CSourcePath np(inPath);
np.push_front(idx); np.push_front(idx);
...@@ -97,13 +97,13 @@ inline CSourcePath path_append_front(const CSourcePath& inPath, int idx) ...@@ -97,13 +97,13 @@ inline CSourcePath path_append_front(const CSourcePath& inPath, int idx)
} }
// this is the NEW workhorse! // this is the NEW workhorse!
int bidirDepthFirstSearch(threadDB* thread_db, CSourcePath partialPath, int bestLGIdx = -1) CellID bidirDepthFirstSearch(threadDB* thread_db, CSourcePath partialPath, CellID bestLGIdx = wrapID(-1))
{ {
// Get backward-looking edges from start of path // Get backward-looking edges from start of path
int lEdgeCount = gccInEdges.count(partialPath.peek_front()); int lEdgeCount = gccInEdges.count(partialPath.peek_front());
if (lEdgeCount > 0) if (lEdgeCount > 0)
{ {
std::multimap<int,int>::iterator lEdgeIter = gccInEdges.find(partialPath.peek_front()); std::multimap<CellID,CellID>::iterator lEdgeIter = gccInEdges.find(partialPath.peek_front());
for ( ; lEdgeIter != gccInEdges.end(); ++lEdgeIter ) for ( ; lEdgeIter != gccInEdges.end(); ++lEdgeIter )
{ {
bestLGIdx = bidirDepthFirstSearch(thread_db, path_append_back(partialPath, lEdgeIter->second), bestLGIdx); bestLGIdx = bidirDepthFirstSearch(thread_db, path_append_back(partialPath, lEdgeIter->second), bestLGIdx);
...@@ -114,7 +114,7 @@ int bidirDepthFirstSearch(threadDB* thread_db, CSourcePath partialPath, int best ...@@ -114,7 +114,7 @@ int bidirDepthFirstSearch(threadDB* thread_db, CSourcePath partialPath, int best
int rEdgeCount = gccOutEdges.count(partialPath.peek_back()); int rEdgeCount = gccOutEdges.count(partialPath.peek_back());
if ( rEdgeCount > 0 ) if ( rEdgeCount > 0 )
{ {
std::multimap<int, int>::iterator rEdgeIter = gccOutEdges.find(partialPath.peek_back()); std::multimap<CellID,CellID>::iterator rEdgeIter = gccOutEdges.find(partialPath.peek_back());
for ( ; rEdgeIter != gccOutEdges.end(); ++rEdgeIter ) for ( ; rEdgeIter != gccOutEdges.end(); ++rEdgeIter )
{ {
bestLGIdx = bidirDepthFirstSearch(thread_db, path_append_front(partialPath, rEdgeIter->second), bestLGIdx); bestLGIdx = bidirDepthFirstSearch(thread_db, path_append_front(partialPath, rEdgeIter->second), bestLGIdx);
...@@ -132,46 +132,46 @@ int bidirDepthFirstSearch(threadDB* thread_db, CSourcePath partialPath, int best ...@@ -132,46 +132,46 @@ int bidirDepthFirstSearch(threadDB* thread_db, CSourcePath partialPath, int best
// bestEdges is returned as a pair <i1,i2> i1 is best incoming path for i2, i2 is the next hull we start bidirectional searc from // bestEdges is returned as a pair <i1,i2> i1 is best incoming path for i2, i2 is the next hull we start bidirectional searc from
// step is so each thread has a worklist based on stride step into the list of hulls in the t+1 frame // step is so each thread has a worklist based on stride step into the list of hulls in the t+1 frame
void threadedBestPaths(threadDB* thread_db, std::vector<std::pair<int,int>>& bestEdges, int offset, int step) void threadedBestPaths(threadDB* thread_db, std::vector<std::pair<CellID,CellID>>& bestEdges, int offset, int step)
{ {
int rc; int rc;
for ( int i = offset; i < bestEdges.size(); i += step ) for ( int i = offset; i < bestEdges.size(); i += step )
{ {
int nextGIdx = bestEdges[i].second; CellID nextGIdx = bestEdges[i].second;
CSourcePath path(nextGIdx); CSourcePath path(nextGIdx);
bestEdges[i].first = bidirDepthFirstSearch(thread_db, path); bestEdges[i].first = bidirDepthFirstSearch(thread_db, path);
} }
} }
void resolveGOutEdges(std::vector<std::pair<int,int>>& edges) void resolveGOutEdges(std::vector<std::pair<CellID,CellID>>& edges)
{ {
for ( const auto& e : edges ) for ( const auto& e : edges )
{ {
int nextGIdx = e.second; CellID nextGIdx = e.second;
for ( const auto& fe : gTrackerData.connectIn[nextGIdx] ) for ( const auto& fe : gTrackerData.connectIn[nextGIdx] )
{ {
CSourcePath* path = fe.second; CSourcePath* path = fe.second;
int srcpIdx = path->src_index(); int srcpIdx = path->src_index();
int srcGIdx = path->indices[srcpIdx]; CellID srcGIdx = path->indices[srcpIdx];
gTrackerData.connectOut[srcGIdx].insert({nextGIdx,path}); gTrackerData.connectOut[srcGIdx].insert({nextGIdx,path});
} }
} }
} }
void FindNextHulls(std::set<int>& nextCells, int t) void FindNextHulls(std::set<CellID>& nextCells, int t)
{ {
nextCells.clear(); nextCells.clear();
for ( int hull : gHashedHulls[t] ) for ( HullIdx hull : gHashedHulls[t] )
{ {
int cellID = gHulls[hull].get_cellID(); CellID cellID = gHulls[unwrapIdx(hull)].get_cellID();
std::multimap<int,int>::iterator nhIter = gccOutEdges.find(cellID); std::multimap<CellID,CellID>::iterator nhIter = gccOutEdges.find(cellID);
for ( ; nhIter != gccOutEdges.end(); ++nhIter ) for ( ; nhIter != gccOutEdges.end(); ++nhIter )
{ {
// Only add t+1 hulls to the list // Only add t+1 hulls to the list
int hullIdx = getHullIdx(nhIter->second); HullIdx hullIdx = getHullIdx(nhIter->second);
if ( gHashedHulls[t+1].count(hullIdx) > 0 ) if ( gHashedHulls[t+1].count(hullIdx) > 0 )
nextCells.insert(nhIter->second); nextCells.insert(nhIter->second);
} }
...@@ -180,9 +180,9 @@ void FindNextHulls(std::set<int>& nextCells, int t) ...@@ -180,9 +180,9 @@ void FindNextHulls(std::set<int>& nextCells, int t)
// MRW - Have to make sure connectIn entries are already available for each nextHull // MRW - Have to make sure connectIn entries are already available for each nextHull
// otherwise the map access is not threadsafe // otherwise the map access is not threadsafe
void initConnectInMap(const std::set<int>& nextCells) void initConnectInMap(const std::set<CellID>& nextCells)
{ {
for ( int nc : nextCells) for ( CellID nc : nextCells )
{ {
// Initialized with the next hull cellID and an empty map<int,CSourcePath*> // Initialized with the next hull cellID and an empty map<int,CSourcePath*>
gTrackerData.connectIn.insert({nc,{}}); gTrackerData.connectIn.insert({nc,{}});
...@@ -190,22 +190,22 @@ void initConnectInMap(const std::set<int>& nextCells) ...@@ -190,22 +190,22 @@ void initConnectInMap(const std::set<int>& nextCells)
} }
void BuildBestPaths(std::map<int,int>& bestInEdges, int t) void BuildBestPaths(std::map<CellID,CellID>& bestInEdges, int t)
{ {
// Get the fesible next-frame hulls from all hulls in t // Get the feasible next-frame hulls from all hulls in t
std::set<int> nextCells; std::set<CellID> nextCells;
FindNextHulls(nextCells, t); FindNextHulls(nextCells, t);
initConnectInMap(nextCells); initConnectInMap(nextCells);
std::vector<std::pair<int,int>> bestEdges; std::vector<std::pair<CellID,CellID>> bestEdges;
// best edges is sized here. this size is fixed. this makes it thread safe. // best edges is sized here. this size is fixed. this makes it thread safe.
bestEdges.reserve(nextCells.size()); bestEdges.reserve(nextCells.size());
// Initialize IO structure for threads (bestEdges) // Initialize IO structure for threads (bestEdges)
for ( int nc : nextCells ) for ( CellID nc : nextCells )
{ {
bestEdges.push_back({-1,nc}); bestEdges.push_back({wrapID(-1),nc});
} }
// Kick off threads (up to the number of frame hulls) // Kick off threads (up to the number of frame hulls)
...@@ -229,7 +229,7 @@ void BuildBestPaths(std::map<int,int>& bestInEdges, int t) ...@@ -229,7 +229,7 @@ void BuildBestPaths(std::map<int,int>& bestInEdges, int t)
for ( const auto& be : bestEdges ) for ( const auto& be : bestEdges )
{ {
if ( be.first < 0 ) if ( invalidID(be.first) )
continue; continue;
bestInEdges.insert({be.second,be.first}); bestInEdges.insert({be.second,be.first});
......
...@@ -36,7 +36,7 @@ class CSourcePath ...@@ -36,7 +36,7 @@ class CSourcePath
public: public:
// MRW: HACK - Initialize using nextIdx and search backwards to actual "source" nodes // MRW: HACK - Initialize using nextIdx and search backwards to actual "source" nodes
// See bestPathSearch calls for details // See bestPathSearch calls for details
CSourcePath(int nextIdx) CSourcePath(CellID nextIdx)
{ {
cost = dbltype::infinity(); cost = dbltype::infinity();
...@@ -57,7 +57,7 @@ public: ...@@ -57,7 +57,7 @@ public:
return (indices.size() - 1); return (indices.size() - 1);
} }
void push_back(int idx) void push_back(CellID idx)
{ {
if (endIdx >= indices.size() - 1) if (endIdx >= indices.size() - 1)
return; return;
...@@ -66,7 +66,7 @@ public: ...@@ -66,7 +66,7 @@ public:
indices[endIdx] = idx; indices[endIdx] = idx;
} }
void push_front(int idx) void push_front(CellID idx)
{ {
if ( startIdx < 1 ) if ( startIdx < 1 )
return; return;
...@@ -80,12 +80,12 @@ public: ...@@ -80,12 +80,12 @@ public:
return (indices.size() / 2); return (indices.size() / 2);
} }
int peek_front() const CellID peek_front() const
{ {
return indices[startIdx]; return indices[startIdx];
} }
int peek_back() const CellID peek_back() const
{ {
return indices[endIdx]; return indices[endIdx];
} }
...@@ -99,7 +99,7 @@ public: ...@@ -99,7 +99,7 @@ public:
int startIdx; int startIdx;
int endIdx; int endIdx;
std::array<int,(2*WINDOW_SIZE_DEFAULT+1)> indices; std::array<CellID,(2*WINDOW_SIZE_DEFAULT+1)> indices;
}; };
void BuildBestPaths(std::map<int,int>& bestInEdges, int t); void BuildBestPaths(std::map<CellID, CellID>& bestInEdges, int t);
...@@ -40,10 +40,10 @@ void TrackerData::clear() ...@@ -40,10 +40,10 @@ void TrackerData::clear()
} }
// Find the path with the best outgoing cost // Find the path with the best outgoing cost
int FindMinOutEdgeIdx(int srcGIdx) CellID FindMinOutEdgeIdx(CellID srcGIdx)
{ {
double cmin = dbltype::infinity(); double cmin = dbltype::infinity();
int bestNextIdx = -1; CellID bestNextIdx = wrapID(-1);
for ( const auto& outEdge : gTrackerData.connectOut[srcGIdx] ) for ( const auto& outEdge : gTrackerData.connectOut[srcGIdx] )
{ {
...@@ -65,16 +65,13 @@ void resetTargetTrackIDs(unsigned int t) ...@@ -65,16 +65,13 @@ void resetTargetTrackIDs(unsigned int t)
// don't do again here as this kills patching. as a safeguard, trackids are reset // don't do again here as this kills patching. as a safeguard, trackids are reset
// during calls to setlabel // during calls to setlabel
return; return;
std::set<int>::iterator hullIter;
// tracking is from t->t + 1 // tracking is from t->t + 1
// reset ids at t+1 before we start // reset ids at t+1 before we start
hullIter = gHashedHulls[t+1].begin(); for (HullIdx hidx : gHashedHulls[t + 1])
while (hullIter != gHashedHulls[t+1].end())
{ {
gHulls[*hullIter].set_trackID(gHulls[*hullIter].get_cellID()); gHulls[unwrapIdx(hidx)].set_trackID(gHulls[unwrapIdx(hidx)].get_cellID());
++hullIter;
} }
return;
} // resetTargetTrackIDs } // resetTargetTrackIDs
void initTrackStructures(unsigned int tTarget) void initTrackStructures(unsigned int tTarget)
...@@ -92,7 +89,7 @@ void initTrackStructures(unsigned int tTarget) ...@@ -92,7 +89,7 @@ void initTrackStructures(unsigned int tTarget)
// ComputeFrameCosts -- called by trackHulls. Set up costs before naming. // ComputeFrameCosts -- called by trackHulls. Set up costs before naming.
void ComputeFrameCosts(unsigned int t) void ComputeFrameCosts(unsigned int t)
{ {
std::map<int,int> bestInEdges; std::map<CellID,CellID> bestInEdges;
// future frames -- how far forward we can go // future frames -- how far forward we can go
if (gHashedHulls.size() > t + 1) if (gHashedHulls.size() > t + 1)
...@@ -113,22 +110,22 @@ void ComputeFrameCosts(unsigned int t) ...@@ -113,22 +110,22 @@ void ComputeFrameCosts(unsigned int t)
// Iterate over best edges and check for "true love" matches // Iterate over best edges and check for "true love" matches
for ( const auto& be : bestInEdges ) for ( const auto& be : bestInEdges )
{ {
int nextGIdx = be.first; CellID nextGIdx = be.first;
int bestSrcGIdx = be.second; CellID bestSrcGIdx = be.second;
// Find the best forward-looking edge // Find the best forward-looking edge
int chkNextGIdx = FindMinOutEdgeIdx(bestSrcGIdx); CellID chkNextGIdx = FindMinOutEdgeIdx(bestSrcGIdx);
// Check if non-"true love" (forward/back best edges don't match) // Check if non-"true love" (forward/back best edges don't match)
if (nextGIdx != chkNextGIdx) if (nextGIdx != chkNextGIdx)
continue; continue;
// Need hull idx not cellIDs // Need hull idx not cellIDs
int srcHullIdx = getHullIdx(bestSrcGIdx); HullIdx srcHullIdx = getHullIdx(bestSrcGIdx);
int nextHullIdx = getHullIdx(nextGIdx); HullIdx nextHullIdx = getHullIdx(nextGIdx);
// use the trackID from srcGIdx to set bestNextIdx // use the trackID from srcGIdx to set bestNextIdx
if (gHulls[srcHullIdx].get_parent() < 0) if ( invalidID(gHulls[unwrapIdx(srcHullIdx)].get_parent()) )
gHulls[nextHullIdx].set_trackID(bestSrcGIdx); gHulls[unwrapIdx(nextHullIdx)].set_trackID(bestSrcGIdx);
} }
} }
......
...@@ -28,7 +28,9 @@ ...@@ -28,7 +28,9 @@
#include "const_defines.h" #include "const_defines.h"
#include "../matdb/cidtypes.h"
#include "../matdb/matdb.h" #include "../matdb/matdb.h"
#include "cost.h" #include "cost.h"
#include "paths.h" #include "paths.h"
...@@ -46,11 +48,11 @@ public: ...@@ -46,11 +48,11 @@ public:
//savers //savers
void clear(); void clear();
double getDistance(threadDB* thread_db, int hull1, int hull2) { return getHullDistance(thread_db, hull1, hull2); }; double getDistance(threadDB* thread_db, CellID cell_src, CellID cell_dst) { return getHullDistance(thread_db, cell_src, cell_dst); };
//member variables //member variables
std::map<int,std::map<int,CSourcePath*>> connectOut; std::map<CellID,std::map<CellID,CSourcePath*>> connectOut;
std::map<int, std::map<int, CSourcePath*>> connectIn; std::map<CellID, std::map<CellID, CSourcePath*>> connectIn;
std::list<std::unique_ptr<CSourcePath>> pathList; std::list<std::unique_ptr<CSourcePath>> pathList;
}; };
......
...@@ -161,6 +161,7 @@ ...@@ -161,6 +161,7 @@
<None Include="mat\trackerMex.def" /> <None Include="mat\trackerMex.def" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="matdb\cidtypes.h" />
<ClInclude Include="matdb\matdb.h" /> <ClInclude Include="matdb\matdb.h" />
<ClInclude Include="matdb\stdafx.h" /> <ClInclude Include="matdb\stdafx.h" />
<ClInclude Include="matdb\targetver.h" /> <ClInclude Include="matdb\targetver.h" />
......
...@@ -88,5 +88,8 @@ ...@@ -88,5 +88,8 @@
<ClInclude Include="mat\const_defines.h"> <ClInclude Include="mat\const_defines.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="matdb\cidtypes.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
#pragma once
#define STATIC_CELLID_CHECK (0)
#if STATIC_CELLID_CHECK
// Debug defines to make sure we're correctly using cellIDs/hullIdxs
//
typedef struct CellID
{
int id;
} CellID;
typedef struct HullIdx
{
int idx;
} HullIdx;
inline bool operator<(CellID a, CellID b) {return (a.id < b.id);}
inline bool operator==(CellID a, CellID b) {return (a.id == b.id);}
inline bool operator!=(CellID a, CellID b) {return (a.id != b.id);}
inline bool operator<(HullIdx a, HullIdx b) {return (a.idx < b.idx);}
inline bool operator==(HullIdx a, HullIdx b) {return (a.idx == b.idx);}
inline CellID wrapID(int cellID) {return {cellID};}
inline int unwrapID(CellID cellID) {return cellID.id;}
inline HullIdx wrapIdx(int hullIdx) {return {hullIdx};}
inline int unwrapIdx(HullIdx hullIdx) {return hullIdx.idx;}
//
// End debug
#else
typedef int CellID;
typedef int HullIdx;
inline CellID wrapID(int cellID) {return cellID;}
inline int unwrapID(CellID cellID) {return cellID;}
inline HullIdx wrapIdx(int hullIdx) {return hullIdx;}
inline int unwrapIdx(HullIdx hullIdx) {return hullIdx;}
#endif
inline bool invalidID(CellID cid) { return (unwrapID(cid) < 0); }
...@@ -16,14 +16,14 @@ ...@@ -16,14 +16,14 @@
sqlite3 *gdb; sqlite3 *gdb;
threadDB* gdbPool; threadDB* gdbPool;
unsigned int gnThreads; unsigned int gnThreads;
std::map<int,int> gOverRideTrackIDs; std::map<CellID,CellID> gOverRideTrackIDs;
char gszSqlCmd[1024]; char gszSqlCmd[1024];
char *gszDB; char *gszDB;
std::map<std::pair<int,int>, double> gccDistMap; std::map<std::pair<CellID,CellID>,double> gccDistMap;
std::multimap<int,int> gccOutEdges; std::multimap<CellID,CellID> gccOutEdges;
std::multimap<int,int> gccInEdges; std::multimap<CellID,CellID> gccInEdges;
std::map<int,int> gCellHullMap; std::map<CellID,HullIdx> gCellHullMap;
int dbExec(char * szCmd, int(*callback)(void*, int, char**, char**), void * parg, const char * szCaller) int dbExec(char * szCmd, int(*callback)(void*, int, char**, char**), void * parg, const char * szCaller)
...@@ -76,30 +76,24 @@ static int overrideQueryCallback(void *po, int argc, char **argv, char **azColNa ...@@ -76,30 +76,24 @@ static int overrideQueryCallback(void *po, int argc, char **argv, char **azColNa
return 0; return 0;
} // overrideQueryCallback } // overrideQueryCallback
int getHullIdx(int cellID) HullIdx getHullIdx(CellID cellID)
{ {
return gCellHullMap.at(cellID); return gCellHullMap.at(cellID);
} }
CellID getCellID(HullIdx hullIdx)
{
return gHulls[unwrapIdx(hullIdx)].get_cellID();
}
// read hull distance out of map. map loaded by readCCDist. // read hull distance out of map. map loaded by readCCDist.
double getHullDistance(threadDB* thread_db, int hull1, int hull2) double getHullDistance(threadDB* thread_db, CellID cell_src, CellID cell_dst)
{ {
double cost; if (gccDistMap.count({cell_src,cell_dst}) > 0)
std::map<std::pair<int,int>, double>::iterator it; return gccDistMap.at({cell_src,cell_dst});
int cellID_src, cellID_dst;
cellID_src = gHulls[hull1].get_cellID(); return dbltype::infinity();
cellID_dst = gHulls[hull2].get_cellID();
it = gccDistMap.find({cellID_src,cellID_dst});
if (it == gccDistMap.end()) {
cost= dbltype::infinity();
}
else {
cost = it->second;
} }
return cost;
} //getHullDistance
static int getCCdistCallback(void* pvnull, int argc, char** argv, char** azColName) static int getCCdistCallback(void* pvnull, int argc, char** argv, char** azColName)
{ {
...@@ -118,9 +112,11 @@ static int getCCdistCallback(void* pvnull, int argc, char** argv, char** azColNa ...@@ -118,9 +112,11 @@ static int getCCdistCallback(void* pvnull, int argc, char** argv, char** azColNa
cost = atof(argv[i]); cost = atof(argv[i]);
} }
} }
gccDistMap[{cellID_src,cellID_dst}] = cost;
gccOutEdges.insert({cellID_src, cellID_dst}); gccDistMap[{wrapID(cellID_src),wrapID(cellID_dst)}] = cost;
gccInEdges.insert({cellID_src, cellID_dst}); gccOutEdges.insert({wrapID(cellID_src),wrapID(cellID_dst)});
gccInEdges.insert({wrapID(cellID_src),wrapID(cellID_dst)});
return 0; return 0;
} // getCCdistCallback } // getCCdistCallback
...@@ -144,12 +140,12 @@ int readCCDist(int t) ...@@ -144,12 +140,12 @@ int readCCDist(int t)
} // readCCDist } // readCCDist
// we have a track connection in tblManualEdits. Write that back to the db right meow. // we have a track connection in tblManualEdits. Write that back to the db right meow.
int OverRideTrackID(Hull *pNewHull, int cellID_parent) int OverRideTrackID(Hull *pNewHull, CellID cellID_parent)
{ {
int cellID_src = cellID_parent; CellID cellID_src = cellID_parent;
int cellID_dst= pNewHull->get_cellID(); CellID cellID_dst = pNewHull->get_cellID();
SetDBTrackID(cellID_src,cellID_dst); SetDBTrackID(unwrapID(cellID_src),unwrapID(cellID_dst));
gOverRideTrackIDs[cellID_parent] = cellID_dst; gOverRideTrackIDs[cellID_parent] = cellID_dst;
return 0; return 0;
...@@ -166,7 +162,7 @@ static int getCellsCallback(void *pvnull, int argc, char **argv, char **azColNam ...@@ -166,7 +162,7 @@ static int getCellsCallback(void *pvnull, int argc, char **argv, char **azColNam
int area=0; int area=0;
float centroid[3] = { 0, 0, 0 }; float centroid[3] = { 0, 0, 0 };
Hull newHull; Hull newHull;
int nID_MAT; HullIdx nID_MAT;
for (i = 0; i<argc; i++) { for (i = 0; i<argc; i++) {
// printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
...@@ -208,23 +204,23 @@ static int getCellsCallback(void *pvnull, int argc, char **argv, char **azColNam ...@@ -208,23 +204,23 @@ static int getCellsCallback(void *pvnull, int argc, char **argv, char **azColNam
trackID = cellID; trackID = cellID;
// printf("cellID=%d, trackID=%d, time=%d, centroid=[%d,%d]\n",cellID,trackID,time,COM[0],COM[1]); // printf("cellID=%d, trackID=%d, time=%d, centroid=[%d,%d]\n",cellID,trackID,time,COM[0],COM[1]);
newHull.set_cellID(cellID); newHull.set_cellID(wrapID(cellID));
newHull.set_COM(centroid); newHull.set_COM(centroid);
newHull.set_time(time); newHull.set_time(time);
newHull.setNumPixels(area); newHull.setNumPixels(area);
newHull.setOverride(-1); newHull.setOverride(wrapID(-1));
// nParent>0 means the cell can't track *to* anyone // nParent>0 means the cell can't track *to* anyone
// nOverride>0 means the cell can't track *from* anyone // nOverride>0 means the cell can't track *from* anyone
if (nParent >= 0 && cellID != nParent) { if (nParent >= 0 && cellID != nParent) {
// this cell is one of the daughters // this cell is one of the daughters
if (-1 == nChild2) { if (-1 == nChild2) {
// it's a patch. update the trackID right meow // it's a patch. update the trackID right meow
OverRideTrackID(&newHull, nParent); OverRideTrackID(&newHull, wrapID(nParent));
} }
// else it's a mitosis...leave cellID=trackID for both daughters // else it's a mitosis...leave cellID=trackID for both daughters
// no one else can track to this child // no one else can track to this child
newHull.setOverride(nChild1); newHull.setOverride(wrapID(nChild1));
} }
// nParent only set for cell that is actually the parent // nParent only set for cell that is actually the parent
// both daughters will also pick up the parentID, but we need to allow daughter cells // both daughters will also pick up the parentID, but we need to allow daughter cells
...@@ -233,7 +229,7 @@ static int getCellsCallback(void *pvnull, int argc, char **argv, char **azColNam ...@@ -233,7 +229,7 @@ static int getCellsCallback(void *pvnull, int argc, char **argv, char **azColNam
nParent = -1; nParent = -1;
} }
newHull.setParent(nParent); newHull.setParent(wrapID(nParent));
newHull.init_trackID(trackID); newHull.init_trackID(trackID);
...@@ -243,10 +239,10 @@ static int getCellsCallback(void *pvnull, int argc, char **argv, char **azColNam ...@@ -243,10 +239,10 @@ static int getCellsCallback(void *pvnull, int argc, char **argv, char **azColNam
gHulls.push_back(newHull); gHulls.push_back(newHull);
// hull id in mat struct for this hull // hull id in mat struct for this hull
nID_MAT = gHulls.size() - 1; nID_MAT = wrapIdx((int)gHulls.size() - 1);
// hashed hulls is a list of hulls for each time // hashed hulls is a list of hulls for each time
gHashedHulls[time].insert(nID_MAT); gHashedHulls[time].insert(nID_MAT);
gCellHullMap[cellID] = nID_MAT; gCellHullMap[wrapID(cellID)] = nID_MAT;
return 0; return 0;
} // getCellsCallback } // getCellsCallback
......
#pragma once #pragma once
#include "cidtypes.h"
#include "../sqlite3/sqlite3.h" #include "../sqlite3/sqlite3.h"
#include <map> #include <map>
...@@ -26,11 +28,14 @@ extern sqlite3 *gdb; ...@@ -26,11 +28,14 @@ extern sqlite3 *gdb;
extern char* gszDB; // database full path extern char* gszDB; // database full path
extern char gszSqlCmd[1024]; extern char gszSqlCmd[1024];
extern std::multimap<int,int> gccOutEdges; extern std::multimap<CellID,CellID> gccOutEdges;
extern std::multimap<int,int> gccInEdges; extern std::multimap<CellID,CellID> gccInEdges;
HullIdx getHullIdx(CellID cellID);
double getHullDistance(threadDB* thread_db, CellID cell_src, CellID cell_dst);
double getHullDistance(threadDB* thread_db, HullIdx hull_src, HullIdx hull_dst);
int getHullIdx(int cellID);
double getHullDistance(threadDB* thread_db, int hull1, int hull2);
int SetDBTrackID(int cellID_src, int cellID_dst); int SetDBTrackID(int cellID_src, int cellID_dst);
int goTrack(cmdElement* pcmd); int goTrack(cmdElement* pcmd);
int cmdLoop(); int cmdLoop();
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment