diff --git a/CMakeLists.txt b/CMakeLists.txt index c503699e7cb70250d418dae5d8edcd800499b95d..7aa2854f9ff5ef943923e78c654f537c1714ff9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,5 +40,5 @@ endif() add_subdirectory(addEmiDataToMesh) add_subdirectory(addScalarArrayTimeSeries) add_subdirectory(EmiData2PolyData) -# add_subdirectory(ErtData2Mesh) if (QT4_FOUND) add_subdirectory(makeBuildings) -# endif() +add_subdirectory(ErtData2Mesh) +# add_subdirectory(makeBuildings) diff --git a/ErtData2Mesh/CMakeLists.txt b/ErtData2Mesh/CMakeLists.txt index 412744ed68afff29e0e2b7695b3065e59f9e82ee..888951c18b7c0139d2f9df3491a1248ac7f84d7a 100644 --- a/ErtData2Mesh/CMakeLists.txt +++ b/ErtData2Mesh/CMakeLists.txt @@ -1,10 +1,5 @@ add_executable(ErtData2Mesh ErtData2Mesh.cpp) -target_link_libraries(ErtData2Mesh - logog - BaseLib - FileIO - InSituLib - ${VTK_LIBRARIES} +target_link_libraries( + ErtData2Mesh BaseLib ApplicationsFileIO MeshLib tclap ogs_include ) -ADD_VTK_DEPENDENCY(ErtData2Mesh) set_target_properties(ErtData2Mesh PROPERTIES FOLDER Utilities) diff --git a/ErtData2Mesh/ErtData2Mesh.cpp b/ErtData2Mesh/ErtData2Mesh.cpp index 6bb73efb00d909dc8880915e2ade498f1746d409..07f587d050bea16ab3693aa3b7bf4d6ffee30754 100644 --- a/ErtData2Mesh/ErtData2Mesh.cpp +++ b/ErtData2Mesh/ErtData2Mesh.cpp @@ -17,16 +17,10 @@ // TCLAP #include "tclap/CmdLine.h" -// ThirdParty/logog -#include "logog/include/logog.hpp" - -// BaseLib -#include "BaseLib/LogogSimpleFormatter.h" - // FileIO #include "MeshLib/IO/VtkIO/VtuInterface.h" -#include "FileIO/CsvInterface.h" -#include "GeoLib/IO/AsciiRasterInterface.h" +#include "Applications/FileIO/CsvInterface.h" +#include "Applications/FileIO/AsciiRasterInterface.h" // GeoLib #include "GeoLib/Point.h" @@ -41,12 +35,11 @@ #include "MeshLib/Elements/Quad.h" #include "MeshLib/MeshEditing/MeshRevision.h" - -std::vector<double> getElevationCorrectionValues(GeoLib::Raster const& dem, std::vector<MeshLib::Node*> &nodes) +std::vector<double> getElevationCorrectionValues(GeoLib::Raster const &dem, std::vector<MeshLib::Node *> &nodes) { - std::size_t const n_sfc_nodes (nodes.size()); + std::size_t const n_sfc_nodes(nodes.size()); std::vector<double> elevation_correction; - for (std::size_t i=0; i<n_sfc_nodes; ++i) + for (std::size_t i = 0; i < n_sfc_nodes; ++i) { double a = (*nodes[i])[2]; double b = dem.getValueAtPoint(*nodes[i]); @@ -56,35 +49,30 @@ std::vector<double> getElevationCorrectionValues(GeoLib::Raster const& dem, std: return elevation_correction; } -int main (int argc, char* argv[]) +int main(int argc, char *argv[]) { - LOGOG_INITIALIZE(); - logog::Cout* logog_cout (new logog::Cout); - BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); - logog_cout->SetFormatter(*custom_format); - TCLAP::CmdLine cmd("Converts a CSV file containing ERT data to a quad mesh.", ' ', "0.1"); // I/O params TCLAP::ValueArg<std::string> mesh_out("o", "mesh-output-file", - "The name of the new mesh file", true, - "", "file name of output mesh"); + "The name of the new mesh file", true, + "", "file name of output mesh"); cmd.add(mesh_out); TCLAP::ValueArg<std::string> csv_in("i", "csv-input-file", - "CSV-file containing ERT information.", - true, "", "name of the csv input file"); + "CSV-file containing ERT information.", + true, "", "name of the csv input file"); cmd.add(csv_in); TCLAP::ValueArg<std::string> dem_in("s", "DEM-file", - "Surface DEM for mapping ERT data", false, - "", "file name of the Surface DEM"); + "Surface DEM for mapping ERT data", false, + "", "file name of the Surface DEM"); cmd.add(dem_in); cmd.parse(argc, argv); std::vector<std::size_t> ids; int const e = FileIO::CsvInterface::readColumn<std::size_t>(csv_in.getValue(), '\t', ids, "x2/m"); - std::size_t const n_nodes_per_layer (ids.back()+1); - std::vector<GeoLib::Point*> points1; - std::vector<GeoLib::Point*> points2; + std::size_t const n_nodes_per_layer(ids.back() + 1); + std::vector<GeoLib::Point *> points1; + std::vector<GeoLib::Point *> points2; int const r1 = FileIO::CsvInterface::readPoints(csv_in.getValue(), '\t', points1, "E1", "N1", "H1"); int const r2 = FileIO::CsvInterface::readPoints(csv_in.getValue(), '\t', points2, "E2", "N2", "H2"); std::vector<double> z1; @@ -92,76 +80,76 @@ int main (int argc, char* argv[]) int const c1 = FileIO::CsvInterface::readColumn<double>(csv_in.getValue(), '\t', z1, "z1/m"); int const c2 = FileIO::CsvInterface::readColumn<double>(csv_in.getValue(), '\t', z2, "z2/m"); - if (e!= 0 || r1 != 0 || r2 != 0 || c1 != 0 || c2 != 0) + if (e != 0 || r1 != 0 || r2 != 0 || c1 != 0 || c2 != 0) { ERR("Error reading data from file"); return 1; } - std::size_t const n_quads (points1.size()); - for (std::size_t i=1; i<n_quads; ++i) + std::size_t const n_quads(points1.size()); + for (std::size_t i = 1; i < n_quads; ++i) { - if ((*points1[i-1])[0] == (*points2[i])[0] || - (*points1[i-1])[1] == (*points2[i])[1] || - (*points1[i-1])[2] == (*points2[i])[2]) + if ((*points1[i - 1])[0] == (*points2[i])[0] || + (*points1[i - 1])[1] == (*points2[i])[1] || + (*points1[i - 1])[2] == (*points2[i])[2]) { - ERR ("Error in ERT file."); + ERR("Error in ERT file."); return 1; } } - std::vector<MeshLib::Node*> nodes; - std::vector<MeshLib::Element*> quads; + std::vector<MeshLib::Node *> nodes; + std::vector<MeshLib::Element *> quads; quads.reserve(n_quads); std::vector<int> materials; materials.reserve(n_quads); - nodes.push_back(new MeshLib::Node((*points1[0])[0], (*points1[0])[1], (*points1[0])[2] - z1[0], nodes.size() )); - for (std::size_t i=0; i<n_nodes_per_layer; ++i) - nodes.push_back(new MeshLib::Node((*points2[i])[0], (*points2[i])[1], (*points2[i])[2] - z1[i], nodes.size() )); + nodes.push_back(new MeshLib::Node((*points1[0])[0], (*points1[0])[1], (*points1[0])[2] - z1[0], nodes.size())); + for (std::size_t i = 0; i < n_nodes_per_layer; ++i) + nodes.push_back(new MeshLib::Node((*points2[i])[0], (*points2[i])[1], (*points2[i])[2] - z1[i], nodes.size())); - std::vector<double> elevation_correction (nodes.size(), 0.0); + std::vector<double> elevation_correction(nodes.size(), 0.0); if (dem_in.isSet()) { - GeoLib::Raster* dem = GeoLib::IO::AsciiRasterInterface::readRaster(dem_in.getValue()); + GeoLib::Raster *dem = FileIO::AsciiRasterInterface::readRaster(dem_in.getValue()); elevation_correction = getElevationCorrectionValues(*dem, nodes); delete dem; } - std::size_t const n_layers ((n_quads / n_nodes_per_layer)); - for (std::size_t mat_id=0; mat_id<n_layers; ++mat_id) + std::size_t const n_layers((n_quads / n_nodes_per_layer)); + for (std::size_t mat_id = 0; mat_id < n_layers; ++mat_id) { - std::size_t const base_idx (mat_id * n_nodes_per_layer); + std::size_t const base_idx(mat_id * n_nodes_per_layer); double z = (*points1[base_idx])[2] - elevation_correction[0] - z2[base_idx]; - nodes.push_back(new MeshLib::Node((*points1[base_idx])[0], (*points1[base_idx])[1], z, nodes.size() )); - for (std::size_t i=0; i<n_nodes_per_layer; ++i) + nodes.push_back(new MeshLib::Node((*points1[base_idx])[0], (*points1[base_idx])[1], z, nodes.size())); + for (std::size_t i = 0; i < n_nodes_per_layer; ++i) { - std::size_t const idx (base_idx + i); - std::array<MeshLib::Node*, 4> quad_nodes; + std::size_t const idx(base_idx + i); + std::array<MeshLib::Node *, 4> quad_nodes; quad_nodes[0] = nodes[base_idx + mat_id + i]; - quad_nodes[1] = nodes[nodes.size()-1]; - z = (*points2[idx])[2] - elevation_correction[i+1] - z2[base_idx+i]; - nodes.push_back(new MeshLib::Node((*points2[idx])[0], (*points2[idx])[1], z, nodes.size() )); + quad_nodes[1] = nodes[nodes.size() - 1]; + z = (*points2[idx])[2] - elevation_correction[i + 1] - z2[base_idx + i]; + nodes.push_back(new MeshLib::Node((*points2[idx])[0], (*points2[idx])[1], z, nodes.size())); quad_nodes[2] = nodes.back(); - quad_nodes[3] = nodes[base_idx + mat_id + i+1]; + quad_nodes[3] = nodes[base_idx + mat_id + i + 1]; quads.push_back(new MeshLib::Quad(quad_nodes)); materials.push_back(mat_id); } } MeshLib::Mesh mesh("ERT Mesh", nodes, quads); - - boost::optional<std::vector<int>&> mat_prop (mesh.getProperties().createNewPropertyVector<int>("MaterialIDs", MeshLib::MeshItemType::Cell)); + + auto mat_prop(mesh.getProperties().createNewPropertyVector<int>("MaterialIDs", MeshLib::MeshItemType::Cell)); mat_prop->insert(mat_prop->end(), materials.begin(), materials.end()); - boost::optional<std::vector<double>&> resistance (mesh.getProperties().createNewPropertyVector<double>("Resistance", MeshLib::MeshItemType::Cell)); + auto resistance(mesh.getProperties().createNewPropertyVector<double>("Resistance", MeshLib::MeshItemType::Cell)); int const errors_res = FileIO::CsvInterface::readColumn<double>(csv_in.getValue(), '\t', *resistance, "rho/Ohmm "); if (errors_res != 0 || resistance->size() != n_quads) - WARN ("Erros reading resistance values."); + WARN("Erros reading resistance values."); - boost::optional<std::vector<double>&> coverage (mesh.getProperties().createNewPropertyVector<double>("Coverage", MeshLib::MeshItemType::Cell)); + auto coverage(mesh.getProperties().createNewPropertyVector<double>("Coverage", MeshLib::MeshItemType::Cell)); int const errors_cov = FileIO::CsvInterface::readColumn<double>(csv_in.getValue(), '\t', *coverage, "coverage"); if (errors_cov != 0 || coverage->size() != n_quads) - WARN ("Erros reading coverage values."); - + WARN("Erros reading coverage values."); + /* TODO writing arrays with tuple size > 1 needs fixing double const max_cov = *std::max_element(coverage->cbegin(), coverage->cend()); boost::optional<std::vector<double>&> conduct (mesh.getProperties().createNewPropertyVector<double>("Conductivity", MeshLib::MeshItemType::Cell, 1)); @@ -174,18 +162,12 @@ int main (int argc, char* argv[]) } } */ - - INFO ("Writing result..."); + + INFO("Writing result..."); MeshLib::IO::VtuInterface vtu(&mesh); vtu.writeToFile(mesh_out.getValue()); //delete mesh; - delete custom_format; - delete logog_cout; - LOGOG_SHUTDOWN(); return 0; } - - -