Esempio n. 1
0
        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            btnGo.Enabled = true;
            btnGo.Text    = "go";
            btnGo.Tag     = false;

            if (gaugeProgressBar1.Value == 0)
            {
                if ((_fileNames == null) || (_fileNames.Length <= 3))
                {
                    MessageBox.Show("Nothing to do (select more files)");
                    return;
                }
                return;
            }

            gaugeProgressBar1.Value = 0;

            if (!e.Cancelled)
            {
                try
                {
                    DisplayedBmpIdx = 0;

                    _showdepthForm.DisplayedBitmap = MapComputer.Map2BmpFauxColors(_maxMap, 255.0f / (float)_imgfs.Count);
                }
                catch { }
                gaugeProgressBar1.Label = "done";
            }
            else
            {
                gaugeProgressBar1.Label = "canceled";
            }
        }
Esempio n. 2
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            if ((_fileNames == null) || (_fileNames.Length <= 3))
            {
                return;
            }

            _imgfs.Clear();

            int fileCount = _fileNames.Length;

            float progressStep = 100.0f / (fileCount * 2.0f);
            float progress     = 0;

            backgroundWorker1.ReportProgress((int)progress, "converting");

            Stopwatch sw = new Stopwatch();

            sw.Start();

            // for each selected file
            for (int fileIdx = 0; fileIdx < fileCount; ++fileIdx)
            {
                string fileName = _fileNames[fileIdx];

                // load bitmap
                using (var _bmp = new Bitmap(fileName))
                {
                    if (fileIdx == 0)
                    {
                        _h = _bmp.Height;
                        _w = _bmp.Width;
                    }
                    else
                    {
                        if ((_h != _bmp.Height) || (_w != _bmp.Width))
                        {
                            MessageBox.Show("Images must have same size!");
                            return;
                        }
                    }

                    Bitmap sizedBmp = new Bitmap(_bmp, new Size(_bmp.Width / PreShrinkTimes, _bmp.Height / PreShrinkTimes));


                    FloatMap imgf;

                    // get luminance map
                    imgf = MapComputer.Bmp2Map(sizedBmp);

                    _imgfs.Add(imgf);
                }

                // update and report progress
                progress += progressStep;
                backgroundWorker1.ReportProgress((int)progress);

                // check for cancellation
                if (backgroundWorker1.CancellationPending)
                {
                    return;
                }
            }

            List <FloatMap> newImgfs = new List <FloatMap>();

            backgroundWorker1.ReportProgress((int)progress, "getting contrast");

            // for each luminance map
            foreach (var imgf in _imgfs)
            {
                // get contrast, then shrink result (averaging pixels)
                FloatMap newImgf = MapComputer.HalfMap(MapComputer.GetMultiResContrastEvaluation(imgf, MultiResSteps), ShrinkContrastTimes);

                newImgfs.Add(newImgf);

                // update and report progress
                progress += progressStep;
                backgroundWorker1.ReportProgress((int)progress);

                // check for cancellation
                if (backgroundWorker1.CancellationPending)
                {
                    return;
                }
            }

            _imgfs = newImgfs;

            smoothDepth(); smoothDepth();

            _maxMap = getMaxMap();

            // smooth
            for (int i = 0; i < BlurTimes; ++i)
            {
                _maxMap = MapComputer.GaussianBlur(_maxMap, BlurSigma);
            }

            // filter out spikes
            _maxMap = MapComputer.SpikesFilter(_maxMap, SpikeFilterTreshold);

            // cap holes
            _maxMap = MapComputer.CapHoles(_maxMap, CapHolesFilterEmisize);

            // TODO: correct the bell-distorsion

            sw.Stop();

            Console.WriteLine("Batch processed in {0} ms.", sw.ElapsedMilliseconds);

            savePLY();

            saveObj();
        }