Ejemplo n.º 1
0
        internal override void SettingsUpdated()
        {
            base.SettingsUpdated();

            var firstNotSecond = ResponseValues.Select(c => c.Y).Except(Parent.SettingContainer.Settings.CalibrationSettings.PhotometricCalibrationSettings.ResponseValues).ToList();
            var secondNotFirst = Parent.SettingContainer.Settings.CalibrationSettings.PhotometricCalibrationSettings.ResponseValues.Except(ResponseValues.Select(c => c.Y)).ToList();

            bool changed = firstNotSecond.Any() || secondNotFirst.Any();

            if (changed)
            {
                List <double> l = Parent.SettingContainer.Settings.CalibrationSettings.PhotometricCalibrationSettings.ResponseValues.ToList();
                ResponseValues.Clear();
                ResponseValues.AddRange(l.Select((c, i) => new DataPoint(i, c)));
            }
            Vignette = new CvImageContainer();
            try
            {
                if (!string.IsNullOrEmpty(Parent.SettingContainer.Settings.CalibrationSettings.PhotometricCalibrationSettings.VignetteFileBase64))
                {
                    byte[] data = Convert.FromBase64String(Parent.SettingContainer.Settings.CalibrationSettings.PhotometricCalibrationSettings.VignetteFileBase64);
                    Mat    temp = new Mat();
                    CvInvoke.Imdecode(data, Emgu.CV.CvEnum.ImreadModes.Grayscale, temp);
                    Vignette.CvImage = temp;
                }
            }
            catch (Exception)
            {
            }
        }
Ejemplo n.º 2
0
        private void ResponseValues_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Add || e.Action == NotifyCollectionChangedAction.Remove)
            {
                var firstNotSecond = ResponseValues.Select(c => c.Y).Except(Parent.SettingContainer.Settings.CalibrationSettings.PhotometricCalibrationSettings.ResponseValues).ToList();
                var secondNotFirst = Parent.SettingContainer.Settings.CalibrationSettings.PhotometricCalibrationSettings.ResponseValues.Except(ResponseValues.Select(c => c.Y)).ToList();

                bool changed = firstNotSecond.Any() || secondNotFirst.Any();

                if (changed)
                {
                    Parent.SettingContainer.Settings.CalibrationSettings.PhotometricCalibrationSettings.ResponseValues = ResponseValues.Select(c => c.Y).ToList();
                    Parent.UpdateSettings(false);
                }
            }
        }
Ejemplo n.º 3
0
        private void ParseResponseResult(string outputPath)
        {
            ResponseValues.Clear();
            int    i       = 0;
            string file    = Path.Combine(outputPath, "photoCalibResult", "pcalib.txt");
            string content = File.ReadAllText(file);

            foreach (string item in content.Split(' '))
            {
                if (i >= 256)
                {
                    break;
                }
                double val = 0.0;
                double.TryParse(item, NumberStyles.Any, CultureInfo.InvariantCulture, out val);
                ResponseValues.Add(new DataPoint(i++, val));
            }
        }
Ejemplo n.º 4
0
        public override ResponseValues <TEntity> GetValues()
        {
            var response = new ResponseValues <TEntity>();
            var query    = repository.Search(Filter, Sorter, Includes);

            if (HasCount)
            {
                response.Count = query.Count();
            }

            if (ClientDrivenPaging)
            {
                if (Skip != null)
                {
                    query = query.Skip(Skip.Value);
                }
                if (Top != null)
                {
                    if (Top > ApiConfig.Default.MaxQueryCount)
                    {
                        throw new BadArgumentException(ApiParams.TOP);
                    }

                    query = query.Take(Top.Value);
                }

                response.Value = query.ToList();
            }
            else if (ServerDrivenPaging)
            {
                // Not Supported
                throw new NotSupportedException();
            }
            else
            {
                response.Value = query.Take(ApiConfig.Default.MaxQueryCount).ToList();
            }

            return(response);
        }
