Esempio n. 1
0
        private void buttonBuildLUT_Click(object sender, EventArgs e)
        {
            using (QTrkInstance inst = new QTrkInstance(GetTrackerConfig()))
            {
                inst.SetRadialZLUTSize(beadPosList.Count, numLUTSteps);

                inst.BeginLUT(true);

                for (int i = 0; i < numLUTSteps; i++)
                {
                    string path = GetImagePath(Settings.LUTDir, i);
                    if (!File.Exists(path))
                    {
                        MessageBox.Show("File " + path + " missing");
                        break;
                    }
                    using (Bitmap bmp = new Bitmap(path))
                    {
                        using (var fi = new FloatImg(bmp, 0))
                        {
                            inst.ProcessLUTFrame(fi.ImageData, beadPosList.ToArray(), i);
                        }
                    }
                }

                inst.FinalizeLUT();
                luts = inst.GetRadialZLUT();

                lutViewer.LUTs = luts;
            }
        }
Esempio n. 2
0
        private void OfflineTrackerDlg_Load(object sender, EventArgs e)
        {
            settings = Settings.Load(SettingsXMLFile);

            if (settings != null)
            {
                QTrkInstance.SelectDLL(settings.libraryConfig.useDebug, settings.libraryConfig.useCUDA);
            }

            if (settings == null)
            {
                QTrkInstance.SelectDLL(false, false);
                settings = new Settings();
                settings.trackerConfig = QTrkConfig.Default;
            }

            UpdateExpBaseDir();
            UpdateFileLists();

            UpdateConfigurationUIComponents();

            EventHandler update = delegate { ConfigurationSettingChanged(); };

            textBoxPixelSize.TextChanged   += update;
            textBoxLUTStep.TextChanged     += update;
            textBoxZCorrection.TextChanged += update;
            textBoxROI.TextChanged         += update;

//			introDlg.Close();
        }
Esempio n. 3
0
        private void buttonBuildLUT_Click(object sender, EventArgs e)
        {
            if (beadCenterPosList.Count == 0)
            {
                MessageBox.Show("No beads selected");
                return;
            }

            CheckBeadPos();

            var dlg = new ProgressBarDlg();

            dlg.Show(new Action(delegate
            {
                using (QTrkInstance inst = new QTrkInstance(settings.trackerConfig))
                {
                    inst.SetRadialZLUTSize(beadCenterPosList.Count, numLUTSteps);
                    inst.BeginLUT(true);

                    int roi = settings.ROI;
                    using (FloatImg tmp = new FloatImg(roi, roi * beadCenterPosList.Count))
                    {
                        for (int i = 0; i < numLUTSteps; i++)
                        {
                            string path = lutFiles[i];
                            if (!File.Exists(path))
                            {
                                MessageBox.Show("File " + path + " missing");
                                break;
                            }
                            dlg.Update(i / (float)numLUTSteps, path, string.Format("Processing LUT Frame {0}/{1}", i, numLUTSteps));
                            using (Bitmap bmp = new Bitmap(path))
                            {
                                if (bmp.Size != imageSize)
                                {
                                    MessageBox.Show(string.Format("{0} has invalid size {1},{2}", path, bmp.Width, bmp.Height));
                                    break;
                                }
                                using (var fi = new FloatImg(bmp, 0))
                                {
                                    // build one image with all beads
                                    for (int b = 0; b < beadCenterPosList.Count; b++)
                                    {
                                        fi.CopySubimage(tmp, beadCenterPosList[b].x - roi / 2, beadCenterPosList[b].y - roi / 2, 0, roi * b, roi, roi);
                                    }
                                    inst.BuildLUT(tmp, i);
                                }
                            }
                        }
                    }
                    inst.FinalizeLUT();
                    lut = inst.GetRadialZLUT();
                }
            }));
            UpdateFileLists();
            tabControl.SelectedTab = tabPageTrack;
        }
Esempio n. 4
0
        public ExampleDlg()
        {
            InitializeComponent();

            QTrkInstance.SelectDLL(false, false);

            QTrkDLL.TestDLLCallConv(10);

            QTrkConfig cfg = QTrkConfig.Default;

            cfg.width = cfg.height = 60;

            propertyGridSettings.SelectedObject = cfg;
        }
