public void LoadProject() { if (level == 3) if (!SureClose("Unsaved data will be lost, do you want to continue?", "Warning")) return; DialogResult result = openFileDialog1.ShowDialog(); if (result == DialogResult.OK || result == DialogResult.Yes) { if (images == null) images = new ImagesClass(); ImagesClass mages = DeSerializeObject(openFileDialog1.FileName); projectName = Path.GetFileNameWithoutExtension(openFileDialog1.FileName); this.Text = formName + projectName; for (int i = 0; i < mages.listFixedInImage.Count; i++) { string[] s = mages.listFixedInImage[i].color.Replace("]", "[").Split('['); mages.listFixedInImage[i].pen = new Pen(Color.FromName(s[1]), 2); } for (int i = 0; i < mages.listFixedInObject.Count; i++) { string[] s = mages.listFixedInObject[i].color.Replace("]", "[").Split('['); mages.listFixedInObject[i].pen = new Pen(Color.FromName(s[1]), 2); } MeasureParameters.k = mages.k; MeasureParameters.wave_lenght = mages.wave_lenght; MeasureParameters.L = mages.L; MeasureParameters.R = mages.R; MeasureParameters.K = mages.K; MeasureParameters.p0 = mages.p0; MeasureParameters.t0 = mages.t0; MeasureParameters.tau0 = mages.tau0; MeasureParameters.dTau = mages.dTau; MeasureParameters.w0 = mages.w0; MeasureParameters.M = mages.M; tb_heat.Text = mages.k.ToString(CultureInfo.CreateSpecificCulture("en-GB")); tb_wave.Text = mages.wave_lenght.ToString(CultureInfo.CreateSpecificCulture("en-GB")); tb_L.Text = mages.L.ToString(CultureInfo.CreateSpecificCulture("en-GB")); tb_R.Text = mages.R.ToString(CultureInfo.CreateSpecificCulture("en-GB")); tb_K.Text = mages.K.ToString(CultureInfo.CreateSpecificCulture("en-GB")); tb_p0.Text = mages.p0.ToString(CultureInfo.CreateSpecificCulture("en-GB")); tb_dTau.Text = mages.dTau.ToString(CultureInfo.CreateSpecificCulture("en-GB")); tb_tau0.Text = mages.tau0.ToString(CultureInfo.CreateSpecificCulture("en-GB")); tb_t0.Text = mages.t0.ToString(CultureInfo.CreateSpecificCulture("en-GB")); tb_mach.Text = mages.M.ToString(CultureInfo.CreateSpecificCulture("en-GB")); A = mages.A; B = mages.B; calibrateProfilePoint1 = mages.calibrateProfilePoint1; calibrateProfilePoint2 = mages.calibrateProfilePoint2; calibratePoint1 = mages.calibratePoint1; calibratePoint2 = mages.calibratePoint2; PercentRealLenght = mages.PercentRealLenght; realLength = mages.realLength; idealLength = mages.idealLength; tb_scale.Text = mages.scale.ToString(); GlobalSettings.ratio = mages.ratio; listFixedInImage = mages.listFixedInImage; listFixedInObject = mages.listFixedInObject; distanceBetweenCalibratePoints = GetDistanceBetween(calibratePoint1.Point, calibratePoint2.Point); path_airfoil = mages.path_airfoil; MainWindow.arrayProfile = mages.arrayProfile; images = mages; check_eqHist.Checked = mages.isEqualizer; track_gamma.Value = mages.gammaCorrection; tb_real_length.Text = mages.tb_real; tb_ideal_legth.Text = mages.tb_ideal; tb_w0.Text = px2mm(mages.w0).ToString(CultureInfo.CreateSpecificCulture("en-GB")); string new_path = Path.GetDirectoryName(openFileDialog1.FileName); foreach (MyImage im in images.imagesList) { im.path = new_path + "\\" + im.name; } if (!isInit) { initProgram(); isInit = true; flowLayoutPanel7.Enabled = false; flowLayoutPanel8.Enabled = false; panelScale.Enabled = false; panel2.Enabled = true; saveToolStripMenuItem.Enabled = true; } tabControl1.SelectedIndex = 3; images.getByIndex(images.pointer); OpenImage(new Image<Gray, Byte>(images.getActual().path)); trackBar1.Maximum = images.getCount(); trackBar1.Value = images.pointer + 1; l_min.Text = MeasureParameters.tau0.ToString(); l_max.Text = (MeasureParameters.tau0 + (images.imagesList.Count) * MeasureParameters.dTau).ToString(); UpdateInfo(); UpdateObjectFixedPoints(); UpdateStatusBar(); foreach (MyImage im in images.imagesList) { im.path = new_path + "\\" + im.name; im.test_to_compute_DLM(ref im.EA); im.setPoint1(im.point1.Point); } if (images.imagesList != null) { foreach (Line l in images.getActual().listLines) { images.getActual().setLine(l, l.pointOfProfile.Point); } } imageBox.Invalidate(); setDataGrids(); level = 3; } }
public void SerializeObject(string filename, ImagesClass objectToSerialize) { //System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(objectToSerialize.GetType()); //using (TextWriter writer = new StreamWriter(filename)) //{ // x.Serialize(writer, objectToSerialize); //} SerializationWriter sw = new SerializationWriter(); Stream stream = File.Open(filename, FileMode.Create); BinaryFormatter bFormatter = new BinaryFormatter(); bFormatter.Serialize(stream, objectToSerialize); stream.Close(); }
private void loadImage_Click(object sender, EventArgs e) { if(images.countImages != 0) if (!SureClose("Unsaved data will be lost, do you want to create new project?", "Warning")) return; DialogResult result = openFileDialog.ShowDialog(); if (result == DialogResult.OK || result == DialogResult.Yes) { if (openFileDialog.FileName != null) { path = openFileDialog.FileName; OpenDialog od = new OpenDialog(Path.GetDirectoryName(path), new DirectoryInfo(Path.GetDirectoryName(path)).Name); od.ShowDialog(); if (od.OK == false) return; images = new ImagesClass(Path.GetDirectoryName(path), Path.GetExtension(path)); //vytvoreni tridy vsech obrazku //tb_project_name.Text = od.name; this.Text = formName + od.name; projectName = od.name; //calibrate Points calibratePoint1 = new Mark(9, Color.Red); calibratePoint2 = new Mark(9, Color.Red); //calibrate moving profile calibrateProfilePoint1 = new Mark(9, Color.Red); calibrateProfilePoint2 = new Mark(9, Color.Red); //Physical points listFixedInImage = new List<ImagePoint>(); listFixedInObject = new List<ObjectPoint>(); arrayProfile = null; flowLayoutPanel7.Enabled = false; flowLayoutPanel8.Enabled = false; panel2.Enabled = false; //panel5.Enabled = true; panelScale.Enabled = true; //panel5.Enabled = true; panelScale.Enabled = true; tabControl1.SelectedIndex = 0; initProgram(); #region Clear tb tb_scale.Text = ""; tb_real_length.Text = ""; tb_ideal_legth.Text = ""; tb_dTau.Text = ""; tb_heat.Text = ""; tb_K.Text = ""; tb_L.Text = ""; tb_p0.Text = ""; tb_R.Text = ""; tb_t0.Text = ""; tb_tau0.Text = ""; tb_w0.Text = ""; tb_wave.Text = ""; l_min.Text = ""; l_max.Text = ""; #endregion isInit = true; } } }