Ejemplo n.º 5
0
        private Action <ReplaySelectDialogModel> OnReplaySelectDialogClose(bool response, CustomDialog customDialog)
        {
            return(obj =>
            {
                Parent.SyncContext.Send(d =>
                {
                    Parent.DialogCoordinator.HideMetroDialogAsync(Parent, customDialog);
                }, null);

                Parent.SyncContext.Post(d =>
                {
                    Task.Factory.StartNew(async() =>
                    {
                        ReplaySelectDialogModel replaySelectDialogModel = obj as ReplaySelectDialogModel;
                        if (replaySelectDialogModel.SelectedFile != null)
                        {
                            MetroDialogSettings settings = new MetroDialogSettings()
                            {
                                AnimateShow = false,
                                AnimateHide = false
                            };
                            var controller = await Parent.DialogCoordinator.ShowProgressAsync(Parent, "Please wait...", "Photometric calibration!", settings: Parent.MetroDialogSettings);
                            controller.SetCancelable(false);
                            controller.SetIndeterminate();

                            string file = null;
                            string outputPath = null;

                            double fxO = 0.0;
                            double fyO = 0.0;
                            double cxO = 0.0;
                            double cyO = 0.0;

                            double fxN = 0.0;
                            double fyN = 0.0;
                            double cxN = 0.0;
                            double cyN = 0.0;

                            double k1 = 0.0;
                            double k2 = 0.0;
                            double k3 = 0.0;
                            double k4 = 0.0;

                            int width = 0;
                            int height = 0;
                            List <double> responseValues = new List <double>();
                            Parent.SyncContext.Send(d2 =>
                            {
                                file = replaySelectDialogModel.SelectedFile.FullPath;
                                outputPath = Path.Combine(Path.GetTempPath(), "firefly", Guid.NewGuid().ToString());

                                fxO = Parent.CameraViewModel.OrginalCameraMatrix.GetValue(0, 0);
                                fyO = Parent.CameraViewModel.OrginalCameraMatrix.GetValue(1, 1);
                                cxO = Parent.CameraViewModel.OrginalCameraMatrix.GetValue(0, 2);
                                cyO = Parent.CameraViewModel.OrginalCameraMatrix.GetValue(1, 2);

                                fxN = Parent.CameraViewModel.NewCameraMatrix.GetValue(0, 0);
                                fyN = Parent.CameraViewModel.NewCameraMatrix.GetValue(1, 1);
                                cxN = Parent.CameraViewModel.NewCameraMatrix.GetValue(0, 2);
                                cyN = Parent.CameraViewModel.NewCameraMatrix.GetValue(1, 2);

                                k1 = Parent.CameraViewModel.DistortionCoefficients.GetValue(0, 0);
                                k2 = Parent.CameraViewModel.DistortionCoefficients.GetValue(0, 1);
                                k3 = Parent.CameraViewModel.DistortionCoefficients.GetValue(0, 2);
                                k4 = Parent.CameraViewModel.DistortionCoefficients.GetValue(0, 3);

                                if (!response)
                                {
                                    responseValues.AddRange(ResponseValues.Select(f => f.Y));
                                }

                                width = Parent.CameraViewModel.ImageWidth;
                                height = Parent.CameraViewModel.ImageHeight;
                            }, null);

                            RawDataReader reader = new RawDataReader(file, RawReaderMode.Camera0);

                            reader.Open();

                            PhotometricCalibratrionExporter exporter = new PhotometricCalibratrionExporter(fxO, fyO, cxO, cyO, fxN, fyN, cxN, cyN, width, height, k1, k2, k3, k4, outputPath, response, responseValues);
                            exporter.Open();
                            exporter.AddFromReader(reader, delegate(double percent)
                            {
                                double value = percent * 0.33;
                                value = value > 1 ? 1 : value;
                                controller.SetProgress(value);
                            });
                            exporter.Close();
                            reader.Close();

                            Process p = new Process();
                            p.StartInfo.RedirectStandardOutput = true;
                            p.StartInfo.UseShellExecute = false;
                            p.StartInfo.WorkingDirectory = outputPath;
                            p.StartInfo.CreateNoWindow = true;
                            p.EnableRaisingEvents = true;

                            string options = "";

                            if (response)
                            {
                                p.StartInfo.FileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Tools", "responseCalib.exe");
                            }
                            else
                            {
                                p.StartInfo.FileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Tools", "vignetteCalib.exe");
                                options = "facW=7 facH=7";
                            }
                            p.StartInfo.Arguments = string.Format("{0}\\ -noGUI -showPercent {1}", outputPath, options);

                            p.OutputDataReceived += new DataReceivedEventHandler((s, e) =>
                            {
                                Debug.WriteLine(e.Data);
                                if (!string.IsNullOrEmpty(e.Data))
                                {
                                    foreach (string line in e.Data.Split('\n'))
                                    {
                                        if (line.StartsWith("percent: "))
                                        {
                                            double percent = double.Parse(line.Replace("percent: ", ""), CultureInfo.InvariantCulture);
                                            double value = 0.33 + percent * 0.66;
                                            value = value > 1 ? 1 : value;
                                            controller.SetProgress(value);
                                        }
                                    }
                                }
                            }
                                                                                 );

                            p.Exited += new EventHandler((s, e) =>
                            {
                                Parent.SyncContext.Post(async x =>
                                {
                                    if (response)
                                    {
                                        ParseResponseResult(outputPath);
                                    }
                                    else
                                    {
                                        ParseVignetteResult(outputPath);
                                    }
                                    Directory.Delete(outputPath, true);
                                    await controller.CloseAsync();
                                }, null);
                            });

                            p.Start();
                            p.BeginOutputReadLine();
                        }
                    }, TaskCreationOptions.LongRunning);
                }, null);
            });
        }