22 trackerListMutex.
lock();
29 int msglen = strlen(text);
30 MgErr err = NumericArrayResize(uB, 1, (UHandle*)&str, msglen);
33 MoveBlock(text, LStrBuf(*str), msglen);
34 LStrLen(*str) = msglen;
40 std::vector<std::string> result(count);
42 for (
int x=0;x<count;x++) {
43 uChar *val = LHStrBuf(str[x]);
44 int len = LHStrLen (str[x]);
45 result[x]=std::string((
const char*)val, (
size_t)len );
54 error->
status = LVBooleanTrue;
68 if (std::find(trackerList.begin(), trackerList.end(), tracker)==trackerList.end()) {
69 ArgumentErrorMsg(e,
SPrintf(
"QTrk C++ function %s called with invalid tracker pointer: %p", funcname, tracker));
82 for (
int i=0;i<w*h;i++) (*data)->elem[i]=img[i];
111 dbgprintf(
"Setting ZLUT size: %d beads, %d planes, %d radialsteps\n", numLUTs, planes, res);
114 if (zcmpWindow && (*zcmpWindow)->
dimSize > 0) {
115 if ( (*zcmpWindow)->dimSize != res)
116 ArgumentErrorMsg(e,
SPrintf(
"Z Compare window should have the same resolution as the ZLUT (%d elements)", res));
118 zcmp = (*zcmpWindow)->elem;
121 if (numLUTs * planes * res == 0) {
145 if(dims[0]*dims[1]*dims[2]>0) {
160 if ( (*imageLUT)->numElem () > 0 ){
169 if ( (*imageLUT)->numElem () == 0 ){
173 qtrk->
SetImageZLUT( (*imageLUT)->elem, (*radialZLUT)->elem, (*imageLUT)->dimSizes );
188 int count, planes, radialSteps;
191 float *offset_data = 0, *gain_data = 0;
193 if((*offset)->dimSizes[0] != 0) {
194 if (qtrk->
cfg.
width != (*offset)->dimSizes[2] || qtrk->
cfg.
height != (*offset)->dimSizes[1]) {
195 ArgumentErrorMsg(e,
SPrintf(
"set_pixel_calib: Offset images passed with invalid dimension (%d,%d)", (*offset)->dimSizes[2], (*offset)->dimSizes[1]));
198 if (count != (*offset)->dimSizes[0]) {
199 ArgumentErrorMsg(e,
SPrintf(
"set_pixel_calib: Expecting offset to have %d images (same as ZLUT). %d given", count, (*offset)->dimSizes[0]));
202 offset_data = (*offset)->elem;
205 if((*gain)->dimSizes[0] != 0) {
206 if (qtrk->
cfg.
width != (*gain)->dimSizes[2] || qtrk->
cfg.
height != (*gain)->dimSizes[1]) {
207 ArgumentErrorMsg(e,
SPrintf(
"set_pixel_calib: Gain images passed with invalid dimension (%d,%d)", (*gain)->dimSizes[2], (*gain)->dimSizes[1]));
210 if (count != (*gain)->dimSizes[0]) {
211 ArgumentErrorMsg(e,
SPrintf(
"set_pixel_calib: Expecting gain to have %d images (same as ZLUT). %d given", count, (*gain)->dimSizes[0]));
214 gain_data = (*gain)->elem;
233 trackerListMutex.
lock();
234 trackerList.push_back(tracker);
235 trackerListMutex.
unlock();
236 }
catch(
const std::runtime_error &exc) {
244 trackerListMutex.
lock();
246 auto pos = std::find(trackerList.begin(),trackerList.end(),qtrk);
247 if (pos == trackerList.end()) {
252 trackerList.erase(pos);
254 trackerListMutex.
unlock();
256 if(qtrk)
delete qtrk;
265 }
else if( (*data)->dimSizes[1] != qtrk->
cfg.
width || (*data)->dimSizes[0] != qtrk->
cfg.
height ) {
311 pitch =
sizeof(float);
319 pitch *= (*data)->dimSizes[1];
331 for (
int i=0;i<4;i++)
332 timestamp[i] = image[i];
342 ArgumentErrorMsg(e,
SPrintf(
"Not all ROIs (%d out of %d) were queued. Check image borders vs ROIs.", nQueued, numROI));
358 if ((*data)->dimSizes[2] != qtrk->
cfg.
width || (*data)->dimSizes[1] != qtrk->
cfg.
height) {
363 int cnt,planes,rsteps;
366 if ((*data)->dimSizes[0] != cnt) {
367 ArgumentErrorMsg(err,
SPrintf(
"Invalid number of images given (%d). Expecting %d", (*data)->dimSizes[0], cnt));
407 int resultCount = qtrk->
FetchResults(results, maxResults);
410 std::sort(results, results+resultCount, [](decltype(*results) a, decltype(*results) b) {
return a.
job.
frame<b.job.frame; } );
422 int cnt,planes,rsteps;
447 return qtrk->
IsIdle() ? 1 : 0;
458 result.
copyTo ( (*lvresult)->elem );
465 int numbeads,planes,radialsteps;
468 if ((*biastbl)->dimSizes[1] != numbeads) {
469 ArgumentErrorMsg(e,
SPrintf(
"Bias table should be [numbeads] high and [biasplanes] wide. Expected #beads=%d", numbeads) );
479 ImageData img((*image)->elem, (*image)->dimSizes[1], (*image)->dimSizes[0]);
488 float *LUTradii,
vector2f* position,
float z,
float M,
float sigma_noise)
490 ImageData img((*image)->elem, (*image)->dimSizes[1], (*image)->dimSizes[0]);
491 ImageData zlut((*lut)->elem, (*lut)->dimSizes[1], (*lut)->dimSizes[0]);
504 _CrtDumpMemoryLeaks();
518 ImageData lutImg( (*lut)->elem, (*lut)->dimSizes[1], (*lut)->dimSizes[0] );
520 Matrix3X3 mat = fm.
ComputeAverageFisher(*pos, Nsamples,
vector3f(1,1,1),
vector3f(1,1,1)*0.001f, cfg->
width, cfg->
height, [&](
ImageData&out,
vector3f pos) {
521 GenerateImageFromLUT(&out, &lutImg, cc.zlut_minradius,cc.zlut_maxradius, pos);
526 for (
int i=0;i<9;i++)
527 (*fisherMatrix)->elem[i] = mat[i];
533 for (
int i=0;i<9;i++)
534 (*inverseMatrix)->elem[i] = inv[i];
548 auto results =
BeadFinder::Find(image, pitch, w,h, smpCornerPos[0], smpCornerPos[1], &cfg);
551 for (
uint i=0;i<results.size();i++)
553 (*output)->get(i, 0) = results[i].x;
554 (*output)->get(i, 1) = results[i].y;
561 for (
int i=0;i<(*int2D)->dimSizes[0];i++)
563 for (
int j=0;j<(*int2D)->dimSizes[1];j++)
574 for (
int i=0;i<n;i++) {
575 (*int1D)->elem[i]=(i+1)*i;
576 (*flt1D)->elem[i]=sqrtf(i);
577 for (
int j=0;j<n/2;j++) {
578 (*int2D)->get(j, i) = j*2+i;
579 (*flt2D)->get(j, i) = j*2+i;
588 int nZLUT, nPlanes, nRadialSteps;
591 float* lut =
new float[nZLUT*nPlanes*nRadialSteps];
596 zlut.
data = & lut [nRadialSteps*nPlanes*beadIndex];
597 zlut.
w = nRadialSteps;
601 std::vector<vector3f> positions(nsmp);
602 for (
int i=0;i<nsmp;i++) {
603 vector3f pos = *centerPos + *range *
vector3f(rand_uniform<float>(), rand_uniform<float>(), rand_uniform<float>());
618 for (
int i=0;i<nsmp;i++) {
620 vector3f diff = results[i].pos - truepos;
624 for (
int i=0;i<nsmp;i++) {
626 vector3f diff = results[i].pos - truepos;
628 sumScatter += diff*diff;
630 *outScatter =
sqrt (sumScatter / nsmp);
636 #if defined(CUDA_TRACK) || defined(DOXYGEN) 638 #include "cuda_runtime.h" 660 info->
major = prop.major;
661 info->
minor = prop.minor;
673 #else // Generate empty functions to prevent labview crashes static Threads::Mutex trackerListMutex
virtual int GetResultCount()=0
Get the number of finished localization jobs (=results) available in memory.
float zlut_minradius
Distance in pixels from the bead center from which to start sampling profiles. Default 1...
virtual int ScheduleFrame(void *imgptr, int pitch, int width, int height, ROIPosition *positions, int numROI, QTRK_PixelDataType pdt, const LocalizationJob *jobInfo)
Schedule an entire frame at once, allowing for further optimizations.
CDLL_EXPORT void qtrk_set_zlut_bias_table(QueuedTracker *qtrk, LVArray2D< float > **biastbl, ErrorCluster *e)
virtual void BuildLUT(void *data, int pitch, QTRK_PixelDataType pdt, int plane, vector2f *known_pos=0)=0
Add a new lookup table plane.
CDLL_EXPORT int qtrk_get_queue_len(QueuedTracker *qtrk, int *maxQueueLen, ErrorCluster *e)
void ApplyGaussianNoise(ImageData &img, float sigma)
virtual void GetRadialZLUTSize(int &count, int &planes, int &radialsteps)=0
Get the dimensions of the radial lookup table data.
CDLL_EXPORT void DLL_CALLCONV qtrk_get_computed_config(QueuedTracker *qtrk, QTrkComputedConfig *cc, ErrorCluster *err)
TImageData< float > ImageData
CDLL_EXPORT int qtrk_get_debug_image(QueuedTracker *qtrk, int id, LVArray2D< float > **data, ErrorCluster *e)
CDLL_EXPORT void DLL_CALLCONV qtrk_get_ZLUT(QueuedTracker *tracker, LVArray3D< float > **pzlut, ErrorCluster *e)
CDLL_EXPORT void qtrk_destroy(QueuedTracker *qtrk, ErrorCluster *error)
CDLL_EXPORT void DLL_CALLCONV qtrk_set_pixel_calib(QueuedTracker *qtrk, LVArray3D< float > **offset, LVArray3D< float > **gain, ErrorCluster *e)
Set pixel calibration images.
CDLL_EXPORT uint qtrk_read_timestamp(uchar *image, int w, int h)
int width
Width of regions of interest to be handled. Typically equals height (square ROI). ...
virtual void Flush()=0
Stop waiting for more jobs to do, and just process the current batch.
CDLL_EXPORT uint qtrk_queue_frame(QueuedTracker *qtrk, uchar *image, int pitch, int w, int h, uint pdt, ROIPosition *pos, int numROI, const LocalizationJob *pJobInfo, QueueFrameFlags flags, ErrorCluster *e)
CDLL_EXPORT void qtrkcuda_enable_texture_cache(QueuedTracker *qtrk, int enable, ErrorCluster *e)
void WriteToLog()
Write all settings to specified log file (Jelmer)
CDLL_EXPORT void DLL_CALLCONV qtrk_get_image_lut(QueuedTracker *qtrk, LVArrayND< float, 4 > **imageLUT, ErrorCluster *e)
Struct used to define the top-left corner position of an ROI within a frame. ROI is [ x ...
virtual void SetConfigValue(std::string name, std::string value)=0
Set an additional setting.
QueuedTracker * CreateQueuedTracker(const QTrkComputedConfig &cc)
Helper function to create a QueuedTracker instance.
bool ValidateTracker(QueuedTracker *tracker, ErrorCluster *e, const char *funcname)
Verify the referenced tracker is a valid QueuedTracker instance.
void SetLVString(LStrHandle str, const char *text)
void GenerateImageFromLUT(ImageData *image, ImageData *zlut, float minradius, float maxradius, vector3f pos, bool splineInterp, int oversampleSubdiv)
CDLL_EXPORT void qtrk_set_localization_mode(QueuedTracker *qtrk, uint locType, ErrorCluster *e)
CDLL_EXPORT void qtrk_queue_u16(QueuedTracker *qtrk, ErrorCluster *error, LVArray2D< ushort > **data, const LocalizationJob *jobInfo)
CDLL_EXPORT void qtrk_flush(QueuedTracker *qtrk, ErrorCluster *e)
void ResizeLVArray(LVArrayND< T, N > **&d, int *dims)
virtual void GetRadialZLUT(float *dst)=0
Get the radial lookup tables used for z tracking.
bool CheckImageInput(QueuedTracker *qtrk, LVArray2D< T > **data, ErrorCluster *error)
CDLL_EXPORT void qtrk_dump_memleaks()
CDLL_EXPORT void qtrk_get_profile_report(QueuedTracker *qtrk, LStrHandle str)
Structure for job results.
static bool CheckCUDAErrorLV(cudaError err, ErrorCluster *e)
CDLL_EXPORT int qtrk_get_results(QueuedTracker *qtrk, LocalizationResult *results, int maxResults, int sortByID, ErrorCluster *e)
CDLL_EXPORT void qtrk_build_lut_plane(QueuedTracker *qtrk, LVArray3D< float > **data, uint flags, int plane, ErrorCluster *err)
int height
Height of regions of interest to be handled. Typically equals width (square ROI). ...
void normalize(TPixel *d, uint w, uint h)
CDLL_EXPORT void DLL_CALLCONV qtrk_generate_gaussian_spot(LVArray2D< float > **image, vector2f *pos, float sigma, float I0, float Ibg, int applyNoise)
virtual void SetPixelCalibrationFactors(float offsetFactor, float gainFactor)=0
Set the pixel calibration factors.
CDLL_EXPORT void qtrk_queue_float(QueuedTracker *qtrk, ErrorCluster *error, LVArray2D< float > **data, const LocalizationJob *jobInfo)
virtual bool GetDebugImage(int ID, int *w, int *h, float **pData)
Get the debug image for a specific thread.
CDLL_EXPORT void qtrk_enable_zlut_cmpprof(QueuedTracker *qtrk, bool enable, ErrorCluster *e)
CDLL_EXPORT void qtrk_finalize_lut(QueuedTracker *qtrk, ErrorCluster *e)
Structure for the settings used by the algorithms implemented in QueuedTracker.
int zlut_radialsteps
Number of radial steps to sample on.
vector3< T > sqrt(const vector3< T > &a)
std::vector< Position > Find(ImageData *img, float *sample, Config *cfg)
virtual void FinalizeLUT()=0
Finalize the lookup tables in memory.
uint timestamp
Time stamp of the frame.
virtual void SetLocalizationMode(LocMode_t locType)=0
Select which algorithm is to be used.
uint frame
Frame number this ROI belongs to.
static TImageData alloc(int w, int h)
CDLL_EXPORT void DLL_CALLCONV qtrk_set_logfile_path(const char *path)
CDLL_EXPORT void qtrkcuda_get_device(int device, CUDADeviceInfo *info, ErrorCluster *e)
virtual void SetRadialZLUT(float *data, int count, int planes)=0
Set the radial lookup tables to be used for z tracking.
void ResizeLVArray3D(LVArray3D< T > **&d, int depth, int rows, int cols)
void SetZLUTBiasCorrection(const CImageData &data)
virtual std::string GetWarnings()
Get a report of encountered errors.
CDLL_EXPORT void qtrk_test_array_passing(int n, LVArray< float > **flt1D, LVArray2D< float > **flt2D, LVArray< int > **int1D, LVArray2D< int > **int2D)
CDLL_EXPORT void DLL_CALLCONV qtrk_set_image_lut(QueuedTracker *qtrk, LVArrayND< float, 4 > **imageLUT, LVArray3D< float > **radialZLUT, ErrorCluster *e)
Matrix3X3 Inverse() const
CDLL_EXPORT void qtrk_queue_pitchedmem(QueuedTracker *qtrk, uchar *data, int pitch, uint pdt, const LocalizationJob *jobInfo)
virtual bool IsIdle()=0
Test to see if the tracker is idle.
void ArgumentErrorMsg(ErrorCluster *e, const std::string &msg)
virtual bool SetImageZLUT(float *src, float *radial_zlut, int *dims)
Set the image lookup tables to be used for z tracking.
CDLL_EXPORT void qtrk_queue_array(QueuedTracker *qtrk, ErrorCluster *error, LVArray2D< uchar > **data, uint pdt, const LocalizationJob *jobInfo)
virtual void GetRadialZLUTCompareProfile(float *dst)=0
Get saved error curve.
void GenerateGaussianSpotImage(ImageData *img, vector2f pos, float sigma, float I0, float Ibg)
virtual int GetQueueLength(int *maxQueueLen=0)=0
Get the lengths of the queue of jobs to be handled.
virtual void GetImageZLUTSize(int *dims)
Get the dimensions of the image lookup table data.
CDLL_EXPORT void qtrk_find_beads(uint8_t *image, int pitch, int w, int h, int *smpCornerPos, int roi, float imgRelDist, float acceptance, LVArray2D< uint32_t > **output)
CDLL_EXPORT QueuedTracker * qtrk_create(QTrkSettings *settings, LStrHandle warnings, ErrorCluster *e)
virtual void EnableRadialZLUTCompareProfile(bool enabled)=0
Set a flag to enable saving of error curves.
void dbgsetlogfile(const char *path)
CDLL_EXPORT void DLL_CALLCONV qtrk_set_pixel_calib_factors(QueuedTracker *qtrk, float offsetFactor, float gainFactor, ErrorCluster *e)
Set pixel calibration factors.
virtual void ScheduleLocalization(void *data, int pitch, QTRK_PixelDataType pdt, const LocalizationJob *jobInfo)=0
Add a job to the queue to be processed. A job entails running the required algorithms on a single reg...
LocalizationJob job
Job metadata. See LocalizationJob.
QTrkComputedConfig cfg
The settings used by this instance of QueuedTracker.
CDLL_EXPORT void qtrk_queue_u8(QueuedTracker *qtrk, ErrorCluster *error, LVArray2D< uchar > **data, const LocalizationJob *jobInfo)
void ResizeLVArray2D(LVArray2D< T > **&d, int rows, int cols)
virtual void SetPixelCalibrationImages(float *offset, float *gain)=0
Set the pixel calibration images.
CDLL_EXPORT void DLL_CALLCONV qtrk_free_all()
void DeleteAllElems(T &c)
QTRK_PixelDataType
Flags indicating the data type of image data.
virtual std::string GetProfileReport()
Get the output of performance profiling.
Matrix3X3 ComputeAverageFisher(vector3f pos, int Nsamples, vector3f sampleRange, vector3f delta, int w, int h, std::function< void(ImageData &out, vector3f pos)> imggen)
CDLL_EXPORT int qtrkcuda_device_count(ErrorCluster *e)
virtual void GetImageZLUT(float *dst)
Get the image lookup tables used.
Structure for derived settings computed from base settings in QTrkSettings.
LabVIEW N dimensions array template.
CDLL_EXPORT int qtrk_idle(QueuedTracker *qtrk, ErrorCluster *e)
LabVIEW 3D Array template.
LabVIEW 2D Array template.
CDLL_EXPORT void qtrk_get_zlut_cmpprof(QueuedTracker *qtrk, LVArray2D< float > **output, ErrorCluster *e)
CDLL_EXPORT void DLL_CALLCONV qtrk_set_ZLUT(QueuedTracker *tracker, LVArray3D< float > **pZlut, LVArray< float > **zcmpWindow, int normalize, ErrorCluster *e)
void SetCUDADevices(int *devices, int numdev)
Set the list of devices to be used when QTrkComputedConfig::cuda_device is set to QTrkCUDA_UseList...
static std::vector< QueuedTracker * > trackerList
vector3< float > vector3f
void dbgprintf(const char *fmt,...)
std::vector< std::string > LVGetStringArray(int count, LStrHandle *str)
CDLL_EXPORT void qtrk_simulate_tracking(QueuedTracker *qtrk, int nsmp, int beadIndex, vector3f *centerPos, vector3f *range, vector3f *outBias, vector3f *outScatter, float photonsPerWell, ErrorCluster *e)
void ComputeZBiasCorrection(int bias_planes, CImageData *result, int smpPerPixel, bool useSplineInterp)
CDLL_EXPORT void DLL_CALLCONV qtrk_generate_image_from_lut(LVArray2D< float > **image, LVArray2D< float > **lut, float *LUTradii, vector2f *position, float z, float M, float sigma_noise)
CDLL_EXPORT void qtrkcuda_set_device_list(LVArray< int > **devices)
virtual int FetchResults(LocalizationResult *results, int maxResults)=0
Fetch available results.
virtual void SetRadialWeights(float *zcmp)=0
Set radial weights used for comparing LUT profiles.
virtual void ClearResults()=0
Clear results.
Abstract tracker interface, implemented by QueuedCUDATracker and QueuedCPUTracker.
CDLL_EXPORT void qtrk_clear_results(QueuedTracker *qtrk, ErrorCluster *e)
CDLL_EXPORT void qtrk_compute_fisher(LVArray2D< float > **lut, QTrkSettings *cfg, vector3f *pos, LVArray2D< float > **fisherMatrix, LVArray2D< float > **inverseMatrix, vector3f *xyzVariance, int Nsamples, float maxPixelValue)
Structure for region of interest metadata.
float zlut_maxradius
Max radius in pixels of the sampling circle.
CDLL_EXPORT void qtrk_compute_zlut_bias_table(QueuedTracker *qtrk, int bias_planes, LVArray2D< float > **lvresult, int smpPerPixel, int useSplineInterp, ErrorCluster *e)
CDLL_EXPORT int qtrk_resultcount(QueuedTracker *qtrk, ErrorCluster *e)
std::string SPrintf(const char *fmt,...)
void NormalizeZLUT(float *zlut, int numBeads, int planes, int radialsteps)
MgErr FillErrorCluster(MgErr err, const char *message, ErrorCluster *error)
void ApplyPoissonNoise(ImageData &img, float poissonMax, float maxval)