MatFileIO.h 4.3 KB

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