/// <summary> /// Called when an item is saved. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">Event arguments.</param> public void OnSaveClicked(object sender, EventArgs e) { Model3DFile file = this.listModel3DPanel.GetSelectedItem <Model3DFile>(); if (file != null) { this.saveFileDialog.InitialDirectory = Path.GetDirectoryName(file.OriginalPath); this.saveFileDialog.FileName = file.Name; DialogResult dialogResult = this.saveFileDialog.ShowDialog(); if (dialogResult == DialogResult.OK) { this.statusLabel.Text = "Writing " + file.Name + " to " + this.saveFileDialog.FileName + "."; FileReader fileReader = new FileReader(); Model3DData model3D = fileReader.ReadModel(file.EditPath); try { ObjFileWriter fileWriter = new ObjFileWriter(this.saveFileDialog.FileName); fileWriter.WriteModel(model3D.Model); fileWriter.Close(); this.statusLabel.Text = "Writing was finished."; file.Exported = true; this.listModel3DPanel.Refresh(); } catch { MessageBox.Show(this, "An error occurred when writing to a file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show(this, "Please select a model that should be saved.", "Model not selected", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Starts a nonrigid registration. /// </summary> /// <param name="sender">The sender of an event.</param> /// <param name="e">Event arguments.</param> private void toolsRegistrationNonrigidMenuItem_Click(object sender, EventArgs e) { NonrigidSettingsForm nonrigidSettingsForm = new NonrigidSettingsForm(this.model3DBean.ModelListBean); nonrigidSettingsForm.ShowDialog(this); if (nonrigidSettingsForm.DialogResult == DialogResult.OK) { this.statusProgressBar.Visible = true; this.statusLabel.Text = "Registration task is in progress."; for (int i = 0; i < nonrigidSettingsForm.SourceModels.Count; i++) { for (int j = 0; j < nonrigidSettingsForm.TargetModels.Count; j++) { BackgroundWorker worker = new BackgroundWorker(); worker.RunWorkerCompleted += this.ReportTaskCompleted; worker.DoWork += (obj, args) => { NonrigidArgs nonrigidArgs = (NonrigidArgs)args.Argument; FileReader fileReader = new FileReader(); Model3DData sourceModel = fileReader.ReadModel(nonrigidArgs.SourceModel.EditPath); Model3DData targetModel = fileReader.ReadModel(nonrigidArgs.TargetModel.EditPath); List <Vector <float> > sourceVertexBuffer = sourceModel.GetVertices(); List <Vector <float> > targetVertexBuffer = targetModel.GetVertices(); RigidRegistration rigidRegistration = new RigidRegistration(new KdTreeMapping(), nonrigidArgs.NumberOfIterations); NonrigidRegistration nonrigidRegistration = new NonrigidRegistration(rigidRegistration); sourceVertexBuffer = nonrigidRegistration.ComputeRegistration(sourceVertexBuffer, targetVertexBuffer); sourceModel.SetVertices(sourceVertexBuffer); ObjFileWriter fileWriter = new ObjFileWriter(nonrigidArgs.SourceModel.EditPath); fileWriter.WriteModel(sourceModel.Model); fileWriter.Close(); nonrigidArgs.SourceModel.Changed = true; nonrigidArgs.SourceModel.Exported = false; }; worker.RunWorkerAsync(new NonrigidArgs(nonrigidSettingsForm.SourceModels[i], nonrigidSettingsForm.TargetModels[j], nonrigidSettingsForm.MaxIterations)); } } } }