All Projects → ami-iit → matio-cpp

ami-iit / matio-cpp

Licence: BSD-2-Clause license
A C++ wrapper of the matio library, with memory ownership handling, to read and write .mat files.

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to matio-cpp

h5pp
A C++17 interface for HDF5
Stars: ✭ 60 (+150%)
Mutual labels:  eigen, hdf5
osqp-cpp
A C++ interface for the OSQP quadratic programming solver.
Stars: ✭ 160 (+566.67%)
Mutual labels:  eigen
Hole fixer
Demo implementation of smoothly filling holes in 3D meshes using surface fairing
Stars: ✭ 165 (+587.5%)
Mutual labels:  eigen
SimplexSolver
An easy-to-use Simplex solver class for linear programming.
Stars: ✭ 18 (-25%)
Mutual labels:  eigen
Mathtoolbox
Mathematical tools (interpolation, dimensionality reduction, optimization, etc.) written in C++11 with Eigen
Stars: ✭ 172 (+616.67%)
Mutual labels:  eigen
ASALI
Do you work with chemical reactors? Are you curious about them? ASALI is the open-source code that you are looking for. Chemical reactor models, transport/thermodynamic properties of gases, equilibrium calculations. ASALI couples all these features with an user friendly graphical interface. Modeling catalytic reactors has never been so easy.
Stars: ✭ 38 (+58.33%)
Mutual labels:  octave
Pydensecrf
Python wrapper to Philipp Krähenbühl's dense (fully connected) CRFs with gaussian edge potentials.
Stars: ✭ 1,633 (+6704.17%)
Mutual labels:  eigen
jupyterlab-h5web
A JupyterLab extension to explore and visualize HDF5 file contents. Based on https://github.com/silx-kit/h5web.
Stars: ✭ 41 (+70.83%)
Mutual labels:  hdf5
octave-docker
Dockerfile to build an Octave container
Stars: ✭ 11 (-54.17%)
Mutual labels:  octave
lama-cleaner
Image inpainting tool powered by SOTA AI Model. Remove any unwanted object, defect, people from your pictures or erase and replace(powered by stable diffusion) any thing on your pictures.
Stars: ✭ 9,099 (+37812.5%)
Mutual labels:  mat
eigen
Owl's OCaml Interface to Eigen3 C++ Library
Stars: ✭ 30 (+25%)
Mutual labels:  eigen
Dive Into Ml System
Dive into machine learning system, start from reinventing the wheel.
Stars: ✭ 220 (+816.67%)
Mutual labels:  eigen
go-redis
GNU Octave Redis client (for Matlab too)
Stars: ✭ 23 (-4.17%)
Mutual labels:  octave
Modernroboticscpp
Modern Robotics: Mechanics, Planning, and Control C++ Library --- The primary purpose of the provided software is to be easy to read and educational, reinforcing the concepts in the book. The code is optimized neither for efficiency nor robustness. http://modernrobotics.org/
Stars: ✭ 170 (+608.33%)
Mutual labels:  eigen
RcppEigen
Rcpp integration for the Eigen templated linear algebra library
Stars: ✭ 89 (+270.83%)
Mutual labels:  eigen
Monocular Visual Odometry
A simple monocular visual odometry (part of vSLAM) by ORB keypoints with initialization, tracking, local map and bundle adjustment. (WARNING: Hi, I'm sorry that this project is just tuned for course demo, not for real world applications !!!)
Stars: ✭ 147 (+512.5%)
Mutual labels:  eigen
eigen-js
⚡ Eigen-js is a port of the Eigen C++ linear algebra library
Stars: ✭ 78 (+225%)
Mutual labels:  eigen
PH5
Library of PH5 clients, apis, and utilities
Stars: ✭ 14 (-41.67%)
Mutual labels:  hdf5
EMsoft
Public EMsoft repository
Stars: ✭ 44 (+83.33%)
Mutual labels:  hdf5
TDoA
Time difference of arrival (TDoA) multi-lateration
Stars: ✭ 48 (+100%)
Mutual labels:  octave

matio-cpp C++ Standard

matio-cpp is a C++ wrapper for the matio library, automatically dealing with memory allocation and deallocation. It can be used for reading and writing binary MATLAB .mat files from C++, without the need to access or rely on MATLAB's own shared libraries.

Overview

Installation

Dependencies

The depencies are CMake (minimum version 3.10) and matio. While we suggest to follow the build instructions provided in the matio home page, it can also installed from common package managers:

  • Linux: sudo apt install libmatio-dev
  • macOS: brew install libmatio
  • Windows, via vcpkg: vcpkg install --triplet x64-windows matio

Eigen is an optional dependency. If available, some conversions are defined.

For running the tests, it is necessary to install Catch2. Where supported, valgrind can be installed to check for memory leaks.

Linux/macOS

git clone https://github.com/ami-iit/matio-cpp
cd matio-cpp
mkdir build && cd build
cmake ../
make
[sudo] make install

Notice: sudo is not necessary if you specify the CMAKE_INSTALL_PREFIX. In this case it is necessary to add in the .bashrc or .bash_profile the following lines:

export matioCpp_DIR=/path/where/you/installed/

Windows

With IDE build tool facilities, such as Visual Studio:

git clone https://github.com/ami-iit/matio-cpp
cd matio-cpp
mkdir build && cd build
cmake ..
cmake --build . --target ALL_BUILD --config Release
cmake --build . --target INSTALL --config Release

In order to allow CMake finding matio-cpp, it is necessary that the installation folder is in the PATH.

Inclusion

matio-cpp provides native CMake support which allows the library to be easily used in CMake projects

In order to use matio-cpp in your project, add the following in your CMakeLists.txt

find_package(matioCpp REQUIRED)

# ...

target_link_libraries(yourTarget PRIVATE matioCpp::matioCpp)

Supported Data Types

matio-cpp can handle the following data types:

  • Element, like double, int, ...
  • String
  • Vector, i.e. 1-dimensional arrays of primitive types
  • MultiDimensionalArray, i.e. n-dimensional arrays of primitive types
  • CellArray, i.e. n-dimensional arrays of generic types
  • Struct, i.e. a collection of name/variable pairs
  • StructArray, i.e. n-dimensional arrays of Structs

All these types can be read/written from/to .mat files.

Example of usage

Read a .mat file

#include <matioCpp/matioCpp.h>

// ...

matioCpp::File input("input.mat");
// You can check if input is open with the isOpen() method
matioCpp::CellArray cellArray = input.read("cell_array").asCellArray(); //Read a Cell Array named "cell_array"
matioCpp::Element<double> doubleVar = cellArray({1,2,3}).asElement<double>(); //Get the element in the cell array at position (1,2,3) (0-based), casting it as a double Element
doubleVar = 3.14; //Set the doubleVar to a new value
assert(cellArray({1,2,3}).asElement<double>()() == 3.14); //Also the original cell array is modified, but not in the file.

Write a .mat file

#include <matioCpp/matioCpp.h>

// ...

matioCpp::File file = matioCpp::File::Create("test.mat"); //If the file already exists, use the same cnstructor as the example above

std::vector<double> in = {2.0,4.0,6.0,8.0};
matioCpp::Vector<double> out("test_vector");
out = in;
file.write(out);

matioCpp::String testString("string_name");
testString = "string content";
file.write(testString);

It is possibile to convert common types to matioCpp types with the function matioCpp::make_variable. Examples:

std::vector<double> stdVec = {1.0, 2.0, 3.0, 4.0, 5.0};
auto toMatioVec = matioCpp::make_variable("test", stdVec);

std::array<float,3> array = {1.0, 2.0, 3.0};
auto toMatioArray = matioCpp::make_variable("test", array);

int classicalArray[] = {1, 2, 3};
auto toMatioClassic = matioCpp::make_variable("test", matioCpp::make_span(classicalArray, 3));

std::string string("something");
auto toMatioString = matioCpp::make_variable("name", string);

std::vector<bool> vecOfBool = {true, false, true};
auto toVecofBool = matioCpp::make_variable("vecOfBool", vecOfBool);

auto matioDouble = matioCpp::make_variable("double", 5.0);

auto matioBool = matioCpp::make_variable("bool", true);

auto matioInt = matioCpp::make_variable("int", 2);

auto matioChar = matioCpp::make_variable("char", 'f');

std::vector<std::string> stringVector = {"Huey", "Dewey", "Louie"};
auto matioCell = matioCpp::make_variable("stringVector", stringVector);

If eigen is available, it is also possible to convert from and to eigen types:

matioCpp::Vector<double> vector("vector", 5);                                               
Eigen::VectorXd eigenVec = matioCpp::to_eigen(vector);                                      
matioCpp::MultiDimensionalArray<float> matioCppMatrix("matrix"); 

Eigen::MatrixXf toEigenMatrix = matioCpp::to_eigen(matioCppMatrix);

Eigen::Matrix3f eigenMatrix;                                                    
eigenMatrix << 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0;                     
auto toMatioMatrix = matioCpp::make_variable("testMatrix", eigenMatrix);        
Eigen::Vector3i eigenVec;      
eigenVec << 2, 4, 6;                                                            
auto toMatioEigenVec = matioCpp::make_variable("testEigen", eigenVec);          

matioCpp also exploits visit_struct to parse C++ structs into matioCpp structs. Example:

struct testStruct
{
    int i{1};
    double d{2.0};
    std::string s{"test"};
    std::vector<double> stdVec = {1.0, 2.0, 3.0, 4.0, 5.0};
    int* notSupported = nullptr;
    std::vector<std::string> stringVector = {"Huey", "Dewey", "Louie"};
    std::vector<bool> vecOfBool = {true, false, true};
};
VISITABLE_STRUCT(testStruct, i, d, s, stdVec, vecOfBool, stringVector);

//----------

testStruct s;
matioCpp::Struct automaticStruct = matioCpp::make_variable("testStruct", s);

Known Limitations

  • Complex arrays are not yet supported
  • Cannot read timeseries from a .mat file (this is a matio limitation tbeu/matio#99)
  • Cannot read string arrays from a .mat file (this is a matio limitation tbeu/matio#98)
  • Cannot read strings in a Struct from a .mat file (this is a matio limitation related to tbeu/matio#98)

Similar Projects

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].