diff --git a/Core/include/Acts/Visualization/IVisualization3D.hpp b/Core/include/Acts/Visualization/IVisualization3D.hpp index 6daf34c4e2f..6848124f14a 100644 --- a/Core/include/Acts/Visualization/IVisualization3D.hpp +++ b/Core/include/Acts/Visualization/IVisualization3D.hpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -67,28 +68,11 @@ class IVisualization3D { /// Write the content of the helper to an outstream. /// @param path is the file system path for writing the file - /// @note will change to std::filesystem::path once gcc9 is standard - virtual void write(const std::string& path) const = 0; + virtual void write(const std::filesystem::path& path) const = 0; /// Remove all contents of this helper /// virtual void clear() = 0; - - protected: - /// Helper: check for extension - /// - /// @note this is a placeholder for std::filesystem::has_extension - /// which needs special linking until gcc9 - /// @param path the path to be checked - bool hasExtension(const std::string& path) const; - - /// Helper: replace the extension - /// - /// @note this is a placeholder for std::filesystem::replace_extension - /// which needs special linking until gcc9 - /// @param path [in,out] the path to be changed - /// @param suffix the extension to be added - void replaceExtension(std::string& path, const std::string& suffix) const; }; /// Overload of the << operator to facilitate writing to streams. diff --git a/Core/include/Acts/Visualization/ObjVisualization3D.hpp b/Core/include/Acts/Visualization/ObjVisualization3D.hpp index a915ecadee8..977b5693a68 100644 --- a/Core/include/Acts/Visualization/ObjVisualization3D.hpp +++ b/Core/include/Acts/Visualization/ObjVisualization3D.hpp @@ -61,8 +61,8 @@ class ObjVisualization3D : public IVisualization3D { const std::vector& faces, ColorRGB color = {0, 0, 0}) final; - /// @copydoc Acts::IVisualization3D::write(const std::string&) const - void write(const std::string& path) const final; + /// @copydoc Acts::IVisualization3D::write(const std::filesystem::path&) const + void write(const std::filesystem::path& path) const final; /// @copydoc Acts::IVisualization3D::write(std::ostream&) const void write(std::ostream& os) const final; diff --git a/Core/include/Acts/Visualization/PlyVisualization3D.hpp b/Core/include/Acts/Visualization/PlyVisualization3D.hpp index b28783a0bcd..fe47937ed52 100644 --- a/Core/include/Acts/Visualization/PlyVisualization3D.hpp +++ b/Core/include/Acts/Visualization/PlyVisualization3D.hpp @@ -50,8 +50,8 @@ class PlyVisualization3D : public IVisualization3D { void line(const Vector3& a, const Vector3& b, ColorRGB color = {120, 120, 120}) final; - /// @copydoc Acts::IVisualization3D::write(const std::string&) const - void write(const std::string& path) const final; + /// @copydoc Acts::IVisualization3D::write(const std::filesystem::path&) const + void write(const std::filesystem::path& path) const final; /// @copydoc Acts::IVisualization3D::write(std::ostream&) const void write(std::ostream& os) const final; diff --git a/Core/include/Acts/Visualization/ViewConfig.hpp b/Core/include/Acts/Visualization/ViewConfig.hpp index 06c4f7a675b..c8955d1e71d 100644 --- a/Core/include/Acts/Visualization/ViewConfig.hpp +++ b/Core/include/Acts/Visualization/ViewConfig.hpp @@ -9,6 +9,7 @@ #pragma once #include +#include #include namespace Acts { @@ -42,7 +43,7 @@ struct ViewConfig { /// Whether to triangulate or not bool triangulate = false; /// Write name - non-empty string indicates writing - std::string outputName = ""; + std::filesystem::path outputName = std::filesystem::path(""); }; } // namespace Acts diff --git a/Core/include/Acts/Visualization/detail/ObjVisualization3D.ipp b/Core/include/Acts/Visualization/detail/ObjVisualization3D.ipp index 51a0854b85e..7644ceb42ce 100644 --- a/Core/include/Acts/Visualization/detail/ObjVisualization3D.ipp +++ b/Core/include/Acts/Visualization/detail/ObjVisualization3D.ipp @@ -69,15 +69,15 @@ void ObjVisualization3D::faces(const std::vector& vtxs, } template -void ObjVisualization3D::write(const std::string& path) const { +void ObjVisualization3D::write(const std::filesystem::path& path) const { std::ofstream os; - std::string objectpath = path; - if (!IVisualization3D::hasExtension(objectpath)) { - objectpath += std::string(".obj"); + std::filesystem::path objectpath = path; + if (!objectpath.has_extension()) { + objectpath.replace_extension(std::filesystem::path("obj")); } os.open(objectpath); - std::string mtlpath = objectpath; - IVisualization3D::replaceExtension(mtlpath, ".mtl"); + std::filesystem::path mtlpath = objectpath; + mtlpath.replace_extension(std::filesystem::path("mtl")); os << "mtllib " << mtlpath << "\n"; std::ofstream mtlos; mtlos.open(mtlpath); diff --git a/Core/include/Acts/Visualization/detail/PlyVisualization3D.ipp b/Core/include/Acts/Visualization/detail/PlyVisualization3D.ipp index b97dbde0fc9..ba02c6a5d9c 100644 --- a/Core/include/Acts/Visualization/detail/PlyVisualization3D.ipp +++ b/Core/include/Acts/Visualization/detail/PlyVisualization3D.ipp @@ -41,11 +41,11 @@ void PlyVisualization3D::line(const Vector3& a, const Vector3& b, } template -void PlyVisualization3D::write(const std::string& path) const { +void PlyVisualization3D::write(const std::filesystem::path& path) const { std::ofstream os; - std::string objectpath = path; - if (!IVisualization3D::hasExtension(path)) { - objectpath += std::string(".ply"); + std::filesystem::path objectpath = path; + if (!path.has_extension()) { + objectpath.replace_extension(std::filesystem::path("ply")); } os.open(objectpath); write(os); diff --git a/Core/src/Visualization/GeometryView3D.cpp b/Core/src/Visualization/GeometryView3D.cpp index f5590614b3c..7d2214c4511 100644 --- a/Core/src/Visualization/GeometryView3D.cpp +++ b/Core/src/Visualization/GeometryView3D.cpp @@ -53,18 +53,26 @@ namespace { /// @param relativeFilePath The relative file path to be combined with the base directory. /// /// @return Absolute path created by combining baseDir and pathFileRelative, if pathFileRelative is not absolute. -std::filesystem::path makeAbsPath( - std::filesystem::path pathBaseDir, - const std::filesystem::path& pathFileRelative) { - if (pathFileRelative.is_absolute()) { - return pathFileRelative; - } - - if (pathBaseDir.empty()) { - pathBaseDir = std::filesystem::current_path(); - } - - return pathBaseDir / pathFileRelative; +// std::filesystem::path makeAbsPath( +// std::filesystem::path pathBaseDir, +// const std::filesystem::path& pathFileRelative) { +// if (pathFileRelative.is_absolute()) { +// return pathFileRelative; +// } +// +// if (pathBaseDir.empty()) { +// pathBaseDir = std::filesystem::current_path(); +// } +// +// return pathBaseDir / pathFileRelative; +// } + +// TODO write summary +std::filesystem::path tryToInterpretAsCurrentPath( + const std::filesystem::path& testPath) { + return testPath == std::filesystem::path(".") || testPath.empty() + ? std::filesystem::current_path() + : testPath; } } // namespace @@ -109,9 +117,7 @@ void Acts::GeometryView3D::drawSurfaceArray( const ViewConfig& sensitiveConfig, const ViewConfig& passiveConfig, const ViewConfig& gridConfig, const std::filesystem::path& _outputDir) { const std::filesystem::path outputDir = - _outputDir == std::filesystem::path(".") - ? std::filesystem::current_path() - : std::filesystem::path(_outputDir); + tryToInterpretAsCurrentPath(_outputDir); // Draw all the surfaces Extent arrayExtent; for (const auto& sf : surfaceArray.surfaces()) { @@ -124,8 +130,7 @@ void Acts::GeometryView3D::drawSurfaceArray( } if (!sensitiveConfig.outputName.empty()) { - helper.write(makeAbsPath( - outputDir, std::filesystem::path(sensitiveConfig.outputName))); + helper.write(outputDir / sensitiveConfig.outputName); helper.clear(); } @@ -189,8 +194,7 @@ void Acts::GeometryView3D::drawSurfaceArray( } if (!gridConfig.outputName.empty()) { - helper.write( - makeAbsPath(outputDir, std::filesystem::path(gridConfig.outputName))); + helper.write(outputDir / gridConfig.outputName); helper.clear(); } } @@ -250,9 +254,7 @@ void Acts::GeometryView3D::drawLayer( const ViewConfig& layerConfig, const ViewConfig& sensitiveConfig, const ViewConfig& gridConfig, const std::filesystem::path& _outputDir) { const std::filesystem::path outputDir = - _outputDir == std::filesystem::path(".") - ? std::filesystem::current_path() - : std::filesystem::path(_outputDir); + tryToInterpretAsCurrentPath(_outputDir); if (layerConfig.visible) { auto layerVolume = layer.representingVolume(); @@ -265,8 +267,7 @@ void Acts::GeometryView3D::drawLayer( layerConfig); } if (!layerConfig.outputName.empty()) { - helper.write(makeAbsPath(outputDir, - std::filesystem::path(layerConfig.outputName))); + helper.write(outputDir / layerConfig.outputName); helper.clear(); } } @@ -287,8 +288,8 @@ void Acts::GeometryView3D::drawTrackingVolume( const ViewConfig& sensitiveView, const ViewConfig& gridView, bool writeIt, const std::string& tag, const std::filesystem::path& _outputDir) { const std::filesystem::path outputDir = - _outputDir == std::filesystem::path(".") ? std::filesystem::current_path() - : _outputDir; + tryToInterpretAsCurrentPath(_outputDir); + if (tVolume.confinedVolumes() != nullptr) { const auto& subVolumes = tVolume.confinedVolumes()->arrayObjects(); for (const auto& tv : subVolumes) { @@ -316,7 +317,9 @@ void Acts::GeometryView3D::drawTrackingVolume( } if (tVolume.confinedVolumes() == nullptr) { vcConfig = vConfig; - vcConfig.outputName = vname + std::string("_boundaries") + tag; + // TODO FS + vcConfig.outputName = + std::filesystem::path(vname + std::string("_boundaries") + tag); } else { std::stringstream vs; vs << "Container"; @@ -331,7 +334,9 @@ void Acts::GeometryView3D::drawTrackingVolume( vs << "_v" << ids[i]; } vname = vs.str(); - vcConfig.outputName = vname + std::string("_boundaries") + tag; + // TODO FS + vcConfig.outputName = + std::filesystem::path(vname + std::string("_boundaries") + tag); } } @@ -341,8 +346,7 @@ void Acts::GeometryView3D::drawTrackingVolume( Transform3::Identity(), vcConfig); } if (writeIt) { - std::string outputName = - makeAbsPath(outputDir, std::filesystem::path(vcConfig.outputName)); + const std::filesystem::path outputName = outputDir / vcConfig.outputName; helper.write(outputName); helper.clear(); } @@ -352,6 +356,7 @@ void Acts::GeometryView3D::drawTrackingVolume( std::size_t il = 0; for (const auto& tl : layers) { if (writeIt) { + // TODO FS lConfig.outputName = vname + std::string("_passives_l") + std::to_string(il) + tag; sConfig.outputName = diff --git a/Core/src/Visualization/IVisualization3D.cpp b/Core/src/Visualization/IVisualization3D.cpp index aad131a156d..849fbd26ca4 100644 --- a/Core/src/Visualization/IVisualization3D.cpp +++ b/Core/src/Visualization/IVisualization3D.cpp @@ -6,18 +6,21 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -#include "Acts/Visualization/IVisualization3D.hpp" +// TODO REMOVE THIS FILE -bool Acts::IVisualization3D::hasExtension(const std::string& path) const { - return (path.find(".") != std::string::npos); -} - -void Acts::IVisualization3D::replaceExtension(std::string& path, - const std::string& suffix) const { - auto ppoint = path.find_last_of("."); - if (ppoint != std::string::npos) { - path.replace(ppoint, path.length(), suffix); - } else { - path += suffix; - } -} +// #include "Acts/Visualization/IVisualization3D.hpp" +// +// bool Acts::IVisualization3D::hasExtension(const std::string& path) const { +// return (path.find(".") != std::string::npos); +// } +// +// void Acts::IVisualization3D::replaceExtension(std::string& path, +// const std::string& suffix) +// const { +// auto ppoint = path.find_last_of("."); +// if (ppoint != std::string::npos) { +// path.replace(ppoint, path.length(), suffix); +// } else { +// path += suffix; +// } +// }