| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- // This file is part of libigl, a simple c++ geometry processing library.
- //
- // Copyright (C) 2013 Alec Jacobson <[email protected]>
- //
- // This Source Code Form is subject to the terms of the Mozilla Public License
- // v. 2.0. If a copy of the MPL was not distributed with this file, You can
- // obtain one at http://mozilla.org/MPL/2.0/.
- #ifndef IGL_MATLAB_FORMAT_H
- #define IGL_MATLAB_FORMAT_H
- #include "igl_inline.h"
- #include <Eigen/Core>
- #include <Eigen/Sparse>
- #include <string>
- #include <vector>
- namespace igl
- {
- /// This is a routine to print a matrix using format suitable for pasting into
- /// the matlab IDE
- ///
- /// @tparam DerivedM e.g. derived from Eigen::MatrixXd
- /// @param[in] input some matrix to be formatted
- /// @param[in] name name of matrix (optional)
- /// @return Formatted matrix
- ///
- /// #### Example:
- /// \code{cpp}
- /// // M := [1 2 3;4 5 6];
- /// cout<<matlab_format(M)<<endl;
- /// // Prints:
- /// // [
- /// // 1 2 3
- /// // 4 5 6
- /// // ];
- /// cout<<matlab_format(M,"M")<<endl;
- /// // Prints:
- /// // M = [
- /// // 1 2 3
- /// // 4 5 6
- /// // ];
- /// \endcode
- template <typename DerivedM>
- IGL_INLINE const Eigen::WithFormat< DerivedM > matlab_format(
- const Eigen::DenseBase<DerivedM> & M,
- const std::string name = "");
- /// \overload
- ///
- /// \brief Add +1 to every entry before formatting.
- template <typename DerivedM>
- IGL_INLINE std::string matlab_format_index(
- const Eigen::MatrixBase<DerivedM> & M,
- const std::string name = "");
- template <typename T>
- IGL_INLINE std::string matlab_format_index(
- const std::vector<T> & Mvec,
- const std::string name = "");
- /// Same but for sparse matrices. Print IJV format into an auxiliary variable
- /// and then print a call to sparse which will construct the sparse matrix
- ///
- /// #### Example:
- /// \code{cpp}
- /// // S := [0 2 3;4 5 0];
- /// cout<<matlab_format(S,"S")<<endl;
- /// // Prints:
- /// // SIJV = [
- /// // 2 1 4
- /// // 1 2 2
- /// // 2 2 5
- /// // 1 3 3
- /// // ];
- /// // S = sparse(SIJV(:,1),SIJV(:,2),SIJV(:,3));
- /// \endcode
- ///
- template <typename DerivedS>
- IGL_INLINE const std::string matlab_format(
- const Eigen::SparseMatrix<DerivedS> & S,
- const std::string name = "");
- /// \overload
- /// \brief Scalars.
- IGL_INLINE const std::string matlab_format(
- const double v,
- const std::string name = "");
- /// \overload
- IGL_INLINE const std::string matlab_format(
- const float v,
- const std::string name = "");
- /// Just build and return the format.
- /// @return eigen IOFormat object
- ///
- /// #### Example:
- /// \code{cpp}
- /// // M := [1 2 3;4 5 6];
- /// cout<<M.format(matlab_format())<<endl;
- /// // Prints:
- /// // [
- /// // 1 2 3
- /// // 4 5 6
- /// // ];
- /// \endcode
- IGL_INLINE Eigen::IOFormat matlab_format();
- }
- #ifndef IGL_STATIC_LIBRARY
- # include "matlab_format.cpp"
- #endif
- #endif
|