| 47 | } |
| 48 | |
| 49 | ImageReader::ImageReader(const ImageReaderOptions& options, Database* database) |
| 50 | : options_(options), database_(database), image_index_(0) { |
| 51 | THROW_CHECK(options_.Check()); |
| 52 | |
| 53 | // Get a list of all files in the image path, sorted by image name. |
| 54 | if (options_.image_names.empty()) { |
| 55 | auto image_paths = GetRecursiveFileList(options_.image_path); |
| 56 | std::sort(image_paths.begin(), image_paths.end()); |
| 57 | options_.image_names.reserve(image_paths.size()); |
| 58 | for (const auto& image_path : image_paths) { |
| 59 | options_.image_names.push_back( |
| 60 | GetNormalizedRelativePath(image_path, options_.image_path)); |
| 61 | } |
| 62 | } else { |
| 63 | if (!std::is_sorted(options_.image_names.begin(), |
| 64 | options_.image_names.end())) { |
| 65 | std::sort(options_.image_names.begin(), options_.image_names.end()); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | if (static_cast<camera_t>(options_.existing_camera_id) != kInvalidCameraId) { |
| 70 | THROW_CHECK(database->ExistsCamera(options_.existing_camera_id)); |
| 71 | prev_camera_ = database->ReadCamera(options_.existing_camera_id); |
| 72 | if (std::optional<Rig> rig = |
| 73 | database->ReadRigWithSensor(prev_camera_.SensorId()); |
| 74 | rig.has_value()) { |
| 75 | prev_rig_ = std::move(*rig); |
| 76 | } else { |
| 77 | // For backwards compatibility with old databases without rigs. |
| 78 | prev_rig_.AddRefSensor(prev_camera_.SensorId()); |
| 79 | prev_rig_.SetRigId(database_->WriteRig(prev_rig_)); |
| 80 | } |
| 81 | } else { |
| 82 | // Set the manually specified camera parameters. |
| 83 | prev_camera_.camera_id = kInvalidCameraId; |
| 84 | THROW_CHECK(ExistsCameraModelWithName(options_.camera_model)); |
| 85 | prev_camera_.model_id = CameraModelNameToId(options_.camera_model); |
| 86 | prev_camera_.params.resize(CameraModelNumParams(prev_camera_.model_id), 0.); |
| 87 | if (!options_.camera_params.empty()) { |
| 88 | THROW_CHECK(prev_camera_.SetParamsFromString(options_.camera_params)); |
| 89 | prev_camera_.has_prior_focal_length = true; |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | ImageReader::Status ImageReader::Next(Rig* rig, |
| 95 | Camera* camera, |
nothing calls this directly
no test coverage detected