| 40 | namespace fs = std::filesystem; |
| 41 | |
| 42 | bool exportToPMVSFormat(const SfMData& sfm_data, |
| 43 | const std::string& sOutDirectory, // Output PMVS files folder |
| 44 | const int downsampling_factor, |
| 45 | const int CPU_core_count, |
| 46 | const bool b_VisData = true) |
| 47 | { |
| 48 | bool bOk = true; |
| 49 | if (!utils::exists(sOutDirectory)) |
| 50 | { |
| 51 | fs::create_directory(sOutDirectory); |
| 52 | bOk = fs::is_directory(sOutDirectory); |
| 53 | } |
| 54 | |
| 55 | // Create basis folder structure |
| 56 | fs::create_directory(fs::path(sOutDirectory) / std::string("models")); |
| 57 | fs::create_directory(fs::path(sOutDirectory) / std::string("txt")); |
| 58 | fs::create_directory(fs::path(sOutDirectory) / std::string("visualize")); |
| 59 | |
| 60 | if (bOk && fs::is_directory(fs::path(sOutDirectory) / std::string("models")) && fs::is_directory(fs::path(sOutDirectory) / std::string("txt")) && |
| 61 | fs::is_directory(fs::path(sOutDirectory) / std::string("visualize"))) |
| 62 | { |
| 63 | bOk = true; |
| 64 | } |
| 65 | else |
| 66 | { |
| 67 | std::cerr << "Cannot access to one of the desired output folder" << std::endl; |
| 68 | } |
| 69 | |
| 70 | if (bOk) |
| 71 | { |
| 72 | auto progressDisplay = system::createConsoleProgressDisplay(sfm_data.getViews().size() * 2, std::cout); |
| 73 | |
| 74 | // Since PMVS requires contiguous camera index, and that some views can have some missing poses, |
| 75 | // we reindex the poses to ensure a contiguous pose list. |
| 76 | std::map<IndexT, IndexT> map_viewIdToContiguous; |
| 77 | |
| 78 | // Export valid views as Projective Cameras: |
| 79 | for (Views::const_iterator iter = sfm_data.getViews().begin(); iter != sfm_data.getViews().end(); ++iter, ++progressDisplay) |
| 80 | { |
| 81 | const View* view = iter->second.get(); |
| 82 | if (!sfm_data.isPoseAndIntrinsicDefined(view)) |
| 83 | continue; |
| 84 | |
| 85 | const Pose3 pose = sfm_data.getPose(*view).getTransform(); |
| 86 | Intrinsics::const_iterator iterIntrinsic = sfm_data.getIntrinsics().find(view->getIntrinsicId()); |
| 87 | |
| 88 | // View Id re-indexing |
| 89 | map_viewIdToContiguous.insert(std::make_pair(view->getViewId(), map_viewIdToContiguous.size())); |
| 90 | |
| 91 | std::shared_ptr<camera::IntrinsicBase> cam = iterIntrinsic->second; |
| 92 | std::shared_ptr<camera::Pinhole> camPinHole = std::dynamic_pointer_cast<camera::Pinhole>(cam); |
| 93 | if (!camPinHole) |
| 94 | { |
| 95 | ALICEVISION_LOG_ERROR("Camera is not pinhole in filter"); |
| 96 | continue; |
| 97 | } |
| 98 | |
| 99 | // We have a valid view with a corresponding camera & pose |
no test coverage detected