QTrk
|
Class that handles data gathering and saving from QueuedTracker instances. More...
#include <ResultManager.h>
Classes | |
struct | FrameCounters |
Structure to keep track of frame counts. More... | |
struct | FrameResult |
Structure to save all bead results of a single frame in memory. More... | |
Public Member Functions | |
ResultManager (const char *outfile, const char *frameinfo, ResultManagerConfig *cfg, std::vector< std::string > colnames) | |
Create an instance of ResultManager. More... | |
~ResultManager () | |
Destroy an instance of ResultManager. More... | |
void | SaveSection (int start, int end, const char *beadposfile, const char *infofile) |
Save an interval of frames to a file. More... | |
void | SetTracker (QueuedTracker *qtrk) |
Set the tracker from which to fetch results. More... | |
QueuedTracker * | GetTracker () |
Get the tracker from which results are fetched. More... | |
int | GetBeadPositions (int startFrame, int endFrame, int bead, LocalizationResult *r) |
Get the positions of a single bead over an interval of frames. More... | |
int | GetResults (LocalizationResult *results, int startFrame, int numResults) |
Get the positions of all beads over an interval of frames. More... | |
void | Flush () |
Write all available data regardless of ResultManagerConfig::writeInterval. More... | |
FrameCounters | GetFrameCounters () |
Returns a FrameCounters structure with the current counts. More... | |
void | StoreFrameInfo (int frame, double timestamp, float *columns) |
Store metadata for a frame. This data will be saved in the info file. More... | |
int | GetFrameCount () |
Returns the number of captured frames. More... | |
bool | RemoveBeadResults (int bead) |
Remove all results of a certain bead. More... | |
const ResultManagerConfig & | Config () |
Returns a reference to the used configuration to review. More... | |
Protected Member Functions | |
bool | CheckResultSpace (int fr) |
Checks if a frame index is valid. More... | |
void | Write () |
Write available results to output files. More... | |
void | WriteBinaryResults () |
Write available data to a binary file. More... | |
void | WriteTextResults () |
Write available data to a text file. More... | |
void | StoreResult (LocalizationResult *r) |
Copies results from QueuedTracker to internal data structures. More... | |
bool | Update () |
General worker function called from ThreadLoop. More... | |
void | WriteBinaryFileHeader () |
Writes metadata to the header of a binary data file. More... | |
Static Protected Member Functions | |
static void | ThreadLoop (void *param) |
The base loop of the gathering and saving thread. More... | |
Protected Attributes | |
Threads::Mutex | resultMutex |
Mutex to govern access to frameResults. More... | |
Threads::Mutex | trackerMutex |
Mutex to govern access to the linked QueuedTracker instance. More... | |
std::vector< std::string > | frameInfoNames |
Vector with frame info column names. See WriteBinaryFileHeader. More... | |
std::deque< FrameResult *> | frameResults |
Vector to hold the results for all frames. More... | |
FrameCounters | cnt |
Local instance of FrameCounters to maintain counts accross functions. More... | |
ResultManagerConfig | config |
Local instance of ResultManagerConfig with the settings used by this instance of ResultManager. More... | |
ResultFile * | resultFile |
Local instance of ResultFile to generalize output to text or binary files. Not used. More... | |
QueuedTracker * | qtrk |
Pointer to the QueuedTracker instance to check. More... | |
std::string | outputFile |
Path and filename of the main data output file. More... | |
std::string | frameInfoFile |
Path and filename of the frame info (metadata) file. More... | |
Threads::Handle * | thread |
Handle to the thread running the ThreadLoop. More... | |
Atomic< bool > | quit |
Flag to exit the threads. More... | |
Class that handles data gathering and saving from QueuedTracker instances.
Creates a separate thread to check a linked QTrk instance for new data. Gathers data and saves to the disk at regular intervals. Mutexes used to ensure thread safety.
Results from QueuedTracker are sorted as [frame][bead] to enable saving data on a frame-per-line basis.
Definition at line 91 of file ResultManager.h.
ResultManager::ResultManager | ( | const char * | outfile, |
const char * | frameinfo, | ||
ResultManagerConfig * | cfg, | ||
std::vector< std::string > | colnames | ||
) |
Create an instance of ResultManager.
[in] | outfile | String (char array) with full path and filename of desired output file for data. |
[in] | frameinfo | String (char array) with full path and filename of desired output file for frame metadata. |
[in] | cfg | Pointer to structure ResultManagerConfig with settings to use. |
[in] | colnames | Vector of names for the columns in the frame info file. Size must equal ResultManagerConfig::numFrameInfoColumns. Only used for binary files. |
Definition at line 42 of file ResultManager.cpp.
ResultManager::~ResultManager | ( | ) |
Destroy an instance of ResultManager.
Sets a flag to stop the thread and frees all results from memory.
Definition at line 95 of file ResultManager.cpp.
|
protected |
Checks if a frame index is valid.
Frame index is valid if within bounds of the current frames allowed in memory. Initializes the required FrameResult to store data for the frame fr
if it is valid.
[in] | fr | Frame index to be checked. |
True | Index is fine. New FrameResult initialized and added to results vector. |
False | Index is invalid. Can't process this frame index. |
Definition at line 361 of file ResultManager.cpp.
|
inline |
Returns a reference to the used configuration to review.
Definition at line 208 of file ResultManager.h.
void ResultManager::Flush | ( | ) |
Write all available data regardless of ResultManagerConfig::writeInterval.
Use to write unsaved frames from memory when no new ones are expected anymore. Writes all leftover data after waiting for the linked QueuedTracker to finish its queued localizations.
Definition at line 307 of file ResultManager.cpp.
int ResultManager::GetBeadPositions | ( | int | startFrame, |
int | endFrame, | ||
int | bead, | ||
LocalizationResult * | r | ||
) |
Get the positions of a single bead over an interval of frames.
[in] | startFrame | Framenumber of the start of the interval to save. |
[in] | endFrame | Framenumber of the end of the interval to save. |
[in] | bead | Beadnumber of the bead for which the results are requested. |
[out] | r | Array of LocalizationResult in which to store the data. Has to be initialized before calling this function. Size has to be equal to endFrame - startFrame . |
Definition at line 285 of file ResultManager.cpp.
int ResultManager::GetFrameCount | ( | ) |
Returns the number of captured frames.
Definition at line 399 of file ResultManager.cpp.
ResultManager::FrameCounters ResultManager::GetFrameCounters | ( | ) |
Returns a FrameCounters structure with the current counts.
Definition at line 337 of file ResultManager.cpp.
int ResultManager::GetResults | ( | LocalizationResult * | results, |
int | startFrame, | ||
int | numResults | ||
) |
Get the positions of all beads over an interval of frames.
[in] | startFrame | Framenumber of the start of the interval to save. |
[in] | numResults | Number of frames to save. |
[out] | results | Array of LocalizationResult in which to store the data. Has to be initialized before calling this function. Size has to be equal to numResults . |
Definition at line 345 of file ResultManager.cpp.
QueuedTracker * ResultManager::GetTracker | ( | ) |
Get the tracker from which results are fetched.
Definition at line 207 of file ResultManager.cpp.
bool ResultManager::RemoveBeadResults | ( | int | bead | ) |
Remove all results of a certain bead.
Currently only removes from memory.
[in] | bead | The index of the bead for which to remove the data. |
Definition at line 407 of file ResultManager.cpp.
void ResultManager::SaveSection | ( | int | start, |
int | end, | ||
const char * | beadposfile, | ||
const char * | infofile | ||
) |
Save an interval of frames to a file.
[in] | start | Framenumber of the start of the interval to save. |
[in] | end | Framenumber of the end of the interval to save. |
[in] | beadposfile | String (char array) with full path and filename of desired output file for data. |
[in] | infofile | String (char array) with full path and filename of desired output file for frame metadata. |
void ResultManager::SetTracker | ( | QueuedTracker * | qtrk | ) |
Set the tracker from which to fetch results.
[in] | qtrk | Pointer to the QueuedTracker instance to fetch results from. |
Definition at line 215 of file ResultManager.cpp.
void ResultManager::StoreFrameInfo | ( | int | frame, |
double | timestamp, | ||
float * | columns | ||
) |
Store metadata for a frame. This data will be saved in the info file.
[in] | frame | Frame number for which to store the data. |
[in] | timestamp | Timestamp for the frame. |
[in] | columns | Array of float values for the metadata columns. Size must equal ResultManagerConfig::numFrameInfoColumns. |
Definition at line 379 of file ResultManager.cpp.
|
protected |
Copies results from QueuedTracker to internal data structures.
Adds a result to the pre-allocated memory of frame results so it can later be saved on a per-frame basis.
[in] | r | A pointer to a LocalizationResult of a single localization. |
Definition at line 104 of file ResultManager.cpp.
|
staticprotected |
The base loop of the gathering and saving thread.
Called when initialization is done.
[in] | param | Pointer to the instance of ResultManager to work for. |
Definition at line 272 of file ResultManager.cpp.
|
protected |
General worker function called from ThreadLoop.
Fetches results from QueuedTracker (FetchResults), sorts them (StoreResult) and saves them if needed (Write).
Definition at line 222 of file ResultManager.cpp.
|
protected |
Write available results to output files.
Chooses between WriteBinaryResults and WriteTextResults depending on settings.
Definition at line 193 of file ResultManager.cpp.
|
protected |
Writes metadata to the header of a binary data file.
The saved header for file version 3 is:
Name | Description | Size (bytes) |
---|---|---|
version | Binary file version | 4 (int) |
numBead | Number of beads in the file | 4 (int) |
numFrameInfoColumns | Number of metadata columns | 4 (int) |
data_offset | File offset to starting point of frame data | 8 (long) |
frameInfoNames | The names/identifiers for the metadata columns | variable (numFrameInfoColumns * strings) |
Definition at line 67 of file ResultManager.cpp.
|
protected |
Write available data to a binary file.
Definition at line 131 of file ResultManager.cpp.
|
protected |
Write available data to a text file.
Definition at line 165 of file ResultManager.cpp.
|
protected |
Local instance of FrameCounters to maintain counts accross functions.
Definition at line 299 of file ResultManager.h.
|
protected |
Local instance of ResultManagerConfig with the settings used by this instance of ResultManager.
Definition at line 300 of file ResultManager.h.
|
protected |
Path and filename of the frame info (metadata) file.
Definition at line 307 of file ResultManager.h.
|
protected |
Vector with frame info column names. See WriteBinaryFileHeader.
Definition at line 296 of file ResultManager.h.
|
protected |
Vector to hold the results for all frames.
Definition at line 298 of file ResultManager.h.
|
protected |
Path and filename of the main data output file.
Definition at line 306 of file ResultManager.h.
|
protected |
Pointer to the QueuedTracker instance to check.
Definition at line 304 of file ResultManager.h.
|
protected |
Flag to exit the threads.
Definition at line 309 of file ResultManager.h.
|
protected |
Local instance of ResultFile to generalize output to text or binary files. Not used.
Definition at line 302 of file ResultManager.h.
|
protected |
Mutex to govern access to frameResults.
Definition at line 293 of file ResultManager.h.
|
protected |
Handle to the thread running the ThreadLoop.
Definition at line 308 of file ResultManager.h.
|
protected |
Mutex to govern access to the linked QueuedTracker instance.
Definition at line 294 of file ResultManager.h.