MatFileIO.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /**
  2. * @file MatFileIO.h
  3. * @brief Read and write mat-files
  4. * @author Paul Bodesheim
  5. * @date 06-01-2012 (dd-mm-yyyy)
  6. */
  7. #ifndef MATFILEIOH_INCLUDE
  8. #define MATFILEIOH_INCLUDE
  9. #include <cstdlib>
  10. #include <stdlib.h>
  11. #include <stdarg.h>
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include <math.h>
  15. #include <vector>
  16. #include <core/basics/Exception.h>
  17. #include <core/vector/VectorT.h>
  18. #ifndef NICE_USELIB_MATIO
  19. #pragma message NICE_WARNING("We need the MATIO Library for accessing MATLAB structures. Otherwise this is not compiling.")
  20. #else //#ifdef NICE_USELIB_MATIO
  21. #include <matio.h>
  22. #ifndef sparse_t
  23. #define sparse_t mat_sparse_t
  24. #endif
  25. namespace NICE {
  26. class MatFileIO {
  27. protected:
  28. mat_t *mat; // struct for the mat-file, defined in matio.h
  29. public:
  30. //------------------------------------------------------
  31. // several constructors and destructors
  32. //----------------------------------------------------
  33. /**
  34. * @brief Default constructor
  35. * @author Paul Bodesheim
  36. * @date 06-01-2012 (dd-mm-yyyy)
  37. */
  38. MatFileIO();
  39. /**
  40. * @brief Recommended constructor
  41. * @author Paul Bodesheim
  42. * @date 06-01-2012 (dd-mm-yyyy)
  43. * @param _filename name of the mat-file, if mode = MAT_ACC_RDWR and _filename does not exist, a new file will be created
  44. * @param mode file access mode: MAT_ACC_RDONLY (read only) or MAT_ACC_RDWR (read + write)
  45. */
  46. MatFileIO(std::string _filename, const mat_acc mode);
  47. /**
  48. * @brief Default destructor
  49. * @author Paul Bodesheim
  50. * @date 06-01-2012 (dd-mm-yyyy)
  51. */
  52. ~MatFileIO();
  53. //------------------------------------------------------
  54. // enumeration
  55. //------------------------------------------------------
  56. /**
  57. * @brief feature matrix order
  58. * @author Paul Bodesheim
  59. * @date 09-01-2012 (dd-mm-yyyy)
  60. */
  61. enum feature_matrix_order {
  62. NxD = 1, /**< @brief Read only file access */
  63. DxN = 2 /**< @brief Read/Write file access */
  64. };
  65. //------------------------------------------------------
  66. // count number of stored variables
  67. //------------------------------------------------------
  68. /**
  69. * @brief get the number of variables stored in the mat-file referenced by mat
  70. * @author Paul Bodesheim
  71. * @date 06-01-2012 (dd-mm-yyyy)
  72. * @return number of variables
  73. */
  74. int getNumberOfVariables();
  75. //------------------------------------------------------
  76. // several methods for reading data
  77. //------------------------------------------------------
  78. /**
  79. * @brief get the variable with name _name stored in the mat-file referenced by mat
  80. * @author Paul Bodesheim
  81. * @date 06-01-2012 (dd-mm-yyyy)
  82. * @param _name name of the variable
  83. * @return variable with name _name in the matvar_t format
  84. */
  85. matvar_t * getVariableViaName(std::string _name);
  86. /**
  87. * @brief get the sparsely stored variable with name _name stored in the mat-file referenced by mat
  88. * @author Paul Bodesheim
  89. * @date 10-01-2012 (dd-mm-yyyy)
  90. * @param sparseVariable result: sparse variable with name _name in sparse matio-format sparse_t (see matio/src/matio.h)
  91. * @param _name name of the variable
  92. **/
  93. void getSparseVariableViaName(sparse_t & sparseVariable, std::string _name);
  94. /**
  95. * @brief get the feature matrix with name _name stored in the mat-file referenced by mat
  96. * @author Paul Bodesheim
  97. * @date 09-01-2012 (dd-mm-yyyy)
  98. * @param _name name of the variable
  99. * @param order organization of the feature matrix: NxD (each feature in a row and each feature dimension in a coliumn)or DxN (vice versa)
  100. * @param features result: feature matrix with name _name in the fast-HIK format: std::vector<std::vector<double> >
  101. */
  102. void getFeatureMatrixViaName(std::vector<std::vector<double> > & features, std::string _name, const feature_matrix_order order = NxD);
  103. /**
  104. * @brief get vector with name _name stored in the mat-file referenced by mat
  105. * @author Paul Bodesheim
  106. * @date 09-01-2012 (dd-mm-yyyy)
  107. * @param _name name of the variable
  108. * @param vec result: vector with name _name in format NICE::Vector
  109. */
  110. void getVectorViaName(NICE::Vector & vec, std::string _name);
  111. }; // class
  112. } // namespace
  113. #endif
  114. #endif