Exemplo n.º 1
0
        private void SaveBodyModel()
        {
            var dialog = new SaveFileDialog
            {
                Title       = "Save Model",
                Filter      = "Wavefront OBJ|*.obj|STL (binary)|*.stl|PLY (text)|*.ply",
                FilterIndex = 0,
                DefaultExt  = ".obj"
            };

            if (dialog.ShowDialog() == true)
            {
                var flipAxes = true;
                switch (Path.GetExtension(dialog.FileName).ToLowerInvariant())
                {
                case ".obj":
                    using (var writer = File.CreateText(dialog.FileName))
                    {
                        ModelIO.SaveAsciiObjMesh(engine.ScannedMesh, writer, flipAxes);
                    }
                    break;

                case ".stl":
                    using (var file = File.Create(dialog.FileName))
                        using (var writer = new BinaryWriter(file))
                        {
                            ModelIO.SaveBinaryStlMesh(engine.ScannedMesh, writer, flipAxes);
                        }
                    break;

                case ".ply":
                    using (var writer = File.CreateText(dialog.FileName))
                    {
                        ModelIO.SaveAsciiPlyMesh(engine.ScannedMesh, writer, flipAxes);
                    }
                    break;

                default:
                    uis.ShowError("Unsupported file format");
                    break;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Saves the mesh with using ModelIO.cs. Saves the skeleton.csv, gets the values from WindowControl.cs.
        /// </summary>
        private void SaveBodyModel()
        {
            var dialogCSV = new SaveFileDialog
            {
                Title            = "Save Model",
                Filter           = "CSV|*.csv",
                FilterIndex      = 0,
                DefaultExt       = ".csv",
                InitialDirectory = Directory.GetCurrentDirectory() + "\\Recorded_Data"
            };

            string dateTime = DateTime.Now.ToString("yyyyMMdd_hhmmss");

            dialogCSV.FileName = dateTime;


            if (dialogCSV.ShowDialog() == true)
            {
                fileName = dialogCSV.FileName;
                using (var writer = File.CreateText(dialogCSV.FileName))
                {
                    writer.Write("Joints," + "X," + "Y," + "Z");
                    writer.WriteLine();
                }
            }

            WindowControl.namePass   = true;
            WindowControl.nameHolder = Path.GetFileNameWithoutExtension(dialogCSV.FileName);


            using (StreamWriter writer = new StreamWriter(fileName, true))
            {
                writer.Write("Degree" + "," + WindowControl.degree + "," + WindowControl.degree + "," + WindowControl.degree + "\nSpineBase" + "," + WindowControl.spineBase_X + "," + WindowControl.spineBase_Y + "," + WindowControl.spineBase_Z + "\nSpineMid" + "," + WindowControl.spineMid_X + "," + WindowControl.spineMid_Y + "," + WindowControl.spineMid_Z + "\nNeck" + "," + WindowControl.neck_X + "," + WindowControl.neck_Y + "," + WindowControl.neck_Z
                             + "\nHead" + "," + WindowControl.head_X + "," + WindowControl.head_Y + "," + WindowControl.head_Z + "\nShoulderLeft" + "," + WindowControl.shoulderLeft_X + "," + WindowControl.shoulderLeft_Y + "," + WindowControl.shoulderLeft_Z + "\nElbowLeft" + "," + WindowControl.elbowLeft_X + "," + WindowControl.elbowLeft_Y + "," + WindowControl.elbowLeft_Z
                             + "\nWristLeft" + "," + WindowControl.wristLeft_X + "," + WindowControl.wristLeft_Y + "," + WindowControl.wristLeft_Z + "\nHandLeft" + "," + WindowControl.handLeft_X + "," + WindowControl.handLeft_Y + "," + WindowControl.handLeft_Z + "\nShoulderRight" + "," + WindowControl.shoulderRight_X + "," + WindowControl.shoulderRight_Y + "," + WindowControl.shoulderRight_Z
                             + "\nElbowRight" + "," + WindowControl.elbowRight_X + "," + WindowControl.elbowRight_Y + "," + WindowControl.elbowRight_Z + "\nWristRight" + "," + WindowControl.wristRight_X + "," + WindowControl.wristRight_Y + "," + WindowControl.wristRight_Z + "\nHandRight" + "," + WindowControl.handRight_X + "," + WindowControl.handRight_Y + "," + WindowControl.handRight_Z
                             + "\nHipLeft" + "," + WindowControl.hipLeft_X + "," + WindowControl.hipLeft_Y + "," + WindowControl.hipLeft_Z + "\nKneeLeft" + "," + WindowControl.kneeLeft_X + "," + WindowControl.kneeLeft_Y + "," + WindowControl.kneeLeft_Z + "\nAnkleLeft" + "," + WindowControl.ankleLeft_X + "," + WindowControl.ankleLeft_Y + "," + WindowControl.ankleLeft_Z
                             + "\nFootLeft" + "," + WindowControl.footLeft_X + "," + WindowControl.footLeft_Y + "," + WindowControl.footLeft_Z + "\nHipRight" + "," + WindowControl.hipRight_X + "," + WindowControl.hipRight_Y + "," + WindowControl.hipRight_Z + "\nKneeRight" + "," + WindowControl.kneeRight_X + "," + WindowControl.kneeRight_Y + "," + WindowControl.kneeRight_Z
                             + "\nAnkleRight" + "," + WindowControl.ankleRight_X + "," + WindowControl.ankleRight_Y + "," + WindowControl.ankleRight_Z + "\nFootRight" + "," + WindowControl.footRight_X + "," + WindowControl.footRight_Y + "," + WindowControl.footRight_Z + "\nSpineShoulder" + "," + WindowControl.spineShoulder_X + "," + WindowControl.spineShoulder_Y + "," + WindowControl.spineShoulder_Z
                             + "\nHandTipLeft" + "," + WindowControl.handTipLeft_X + "," + WindowControl.handTipLeft_Y + "," + WindowControl.handTipLeft_Z + "\nThumbLeft" + "," + WindowControl.thumbLeft_X + "," + WindowControl.thumbLeft_Y + "," + WindowControl.thumbLeft_Z + "\nHandTipRight" + "," + WindowControl.handTipRight_X + "," + WindowControl.handTipRight_Y + "," + WindowControl.handTipRight_Z
                             + "\nThumbRight" + "," + WindowControl.thumbRight_X + "," + WindowControl.thumbRight_Y + "," + WindowControl.thumbRight_Z);
                writer.WriteLine();
            }

            var dialog = new SaveFileDialog
            {
                Title       = "Save Model",
                Filter      = "Wavefront OBJ|*.obj|STL (binary)|*.stl|PLY (text)|*.ply",
                FilterIndex = 0,
                DefaultExt  = ".obj"
            };

            // Checks If the 3d object will have the same name with skeleton.csv.
            if (WindowControl.namePass)
            {
                dialog.FileName = WindowControl.nameHolder;
            }
            else
            {
                dialog.FileName = DateTime.Now.ToString("yyyyMMdd_hhmmss");
            }

            if (saveFormat == ".obj")
            {
                dialog.Filter     = "OBJ|*.obj";
                dialog.DefaultExt = ".obj";
            }
            else if (saveFormat == ".stl")
            {
                dialog.Filter     = "STL|*.stl";
                dialog.DefaultExt = ".stl";
            }
            else if (saveFormat == ".ply")
            {
                dialog.Filter     = "PLY|*.ply";
                dialog.DefaultExt = ".ply";
            }

            if (dialog.ShowDialog() == true)
            {
                var flipAxes = true;
                switch (Path.GetExtension(dialog.FileName).ToLowerInvariant())
                {
                case ".obj":
                    using (var writer = File.CreateText(dialog.FileName))
                    {
                        ModelIO.SaveAsciiObjMesh(engine.ScannedMesh, writer, flipAxes);
                    }
                    break;

                case ".stl":
                    using (var file = File.Create(dialog.FileName))
                        using (var writer = new BinaryWriter(file))
                        {
                            ModelIO.SaveBinaryStlMesh(engine.ScannedMesh, writer, flipAxes);
                        }
                    break;

                case ".ply":
                    using (var writer = File.CreateText(dialog.FileName))
                    {
                        ModelIO.SaveAsciiPlyMesh(engine.ScannedMesh, writer, flipAxes);
                    }
                    break;

                default:
                    uis.ShowError("Unsupported file format");
                    break;
                }

                // If convertToPCD is true, executes a sub program called pcl_converter_release from Point Cloud Library.
                if (convertToPCD)
                {
                    string filePath      = dialog.FileName;
                    string fileName      = Path.GetFileNameWithoutExtension(filePath);
                    string directoryName = Path.GetDirectoryName(dialog.FileName);
                    string extension     = Path.GetExtension(dialog.FileName).ToLowerInvariant();

                    Process cmd = new Process();
                    cmd.StartInfo.FileName = "cmd.exe";
                    cmd.StartInfo.RedirectStandardInput  = true;
                    cmd.StartInfo.RedirectStandardOutput = true;
                    cmd.StartInfo.CreateNoWindow         = true;
                    cmd.StartInfo.UseShellExecute        = false;
                    cmd.Start();

                    cmd.StandardInput.WriteLine(Directory.GetCurrentDirectory() + "\\pcl_converter_release -c " + filePath + " " + directoryName + "\\" + fileName + ".pcd");
                    cmd.StandardInput.Flush();
                    cmd.StandardInput.Close();
                    cmd.WaitForExit();
                    Console.WriteLine(cmd.StandardOutput.ReadToEnd());

                    // After converting, starts a new process to view the converted PCD file.
                    Process cmd2 = new Process();
                    cmd.StartInfo.FileName = "cmd.exe";
                    cmd.StartInfo.RedirectStandardInput  = true;
                    cmd.StartInfo.RedirectStandardOutput = true;
                    cmd.StartInfo.CreateNoWindow         = true;
                    cmd.StartInfo.UseShellExecute        = false;
                    cmd.Start();

                    cmd.StandardInput.WriteLine(Directory.GetCurrentDirectory() + "\\pcl_viewer_release.exe " + directoryName + "\\" + fileName + ".pcd");
                    cmd.StandardInput.Flush();
                    cmd.StandardInput.Close();
                    cmd.WaitForExit();
                    Console.WriteLine(cmd.StandardOutput.ReadToEnd());
                }
            }
        }