| 104 | |
| 105 | |
| 106 | bool ImportScene(const std::string& sList_filename, const std::string& sBaf_filename, SfM_Scene& sceneBAF) |
| 107 | { |
| 108 | LOG_OUT() << "Reading:\n" |
| 109 | << sList_filename << "\n" |
| 110 | << sBaf_filename << std::endl; |
| 111 | |
| 112 | // Read view list file (view filename, id_intrinsic, id_pose) |
| 113 | // Must be read first, since it allow to establish the link between the ViewId and the camera/poses ids. |
| 114 | std::map< std::pair<uint32_t, uint32_t>, uint32_t > map_cam_pose_toViewId; |
| 115 | { |
| 116 | std::ifstream file(sList_filename.c_str()); |
| 117 | if (!file.good()) { |
| 118 | VERBOSE("error: unable to open file '%s'", sList_filename.c_str()); |
| 119 | return false; |
| 120 | } |
| 121 | Image image; |
| 122 | uint32_t count = 0; |
| 123 | while (file >> image.name >> image.id_camera >> image.id_pose) { |
| 124 | sceneBAF.images.push_back(image); |
| 125 | map_cam_pose_toViewId[std::make_pair(image.id_camera, image.id_pose)] = count++; |
| 126 | LOG_OUT() << image.name << ' ' << image.id_camera << ' ' << image.id_pose << std::endl; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | // Read BAF file |
| 131 | { |
| 132 | std::ifstream file(sBaf_filename.c_str()); |
| 133 | if (!file.good()) { |
| 134 | VERBOSE("error: unable to open file '%s'", sBaf_filename.c_str()); |
| 135 | return false; |
| 136 | } |
| 137 | |
| 138 | uint32_t num_intrinsics, num_poses, num_points; |
| 139 | |
| 140 | // Read header |
| 141 | file >> num_intrinsics; |
| 142 | file >> num_poses; |
| 143 | file >> num_points; |
| 144 | |
| 145 | LOG_OUT() << "Reading BAF file with:\n" |
| 146 | << " num_intrinsics: " << num_intrinsics << "\n" |
| 147 | << " num_poses: " << num_poses << "\n" |
| 148 | << " num_points: " << num_points << "\n"; |
| 149 | |
| 150 | // Read the intrinsics (only support reading Pinhole Radial 3). |
| 151 | { |
| 152 | for (uint32_t i = 0; i < num_intrinsics; ++i) { |
| 153 | double focal, ppx, ppy, k1, k2, k3; |
| 154 | file >> focal >> ppx >> ppy >> k1 >> k2 >> k3; |
| 155 | Camera cam; |
| 156 | cam.K << |
| 157 | focal, 0, ppx, |
| 158 | 0, focal, ppy, |
| 159 | 0, 0, 1; |
| 160 | LOG_OUT() << "\n" << cam.K << std::endl; |
| 161 | sceneBAF.cameras.push_back(cam); |
| 162 | } |
| 163 | } |