Skip to content

Commit

Permalink
Merge pull request #1642 from alicevision/dev/filesystemPath
Browse files Browse the repository at this point in the history
Remove Boost-Filesystem and replace it with the `std::filesystem`
  • Loading branch information
fabiencastan authored Jan 9, 2024
2 parents 0d83606 + 32fbd24 commit f22a026
Show file tree
Hide file tree
Showing 173 changed files with 569 additions and 639 deletions.
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ cd <VCPKG_INSTALL_DIR>
set VCPKG_ROOT=%cd%

vcpkg install ^
boost-algorithm boost-accumulators boost-atomic boost-container boost-date-time boost-exception boost-filesystem boost-geometry boost-graph boost-json boost-log ^
boost-algorithm boost-accumulators boost-atomic boost-container boost-date-time boost-exception boost-geometry boost-graph boost-json boost-log ^
boost-program-options boost-property-tree boost-ptr-container boost-regex boost-serialization boost-system boost-test boost-thread boost-timer ^
lz4 ^
liblemon ^
Expand Down
8 changes: 1 addition & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ endif()
# Boost
# ==============================================================================
option(BOOST_NO_CXX11 "if Boost is compiled without C++11 support (as it is often the case in OS packages) this must be enabled to avoid symbol conflicts (SCOPED_ENUM)." OFF)
set(ALICEVISION_BOOST_COMPONENTS atomic container date_time filesystem graph json log log_setup program_options regex serialization system thread timer)
set(ALICEVISION_BOOST_COMPONENTS atomic container date_time graph json log log_setup program_options regex serialization system thread timer)
if(ALICEVISION_BUILD_TESTS)
set(ALICEVISION_BOOST_COMPONENT_UNITTEST unit_test_framework)
endif()
Expand Down Expand Up @@ -306,12 +306,6 @@ else()
set(Boost_USE_STATIC_LIBS ON)
endif()

if(BOOST_NO_CXX11)
# Avoid link errors on boost filesystem copy_file function
# http://stackoverflow.com/questions/35007134/c-boost-undefined-reference-to-boostfilesystemdetailcopy-file
add_definitions(-DBOOST_NO_CXX11_SCOPED_ENUMS)
endif()


