Skip to content

Commit

Permalink
interface: fix for old GCC without filesystem support
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcseacave committed Sep 1, 2023
1 parent 70de228 commit 5473469
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 33 deletions.
49 changes: 21 additions & 28 deletions apps/InterfaceMVSNet/InterfaceMVSNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,17 +263,15 @@ void RangeToDepthMap(const Image32F& rangeMap, const Camera& camera, DepthMap& d
// K20 K21 K22
//
// DEPTH_MIN DEPTH_INTERVAL (DEPTH_NUM DEPTH_MAX)
bool ParseSceneMVSNet(Scene& scene, const std::filesystem::path& path)
bool ParseSceneMVSNet(Scene& scene, const String& strPath)
{
#if defined(_SUPPORT_CPP17) && (!defined(__GNUC__) || (__GNUC__ > 7))
String strPath(path.string());
Util::ensureValidFolderPath(strPath);
IIndex prevPlatformID = NO_ID;
for (const std::filesystem::directory_entry& entry : std::filesystem::directory_iterator(path / MVSNET_IMAGES_FOLDER)) {
for (const std::filesystem::directory_entry& entry : std::filesystem::directory_iterator((strPath + MVSNET_IMAGES_FOLDER).c_str())) {
if (entry.path().extension() != MVSNET_IMAGES_EXT)
continue;
// parse camera
const std::string strCamFileName((path / MVSNET_CAMERAS_FOLDER / entry.path().stem()).string() + MVSNET_CAMERAS_NAME);
const std::string strCamFileName(strPath + MVSNET_CAMERAS_FOLDER PATH_SEPARATOR_STR + entry.path().stem().string().c_str() + MVSNET_CAMERAS_NAME);
std::ifstream fcam(strCamFileName);
if (!fcam)
continue;
Expand Down Expand Up @@ -365,9 +363,9 @@ bool ParseSceneMVSNet(Scene& scene, const std::filesystem::path& path)
// |--normalxxxx.exr
// ....
// |--transforms.json
bool ParseSceneNerfstudio(Scene& scene, const std::filesystem::path& path)
bool ParseSceneNerfstudio(Scene& scene, const String& strPath)
{
const nlohmann::json data = nlohmann::json::parse(std::ifstream((path / NERFSTUDIO_TRANSFORMS).string()));
const nlohmann::json data = nlohmann::json::parse(std::ifstream(strPath + NERFSTUDIO_TRANSFORMS));
if (data.empty())
return false;
// parse camera
Expand Down Expand Up @@ -400,15 +398,13 @@ bool ParseSceneNerfstudio(Scene& scene, const std::filesystem::path& path)
return false;
}
// parse images
String workPath(path.parent_path().string());
Util::ensureFolderSlash(workPath);
const nlohmann::json& frames = data["frames"];
for (const nlohmann::json& frame: frames) {
// set image
// frames expected to be ordered in JSON
const IIndex imageID = scene.images.size();
const String strFileName((path / frame["file_path"].get<std::string>()).string());
Image& imageData = scene.images.AddEmpty();
const String strFileName(strPath + frame["file_path"].get<std::string>().c_str());
Image& imageData = scene.images.emplace_back();
imageData.platformID = platformID;
imageData.cameraID = 0; // only one camera per platform supported by this format
imageData.poseID = NO_ID;
Expand All @@ -431,9 +427,9 @@ bool ParseSceneNerfstudio(Scene& scene, const std::filesystem::path& path)
};
// revert nerfstudio conversion:
// convert from COLMAP's camera coordinate system (OpenCV) to ours (OpenGL)
// c2w[0:3, 1:3] *= -1
// c2w = c2w[np.array([1, 0, 2, 3]), :]
// c2w[2, :] *= -1
// c2w[0:3, 1:3] *= -1
// c2w = c2w[np.array([1, 0, 2, 3]), :]
// c2w[2, :] *= -1
P.row(2) *= -1;
P.row(0).swap(P.row(1));
P.col(2) *= -1;
Expand All @@ -445,7 +441,7 @@ bool ParseSceneNerfstudio(Scene& scene, const std::filesystem::path& path)
imageData.camera = platform.GetCamera(imageData.cameraID, imageData.poseID);
// try reading depth-map and normal-map
DepthMap depthMap; {
const String depthPath((path.parent_path() / String::FormatString("outputs/depth%04u.exr", imageID).c_str()).string());
const String depthPath(strPath + String::FormatString("outputs/depth%04u.exr", imageID));
const Image32F rangeMap = cv::imread(depthPath, cv::IMREAD_UNCHANGED);
if (rangeMap.empty()) {
VERBOSE("Unable to load depthmap %s.", depthPath.c_str());
Expand All @@ -454,7 +450,7 @@ bool ParseSceneNerfstudio(Scene& scene, const std::filesystem::path& path)
RangeToDepthMap(rangeMap, imageData.camera, depthMap);
}
NormalMap normalMap; {
const String normalPath((path.parent_path() / String::FormatString("outputs/normal%04u.exr", imageID).c_str()).string());
const String normalPath(strPath + String::FormatString("outputs/normal%04u.exr", imageID));
normalMap = cv::imread(normalPath, cv::IMREAD_UNCHANGED);
if (normalMap.empty()) {
VERBOSE("Unable to load normalMap %s.", normalPath.c_str());
Expand All @@ -466,7 +462,7 @@ bool ParseSceneNerfstudio(Scene& scene, const std::filesystem::path& path)
const IIndexArr IDs = {imageID};
double dMin, dMax;
cv::minMaxIdx(depthMap, &dMin, &dMax, NULL, NULL, depthMap > 0);
const String dmapPath(workPath + String::FormatString("depth%04u.dmap", imageID));
const String dmapPath(strPath + String::FormatString("depth%04u.dmap", imageID));
if (!ExportDepthDataRaw(dmapPath,
imageData.name, IDs, resolution,
camera.K, pose.R, pose.C,
Expand All @@ -490,16 +486,13 @@ bool ParseSceneNerfstudio(Scene& scene, const std::filesystem::path& path)
// |--xxx.depth.exr
// |--xxx.json
// ....
bool ParseSceneRTMV(Scene& scene, const std::filesystem::path& path)
bool ParseSceneRTMV(Scene& scene, const String& strPath)
{
String strImagePath((path / "images").string());
Util::ensureFolderSlash(strImagePath);
const String strImagePath(strPath + "images/");
Util::ensureFolder(strImagePath);
String workPath(path.parent_path().string());
Util::ensureFolderSlash(workPath);
std::vector<String> strImageNames;
#if defined(_SUPPORT_CPP17) && (!defined(__GNUC__) || (__GNUC__ > 7))
for (const std::filesystem::directory_entry& entry : std::filesystem::directory_iterator(path)) {
for (const std::filesystem::directory_entry& entry : std::filesystem::directory_iterator(strPath.c_str())) {
if (entry.path().extension() != RTMV_CAMERAS_EXT)
continue;
strImageNames.emplace_back(entry.path().stem().string());
Expand All @@ -520,7 +513,7 @@ bool ParseSceneRTMV(Scene& scene, const std::filesystem::path& path)
const IIndex imageID((IIndex)i);
const String& strImageName(strImageNames[imageID]);
// parse camera
const String strFileName((path / strImageName.c_str()).string());
const String strFileName(strPath + strImageName);
const nlohmann::json dataCamera = nlohmann::json::parse(std::ifstream(strFileName+RTMV_CAMERAS_EXT));
if (dataCamera.empty())
continue;
Expand Down Expand Up @@ -637,7 +630,7 @@ bool ParseSceneRTMV(Scene& scene, const std::filesystem::path& path)
const IIndexArr IDs = {imageID};
double dMin, dMax;
cv::minMaxIdx(depthMap, &dMin, &dMax, NULL, NULL, depthMap > 0);
const String dmapPath(workPath + String::FormatString("depth%04u.dmap", imageID));
const String dmapPath(strPath + String::FormatString("depth%04u.dmap", imageID));
if (!ExportDepthDataRaw(dmapPath,
imageData.name, IDs, resolution,
K, pose.R, pose.C,
Expand Down Expand Up @@ -675,9 +668,9 @@ bool ParseScene(Scene& scene)
}
}
switch (sceneType) {
case NERFSTUDIO: return ParseSceneNerfstudio(scene, path);
case RTMV: return ParseSceneRTMV(scene, path);
default: return ParseSceneMVSNet(scene, path);
case NERFSTUDIO: return ParseSceneNerfstudio(scene, strPath);
case RTMV: return ParseSceneRTMV(scene, strPath);
default: return ParseSceneMVSNet(scene, strPath);
}
#else
VERBOSE("error: C++17 is required to parse MVSNet format");
Expand Down
2 changes: 1 addition & 1 deletion apps/InterfacePolycam/InterfacePolycam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ bool ParseImage(Scene& scene, const String& imagePath, const String& cameraPath,
// parse scene stored in Polycam format
bool ParseScene(Scene& scene, const String& scenePath)
{
#ifdef _SUPPORT_CPP17
#if defined(_SUPPORT_CPP17) && (!defined(__GNUC__) || (__GNUC__ > 7))
size_t numCorrectedFolders(0), numFolders(0);
for (const auto& file: std::filesystem::directory_iterator(scenePath.c_str())) {
if (file.path().stem() == "corrected_cameras" ||
Expand Down
2 changes: 1 addition & 1 deletion libs/Common/Ray.inl
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ bool TestRayTriangleIntersection(unsigned iters) {
typedef SEACAVE::TRay<TYPE,3> Ray;
typedef typename Ray::POINT Point;
typedef typename Point::Scalar Type;
constexpr Type zeroEps(ZEROTOLERANCE<Type>() * 1000);
constexpr Type zeroEps(0.001);
for (unsigned iter=0; iter<iters; ++iter) {
const Type scale(10);
const Triangle triangle(Point::Random()*scale, Point::Random()*scale, Point::Random()*scale);
Expand Down
2 changes: 1 addition & 1 deletion libs/Common/Strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ class GENERAL_API String : public std::string

inline String& operator=(Base&& rhs) { Base::operator=(std::forward<Base>(rhs)); return *this; }
inline String& operator=(String&& rhs) { Base::operator=(std::forward<Base>(rhs)); return *this; }
#endif
inline String& operator=(TCHAR rhs) { Base::operator=(rhs); return *this; }
inline String& operator=(LPCTSTR rhs) { Base::operator=(rhs); return *this; }
inline String& operator=(const String& rhs) { Base::operator=(rhs); return *this; }
#endif

inline String& operator+=(TCHAR rhs) { *this = (*this) + rhs; return *this; }
inline String& operator+=(LPCTSTR rhs) { *this = (*this) + rhs; return *this; }
Expand Down
4 changes: 4 additions & 0 deletions libs/Common/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -2143,7 +2143,11 @@ class TImage : public TDMatrix<TYPE>
inline TImage(const Size& sz) : Base(sz) {}
inline TImage(const Size& sz, const TYPE& v) : Base(sz, v) {}
inline TImage(const Size& sz, TYPE* _data, size_t _step=Base::AUTO_STEP) : Base(sz.height, sz.width, _data, _step) {}
#ifdef _SUPPORT_CPP11
inline TImage(cv::Mat&& rhs) : Base(std::forward<cv::Mat>(rhs)) {}

inline TImage& operator = (cv::Mat&& rhs) { BaseBase::operator=(std::forward<cv::Mat>(rhs)); return *this; }
#endif
inline TImage& operator = (const Base& rhs) { BaseBase::operator=(rhs); return *this; }
inline TImage& operator = (const BaseBase& rhs) { BaseBase::operator=(rhs); return *this; }
inline TImage& operator = (const cv::MatExpr& rhs) { BaseBase::operator=(rhs); return *this; }
Expand Down
5 changes: 4 additions & 1 deletion libs/Common/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,10 @@ class GENERAL_API Util
}

static String getFilePath(const String& path) {
const String::size_type i = path.rfind(PATH_SEPARATOR);
const String::size_type size = path.size();
if (size < 3)
return String();
const String::size_type i = path.rfind(PATH_SEPARATOR, size-2);
return (i != String::npos) ? path.substr(0, i+1) : String();
}
static String getFileFullName(const String& path) {
Expand Down
2 changes: 1 addition & 1 deletion libs/MVS/SceneReconstruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ bool Scene::ReconstructMesh(float distInsert, bool bUseFreeSpaceSupport, bool bU
// create graph
MaxFlow<cell_size_t,edge_cap_t> graph(delaunay.number_of_cells());
// set weights
constexpr edge_cap_t maxCap(FLT_MAX*0.0001f);
constexpr edge_cap_t maxCap(3.402823466e+34f/*FLT_MAX*0.0001f*/);
for (delaunay_t::All_cells_iterator ci=delaunay.all_cells_begin(), ce=delaunay.all_cells_end(); ci!=ce; ++ci) {
const cell_size_t ciID(ci->info());
const cell_info_t& ciInfo(infoCells[ciID]);
Expand Down

0 comments on commit 5473469

Please sign in to comment.