From c4446ff60114c5027ad99566ca08d26980d5f949 Mon Sep 17 00:00:00 2001 From: rinkk <karsten.rink@ufz.de> Date: Wed, 22 Jun 2016 11:14:48 +0200 Subject: [PATCH] moved CSV- and ascii raster interfaces back to FileIO --- .../DataView/DirectConditionGenerator.cpp | 12 +++---- .../DataView/MeshLayerEditDialog.cpp | 6 ++-- .../DataExplorer/DataView/MshView.cpp | 4 +-- .../DataExplorer/VtkVis/VtkRaster.cpp | 6 ++-- .../FileIO}/AsciiRasterInterface.cpp | 9 ++---- .../FileIO}/AsciiRasterInterface.h | 7 ++-- .../FileIO}/CsvInterface.cpp | 6 ++-- .../IO => Applications/FileIO}/CsvInterface.h | 6 ++-- Applications/Utils/MeshEdit/CMakeLists.txt | 5 ++- .../MeshEdit/createLayeredMeshFromRasters.cpp | 4 +-- .../Utils/SimpleMeshCreation/CMakeLists.txt | 5 ++- .../createMeshElemPropertiesFromASCRaster.cpp | 6 ++-- MeshGeoToolsLib/GeoMapper.cpp | 4 +-- Tests/FileIO/TestCsvReader.cpp | 32 +++++++++---------- 14 files changed, 53 insertions(+), 59 deletions(-) rename {GeoLib/IO => Applications/FileIO}/AsciiRasterInterface.cpp (97%) rename {GeoLib/IO => Applications/FileIO}/AsciiRasterInterface.h (96%) rename {GeoLib/IO => Applications/FileIO}/CsvInterface.cpp (98%) rename {GeoLib/IO => Applications/FileIO}/CsvInterface.h (99%) diff --git a/Applications/DataExplorer/DataView/DirectConditionGenerator.cpp b/Applications/DataExplorer/DataView/DirectConditionGenerator.cpp index 34e9b4ddbd0..32d7355b64c 100644 --- a/Applications/DataExplorer/DataView/DirectConditionGenerator.cpp +++ b/Applications/DataExplorer/DataView/DirectConditionGenerator.cpp @@ -20,7 +20,7 @@ #include "DirectConditionGenerator.h" -#include "GeoLib/IO/AsciiRasterInterface.h" +#include "Applications/FileIO/AsciiRasterInterface.h" #include "Raster.h" #include "MeshSurfaceExtraction.h" @@ -37,7 +37,7 @@ DirectConditionGenerator::directToSurfaceNodes(const MeshLib::Mesh& mesh, if (_direct_values.empty()) { GeoLib::Raster* raster( - GeoLib::IO::AsciiRasterInterface::readRaster(filename)); + FileIO::AsciiRasterInterface::readRaster(filename)); if (!raster) { ERR("Error in DirectConditionGenerator::directToSurfaceNodes() - " @@ -72,17 +72,15 @@ DirectConditionGenerator::directToSurfaceNodes(const MeshLib::Mesh& mesh, const std::vector< std::pair<std::size_t,double> >& DirectConditionGenerator::directWithSurfaceIntegration(MeshLib::Mesh &mesh, const std::string &filename, double scaling) { if (!_direct_values.empty()) { - ERR( - "Error in DirectConditionGenerator::directWithSurfaceIntegration()" + ERR("Error in DirectConditionGenerator::directWithSurfaceIntegration()" "- Data vector contains outdated values..."); return _direct_values; } std::unique_ptr<GeoLib::Raster> raster( - GeoLib::IO::AsciiRasterInterface::readRaster(filename)); + FileIO::AsciiRasterInterface::readRaster(filename)); if (!raster) { - ERR( - "Error in DirectConditionGenerator::directWithSurfaceIntegration()" + ERR("Error in DirectConditionGenerator::directWithSurfaceIntegration()" "- could not load raster file."); return _direct_values; } diff --git a/Applications/DataExplorer/DataView/MeshLayerEditDialog.cpp b/Applications/DataExplorer/DataView/MeshLayerEditDialog.cpp index ed19652f2c5..a3866cd621c 100644 --- a/Applications/DataExplorer/DataView/MeshLayerEditDialog.cpp +++ b/Applications/DataExplorer/DataView/MeshLayerEditDialog.cpp @@ -22,7 +22,7 @@ #include "StringTools.h" #include "Mesh.h" -#include "GeoLib/IO/AsciiRasterInterface.h" +#include "Applications/FileIO/AsciiRasterInterface.h" #include "TetGenInterface.h" #include <QCheckBox> @@ -190,7 +190,7 @@ MeshLib::Mesh* MeshLayerEditDialog::createPrismMesh() for (int i=nLayers; i>=0; --i) raster_paths.push_back(this->_edits[i]->text().toStdString()); - auto const rasters = GeoLib::IO::readRasters(raster_paths); + auto const rasters = FileIO::readRasters(raster_paths); if (rasters && mapper.createLayers(*_msh, *rasters, minimum_thickness)) { INFO("Mesh construction time: %d ms.", myTimer0.elapsed()); @@ -231,7 +231,7 @@ MeshLib::Mesh* MeshLayerEditDialog::createTetMesh() raster_paths.push_back(this->_edits[i]->text().toStdString()); LayeredVolume lv; - auto const rasters = GeoLib::IO::readRasters(raster_paths); + auto const rasters = FileIO::readRasters(raster_paths); if (rasters && lv.createLayers(*_msh, *rasters, minimum_thickness)) tg_mesh = lv.getMesh("SubsurfaceMesh").release(); diff --git a/Applications/DataExplorer/DataView/MshView.cpp b/Applications/DataExplorer/DataView/MshView.cpp index e01d5ddc1e1..bf7379b00bf 100644 --- a/Applications/DataExplorer/DataView/MshView.cpp +++ b/Applications/DataExplorer/DataView/MshView.cpp @@ -25,7 +25,7 @@ #include "SHPInterface.h" #include "TetGenInterface.h" -#include "GeoLib/IO/AsciiRasterInterface.h" +#include "Applications/FileIO/AsciiRasterInterface.h" #include "MeshLib/Mesh.h" #include "MeshLib/Node.h" @@ -166,7 +166,7 @@ void MshView::openMap2dMeshDialog() if (dlg.useRasterMapping()) { std::unique_ptr<GeoLib::Raster> raster{ - GeoLib::IO::AsciiRasterInterface::readRaster(dlg.getRasterPath())}; + FileIO::AsciiRasterInterface::readRaster(dlg.getRasterPath())}; if (!raster) { OGSError::box(QString::fromStdString( diff --git a/Applications/DataExplorer/VtkVis/VtkRaster.cpp b/Applications/DataExplorer/VtkVis/VtkRaster.cpp index c3f03ca7873..676608acfc9 100644 --- a/Applications/DataExplorer/VtkVis/VtkRaster.cpp +++ b/Applications/DataExplorer/VtkVis/VtkRaster.cpp @@ -35,7 +35,7 @@ #include <memory> #include <logog/include/logog.hpp> -#include "GeoLib/IO/AsciiRasterInterface.h" +#include "Applications/FileIO/AsciiRasterInterface.h" #include "GeoLib/Raster.h" @@ -47,9 +47,9 @@ vtkImageAlgorithm* VtkRaster::loadImage(const std::string &fileName, std::unique_ptr<GeoLib::Raster> raster(nullptr); if (fileInfo.suffix().toLower() == "asc") - raster.reset(GeoLib::IO::AsciiRasterInterface::getRasterFromASCFile(fileName)); + raster.reset(FileIO::AsciiRasterInterface::getRasterFromASCFile(fileName)); else if (fileInfo.suffix().toLower() == "grd") - raster.reset(GeoLib::IO::AsciiRasterInterface::getRasterFromSurferFile(fileName)); + raster.reset(FileIO::AsciiRasterInterface::getRasterFromSurferFile(fileName)); if (raster) return VtkRaster::loadImageFromArray(raster->begin(), raster->getHeader()); else if ((fileInfo.suffix().toLower() == "tif") || (fileInfo.suffix().toLower() == "tiff")) diff --git a/GeoLib/IO/AsciiRasterInterface.cpp b/Applications/FileIO/AsciiRasterInterface.cpp similarity index 97% rename from GeoLib/IO/AsciiRasterInterface.cpp rename to Applications/FileIO/AsciiRasterInterface.cpp index d8eca1d222a..d308d507a8a 100644 --- a/GeoLib/IO/AsciiRasterInterface.cpp +++ b/Applications/FileIO/AsciiRasterInterface.cpp @@ -21,9 +21,7 @@ #include "GeoLib/Raster.h" -namespace GeoLib -{ -namespace IO +namespace FileIO { GeoLib::Raster* AsciiRasterInterface::readRaster(std::string const& fname) @@ -241,8 +239,7 @@ boost::optional<std::vector<GeoLib::Raster const*>> readRasters( std::vector<GeoLib::Raster const*> rasters; rasters.reserve(raster_paths.size()); for (auto const& path : raster_paths) - rasters.push_back(GeoLib::IO::AsciiRasterInterface::readRaster(path)); + rasters.push_back(FileIO::AsciiRasterInterface::readRaster(path)); return boost::make_optional(rasters); } -} // end namespace IO -} // end namespace GeoLib +} // end namespace FileIO diff --git a/GeoLib/IO/AsciiRasterInterface.h b/Applications/FileIO/AsciiRasterInterface.h similarity index 96% rename from GeoLib/IO/AsciiRasterInterface.h rename to Applications/FileIO/AsciiRasterInterface.h index 37058266985..a2343f74f5c 100644 --- a/GeoLib/IO/AsciiRasterInterface.h +++ b/Applications/FileIO/AsciiRasterInterface.h @@ -21,9 +21,7 @@ #include "GeoLib/Raster.h" -namespace GeoLib -{ -namespace IO +namespace FileIO { /** * Interface for reading and writing a number of ASCII raster formats. @@ -58,7 +56,6 @@ private: /// otherwise the returned vector contains pointers to the read rasters. boost::optional<std::vector<GeoLib::Raster const*>> readRasters( std::vector<std::string> const& raster_paths); -} // end namespace IO -} // end namespace GeoLib +} // end namespace FileIO #endif /* ASCIIRASTERINTERFACE_H_ */ diff --git a/GeoLib/IO/CsvInterface.cpp b/Applications/FileIO/CsvInterface.cpp similarity index 98% rename from GeoLib/IO/CsvInterface.cpp rename to Applications/FileIO/CsvInterface.cpp index 8a2ffa2f608..ce2878960cf 100644 --- a/GeoLib/IO/CsvInterface.cpp +++ b/Applications/FileIO/CsvInterface.cpp @@ -18,8 +18,7 @@ #include "GeoLib/Point.h" -namespace GeoLib { -namespace IO { +namespace FileIO { int CsvInterface::readPoints(std::string const& fname, char delim, std::vector<GeoLib::Point*> &points) @@ -182,5 +181,4 @@ std::size_t CsvInterface::findColumn(std::string const& line, char delim, std::s return count; } -} // end namespace IO -} // end namespace GeoLib +} // end namespace FileIO diff --git a/GeoLib/IO/CsvInterface.h b/Applications/FileIO/CsvInterface.h similarity index 99% rename from GeoLib/IO/CsvInterface.h rename to Applications/FileIO/CsvInterface.h index f01cbab2efb..e78597c96e5 100644 --- a/GeoLib/IO/CsvInterface.h +++ b/Applications/FileIO/CsvInterface.h @@ -31,8 +31,7 @@ namespace GeoLib { class Point; } -namespace GeoLib { -namespace IO { +namespace FileIO { /** * Interface for reading CSV file formats. @@ -181,7 +180,6 @@ private: static std::size_t findColumn(std::string const& line, char delim, std::string const& column_name); }; -} // IO -} // GeoLib +} // FileIO #endif /* CSVINTERFACE_H_ */ diff --git a/Applications/Utils/MeshEdit/CMakeLists.txt b/Applications/Utils/MeshEdit/CMakeLists.txt index ab14a7dc851..bf0b42ad9fd 100644 --- a/Applications/Utils/MeshEdit/CMakeLists.txt +++ b/Applications/Utils/MeshEdit/CMakeLists.txt @@ -56,7 +56,10 @@ target_link_libraries(AddTopLayer MeshLib) set_target_properties(AddTopLayer PROPERTIES FOLDER Utilities) add_executable(createLayeredMeshFromRasters createLayeredMeshFromRasters.cpp) -target_link_libraries(createLayeredMeshFromRasters MeshLib) +target_link_libraries(createLayeredMeshFromRasters + MeshLib + ApplicationsFileIO +) set_target_properties(createLayeredMeshFromRasters PROPERTIES FOLDER Utilities) add_executable(CreateBoundaryConditionsAlongPolylines diff --git a/Applications/Utils/MeshEdit/createLayeredMeshFromRasters.cpp b/Applications/Utils/MeshEdit/createLayeredMeshFromRasters.cpp index 93ab64c13f8..fb8dae41344 100644 --- a/Applications/Utils/MeshEdit/createLayeredMeshFromRasters.cpp +++ b/Applications/Utils/MeshEdit/createLayeredMeshFromRasters.cpp @@ -23,8 +23,8 @@ #include "BaseLib/FileTools.h" #include "MeshLib/IO/readMeshFromFile.h" -#include "GeoLib/IO/AsciiRasterInterface.h" #include "MeshLib/IO/writeMeshToFile.h" +#include "Applications/FileIO/AsciiRasterInterface.h" #include "MeshLib/Mesh.h" #include "MeshLib/MeshGenerators/MeshLayerMapper.h" @@ -114,7 +114,7 @@ int main (int argc, char* argv[]) return EXIT_FAILURE; MeshLib::MeshLayerMapper mapper; - if (auto rasters = GeoLib::IO::readRasters(raster_paths)) + if (auto rasters = FileIO::readRasters(raster_paths)) { if (!mapper.createLayers(*sfc_mesh, *rasters, min_thickness)) return EXIT_FAILURE; diff --git a/Applications/Utils/SimpleMeshCreation/CMakeLists.txt b/Applications/Utils/SimpleMeshCreation/CMakeLists.txt index 6a81a133ae9..9792f3b516b 100644 --- a/Applications/Utils/SimpleMeshCreation/CMakeLists.txt +++ b/Applications/Utils/SimpleMeshCreation/CMakeLists.txt @@ -2,7 +2,10 @@ if(OGS_BUILD_GUI) add_executable(createMeshElemPropertiesFromASCRaster createMeshElemPropertiesFromASCRaster.cpp) set_target_properties(createMeshElemPropertiesFromASCRaster PROPERTIES FOLDER Utilities) - target_link_libraries(createMeshElemPropertiesFromASCRaster MeshLib) + target_link_libraries(createMeshElemPropertiesFromASCRaster + ApplicationsFileIO + MeshLib + ) ADD_VTK_DEPENDENCY(createMeshElemPropertiesFromASCRaster) endif() # OGS_BUILD_GUI (VtkVis-target is existing) diff --git a/Applications/Utils/SimpleMeshCreation/createMeshElemPropertiesFromASCRaster.cpp b/Applications/Utils/SimpleMeshCreation/createMeshElemPropertiesFromASCRaster.cpp index 481fa39185f..8a74156be5c 100644 --- a/Applications/Utils/SimpleMeshCreation/createMeshElemPropertiesFromASCRaster.cpp +++ b/Applications/Utils/SimpleMeshCreation/createMeshElemPropertiesFromASCRaster.cpp @@ -22,7 +22,7 @@ #include "MeshLib/IO/readMeshFromFile.h" #include "MeshLib/IO/writeMeshToFile.h" -#include "GeoLib/IO/AsciiRasterInterface.h" +#include "Applications/FileIO/AsciiRasterInterface.h" #include "GeoLib/Raster.h" @@ -127,7 +127,7 @@ int main (int argc, char* argv[]) // read raster and if required manipulate it auto raster = std::unique_ptr<GeoLib::Raster>( - GeoLib::IO::AsciiRasterInterface::getRasterFromASCFile(raster_arg.getValue())); + FileIO::AsciiRasterInterface::getRasterFromASCFile(raster_arg.getValue())); GeoLib::RasterHeader header (raster->getHeader()); if (refinement_arg.getValue() > 1) { raster->refineRaster(refinement_arg.getValue()); @@ -137,7 +137,7 @@ int main (int argc, char* argv[]) raster_arg.getValue())); new_raster_fname += "-" + std::to_string(header.n_rows) + "x" + std::to_string(header.n_cols) + ".asc"; - GeoLib::IO::AsciiRasterInterface::writeRasterAsASC(*raster, new_raster_fname); + FileIO::AsciiRasterInterface::writeRasterAsASC(*raster, new_raster_fname); } } diff --git a/MeshGeoToolsLib/GeoMapper.cpp b/MeshGeoToolsLib/GeoMapper.cpp index 7d20f1e0dfa..8816ed23d69 100644 --- a/MeshGeoToolsLib/GeoMapper.cpp +++ b/MeshGeoToolsLib/GeoMapper.cpp @@ -19,7 +19,7 @@ #include <logog/include/logog.hpp> -#include "GeoLib/IO/AsciiRasterInterface.h" +#include "Applications/FileIO/AsciiRasterInterface.h" #include "MeshLib/IO/readMeshFromFile.h" #include "GeoLib/AABB.h" @@ -50,7 +50,7 @@ GeoMapper::~GeoMapper() void GeoMapper::mapOnDEM(const std::string &file_name) { - _raster = GeoLib::IO::AsciiRasterInterface::getRasterFromASCFile(file_name); + _raster = FileIO::AsciiRasterInterface::getRasterFromASCFile(file_name); if (! _raster) { ERR("GeoMapper::mapOnDEM(): failed to load %s", file_name.c_str()); return; diff --git a/Tests/FileIO/TestCsvReader.cpp b/Tests/FileIO/TestCsvReader.cpp index be85b8c58f6..8076f413a3c 100644 --- a/Tests/FileIO/TestCsvReader.cpp +++ b/Tests/FileIO/TestCsvReader.cpp @@ -17,7 +17,7 @@ #include "gtest/gtest.h" #include "BaseLib/BuildInfo.h" -#include "GeoLib/IO/CsvInterface.h" +#include "Applications/FileIO/CsvInterface.h" #include "GeoLib/Point.h" class CsvInterfaceTest : public ::testing::Test @@ -56,9 +56,9 @@ TEST_F(CsvInterfaceTest, SimpleReadPoints) { std::vector<GeoLib::Point*> points; std::vector<GeoLib::Point*> points2; - _result = GeoLib::IO::CsvInterface::readPoints(_file_name, '\t', points); + _result = FileIO::CsvInterface::readPoints(_file_name, '\t', points); ASSERT_EQ(0, _result); - _result = GeoLib::IO::CsvInterface::readPoints(_file_name, '\t', points2, "x", "y", "z"); + _result = FileIO::CsvInterface::readPoints(_file_name, '\t', points2, "x", "y", "z"); ASSERT_EQ(0, _result); ASSERT_TRUE(points.size() == 10); ASSERT_TRUE(points2.size() == 10); @@ -77,7 +77,7 @@ TEST_F(CsvInterfaceTest, SimpleReadPoints) TEST_F(CsvInterfaceTest, StringInPointColumn) { std::vector<GeoLib::Point*> points; - _result = GeoLib::IO::CsvInterface::readPoints(_file_name, '\t', points, "x", "y", "name"); + _result = FileIO::CsvInterface::readPoints(_file_name, '\t', points, "x", "y", "name"); ASSERT_EQ(10, _result); ASSERT_TRUE(points.empty()); } @@ -86,11 +86,11 @@ TEST_F(CsvInterfaceTest, StringInPointColumn) TEST_F(CsvInterfaceTest, WrongColumnName) { std::vector<GeoLib::Point*> points; - _result = GeoLib::IO::CsvInterface::readPoints(_file_name, '\t', points, "x", "y", "wrong_column_name"); + _result = FileIO::CsvInterface::readPoints(_file_name, '\t', points, "x", "y", "wrong_column_name"); ASSERT_EQ(-1, _result); ASSERT_TRUE(points.empty()); - _result = GeoLib::IO::CsvInterface::readPoints(_file_name, '\t', points, "wrong_column_name", "y", "id"); + _result = FileIO::CsvInterface::readPoints(_file_name, '\t', points, "wrong_column_name", "y", "id"); ASSERT_EQ(-1, _result); ASSERT_TRUE(points.empty()); } @@ -99,7 +99,7 @@ TEST_F(CsvInterfaceTest, WrongColumnName) TEST_F(CsvInterfaceTest, MissingValues) { std::vector<GeoLib::Point*> points; - _result = GeoLib::IO::CsvInterface::readPoints(_file_name, '\t', points, "z", "value1", "value_two"); + _result = FileIO::CsvInterface::readPoints(_file_name, '\t', points, "z", "value1", "value_two"); ASSERT_EQ(3, _result); ASSERT_EQ(7, points.size()); ASSERT_NEAR(437.539, (*points[4])[2], std::numeric_limits<double>::epsilon()); @@ -111,7 +111,7 @@ TEST_F(CsvInterfaceTest, MissingValues) TEST_F(CsvInterfaceTest, Points2D) { std::vector<GeoLib::Point*> points; - _result = GeoLib::IO::CsvInterface::readPoints(_file_name, '\t', points, "x", "y"); + _result = FileIO::CsvInterface::readPoints(_file_name, '\t', points, "x", "y"); ASSERT_EQ(0, _result); ASSERT_EQ(10, points.size()); for (auto & point : points) @@ -126,11 +126,11 @@ TEST_F(CsvInterfaceTest, CoordinateOrder) std::vector<GeoLib::Point*> points1; std::vector<GeoLib::Point*> points2; std::vector<GeoLib::Point*> points3; - _result = GeoLib::IO::CsvInterface::readPoints(_file_name, '\t', points1, "id", "y", "z"); + _result = FileIO::CsvInterface::readPoints(_file_name, '\t', points1, "id", "y", "z"); ASSERT_EQ(0, _result); - _result = GeoLib::IO::CsvInterface::readPoints(_file_name, '\t', points2, "id", "z", "y"); + _result = FileIO::CsvInterface::readPoints(_file_name, '\t', points2, "id", "z", "y"); ASSERT_EQ(0, _result); - _result = GeoLib::IO::CsvInterface::readPoints(_file_name, '\t', points3, "y", "id", "z"); + _result = FileIO::CsvInterface::readPoints(_file_name, '\t', points3, "y", "id", "z"); ASSERT_EQ(0, _result); ASSERT_EQ(10, points1.size()); ASSERT_EQ(10, points2.size()); @@ -156,12 +156,12 @@ TEST_F(CsvInterfaceTest, CoordinateOrder) TEST_F(CsvInterfaceTest, GetColumn) { std::vector<std::string> names; - _result = GeoLib::IO::CsvInterface::readColumn<std::string>(_file_name, '\t', names, "name"); + _result = FileIO::CsvInterface::readColumn<std::string>(_file_name, '\t', names, "name"); ASSERT_EQ(0, _result); ASSERT_EQ(10, names.size()); std::vector<double> values; - _result = GeoLib::IO::CsvInterface::readColumn<double>(_file_name, '\t', values, "value_two"); + _result = FileIO::CsvInterface::readColumn<double>(_file_name, '\t', values, "value_two"); ASSERT_EQ(2, _result); ASSERT_EQ(8, values.size()); } @@ -170,7 +170,7 @@ TEST_F(CsvInterfaceTest, GetColumn) TEST_F(CsvInterfaceTest, NonExistingColumn) { std::vector<double> values; - _result = GeoLib::IO::CsvInterface::readColumn<double>(_file_name, '\t', values, "value2"); + _result = FileIO::CsvInterface::readColumn<double>(_file_name, '\t', values, "value2"); ASSERT_EQ(-1, _result); ASSERT_TRUE(values.empty()); } @@ -179,12 +179,12 @@ TEST_F(CsvInterfaceTest, NonExistingColumn) TEST_F(CsvInterfaceTest, WrongDataType) { std::vector<double> values; - _result = GeoLib::IO::CsvInterface::readColumn<double>(_file_name, '\t', values, "name"); + _result = FileIO::CsvInterface::readColumn<double>(_file_name, '\t', values, "name"); ASSERT_EQ(10, _result); ASSERT_TRUE(values.empty()); std::vector<std::string> names; - _result = GeoLib::IO::CsvInterface::readColumn<std::string>(_file_name, '\t', names, "value1"); + _result = FileIO::CsvInterface::readColumn<std::string>(_file_name, '\t', names, "value1"); ASSERT_EQ(2, _result); ASSERT_EQ(8, names.size()); } -- GitLab