# ==============================================================================
# OpenEXR >= 2.5
Expand Down
1 change: 0 additions & 1 deletion src/aliceVision/calibration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ alicevision_add_library(aliceVision_calibration
aliceVision_image
aliceVision_system
aliceVision_dataio
Boost::filesystem
Boost::program_options
Boost::boost
Boost::json
Expand Down
5 changes: 2 additions & 3 deletions src/aliceVision/calibration/exportData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
#include <opencv2/calib3d.hpp>
#include <opencv2/imgcodecs.hpp>

#include <boost/filesystem/path.hpp>

#include <filesystem>
#include <fstream>
#include <iostream>
#include <ctime>
Expand Down Expand Up @@ -59,7 +58,7 @@ void exportImages(aliceVision::dataio::FeedProvider& feed,
// drawChessboardCorners(view, boardSize, cv::Mat(pointbuf), found);

aliceVision::camera::UndistortImage(inputImage, &camera, outputImage, static_cast<unsigned char>(0));
const boost::filesystem::path imagePath = boost::filesystem::path(debugFolder) / (std::to_string(currentFrame) + suffix);
const std::filesystem::path imagePath = std::filesystem::path(debugFolder) / (std::to_string(currentFrame) + suffix);
aliceVision::image::writeImage(imagePath.string(), outputImage, image::ImageWriteOptions());
}
ALICEVISION_LOG_DEBUG("... finished");
Expand Down
1 change: 0 additions & 1 deletion src/aliceVision/dataio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ alicevision_add_library(aliceVision_dataio
aliceVision_sfmData
aliceVision_sfmDataIO
aliceVision_system
Boost::filesystem
Boost::boost
)

Expand Down
11 changes: 5 additions & 6 deletions src/aliceVision/dataio/FeedProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
#include "VideoFeed.hpp"
#endif

#include <boost/filesystem.hpp>

#include <filesystem>
#include <exception>
#include <iostream>
#include <string>
Expand All @@ -28,15 +27,15 @@ FeedProvider::FeedProvider(const std::string& feedPath, const std::string& calib
_isLiveFeed(false),
_isSfmData(false)
{
namespace bf = boost::filesystem;
namespace fs = std::filesystem;
if (feedPath.empty())
{
throw std::invalid_argument("Empty filepath.");
}
if (bf::is_regular_file(bf::path(feedPath)))
if (fs::is_regular_file(fs::path(feedPath)))
{
// Image or video file
const std::string extension = bf::path(feedPath).extension().string();
const std::string extension = fs::path(feedPath).extension().string();
if (SfMDataFeed::isSupported(extension))
{
_feeder.reset(new SfMDataFeed(feedPath, calibPath));
Expand Down Expand Up @@ -67,7 +66,7 @@ FeedProvider::FeedProvider(const std::string& feedPath, const std::string& calib
}
// parent_path() returns "/foo/bar/" when input path equals to "/foo/bar/"
// if the user just gives the relative path as "bar", throws invalid argument exception.
else if (bf::is_directory(bf::path(feedPath)) || bf::is_directory(bf::path(feedPath).parent_path()))
else if (fs::is_directory(fs::path(feedPath)) || fs::is_directory(fs::path(feedPath).parent_path()))
{
// Folder or sequence of images
_feeder.reset(new ImageFeed(feedPath, calibPath));
Expand Down
22 changes: 11 additions & 11 deletions src/aliceVision/dataio/ImageFeed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
#include <aliceVision/image/io.hpp>
#include <aliceVision/utils/regexFilter.hpp>

#include <boost/filesystem.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/algorithm/string/replace.hpp>

#include <filesystem>
#include <queue>
#include <iostream>
#include <fstream>
Expand Down Expand Up @@ -86,12 +86,12 @@ ImageFeed::FeederImpl::FeederImpl(const std::string& imagePath, const std::strin
: _isInit(false),
_withCalibration(false)
{
namespace bf = boost::filesystem;
namespace fs = std::filesystem;
// ALICEVISION_LOG_DEBUG(imagePath);
// if it is a json, calibPath is neglected
if (bf::is_regular_file(imagePath))
if (fs::is_regular_file(imagePath))
{
const std::string ext = bf::path(imagePath).extension().string();
const std::string ext = fs::path(imagePath).extension().string();
// if it is an image file
if (image::isSupported(ext) && !image::isVideoExtension(ext))
{
Expand All @@ -111,7 +111,7 @@ ImageFeed::FeederImpl::FeederImpl(const std::string& imagePath, const std::strin
{
// compose the file name as the base path of the inputPath and
// the filename just read
const std::string filename = (bf::path(imagePath).parent_path() / line).string();
const std::string filename = (fs::path(imagePath).parent_path() / line).string();
_images.push_back(filename);
}
// Close file
Expand All @@ -125,16 +125,16 @@ ImageFeed::FeederImpl::FeederImpl(const std::string& imagePath, const std::strin
throw std::invalid_argument("File or mode not yet implemented");
}
}
else if (bf::is_directory(imagePath) || bf::is_directory(bf::path(imagePath).parent_path()))
else if (fs::is_directory(imagePath) || fs::is_directory(fs::path(imagePath).parent_path()))
{
std::string folder = imagePath;
// Recover the pattern : [email protected] (for example)
std::string filePattern;
std::regex re;
if (!bf::is_directory(imagePath))
if (!fs::is_directory(imagePath))
{
filePattern = bf::path(imagePath).filename().string();
folder = bf::path(imagePath).parent_path().string();
filePattern = fs::path(imagePath).filename().string();
folder = fs::path(imagePath).parent_path().string();
ALICEVISION_LOG_DEBUG("filePattern: " << filePattern);
std::string regexStr = filePattern;
re = utils::filterToRegex(regexStr);
Expand All @@ -145,12 +145,12 @@ ImageFeed::FeederImpl::FeederImpl(const std::string& imagePath, const std::strin
}
ALICEVISION_LOG_DEBUG("directory feedImage");
// if it is a directory, list all the images and add them to the list
bf::directory_iterator iterator(folder);
fs::directory_iterator iterator(folder);
// since some OS will provide the files in a random order, first store them
// in a priority queue and then fill the _image queue with the alphabetical
// order from the priority queue
std::priority_queue<std::string, std::vector<std::string>, std::greater<std::string>> tmpSorter;
for (; iterator != bf::directory_iterator(); ++iterator)
for (; iterator != fs::directory_iterator(); ++iterator)
{
// get the extension of the current file to check whether it is an image
const std::string ext = iterator->path().extension().string();
Expand Down
1 change: 0 additions & 1 deletion src/aliceVision/depthMap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ alicevision_add_library(aliceVision_depthMap
aliceVision_mvsData
aliceVision_mvsUtils
aliceVision_system
Boost::filesystem
assimp::assimp
${CUDA_CUDADEVRT_LIBRARY}
${CUDA_CUBLAS_LIBRARIES} #TODO shouldn't be here, but required to build on some machines
Expand Down
4 changes: 0 additions & 4 deletions src/aliceVision/depthMap/DepthMapEstimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
#include <aliceVision/depthMap/cuda/host/DeviceStreamManager.hpp>
#include <aliceVision/depthMap/cuda/planeSweeping/deviceDepthSimilarityMap.hpp>

#include <boost/filesystem.hpp>

namespace fs = boost::filesystem;

namespace aliceVision {
namespace depthMap {

Expand Down
4 changes: 2 additions & 2 deletions src/aliceVision/depthMap/NormalMapEstimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#include <aliceVision/depthMap/cuda/host/DeviceCache.hpp>
#include <aliceVision/depthMap/cuda/planeSweeping/deviceDepthSimilarityMap.hpp>

#include <boost/filesystem.hpp>
#include <filesystem>

namespace fs = boost::filesystem;
namespace fs = std::filesystem;

namespace aliceVision {
namespace depthMap {
Expand Down
1 change: 0 additions & 1 deletion src/aliceVision/feature/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ alicevision_add_library(aliceVision_feature
aliceVision_gpu
vlsift
PRIVATE_LINKS
Boost::filesystem
Boost::boost
)

Expand Down
10 changes: 5 additions & 5 deletions src/aliceVision/feature/ImageDescriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <aliceVision/feature/sift/ImageDescriber_SIFT_vlfeatFloat.hpp>
#include <aliceVision/feature/sift/ImageDescriber_DSPSIFT_vlfeat.hpp>
#include <aliceVision/feature/akaze/ImageDescriber_AKAZE.hpp>
#include <aliceVision/utils/filesIO.hpp>

#if ALICEVISION_IS_DEFINED(ALICEVISION_HAVE_CCTAG)
#include <aliceVision/feature/cctag/ImageDescriber_CCTAG.hpp>
Expand All @@ -28,12 +29,11 @@
#include <aliceVision/feature/openCV/ImageDescriber_AKAZE_OCV.hpp>
#endif // ALICEVISION_HAVE_OPENCV

#include <boost/filesystem.hpp>

#include <algorithm>
#include <filesystem>
#include <stdexcept>

namespace fs = boost::filesystem;
namespace fs = std::filesystem;

namespace aliceVision {
namespace feature {
Expand Down Expand Up @@ -191,9 +191,9 @@ void ImageDescriber::Save(const Regions* regions, const std::string& sfileNameFe
const fs::path bFeatsPath = fs::path(sfileNameFeats);
const fs::path bDescsPath = fs::path(sfileNameDescs);
const std::string tmpFeatsPath =
(bFeatsPath.parent_path() / bFeatsPath.stem()).string() + "." + fs::unique_path().string() + bFeatsPath.extension().string();
(bFeatsPath.parent_path() / bFeatsPath.stem()).string() + "." + utils::generateUniqueFilename() + bFeatsPath.extension().string();
const std::string tmpDescsPath =
(bDescsPath.parent_path() / bDescsPath.stem()).string() + "." + fs::unique_path().string() + bDescsPath.extension().string();
(bDescsPath.parent_path() / bDescsPath.stem()).string() + "." + utils::generateUniqueFilename() + bDescsPath.extension().string();

regions->Save(tmpFeatsPath, tmpDescsPath);

Expand Down
2 changes: 0 additions & 2 deletions src/aliceVision/featureEngine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@ alicevision_add_library(aliceVision_featureEngine
aliceVision_image
aliceVision_sfmData
aliceVision_system
PRIVATE_LINKS
Boost::filesystem
)
5 changes: 3 additions & 2 deletions src/aliceVision/featureEngine/FeatureExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
#include <aliceVision/image/io.hpp>
#include <aliceVision/system/MemoryInfo.hpp>
#include <aliceVision/alicevision_omp.hpp>
#include <boost/filesystem.hpp>

#include <filesystem>
#include <iomanip>

namespace fs = boost::filesystem;
namespace fs = std::filesystem;

namespace aliceVision {
namespace featureEngine {
Expand Down
1 change: 0 additions & 1 deletion src/aliceVision/fuseCut/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ alicevision_add_library(aliceVision_fuseCut
aliceVision_sfmData
aliceVision_system
Geogram::geogram
Boost::filesystem
Boost::graph
Boost::container
PRIVATE_LINKS
Expand Down
10 changes: 5 additions & 5 deletions src/aliceVision/fuseCut/DelaunayGraphCut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

#include <geogram/points/kd_tree.h>

#include <boost/filesystem.hpp>
#include <boost/filesystem/operations.hpp>

#include <cmath>
#include <filesystem>
#include <random>
#include <stdexcept>

Expand All @@ -41,7 +41,7 @@
namespace aliceVision {
namespace fuseCut {

namespace bfs = boost::filesystem;
namespace fs = std::filesystem;

// #define USE_GEOGRAM_KDTREE 1

Expand Down Expand Up @@ -1189,7 +1189,7 @@ void DelaunayGraphCut::fuseFromDepthMaps(const StaticVector<int>& cams, const Po
const std::string nmodMapFilepath = getFileNameFromIndex(_mp, c, mvsUtils::EFileType::nmodMap);
// If we have an nModMap in input (from depthmapfilter) use it,
// else init with a constant value.
if (boost::filesystem::exists(nmodMapFilepath))
if (fs::exists(nmodMapFilepath))
{
image::readImage(nmodMapFilepath, numOfModalsMap, image::EImageColorSpace::NO_CONVERSION);
if (numOfModalsMap.Width() != width || numOfModalsMap.Height() != height)
Expand Down Expand Up @@ -3892,7 +3892,7 @@ void DelaunayGraphCut::exportDebugMesh(const std::string& filename, const Point3
mesh->tris.push_back(t);
}

const std::string tempDirPath = boost::filesystem::temp_directory_path().generic_string();
const std::string tempDirPath = fs::temp_directory_path().generic_string();
mesh->save(tempDirPath + "/" + filename);
meshf->save(tempDirPath + "/" + filename);
}
Expand Down Expand Up @@ -3956,7 +3956,7 @@ void DelaunayGraphCut::exportBackPropagationMesh(const std::string& filename,

void DelaunayGraphCut::writeScoreInCsv(const std::string& filePath, const size_t& sizeLimit)
{
assert(boost::filesystem::path(filePath).extension().string() == std::string(".csv"));
assert(fs::path(filePath).extension().string() == std::string(".csv"));

const unsigned int seed = (unsigned int)_mp.userParams.get<unsigned int>("delaunaycut.seed", 0);
std::mt19937 generator(seed != 0 ? seed : std::random_device{}());
Expand Down
6 changes: 3 additions & 3 deletions src/aliceVision/fuseCut/DelaunayGraphCut_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include <aliceVision/multiview/NViewDataSet.hpp>
#include <aliceVision/fuseCut/DelaunayGraphCut.hpp>

#include <boost/filesystem.hpp>

#include <boost/math/constants/constants.hpp>

#include <string>
Expand All @@ -19,6 +17,8 @@
#include <boost/test/unit_test.hpp>
#include <boost/test/tools/floating_point_comparison.hpp>

#include <filesystem>

using namespace aliceVision;
using namespace aliceVision::fuseCut;
using namespace aliceVision::sfmData;
Expand Down Expand Up @@ -82,7 +82,7 @@ BOOST_AUTO_TEST_CASE(fuseCut_delaunayGraphCut)
for (int i = 0; i < cams.size(); ++i)
cams[i] = i;

const std::string tempDirPath = boost::filesystem::temp_directory_path().generic_string();
const std::string tempDirPath = std::filesystem::temp_directory_path().generic_string();

DelaunayGraphCut delaunayGC(mp);
ALICEVISION_LOG_TRACE("Creating dense point cloud witout support pts.");
Expand Down
Loading

0 comments on commit f22a026

Please sign in to comment.