| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #ifndef COLMAP_SRC_UTIL_MISC_H_ |
| | #define COLMAP_SRC_UTIL_MISC_H_ |
| |
|
| | #include <fstream> |
| | #include <iostream> |
| | #include <string> |
| | #include <vector> |
| |
|
| | #include <boost/filesystem.hpp> |
| |
|
| | #include "util/endian.h" |
| | #include "util/logging.h" |
| | #include "util/string.h" |
| |
|
| | namespace colmap { |
| |
|
| | #ifndef STRINGIFY |
| | #define STRINGIFY(s) STRINGIFY_(s) |
| | #define STRINGIFY_(s) #s |
| | #endif |
| |
|
| | enum class CopyType { COPY, HARD_LINK, SOFT_LINK }; |
| |
|
| | |
| | std::string EnsureTrailingSlash(const std::string& str); |
| |
|
| | |
| | bool HasFileExtension(const std::string& file_name, const std::string& ext); |
| |
|
| | |
| | |
| | void SplitFileExtension(const std::string& path, std::string* root, |
| | std::string* ext); |
| |
|
| | |
| | void FileCopy(const std::string& src_path, const std::string& dst_path, |
| | CopyType type = CopyType::COPY); |
| |
|
| | |
| | bool ExistsFile(const std::string& path); |
| |
|
| | |
| | bool ExistsDir(const std::string& path); |
| |
|
| | |
| | bool ExistsPath(const std::string& path); |
| |
|
| | |
| | void CreateDirIfNotExists(const std::string& path, bool recursive = false); |
| |
|
| | |
| | std::string GetPathBaseName(const std::string& path); |
| |
|
| | |
| | std::string GetParentDir(const std::string& path); |
| |
|
| | |
| | template <typename... T> |
| | std::string JoinPaths(T const&... paths); |
| |
|
| | |
| | std::vector<std::string> GetFileList(const std::string& path); |
| |
|
| | |
| | std::vector<std::string> GetRecursiveFileList(const std::string& path); |
| |
|
| | |
| | std::vector<std::string> GetDirList(const std::string& path); |
| |
|
| | |
| | std::vector<std::string> GetRecursiveDirList(const std::string& path); |
| |
|
| | |
| | size_t GetFileSize(const std::string& path); |
| |
|
| | |
| | void PrintHeading1(const std::string& heading); |
| |
|
| | |
| | void PrintHeading2(const std::string& heading); |
| |
|
| | |
| | template <typename T> |
| | bool VectorContainsValue(const std::vector<T>& vector, const T value); |
| |
|
| | template <typename T> |
| | bool VectorContainsDuplicateValues(const std::vector<T>& vector); |
| |
|
| | |
| | template <typename T> |
| | std::vector<T> CSVToVector(const std::string& csv); |
| |
|
| | |
| | template <typename T> |
| | std::string VectorToCSV(const std::vector<T>& values); |
| |
|
| | |
| | template <typename T> |
| | void ReadBinaryBlob(const std::string& path, std::vector<T>* data); |
| |
|
| | |
| | template <typename T> |
| | void WriteBinaryBlob(const std::string& path, const std::vector<T>& data); |
| |
|
| | |
| | |
| | std::vector<std::string> ReadTextFileLines(const std::string& path); |
| |
|
| | |
| | void RemoveCommandLineArgument(const std::string& arg, int* argc, char** argv); |
| |
|
| | |
| | |
| | |
| |
|
| | template <typename... T> |
| | std::string JoinPaths(T const&... paths) { |
| | boost::filesystem::path result; |
| | int unpack[]{0, (result = result / boost::filesystem::path(paths), 0)...}; |
| | static_cast<void>(unpack); |
| | return result.string(); |
| | } |
| |
|
| | template <typename T> |
| | bool VectorContainsValue(const std::vector<T>& vector, const T value) { |
| | return std::find_if(vector.begin(), vector.end(), [value](const T element) { |
| | return element == value; |
| | }) != vector.end(); |
| | } |
| |
|
| | template <typename T> |
| | bool VectorContainsDuplicateValues(const std::vector<T>& vector) { |
| | std::vector<T> unique_vector = vector; |
| | return std::unique(unique_vector.begin(), unique_vector.end()) != |
| | unique_vector.end(); |
| | } |
| |
|
| | template <typename T> |
| | std::string VectorToCSV(const std::vector<T>& values) { |
| | std::string string; |
| | for (const T value : values) { |
| | string += std::to_string(value) + ", "; |
| | } |
| | return string.substr(0, string.length() - 2); |
| | } |
| |
|
| | template <typename T> |
| | void ReadBinaryBlob(const std::string& path, std::vector<T>* data) { |
| | std::ifstream file(path, std::ios::binary | std::ios::ate); |
| | CHECK(file.is_open()) << path; |
| | file.seekg(0, std::ios::end); |
| | const size_t num_bytes = file.tellg(); |
| | CHECK_EQ(num_bytes % sizeof(T), 0); |
| | data->resize(num_bytes / sizeof(T)); |
| | file.seekg(0, std::ios::beg); |
| | ReadBinaryLittleEndian<T>(&file, data); |
| | } |
| |
|
| | template <typename T> |
| | void WriteBinaryBlob(const std::string& path, const std::vector<T>& data) { |
| | std::ofstream file(path, std::ios::binary); |
| | CHECK(file.is_open()) << path; |
| | WriteBinaryLittleEndian<T>(&file, data); |
| | } |
| |
|
| | } |
| |
|
| | #endif |
| |
|