MCPcopy Create free account
hub / github.com/cdcseacave/openMVS / ParseScene

Function ParseScene

apps/InterfacePolycam/InterfacePolycam.cpp:269–333  ·  view source on GitHub ↗

parse scene stored in Polycam format

Source from the content-addressed store, hash-verified

267
268// parse scene stored in Polycam format
269bool ParseScene(Scene& scene, const String& scenePath)
270{
271 #if defined(_SUPPORT_CPP17) && (!defined(__GNUC__) || (__GNUC__ > 7))
272 size_t numCorrectedFolders(0), numCorrectedDepthFolders(0), numFolders(0), numDepthFolders(0);
273 for (const auto& file: std::filesystem::directory_iterator(scenePath.c_str())) {
274 if (file.path().stem() == "corrected_cameras" ||
275 file.path().stem() == "corrected_images")
276 ++numCorrectedFolders;
277 else if (file.path().stem() == "corrected_depth")
278 ++numCorrectedDepthFolders;
279 else if (file.path().stem() == "cameras" ||
280 file.path().stem() == "images")
281 ++numFolders;
282 else if (file.path().stem() == "depth")
283 ++numDepthFolders;
284 }
285 if (numFolders != 2) {
286 VERBOSE("Invalid scene folder");
287 return false;
288 }
289 scene.nCalibratedImages = 0;
290 if (numCorrectedFolders == 2) {
291 // corrected data
292 CLISTDEFIDX(String, IIndex) imagePaths;
293 for (const auto& file: std::filesystem::directory_iterator((scenePath + "corrected_images").c_str()))
294 imagePaths.emplace_back(file.path().string());
295 VERBOSE("Parsing corrected data: %u...", imagePaths.size());
296 std::unordered_map<String, IIndex> mapImageName;
297 mapImageName.reserve(imagePaths.size());
298 for (String& imagePath: imagePaths) {
299 Util::ensureValidPath(imagePath);
300 mapImageName.emplace(Util::getFileName(imagePath), static_cast<IIndex>(mapImageName.size()));
301 }
302 for (const String& imagePath: imagePaths) {
303 const String imageName = Util::getFileName(imagePath);
304 const String cameraPath(scenePath + "corrected_cameras" + PATH_SEPARATOR_STR + imageName + JSON_EXT);
305 const String depthPath(numCorrectedDepthFolders ? scenePath + "corrected_depth" + PATH_SEPARATOR_STR + imageName + DEPTH_EXT : String());
306 if (!ParseImage(scene, imagePath, cameraPath, depthPath, mapImageName))
307 return false;
308 }
309 } else {
310 // raw data
311 CLISTDEFIDX(String, IIndex) imagePaths;
312 for (const auto& file: std::filesystem::directory_iterator((scenePath + "images").c_str()))
313 imagePaths.emplace_back(file.path().string());
314 VERBOSE("Parsing raw data: %u...", imagePaths.size());
315 std::unordered_map<String, IIndex> mapImageName;
316 mapImageName.reserve(imagePaths.size());
317 for (String& imagePath: imagePaths) {
318 Util::ensureValidPath(imagePath);
319 mapImageName.emplace(Util::getFileName(imagePath), static_cast<IIndex>(mapImageName.size()));
320 }
321 for (const String& imagePath: imagePaths) {
322 const String imageName = Util::getFileName(imagePath);
323 const String cameraPath(scenePath + "cameras" + PATH_SEPARATOR_STR + imageName + JSON_EXT);
324 const String depthPath(numDepthFolders ? scenePath + "depth" + PATH_SEPARATOR_STR + imageName + DEPTH_EXT : String());
325 if (!ParseImage(scene, imagePath, cameraPath, depthPath, mapImageName))
326 return false;

Callers 1

mainFunction · 0.70

Calls 7

getFileNameFunction · 0.85
emplace_backMethod · 0.80
reserveMethod · 0.80
ParseImageFunction · 0.70
StringClass · 0.50
stringMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected