bool Save_Cereal( const SfM_Data & data, const std::string & filename, ESfM_Data flags_part) { // List which part of the file must be considered const bool b_views = (flags_part & VIEWS) == VIEWS; const bool b_intrinsics = (flags_part & INTRINSICS) == INTRINSICS; const bool b_extrinsics = (flags_part & EXTRINSICS) == EXTRINSICS; const bool b_structure = (flags_part & STRUCTURE) == STRUCTURE; const bool b_control_point = (flags_part & CONTROL_POINTS) == CONTROL_POINTS; //Create the stream and check it is ok std::ofstream stream(filename.c_str(), std::ios::binary | std::ios::out); if (!stream.is_open()) return false; // Data serialization { archiveType archive(stream); // since OpenMVG 0.9, the sfm_data version 0.2 is introduced // - it adds control_points storage const std::string version = "0.2"; archive(cereal::make_nvp("sfm_data_version", version)); archive(cereal::make_nvp("root_path", data.s_root_path)); if (b_views) archive(cereal::make_nvp("views", data.views)); else archive(cereal::make_nvp("views", Views())); if (b_intrinsics) archive(cereal::make_nvp("intrinsics", data.intrinsics)); else archive(cereal::make_nvp("intrinsics", Intrinsics())); if (b_extrinsics) archive(cereal::make_nvp("extrinsics", data.poses)); else archive(cereal::make_nvp("extrinsics", Poses())); // Structure -> See for export in another file if (b_structure) archive(cereal::make_nvp("structure", data.structure)); else archive(cereal::make_nvp("structure", Landmarks())); if (version != "0.1") // fast check to assert we are at least using version 0.2 { if (b_control_point) archive(cereal::make_nvp("control_points", data.control_points)); else archive(cereal::make_nvp("control_points", Landmarks())); } } stream.close(); return true; }
bool Save_Cereal( const SfM_Data & data, const std::string & filename, ESfM_Data flags_part) { // List which part of the file must be considered const bool b_views = (flags_part & VIEWS) == VIEWS; const bool b_intrinsics = (flags_part & INTRINSICS) == INTRINSICS; const bool b_extrinsics = (flags_part & EXTRINSICS) == EXTRINSICS; const bool b_structure = (flags_part & STRUCTURE) == STRUCTURE; //Create the stream and check it is ok std::ofstream stream(filename.c_str()); if (!stream.is_open()) return false; // Data serialization { archiveType archive(stream); const std::string version = "0.1"; archive(cereal::make_nvp("sfm_data_version", version)); archive(cereal::make_nvp("root_path", data.s_root_path)); if (b_views) archive(cereal::make_nvp("views", data.views)); else archive(cereal::make_nvp("views", Views())); if (b_intrinsics) archive(cereal::make_nvp("intrinsics", data.intrinsics)); else archive(cereal::make_nvp("intrinsics", Intrinsics())); if (b_extrinsics) archive(cereal::make_nvp("extrinsics", data.poses)); else archive(cereal::make_nvp("extrinsics", Poses())); // Structure -> See for export in another file if (b_structure) archive(cereal::make_nvp("structure", data.structure)); else archive(cereal::make_nvp("structure", Landmarks())); } return true; }
bool Hdf5Dataset::getMultimap(MultiMap &mMap) { hsize_t dims_out[2], count[2], offset[2]; hid_t dataspace = H5Dget_space(this->poses_dataset_); /* dataspace handle */ int rank = H5Sget_simple_extent_ndims(dataspace); herr_t status_n = H5Sget_simple_extent_dims(dataspace, dims_out, NULL); herr_t status; int chunk_size, chunk_itr; if (dims_out[0] % 10) { chunk_itr = 11; } else { chunk_itr = 10; } chunk_size = (dims_out[0] / 10); offset[0] = 0; for (int it = 0; it < chunk_itr; it++) { offset[1] = 0; if ((dims_out[0] - (chunk_size * it)) / chunk_size != 0) { count[0] = chunk_size; offset[0] = chunk_size * it; } else { count[0] = (dims_out[0] - (chunk_size * it)); offset[0] = count[0]; } count[1] = 10; double data_out[count[0]][count[1]]; status = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, offset, NULL, count, NULL); hsize_t dimsm[2]; dimsm[0] = count[0]; dimsm[1] = count[1]; hid_t memspace; memspace = H5Screate_simple(RANK_OUT, dimsm, NULL); status = H5Dread(this->poses_dataset_, H5T_NATIVE_DOUBLE, memspace, dataspace, H5P_DEFAULT, data_out); for(int i=0; i<count[0]; i++) { std::vector<double> sphere_center(3); std::vector<double> Poses(7); for(int j=0; j<3;j++) { sphere_center[j] = data_out[i][j]; } for(int k=3;k<10; k++) { Poses[k-3] = data_out[i][k]; } mMap.insert(std::make_pair(sphere_center, Poses)); } } return 0; }