Esempio n. 5
0
        private unsafe void buttonSpeedTest_Click(object sender, EventArgs e)
        {
            // get lut
            // rescale lut
//			var lut = new Bitmap("lut000.jpg");

            var dlg = new ProgressBarDlg();

            dlg.Show(new Action(delegate
            {
                Bitmap lut = TrackerDlgUtils.Properties.Resources.lut000;
                using (QTrkInstance inst = new QTrkInstance(TrackerConfiguration))
                {
                    int total = Math.Max(100000, inst.GetMaxQueueLength() * 4);

                    Trace.WriteLine(string.Format("Max queue len: {1}, running benchmark with {0} images...", total, inst.GetMaxQueueLength()));

                    dlg.Update(0.0f, "Generating lookup table...", "Benchmark in progress");

                    GetTimestamp();
                    // use LUT to generate images for new rescaled lut table
                    var lutf = new FloatImg(lut, 0);
                    using (FloatImg img = QTrkUtil.RescaleAndSetLUT(inst, lutf, lut.Height)) { }
                    // make sample image

                    var cfg    = inst.Config;
                    var sample = new FloatImg(cfg.config.width, cfg.config.height);
                    QTrkUtil.GenerateImageFromLUT(sample, lutf, cfg.config.ZLUT_minradius, cfg.zlut_maxradius, new Vector3(cfg.config.width / 2, cfg.config.height / 2, lutf.h / 2), false, 1);

                    dlg.Update(0.0f, "Running speed test...", "Benchmark in progress");

                    // measure tracking speed
                    double st           = GetTimestamp();
                    ImageData imgd      = sample.ImageData;
                    LocalizationJob job = new LocalizationJob();
                    LocalizationJob *pj = &job;
                    int lastUpdate      = 0;

                    for (uint i = 0; i < total; i++)
                    {
                        pj->frame     = i;
                        pj->zlutIndex = 0;

                        inst.ScheduleLocalization(ref imgd, pj);

                        int rc = inst.GetResultCount();
                        if (rc - lastUpdate > total / 20)
                        {
                            dlg.Update(rc / (float)total, "Running speed test...", "Benchmark in progress");
                            lastUpdate = rc;
                        }
                    }
                    double st0 = GetTimestamp();
                    inst.Flush();

                    // wait for results
                    while (true)
                    {
                        System.Threading.Thread.Sleep(20);
                        int rc = inst.GetResultCount();

                        if (rc - lastUpdate > total / 20)
                        {
                            dlg.Update(rc / (float)total, "Running speed test...", "Benchmark in progress");
                            lastUpdate = rc;
                        }

                        if (rc == total)
                        {
                            break;
                        }
                    }

                    double end = GetTimestamp();
                    double fps = total / (end - st);

                    double scheduleTime = (st0 - st) * 1000;
                    Trace.WriteLine(string.Format("Scheduling time: {0} ms. Per frame: {1} us. Scheduling FPS={2}. Processing FPS={3}",
                                                  (int)scheduleTime, (int)(scheduleTime / total * 1000), (int)(total / (st0 - st)), (int)fps));

                    Invoke(new Action(delegate { labelSpeedResults.Text = string.Format("{0} frames processed in {1} ms. \nFPS={2}",
                                                                                        total, (int)((end - st) * 1000), (int)fps); }));

                    var results = new LocalizationResult[total];
                    inst.GetResults(results);

                    for (int i = 0; i < 10; i++)
                    {
                        Vector3 p = results[i].pos;
                        Trace.WriteLine(string.Format("x={0}, y={1}, z={2}", p.x, p.y, p.z));
                    }

                    sample.Dispose();
                }
                lut.Dispose();
            }));
        }
Esempio n. 6
0
        public void Run(Action <ProgressState, string> progressReporter)
        {
            ProgressState ps        = new ProgressState();
            int           filesDone = 0;

            Debug.WriteLine("Tracking settings:");
            Util.ForEachObjectField(config.settings.trackerConfig,
                                    (name, value) => Debug.WriteLine("\t{0}={1}", name, value));

            Vector3 scale = new Vector3(config.settings.pixelSize / 1000.0f, config.settings.pixelSize / 1000.0f,
                                        config.settings.zCorrectionFactor * config.settings.lutStep / 1000.0f);

            using (QTrkInstance trk = new QTrkInstance(config.settings.trackerConfig))
            {
                trk.SetRadialZLUT(config.lut, config.beadCornerPos.Length, config.lutplanes);

                for (int expIndex = 0; expIndex < experiments.Count; expIndex++)
                {
                    var exp = experiments[expIndex];
                    using (ResultManager rm = new ResultManager(exp.outputTraceFile, null, new ResultManagerConfig()
                    {
                        binaryOutput = 0,
                        maxFramesInMemory = 100000,
                        numBeads = config.beadCornerPos.Length,
                        numFrameInfoColumns = 0,
                        offset = new Vector3(),
                        scaling = scale,
                        writeInterval = 50
                    }, null))
                    {
                        rm.SetTracker(trk);

                        trk.SetLocalizationMode(LocalizeModeEnum.LocalizeZ | LocalizeModeEnum.QI);

                        ps.currentExp = exp.path;
                        for (int fr = 0; fr < exp.imageFiles.Length; fr++)
                        {
                            if (fr % 50 == 0)
                            {
                                ps.done = filesDone / (float)totalFiles;
                                progressReporter(ps, string.Format("Processing experiment {0} ({1}/{2}).\nFrame {3}/{4}\n",
                                                                   exp.path, expIndex + 1, experiments.Count, fr + 1, exp.imageFiles.Length));
                            }
                            using (var bmp = new Bitmap(exp.imageFiles[fr]))
                            {
                                LocalizationJob[] jobs = Util.Sequence(config.beadCornerPos.Length, (i) => new LocalizationJob()
                                {
                                    zlutIndex = i, frame = (uint)fr
                                });
                                trk.ScheduleFrameBitmap(bmp, config.beadCornerPos, jobs);
                                //	rm.StoreFrameInfo(fr, fr, new float[] { 0 });
                            }

                            filesDone++;
                        }
                        trk.Flush();
                        while (!trk.IsIdle())
                        {
                            Thread.Sleep(10);
                        }
                        rm.Flush();
                    }
                    Debug.WriteLine(string.Format("Experiment {0} done", exp.path));
                    progressReporter(ps, "All done! ");
                }
            }
        }