30 #ifndef OPENCV_FLANN_HDF5_H_
31 #define OPENCV_FLANN_HDF5_H_
47 throw FLANNException(
"Unsupported type for IO operations");
51 hid_t get_hdf5_type<char>() {
return H5T_NATIVE_CHAR; }
53 hid_t get_hdf5_type<unsigned char>() {
return H5T_NATIVE_UCHAR; }
55 hid_t get_hdf5_type<short int>() {
return H5T_NATIVE_SHORT; }
57 hid_t get_hdf5_type<unsigned short int>() {
return H5T_NATIVE_USHORT; }
59 hid_t get_hdf5_type<int>() {
return H5T_NATIVE_INT; }
61 hid_t get_hdf5_type<unsigned int>() {
return H5T_NATIVE_UINT; }
63 hid_t get_hdf5_type<long>() {
return H5T_NATIVE_LONG; }
65 hid_t get_hdf5_type<unsigned long>() {
return H5T_NATIVE_ULONG; }
67 hid_t get_hdf5_type<float>() {
return H5T_NATIVE_FLOAT; }
69 hid_t get_hdf5_type<double>() {
return H5T_NATIVE_DOUBLE; }
73 #define CHECK_ERROR(x,y) if ((x)<0) throw FLANNException((y));
79 #if H5Eset_auto_vers == 2
80 H5Eset_auto( H5E_DEFAULT, NULL, NULL );
82 H5Eset_auto( NULL, NULL );
87 file_id = H5Fopen(filename.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
89 file_id = H5Fcreate(filename.c_str(), H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);
91 CHECK_ERROR(file_id,
"Error creating hdf5 file.");
94 dimsf[0] = dataset.
rows;
95 dimsf[1] = dataset.
cols;
97 hid_t space_id = H5Screate_simple(2, dimsf, NULL);
98 hid_t memspace_id = H5Screate_simple(2, dimsf, NULL);
101 #if H5Dcreate_vers == 2
102 dataset_id = H5Dcreate2(file_id, name.c_str(), get_hdf5_type<T>(), space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
104 dataset_id = H5Dcreate(file_id, name.c_str(), get_hdf5_type<T>(), space_id, H5P_DEFAULT);
108 #if H5Dopen_vers == 2
109 dataset_id = H5Dopen2(file_id, name.c_str(), H5P_DEFAULT);
111 dataset_id = H5Dopen(file_id, name.c_str());
114 CHECK_ERROR(dataset_id,
"Error creating or opening dataset in file.");
116 status = H5Dwrite(dataset_id, get_hdf5_type<T>(), memspace_id, space_id, H5P_DEFAULT, dataset.
data );
117 CHECK_ERROR(status,
"Error writing to dataset");
119 H5Sclose(memspace_id);
121 H5Dclose(dataset_id);
131 hid_t file_id = H5Fopen(filename.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
132 CHECK_ERROR(file_id,
"Error opening hdf5 file.");
135 #if H5Dopen_vers == 2
136 dataset_id = H5Dopen2(file_id, name.c_str(), H5P_DEFAULT);
138 dataset_id = H5Dopen(file_id, name.c_str());
140 CHECK_ERROR(dataset_id,
"Error opening dataset in file.");
142 hid_t space_id = H5Dget_space(dataset_id);
145 H5Sget_simple_extent_dims(space_id, dims_out, NULL);
149 status = H5Dread(dataset_id, get_hdf5_type<T>(), H5S_ALL, H5S_ALL, H5P_DEFAULT, dataset[0]);
150 CHECK_ERROR(status,
"Error reading dataset");
153 H5Dclose(dataset_id);
171 MPI_Comm comm = MPI_COMM_WORLD;
172 MPI_Info info = MPI_INFO_NULL;
174 int mpi_size, mpi_rank;
175 MPI_Comm_size(comm, &mpi_size);
176 MPI_Comm_rank(comm, &mpi_rank);
180 hid_t plist_id = H5Pcreate(H5P_FILE_ACCESS);
181 H5Pset_fapl_mpio(plist_id, comm, info);
182 hid_t file_id = H5Fopen(filename.c_str(), H5F_ACC_RDWR, plist_id);
183 CHECK_ERROR(file_id,
"Error opening hdf5 file.");
186 #if H5Dopen_vers == 2
187 dataset_id = H5Dopen2(file_id, name.c_str(), H5P_DEFAULT);
189 dataset_id = H5Dopen(file_id, name.c_str());
191 CHECK_ERROR(dataset_id,
"Error opening dataset in file.");
193 hid_t space_id = H5Dget_space(dataset_id);
195 H5Sget_simple_extent_dims(space_id, dims, NULL);
200 hsize_t item_cnt = dims[0]/mpi_size+(dims[0]%mpi_size==0 ? 0 : 1);
201 hsize_t cnt = (mpi_rank<mpi_size-1 ? item_cnt : dims[0]-item_cnt*(mpi_size-1));
205 offset[0] = mpi_rank*item_cnt;
208 hid_t memspace_id = H5Screate_simple(2,count,NULL);
210 H5Sselect_hyperslab(space_id, H5S_SELECT_SET, offset, NULL, count, NULL);
212 dataset.
rows = count[0];
213 dataset.
cols = count[1];
216 plist_id = H5Pcreate(H5P_DATASET_XFER);
217 H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE);
218 status = H5Dread(dataset_id, get_hdf5_type<T>(), memspace_id, space_id, plist_id, dataset.
data);
219 CHECK_ERROR(status,
"Error reading dataset");
223 H5Sclose(memspace_id);
224 H5Dclose(dataset_id);
int dims
Definition: core_c.h:218
const CvArr CvArr CvArr const CvPoint2D32f CvPoint2D32f int CvSize int char * status
Definition: tracking.hpp:73
const char const char ** filename
Definition: core_c.h:1750
size_t cols
Definition: matrix.h:52
void load_from_file(cvflann::Matrix< T > &dataset, const std::string &filename, const std::string &name)
Definition: hdf5.h:128
const CvMat const CvMat const CvMat CvMat CvMat CvMat CvMat CvSize CvMat CvMat * T
Definition: calib3d.hpp:270
void save_to_file(const cvflann::Matrix< T > &dataset, const std::string &filename, const std::string &name)
Definition: hdf5.h:76
GLuint GLuint GLsizei count
Definition: core_c.h:973
T * data
Definition: matrix.h:54
GLuint const GLchar * name
Definition: core_c.h:1546
size_t rows
Definition: matrix.h:51
void load_from_file(cvflann::Matrix< T > &dataset, const std::string &filename, const std::string &name)
Definition: hdf5.h:169