QTrk
lv_resultmanager_api.cpp
Go to the documentation of this file.
1 // ResultManager
3 
4 #include "std_incl.h"
5 #include "labview.h"
6 #include "ResultManager.h"
7 #include "utils.h"
8 #include <unordered_set>
9 
10 static std::unordered_set<ResultManager*> rm_instances;
11 
22 static bool ValidRM(ResultManager* rm, ErrorCluster* err)
23 {
24  if(rm_instances.find(rm) == rm_instances.end()) {
25  ArgumentErrorMsg(err, "Invalid ResultManager instance passed.");
26  return false;
27  }
28  return true;
29 }
35 {
36  DeleteAllElems(rm_instances);
37 }
38 
39 CDLL_EXPORT ResultManager* DLL_CALLCONV rm_create(const char *file, const char *frameinfo, ResultManagerConfig* cfg, LStrHandle* names)
40 {
41  std::vector<std::string> colNames;
42 
43  if (names) colNames = LVGetStringArray(cfg->numFrameInfoColumns, names);
44  ResultManager* rm = new ResultManager(file, frameinfo, cfg, colNames);
45 
46  rm_instances.insert(rm);
47  return rm;
48 }
49 
51 {
52  if (ValidRM(rm, err)) {
53  rm->SetTracker(qtrk);
54  }
55 }
56 
58 {
59  if (ValidRM(rm, err)) {
60  rm_instances.erase(rm);
61  delete rm;
62  }
63 }
64 
65 CDLL_EXPORT void DLL_CALLCONV rm_store_frame_info(ResultManager* rm, int frame, double timestamp, float* cols, ErrorCluster* err)
66 {
67  if (ValidRM(rm, err)) {
68 #ifdef _DEBUG
69  dbgprintf("rm_store_frame_info: frame=%d, ts=%f\n", frame,timestamp);
70 #endif
71  rm->StoreFrameInfo(frame, timestamp, cols);
72  }
73 }
74 
75 CDLL_EXPORT int DLL_CALLCONV rm_getbeadresults(ResultManager* rm, int start, int numFrames, int bead, LocalizationResult* results, ErrorCluster* err)
76 {
77  if (ValidRM(rm, err)) {
78  if (bead < 0 || bead >= rm->Config().numBeads)
79  ArgumentErrorMsg(err,SPrintf( "Invalid bead index: %d. Accepted range: [0-%d]", bead, rm->Config().numBeads));
80  else
81  return rm->GetBeadPositions(start,start+numFrames,bead,results);
82  }
83  return 0;
84 }
85 
86 
87 CDLL_EXPORT void DLL_CALLCONV rm_getframecounters(ResultManager* rm, int* startFrame, int* lastSaveFrame,
88  int* endFrame, int *capturedFrames, int *localizationsDone, int *lostFrames, ErrorCluster* err)
89 {
90  if (ValidRM(rm, err)) {
91 
92  auto r = rm->GetFrameCounters();
93 
94  if (startFrame) *startFrame = r.startFrame;
95  if (lastSaveFrame) *lastSaveFrame = r.lastSaveFrame;
96  if (endFrame) * endFrame = r.processedFrames;
97  if (capturedFrames) *capturedFrames = r.capturedFrames;
98  if (localizationsDone) *localizationsDone = r.localizationsDone;
99  if (lostFrames) *lostFrames = r.lostFrames;
100  }
101 }
102 
103 
105 {
106  if (ValidRM(rm, err)) {
107  rm->Flush();
108  }
109 }
110 
111 CDLL_EXPORT int DLL_CALLCONV rm_getresults(ResultManager* rm, int startFrame, int numFrames, LocalizationResult* results, ErrorCluster* err)
112 {
113  if (ValidRM(rm,err)) {
114  return rm->GetResults(results, startFrame, numFrames);
115  }
116  return 0;
117 }
118 
120 {
121  if (ValidRM(rm, err)) {
122  if (rm->GetTracker()) {
123  ArgumentErrorMsg(err, "Cannot discard bead results while tracking in progress");
124  }
125 
126  rm->RemoveBeadResults(bead);
127  }
128 }
129 
130 
131 
133 {
134  if (ValidRM(rm, err)) {
135  *cfg = rm->Config();
136  }
137 }
138 
CDLL_EXPORT int DLL_CALLCONV rm_getbeadresults(ResultManager *rm, int start, int numFrames, int bead, LocalizationResult *results, ErrorCluster *err)
const ResultManagerConfig & Config()
Returns a reference to the used configuration to review.
int numBeads
Number of beads for which to grab results. Should always equal the amount of beads in a single frame...
Definition: ResultManager.h:64
CDLL_EXPORT void DLL_CALLCONV rm_destroy_all()
bool RemoveBeadResults(int bead)
Remove all results of a certain bead.
CDLL_EXPORT int DLL_CALLCONV rm_getresults(ResultManager *rm, int startFrame, int numFrames, LocalizationResult *results, ErrorCluster *err)
QueuedTracker * GetTracker()
Get the tracker from which results are fetched.
CDLL_EXPORT void DLL_CALLCONV rm_flush(ResultManager *rm, ErrorCluster *err)
CDLL_EXPORT ResultManager *DLL_CALLCONV rm_create(const char *file, const char *frameinfo, ResultManagerConfig *cfg, LStrHandle *names)
Structure for job results.
Definition: qtrk_c_api.h:67
void StoreFrameInfo(int frame, double timestamp, float *columns)
Store metadata for a frame. This data will be saved in the info file.
CDLL_EXPORT void DLL_CALLCONV rm_removebead(ResultManager *rm, int bead, ErrorCluster *err)
int startFrame
Index of the first frame for which results are available.
Class that handles data gathering and saving from QueuedTracker instances.
Definition: ResultManager.h:91
int GetResults(LocalizationResult *results, int startFrame, int numResults)
Get the positions of all beads over an interval of frames.
static bool ValidRM(ResultManager *rm, ErrorCluster *err)
Verify the referenced resultmanager is a valid ResultManager instance.
int numFrameInfoColumns
Number of columns in the frame info metadata file. Additional columns can be added to save more data ...
Definition: ResultManager.h:65
CDLL_EXPORT void DLL_CALLCONV rm_getframecounters(ResultManager *rm, int *startFrame, int *lastSaveFrame, int *endFrame, int *capturedFrames, int *localizationsDone, int *lostFrames, ErrorCluster *err)
CDLL_EXPORT void DLL_CALLCONV rm_store_frame_info(ResultManager *rm, int frame, double timestamp, float *cols, ErrorCluster *err)
void ArgumentErrorMsg(ErrorCluster *e, const std::string &msg)
#define CDLL_EXPORT
Definition: dllmacros.h:9
Structure for settings used by ResultManager.
Definition: ResultManager.h:62
void DeleteAllElems(T &c)
Definition: utils.h:19
void SetTracker(QueuedTracker *qtrk)
Set the tracker from which to fetch results.
void Flush()
Write all available data regardless of ResultManagerConfig::writeInterval.
int GetBeadPositions(int startFrame, int endFrame, int bead, LocalizationResult *r)
Get the positions of a single bead over an interval of frames.
FrameCounters GetFrameCounters()
Returns a FrameCounters structure with the current counts.
CDLL_EXPORT void DLL_CALLCONV rm_getconfig(ResultManager *rm, ResultManagerConfig *cfg, ErrorCluster *err)
void dbgprintf(const char *fmt,...)
Definition: utils.cpp:149
std::vector< std::string > LVGetStringArray(int count, LStrHandle *str)
#define DLL_CALLCONV
Definition: dllmacros.h:3
static std::unordered_set< ResultManager * > rm_instances
CDLL_EXPORT void DLL_CALLCONV rm_set_tracker(ResultManager *rm, QueuedTracker *qtrk, ErrorCluster *err)
CDLL_EXPORT void DLL_CALLCONV rm_destroy(ResultManager *rm, ErrorCluster *err)
Abstract tracker interface, implemented by QueuedCUDATracker and QueuedCPUTracker.
Definition: QueuedTracker.h:86
std::string SPrintf(const char *fmt,...)
Definition: utils.cpp:132