| 221 | } |
| 222 | |
| 223 | bool ExportScene(const std::string& sList_filename, const std::string& sBaf_filename, const SfM_Scene& sceneBAF) |
| 224 | { |
| 225 | LOG_OUT() << "Writing:\n" |
| 226 | << sList_filename << "\n" |
| 227 | << sBaf_filename << std::endl; |
| 228 | |
| 229 | // Write view list file (view filename, id_intrinsic, id_pose) |
| 230 | { |
| 231 | std::ofstream file(sList_filename.c_str()); |
| 232 | if (!file.good()) { |
| 233 | VERBOSE("error: unable to open file '%s'", sList_filename.c_str()); |
| 234 | return false; |
| 235 | } |
| 236 | for (uint32_t i=0; i<sceneBAF.images.size(); ++i) { |
| 237 | const Image& image = sceneBAF.images[i]; |
| 238 | file << image.name << ' ' << image.id_camera << ' ' << image.id_pose << std::endl; |
| 239 | LOG_OUT() << image.name << ' ' << image.id_camera << ' ' << image.id_pose << std::endl; |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | // Write BAF file |
| 244 | { |
| 245 | std::ofstream file(sBaf_filename.c_str()); |
| 246 | if (!file.good()) { |
| 247 | VERBOSE("error: unable to open file '%s'", sBaf_filename.c_str()); |
| 248 | return false; |
| 249 | } |
| 250 | |
| 251 | const uint32_t num_intrinsics = (uint32_t)sceneBAF.cameras.size(); |
| 252 | const uint32_t num_poses = (uint32_t)sceneBAF.poses.size(); |
| 253 | const uint32_t num_points = (uint32_t)sceneBAF.vertices.size(); |
| 254 | |
| 255 | LOG_OUT() << "Writing BAF file with:\n" |
| 256 | << " num_intrinsics: " << num_intrinsics << "\n" |
| 257 | << " num_poses: " << num_poses << "\n" |
| 258 | << " num_points: " << num_points << "\n"; |
| 259 | |
| 260 | // Write header |
| 261 | file << num_intrinsics << std::endl; |
| 262 | file << num_poses << std::endl; |
| 263 | file << num_points << std::endl; |
| 264 | |
| 265 | // Write the intrinsics (only support writing Pinhole Radial 3). |
| 266 | { |
| 267 | for (uint32_t i = 0; i < num_intrinsics; ++i) { |
| 268 | const Camera& cam = sceneBAF.cameras[i]; |
| 269 | file << cam.K(0,0) << ' ' << cam.K(0,2) << ' ' << cam.K(1,2) << ' ' << 0 << ' ' << 0 << ' ' << 0 << std::endl; |
| 270 | LOG_OUT() << "\n" << cam.K << std::endl; |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | // Write poses |
| 275 | { |
| 276 | for (uint32_t i = 0; i < num_poses; ++i) { |
| 277 | const Pose& pose = sceneBAF.poses[i]; |
| 278 | for (int r = 0; r < 3; ++r) { |
| 279 | for (int c = 0; c < 3; ++c) { |
| 280 | file << pose.R(r,c) << ' '; |