예제 #1
0
        /// <summary>
        /// Writes the transformation matrix to a mat file.
        /// </summary>
        /// <param name="matFile">The MAT file to write.</param>
        /// <param name="rotationMatrix">The rotation matrix.</param>
        /// <param name="translation">The translation matrix.</param>
        private void WriteRotationMatrixAndTranslationToMatFile(File matFile, double[,] rotationMatrix, double[] translation)
        {
            // Delete the file if a previous one exists
            if (System.IO.File.Exists(matFile.Path))
            {
                System.IO.File.Delete(matFile.Path);
            }

            string xLine = null;
            string yLine = null;
            var    zLine = "";

            // PowerInspect writes the MAT files using Invariant culture.
            string transLine = "   T   " + Convert.ToString(translation[0], CultureInfo.InvariantCulture) + " " +
                               Convert.ToString(translation[1], CultureInfo.InvariantCulture) + " " +
                               Convert.ToString(translation[2], CultureInfo.InvariantCulture);

            var rotations = Angles.GetRotationsFromMatrixXYZ(rotationMatrix);

            zLine = "   R Z " + Convert.ToString(rotations[0].Value, CultureInfo.InvariantCulture);
            yLine = "   R Y " + Convert.ToString(rotations[1].Value, CultureInfo.InvariantCulture);
            xLine = "   R X " + Convert.ToString(rotations[2].Value, CultureInfo.InvariantCulture);
            var lines = new List <string>();

            lines.Add(xLine);
            lines.Add(yLine);
            lines.Add(zLine);
            lines.Add(transLine);
            lines.Add("*");
            lines.Add("");

            // create a new text document
            System.IO.File.WriteAllLines(matFile.Path, lines);
        }
예제 #2
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);
        }