Esempio n. 1
0
        private Task DoUpdateSettingsRemote(object o)
        {
            return(Task.Factory.StartNew(() =>
            {
                Parent.SyncContext.Post(c =>
                {
                    double fxO = Parent.CameraViewModel.OrginalCameraMatrix.GetValue(0, 0);
                    double fyO = Parent.CameraViewModel.OrginalCameraMatrix.GetValue(1, 1);
                    double cxO = Parent.CameraViewModel.OrginalCameraMatrix.GetValue(0, 2);
                    double cyO = Parent.CameraViewModel.OrginalCameraMatrix.GetValue(1, 2);

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

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

                    List <double> responseValues = new List <double>();

                    responseValues.AddRange(Parent.CalibrationViewModel.PhotometricCalibrationViewModel.ResponseValues.Select(f => f.Y));

                    byte[] vignette = null;
                    if (!string.IsNullOrEmpty(Parent.SettingContainer.Settings.CalibrationSettings.PhotometricCalibrationSettings.VignetteFileBase64))
                    {
                        vignette = Convert.FromBase64String(Parent.SettingContainer.Settings.CalibrationSettings.PhotometricCalibrationSettings.VignetteFileBase64);
                    }

                    int width = Parent.CameraViewModel.ImageWidth;
                    int height = Parent.CameraViewModel.ImageHeight;

                    Parent.IOProxy.UpdateSettings();

                    if (SelectedHost != null)
                    {
                        if (SelectedHost.IsLocal)
                        {
                            PhotometricCalibratrionExporter.ExporterSettingsVOLocal(fxO, fyO, cxO, cyO, fxN, fyN, cxN, cyN, width, height, k1, k2, k3, k4, SelectedHost.ExecutablePath, responseValues, vignette);
                        }
                        else
                        {
                            PhotometricCalibratrionExporter.ExporterSettingsVORemote(fxO, fyO, cxO, cyO, fxN, fyN, cxN, cyN, width, height, k1, k2, k3, k4, SelectedHost.ExecutablePath, responseValues, vignette, SelectedHost.Hostname, SelectedHost.IpAddress, SelectedHost.Username, SelectedHost.Password);
                        }
                    }
                }, null);
            }));
        }
Esempio n. 2
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);
            });
        }