Skip to content

Commit

Permalink
scene: implement LoadROI
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcseacave committed Nov 10, 2024
1 parent 0d1a991 commit 168b9a7
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
21 changes: 14 additions & 7 deletions apps/DensifyPointCloud/DensifyPointCloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,19 +325,26 @@ int main(int argc, LPCTSTR* argv)
}
}
if (!OPT::strCropROIFileName.empty()) {
std::ifstream fs(MAKE_PATH_SAFE(OPT::strCropROIFileName));
if (!fs)
if (!scene.LoadROI(MAKE_PATH_SAFE(OPT::strCropROIFileName))) {
VERBOSE("error: cannot load ROI file");
return EXIT_FAILURE;
fs >> scene.obb;
}
scene.CropToROI(scene.obb);
scene.Save(MAKE_PATH_SAFE(Util::getFileFullName(OPT::strOutputFileName))+_T(".mvs"), (ARCHIVE_TYPE)OPT::nArchiveType);
const String baseFileName(MAKE_PATH_SAFE(Util::getFileFullName(OPT::strOutputFileName)));
if (!OPT::strPointCloudFileName.empty() && (ARCHIVE_TYPE)OPT::nArchiveType == ARCHIVE_MVS) {
// save only the cropped dense point-cloud
scene.pointcloud.Save(baseFileName+_T(".ply"), true);
} else {
// save the cropped scene
scene.Save(baseFileName+_T(".mvs"), (ARCHIVE_TYPE)OPT::nArchiveType);
}
return EXIT_SUCCESS;
}
if (!OPT::strImportROIFileName.empty()) {
std::ifstream fs(MAKE_PATH_SAFE(OPT::strImportROIFileName));
if (!fs)
if (!scene.LoadROI(MAKE_PATH_SAFE(OPT::strImportROIFileName))) {
VERBOSE("error: cannot load ROI file");
return EXIT_FAILURE;
fs >> scene.obb;
}
scene.Save(MAKE_PATH_SAFE(Util::getFileFullName(OPT::strOutputFileName))+_T(".mvs"), (ARCHIVE_TYPE)OPT::nArchiveType);
return EXIT_SUCCESS;
}
Expand Down
6 changes: 3 additions & 3 deletions apps/ReconstructMesh/ReconstructMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,10 @@ int main(int argc, LPCTSTR* argv)
}

if (!OPT::strImportROIFileName.empty()) {
std::ifstream fs(MAKE_PATH_SAFE(OPT::strImportROIFileName));
if (!fs)
if (!scene.LoadROI(MAKE_PATH_SAFE(OPT::strImportROIFileName))) {
VERBOSE("error: cannot load ROI file");
return EXIT_FAILURE;
fs >> scene.obb;
}
if (OPT::bCrop2ROI && !scene.mesh.IsEmpty() && !scene.IsValid()) {
TD_TIMER_START();
const size_t numVertices = scene.mesh.vertices.size();
Expand Down
28 changes: 28 additions & 0 deletions libs/MVS/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,34 @@ bool Scene::SaveInterface(const String & fileName, int version) const
/*----------------------------------------------------------------*/


// load region-of-interest from a text file
bool Scene::LoadROI(const String& fileName)
{
TD_TIMER_STARTD();

std::ifstream fs(fileName);
if (!fs)
return false;
// try to read OBB
fs >> obb;
if (fs.fail()) {
// reset fs to the beginning position
fs.clear();
fs.seekg(0, std::ios::beg);
// try to read AABB
AABB3f box;
fs >> box;
if (fs.fail())
return false;
obb = OBB3f(box);
}

DEBUG_EXTRA("Region-of-interest loaded from file '%s' (%s)",
fileName.c_str(), TD_TIMER_GET_FMT().c_str());
return true;
} // LoadROI
/*----------------------------------------------------------------*/

// load depth-map and generate a Multi-View Stereo scene
bool Scene::LoadDMAP(const String& fileName)
{
Expand Down
1 change: 1 addition & 0 deletions libs/MVS/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class MVS_API Scene
bool LoadInterface(const String& fileName);
bool SaveInterface(const String& fileName, int version=-1) const;

bool LoadROI(const String& fileName);
bool LoadDMAP(const String& fileName);
bool LoadViewNeighbors(const String& fileName);
bool SaveViewNeighbors(const String& fileName) const;
Expand Down

0 comments on commit 168b9a7

Please sign in to comment.