MatFileIO.h 4.6 KB

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