MatFileIO.h 4.5 KB

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