Exemplo n.º 1
0
        /// <param name="matrix">The matrix to return as a String</param>
        /// <param name="format">The format to use for each value in the matrix, eg "%f"</param>
        public static string ToString(SimpleMatrix matrix, string format)
        {
            ByteArrayOutputStream stream = new ByteArrayOutputStream();

            MatrixIO.Print(new TextWriter(stream), matrix.GetMatrix(), format);
            return(stream.ToString());
        }
        public void SetOffsetMatrix(Matrix4x4 offsetMatrix)
        {
            var temp = offsetMatrix;

            offsetTranslate = offsetMatrix.GetColumn(3);
            temp.SetColumn(3, Vector4.zero);
            offsetRotation = MatrixIO.QuaternionFromMatrix(temp);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Loads a new matrix from a CSV file.
        /// For the file format <see cref="MatrixIO"/>.
        /// </summary>
        /// <exception cref="IOException"/>
        public TSimple loadCSV(string fileName)
        {
            TSimple ret = createMatrix(1, 1);
            var     m   = (TMatrix)MatrixIO.loadCSV(fileName);

            ret.setMatrix(m);
            return(ret);
        }
Exemplo n.º 4
0
        /**
         * <p>
         * Converts the array into a string format for display purposes.
         * The conversion is done using {@link MatrixIO#print(java.io.PrintStream, FMatrix)}.
         * </p>
         *
         * @return String representation of the matrix.
         */
        public virtual string toString()
        {
            var stream = new MemoryStream();

            MatrixIO.print(stream, this);
            stream.Position = 0;
            var reader = new StreamReader(stream);

            return(reader.ReadToEnd());
        }
        public bool SaveTaskInFile()
        {
            string functionName = MethodInfo.GetCurrentMethod().Name;

            if (HaveErrorsState(functionName))
            {
                return(false);
            }

            MatrixIO.SaveInFile(_model.task);
            return(true);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Saves this matrix to a file in a CSV format.
 /// For the file format <see cref="MatrixIO"/>.
 /// </summary>
 /// <param name="fileName"></param>
 public void saveToFileCSV(string fileName)
 {
     if (mat is DMatrix)
     {
         MatrixIO.saveCSV((DMatrix)mat, fileName);
     }
     else if (mat is FMatrix)
     {
         MatrixIO.saveCSV((FMatrix)mat, fileName);
     }
     else
     {
         throw new InvalidOperationException("Unknown or unsupported matrix type.");
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// Prints the matrix to standard out with the specified precision.
 /// Example resulting string output: {0:F2,5} (numChar = 5, precision = 2).
 /// </summary>
 public void print(int numChar, int precision)
 {
     if (mat is DMatrix)
     {
         MatrixIO.print(Console.OpenStandardOutput(), (DMatrix)mat, numChar, precision);
     }
     else if (mat is FMatrix)
     {
         MatrixIO.print(Console.OpenStandardOutput(), (FMatrix)mat, numChar, precision);
     }
     else
     {
         throw new InvalidOperationException("Unknown or unsupported matrix type.");
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// Prints the matrix to standard out given a floating point format.
 /// Example format: {0:F2,5} (numChar = 5, precision = 2).
 /// </summary>
 public void print(string format)
 {
     if (mat is DMatrix)
     {
         MatrixIO.print(Console.OpenStandardOutput(), (DMatrix)mat, format);
     }
     else if (mat is FMatrix)
     {
         MatrixIO.print(Console.OpenStandardOutput(), (FMatrix)mat, format);
     }
     else
     {
         throw new InvalidOperationException("Unknown or unsupported matrix type.");
     }
 }
Exemplo n.º 9
0
        public static void serializedBinary()
        {
            DMatrixRMaj A = new DMatrixRMaj(2, 3, true, new double[] { 1, 2, 3, 4, 5, 6 });

            try
            {
                MatrixIO.saveBin(A, "matrix_file.data");
                DMatrixRMaj B = MatrixIO.loadBin <DMatrixRMaj>("matrix_file.data");
                B.print();
            }
            catch (IOException e)
            {
                throw new InvalidOperationException(e.Message, e);
            }
        }
Exemplo n.º 10
0
        public static void csv()
        {
            DMatrixRMaj A = new DMatrixRMaj(2, 3, true, new double[] { 1, 2, 3, 4, 5, 6 });

            try
            {
                MatrixIO.saveCSV(A, "matrix_file.csv");
                DMatrixRMaj B = (DMatrixRMaj)MatrixIO.loadCSV("matrix_file.csv");
                B.print();
            }
            catch (IOException e)
            {
                throw new InvalidOperationException(e.Message, e);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Loads a new matrix from a serialized binary file.
        /// </summary>
        /// <param name="fileName"></param>
        /// <see cref="MatrixIO.loadBin{DMatrix}(string)"/>
        public static SimpleMatrixD loadBinary(string fileName)
        {
            DMatrix mat = MatrixIO.loadBin <DMatrix>(fileName);

            // see if its a DMatrixRMaj
            if (mat is DMatrixRMaj)
            {
                return(wrap(mat as DMatrixRMaj));
            }
            else
            {
                // if not convert it into one and wrap it
                return(wrap(new DMatrixRMaj(mat)));
            }
        }
        private void Update()
        {
            var ip        = trackerIp;
            var cstMatrix = cstTransformMatrix;
            var cstScale  = cstScaleFactor;

            if (ipFromBoss || cstFromBoss) // If boss is in use
            {
                var boss = GetTrackerBoss();
                if (boss == null)
                {
                    // No boss in scene so avoid checking every frame
                    enabled = false;
                    throw new System.Exception("TrackerTransform set to derive from TrackerBoss, but no TrackerBoss in scene. TrackerTransform will be disabled.");
                }
                if (ipFromBoss)
                {
                    ip = boss.trackerIp;
                }
                if (cstFromBoss)
                {
                    cstMatrix = boss.CstTransformMatrix;
                    cstScale  = boss.CstScaleFactor;
                }
            }

            // Get tracker pose from VRPN.
            var vrpnRot = VRPN_Handler.vrpnTrackerQuat(trackerId + "@" + ip, 0);
            var vrpnPos = VRPN_Handler.vrpnTrackerPos(trackerId + "@" + ip, 0);
            // Convert from right to left handed coordinate base.
            Quaternion lhRot = LHQuatFromRHQuat(vrpnRot, axis);
            Vector3    lhPos = LHVectorFromRHVector(vrpnPos, axis);
            // Multiply by the CST matrix to transform from tracker worldspace to app worldspace.
            var cstRot = MatrixIO.QuaternionFromMatrix(cstMatrix) * lhRot;
            var cstPos = cstMatrix.MultiplyPoint3x4(lhPos);

            cstPos *= cstScale;
            // Apply offset matrix.
            var trackerTransform = Matrix4x4.TRS(cstPos, cstRot, Vector3.one);

            trackerTransform = trackerTransform * Matrix4x4.TRS(offsetTranslate, offsetRotation, Vector3.one);
            // Decompose and apply to GameObject transform.
            transform.position = trackerTransform.GetColumn(3);
            transform.rotation = MatrixIO.QuaternionFromMatrix(trackerTransform);
        }
        private void Start()
        {
            // Load
            var boss = GetTrackerBoss();

            if (cstFromFile)
            {
                var basePath = "";
                if (cstPathBase == RelativePathBase.ProjectAssets)
                {
                    basePath = Application.dataPath;
                }
                else if (cstPathBase == RelativePathBase.TrackerBoss)
                {
                    if (boss == null)
                    {
                        throw new System.Exception("No TrackerBoss in scene.");
                    }
                    basePath = boss.MatrixDirectory;
                }
                var path      = System.IO.Path.Combine(basePath, cstPath);
                var cstMatrix = MatrixIO.ReadMatrixFromFile(path);
                SetCstMatrix(cstMatrix);
            }
            if (offsetFromFile)
            {
                var basePath = "";
                if (offsetPathBase == RelativePathBase.ProjectAssets)
                {
                    basePath = Application.dataPath;
                }
                else if (offsetPathBase == RelativePathBase.TrackerBoss)
                {
                    if (boss == null)
                    {
                        throw new System.Exception("No TrackerBoss in scene.");
                    }
                    basePath = boss.MatrixDirectory;
                }
                var path         = System.IO.Path.Combine(basePath, offsetPath);
                var offsetMatrix = MatrixIO.ReadMatrixFromFile(path);
                SetOffsetMatrix(offsetMatrix);
            }
        }
 private void Start()
 {
     // Load
     if (cstFromFile)
     {
         var basePath = "";
         if (cstPathBase == TrackerTransform.RelativePathBase.ProjectAssets)
         {
             basePath = Application.dataPath;
         }
         else if (cstPathBase == TrackerTransform.RelativePathBase.TrackerBoss)
         {
             basePath = MatrixDirectory;
         }
         var path      = System.IO.Path.Combine(basePath, cstPath);
         var cstMatrix = MatrixIO.ReadMatrixFromFile(path);
         SetCstMatrix(cstMatrix);
     }
 }
Exemplo n.º 15
0
 /// <summary>
 /// Converts the array into a string format for display purposes.
 /// </summary>
 /// <see cref="MatrixIO.print(Stream, DMatrix)"/>
 public string toString()
 {
     using (var stream = new MemoryStream())
     {
         if (mat is DMatrix)
         {
             MatrixIO.print(stream, (DMatrix)mat);
         }
         if (mat is FMatrix)
         {
             MatrixIO.print(stream, (FMatrix)mat);
         }
         else
         {
             throw new InvalidOperationException("Unknown or unsupported matrix type.");
         }
         stream.Position = 0;
         var reader = new StreamReader(stream);
         return(reader.ReadToEnd());
     }
 }
        public bool LoadTaskFromFile()
        {
            string functionName = MethodInfo.GetCurrentMethod().Name;

            if ((HaveErrorsState(functionName)) && (!_view.AskQuestion("Цель уже была создана, удалить предыдущую?")))
            {
                return(false);
            }

            _model.matrixsCompare.Clear();
            _model.task = null;

            _model.task = MatrixIO.LoadFromFile();



            _model.task?.fields.ForEach(x => _model.matrixsCompare.Add(x, new MatrixTable(x, _model.options)));
            selectedMatrix = _model.task?.name;
            _view.OuputMatrixTask(MatrixToDataTable(_model.task));
            result = false;
            return(true);
        }
Exemplo n.º 17
0
 public virtual void print()
 {
     MatrixIO.print(Console.OpenStandardOutput(), this);
 }
Exemplo n.º 18
0
 public void print()
 {
     MatrixIO.print(Console.OpenStandardOutput(), original, "%6.3ff", row0, row1, col0, col1);
 }
Exemplo n.º 19
0
 public virtual void print(Stream output, Matrix mat)
 {
     MatrixIO.print(output, (DMatrixRMaj)mat);
 }
Exemplo n.º 20
0
 /**
  * <p>
  * Prints the value of this matrix to the screen using the same format as {@link java.io.PrintStream#printf}.
  * </p>
  *
  * @param format The format which each element is printed uses.
  */
 public void print(string format)
 {
     MatrixIO.print(Console.OpenStandardOutput(), this, format);
 }
Exemplo n.º 21
0
 /// <summary>
 /// 从文本文件中加载矩阵
 /// </summary>
 /// <param name="filePath">文件路径</param>
 /// <param name="encoding">编码</param>
 /// <returns></returns>
 public static Matrix Load(string filePath, Encoding encoding)
 {
     return(MatrixIO.Load(filePath, encoding));
 }
Exemplo n.º 22
0
 /// <summary>
 /// 保存矩阵
 /// </summary>
 /// <param name="filePath">文件路径</param>
 public void Save(string filePath)
 {
     MatrixIO.Save(elements, filePath);
 }
Exemplo n.º 23
0
 public override void print()
 {
     MatrixIO.print(Console.OpenStandardOutput(), this);
 }