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; }