Exemplo n.º 1
0
        /// <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);
            }
        }
Exemplo n.º 2
0
        /// <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));
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Shows the sample of surface.
        /// </summary>
        /// <param name="model3D">A WebMech.Web.Model3DData that specifies
        /// data object of 3D model with basic statistic data and list of 3D points.</param>
        public void ShowSample(Model3DData model3D)
        {
            Clear();
            ClearCamera();

            Model3DGroup surface = new Model3DGroup();
            Point3D[] points = GetSurfacePoints(model3D);
            for (int y = 0; y < (surfaceSize * (surfaceSize - 1)); y += surfaceSize)
            {
                for (int x = 0; x < (surfaceSize - 1); x++)
                {
                    surface.Children.Add(
                        CreateTriangleModel(
                                points[x + y + surfaceSize],
                                points[x + y],
                                points[x + y + 1])
                    );
                    surface.Children.Add(
                        CreateTriangleModel(
                                points[x + y + surfaceSize],
                                points[x + y + 1],
                                points[x + y + surfaceSize + 1])
                    );
                }
            }
            ModelVisual3D model = new ModelVisual3D();
            model.Content = surface;
            mainViewport.Children.Add(model);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Generates 3D points for visualization.
        /// </summary>
        /// <param name="model3D">A WebMech.Web.Model3DData that specifies
        /// data object of 3D model with basic statistic data and list of 3D points.</param>
        /// <returns>A Kit3D.Windows.Media.Media3D.Point3D that specifies
        /// 3D point for visualization component.</returns>
        private Point3D[] GetSurfacePoints(Model3DData model3D)
        {
            // normalize for vizualize
            double xMul = 14 / (model3D.Xmax - model3D.Xmin);
            double xPlus = -8 - xMul * model3D.Xmin;
            double yMul = 14 / (model3D.Ymax - model3D.Ymin);
            double yPlus = -8 - yMul * model3D.Ymin;
            double zMul = 4 / (model3D.Zmax - model3D.Zmin);
            double zPlus = 2 - zMul * model3D.Zmin;

            Point3D[] points = new Point3D[surfaceSize * surfaceSize];
            if (points.Length == model3D.PointList.Count)
            {
                for (int idx = 0; idx < model3D.PointList.Count; idx++)
                {
                    double x = model3D.PointList[idx].X;
                    double y = model3D.PointList[idx].Y;
                    double z = model3D.PointList[idx].Z;
                    x *= xMul; x += xPlus;
                    y *= yMul; y += yPlus;
                    z *= zMul; z += zPlus;
                    points[idx] = new Point3D(x, y, z);
                }
            }
            return points;
        }