示例#1
0
        /// <summary>
        /// Writes workplane to a MATRIX file.
        /// </summary>
        /// <param name="matrixFile">The file path to the '.matrix' file.</param>
        public void WriteToMatrix(File matrixFile)
        {
            matrixFile.Delete();

            // The expected format of the transformation matrix is the following:
            //xAxis.i|yAxis.i|zAxis.i|x
            //xAxis.j|yAxis.j|zAxis.j|y
            //xAxis.k|yAxis.k|zAxis.k|z
            //0|0|0|1

            // The 1st column is the new x vector relative to World
            // The 2nd column is the new y vector relative to World
            // The 3rd column is the new z vector relative to World
            // The 4th column is the new origin position relative to World

            string firstTranformationMatrixLine  = $"{XAxis.I}|{YAxis.I}|{ZAxis.I}|{Origin.X}";
            string secondTranformationMatrixLine = $"{XAxis.J}|{YAxis.J}|{ZAxis.J}|{Origin.Y}";
            string thirdTranformationMatrixLine  = $"{XAxis.K}|{YAxis.K}|{ZAxis.K}|{Origin.Z}";
            string fourthTranformationMatrixLine = "0|0|0|1";

            var lines = new List <string>(6);

            lines.Add(firstTranformationMatrixLine);
            lines.Add(secondTranformationMatrixLine);
            lines.Add(thirdTranformationMatrixLine);
            lines.Add(fourthTranformationMatrixLine);

            matrixFile.WriteTextLines(lines);
        }
示例#2
0
        public void DeleteTest()
        {
            string filePath = Path.Combine(_testDirectory, "test123.txt");

            if (!System.IO.File.Exists(filePath))
            {
                System.IO.File.Create(filePath).Dispose();
            }
            File target = new File(filePath);

            target.Delete();
            Assert.IsFalse(System.IO.File.Exists(target.Path), "File should not exist");
        }
示例#3
0
        public void WhenWritingSTLFileFromDMTFile_ThenCheckOutput()
        {
            DMTModel importedModel = DMTModelReader.ReadFile(new File(TestFiles.NormalDmt));
            var      outputFile    = new File(string.Format("{0}\\output.stl", Path.GetTempPath()));

            DMTModelWriter.WriteFile(importedModel, outputFile);
            DMTModel writtenModel = DMTModelReader.ReadFile(outputFile);

            // Ensure that model is written correctly
            Assert.AreEqual(importedModel.BoundingBox.MaxX, writtenModel.BoundingBox.MaxX);
            Assert.AreEqual(importedModel.BoundingBox.MaxY, writtenModel.BoundingBox.MaxY);
            Assert.AreEqual(importedModel.BoundingBox.MaxZ, writtenModel.BoundingBox.MaxZ);
            Assert.AreEqual(importedModel.BoundingBox.MinX, writtenModel.BoundingBox.MinX);
            Assert.AreEqual(importedModel.BoundingBox.MinY, writtenModel.BoundingBox.MinY);
            Assert.AreEqual(importedModel.BoundingBox.MinZ, writtenModel.BoundingBox.MinZ);

            outputFile.Delete();
        }
示例#4
0
        /// <summary>
        /// Writes the transformation matrix to a TRX file.
        /// </summary>
        /// <param name="trxFile">The TRX file to write.</param>
        /// <param name="rotationMatrix">The rotation matrix.</param>
        /// <param name="translation">The translation matrix.</param>
        private void WriteRotationMatrixAndTranslationToTrxFile(
            File trxFile,
            double[,] rotationMatrix,
            double[] translation)
        {
            trxFile.Delete();

            Degree[] rotations     = Angles.GetRotationsFromMatrixXYZ(rotationMatrix);
            string   xRotationLine = "ROT_X: " +
                                     (rotations[2].Value >= 0.0
                                       ? rotations[2].Value.ToString("+0.000")
                                       : rotations[2].Value.ToString("0.000"));
            string yRotationLine = "ROT_Y: " +
                                   (rotations[1].Value >= 0.0
                                       ? rotations[1].Value.ToString("+0.000")
                                       : rotations[1].Value.ToString("0.000"));
            string zRotationLine = "ROT_Z: " +
                                   (rotations[0].Value >= 0.0
                                       ? rotations[0].Value.ToString("+0.000")
                                       : rotations[0].Value.ToString("0.000"));
            string xTranslationLine = "SHIFT_X: " +
                                      (translation[0] >= 0.0
                                          ? translation[0].ToString("+0.000")
                                          : translation[0].ToString("0.000"));
            string yTranslationLine = "SHIFT_Y: " +
                                      (translation[1] >= 0.0
                                          ? translation[1].ToString("+0.000")
                                          : translation[1].ToString("0.000"));
            string zTranslationLine = "SHIFT_Z: " +
                                      (translation[0] >= 0.0
                                          ? translation[2].ToString("+0.000")
                                          : translation[2].ToString("0.000"));

            var lines = new List <string>(6);

            lines.Add(xRotationLine);
            lines.Add(yRotationLine);
            lines.Add(zRotationLine);
            lines.Add(xTranslationLine);
            lines.Add(yTranslationLine);
            lines.Add(zTranslationLine);

            trxFile.WriteTextLines(lines);
        }