diff --git a/Applications/DataExplorer/mainwindow.cpp b/Applications/DataExplorer/mainwindow.cpp index c3c9076c4ca3be47827ce1275e1d48c9b213547a..4e88c40f10c9fa13d30129ddf6a507edd33cec67 100644 --- a/Applications/DataExplorer/mainwindow.cpp +++ b/Applications/DataExplorer/mainwindow.cpp @@ -26,7 +26,7 @@ #include <QSettings> #include <QSignalMapper> #ifndef NDEBUG -#include <QTime> +#include <QElapsedTimer> #endif // NDEBUG // VTK includes @@ -590,15 +590,13 @@ void MainWindow::loadFile(ImportFileType::type t, const QString &fileName) fi.suffix().toLower() == "vtk") { #ifndef NDEBUG - QTime myTimer0; - QTime myTimer1; - myTimer0.start(); + QElapsedTimer myTimer; + myTimer.start(); #endif std::unique_ptr<MeshLib::Mesh> mesh( MeshLib::IO::readMeshFromFile(fileName.toStdString())); #ifndef NDEBUG - INFO("Mesh loading time: {:d} ms.", myTimer0.elapsed()); - myTimer1.start(); + INFO("Mesh loading time: {:d} ms.", myTimer.restart()); #endif if (mesh) { @@ -609,7 +607,7 @@ void MainWindow::loadFile(ImportFileType::type t, const QString &fileName) OGSError::box("Failed to load mesh file."); } #ifndef NDEBUG - INFO("Mesh model setup time: {:d} ms.", myTimer1.elapsed()); + INFO("Mesh model setup time: {:d} ms.", myTimer.elapsed()); #endif } diff --git a/Applications/FileIO/CsvInterface.cpp b/Applications/FileIO/CsvInterface.cpp index d3106ac4d0edea07ec861b351a060c4f2cfa884a..52e213a9322364e77d1f0b93d3bc9f25df9c84cb 100644 --- a/Applications/FileIO/CsvInterface.cpp +++ b/Applications/FileIO/CsvInterface.cpp @@ -19,7 +19,8 @@ #include "GeoLib/Point.h" -namespace FileIO { +namespace FileIO +{ CsvInterface::CsvInterface() = default; std::vector<std::string> CsvInterface::getColumnNames(std::string const& fname, @@ -33,7 +34,7 @@ std::vector<std::string> CsvInterface::getColumnNames(std::string const& fname, return std::vector<std::string>(); } std::string line; - if (!getline(in, line)) + if (!std::getline(in, line)) { return {}; } @@ -59,22 +60,23 @@ std::vector<std::string> CsvInterface::getColumnNames(std::string const& fname, } int CsvInterface::readPoints(std::string const& fname, char delim, - std::vector<GeoLib::Point*> &points) + std::vector<GeoLib::Point*>& points) { std::ifstream in(fname.c_str()); - if (!in.is_open()) { + if (!in.is_open()) + { ERR("CsvInterface::readPoints(): Could not open file {:s}.", fname); return -1; } std::string line; - getline(in, line); + std::getline(in, line); std::size_t line_count(0); std::size_t error_count(0); std::list<std::string>::const_iterator it; - while ( getline(in, line) ) + while (std::getline(in, line)) { line_count++; std::list<std::string> const fields = BaseLib::splitString(line, delim); @@ -89,12 +91,15 @@ int CsvInterface::readPoints(std::string const& fname, char delim, } it = fields.begin(); std::array<double, 3> point{}; - try { + try + { point[0] = std::stod(*it); point[1] = std::stod(*(++it)); point[2] = std::stod(*(++it)); points.push_back(new GeoLib::Point(point[0], point[1], point[2])); - } catch (const std::invalid_argument&) { + } + catch (const std::invalid_argument&) + { ERR("Error converting data to coordinates in line {:d}.", line_count); } @@ -103,26 +108,29 @@ int CsvInterface::readPoints(std::string const& fname, char delim, } int CsvInterface::readPoints(std::string const& fname, char delim, - std::vector<GeoLib::Point*> &points, + std::vector<GeoLib::Point*>& points, std::string const& x_column_name, std::string const& y_column_name, std::string const& z_column_name) { std::ifstream in(fname.c_str()); - std::array<std::string, 3> const column_names = {{x_column_name, y_column_name, z_column_name}}; + std::array<std::string, 3> const column_names = { + {x_column_name, y_column_name, z_column_name}}; - if (!in.is_open()) { + if (!in.is_open()) + { ERR("CsvInterface::readPoints(): Could not open file {:s}.", fname); return -1; } std::string line; - getline(in, line); - std::array<std::size_t, 3> const column_idx = - {{ CsvInterface::findColumn(line, delim, x_column_name), - CsvInterface::findColumn(line, delim, y_column_name), - (z_column_name.empty()) ? CsvInterface::findColumn(line, delim, y_column_name) : - CsvInterface::findColumn(line, delim, z_column_name) }}; + std::getline(in, line); + std::array<std::size_t, 3> const column_idx = { + {CsvInterface::findColumn(line, delim, x_column_name), + CsvInterface::findColumn(line, delim, y_column_name), + (z_column_name.empty()) + ? CsvInterface::findColumn(line, delim, y_column_name) + : CsvInterface::findColumn(line, delim, z_column_name)}}; for (std::size_t i = 0; i < 3; ++i) { @@ -137,14 +145,14 @@ int CsvInterface::readPoints(std::string const& fname, char delim, } int CsvInterface::readPoints(std::string const& fname, char delim, - std::vector<GeoLib::Point*> &points, - std::size_t x_column_idx, - std::size_t y_column_idx, + std::vector<GeoLib::Point*>& points, + std::size_t x_column_idx, std::size_t y_column_idx, std::size_t z_column_idx) { std::ifstream in(fname.c_str()); - if (!in.is_open()) { + if (!in.is_open()) + { ERR("CsvInterface::readPoints(): Could not open file {:s}.", fname); return -1; } @@ -153,34 +161,36 @@ int CsvInterface::readPoints(std::string const& fname, char delim, { z_column_idx = y_column_idx; } - std::array<std::size_t, 3> const column_idx = {{ x_column_idx, y_column_idx, z_column_idx }}; + std::array<std::size_t, 3> const column_idx = { + {x_column_idx, y_column_idx, z_column_idx}}; return readPoints(in, delim, points, column_idx); } -int CsvInterface::readPoints(std::ifstream &in, char delim, - std::vector<GeoLib::Point*> &points, +int CsvInterface::readPoints(std::ifstream& in, char delim, + std::vector<GeoLib::Point*>& points, std::array<std::size_t, 3> const& column_idx) { - std::array<std::size_t, 3> order = {{ 0, 1, 2 }}; + std::array<std::size_t, 3> order = {{0, 1, 2}}; std::sort(order.begin(), order.end(), - [&column_idx](std::size_t idx1, std::size_t idx2) {return column_idx[idx1] < column_idx[idx2];}); - std::array<std::size_t, 3> const column_advance = - {{ column_idx[order[0]], - column_idx[order[1]] - column_idx[order[0]], - column_idx[order[2]] - column_idx[order[1]] }}; + [&column_idx](std::size_t idx1, std::size_t idx2) { + return column_idx[idx1] < column_idx[idx2]; + }); + std::array<std::size_t, 3> const column_advance = { + {column_idx[order[0]], column_idx[order[1]] - column_idx[order[0]], + column_idx[order[2]] - column_idx[order[1]]}}; std::string line; std::size_t line_count(0); std::size_t error_count(0); std::list<std::string>::const_iterator it; - while ( getline(in, line) ) + while (std::getline(in, line)) { line_count++; std::list<std::string> const fields = BaseLib::splitString(line, delim); - if (fields.size() < column_idx[order[2]]+1) + if (fields.size() < column_idx[order[2]] + 1) { ERR("Line {:d} contains not enough columns of data. Skipping " "line...", @@ -191,15 +201,19 @@ int CsvInterface::readPoints(std::ifstream &in, char delim, std::array<double, 3> point{}; it = fields.begin(); - try { + try + { std::advance(it, column_advance[0]); point[order[0]] = std::stod(*it); std::advance(it, column_advance[1]); point[order[1]] = std::stod(*it); std::advance(it, column_advance[2]); - point[order[2]] = (column_idx[1] == column_idx[2]) ? 0 : std::stod(*it); + point[order[2]] = + (column_idx[1] == column_idx[2]) ? 0 : std::stod(*it); points.push_back(new GeoLib::Point(point[0], point[1], point[2])); - } catch (const std::invalid_argument&) { + } + catch (const std::invalid_argument&) + { ERR("Error converting data to coordinates in line {:d}.", line_count); error_count++; @@ -208,7 +222,8 @@ int CsvInterface::readPoints(std::ifstream &in, char delim, return error_count; } -std::size_t CsvInterface::findColumn(std::string const& line, char delim, std::string const& column_name) +std::size_t CsvInterface::findColumn(std::string const& line, char delim, + std::string const& column_name) { std::list<std::string> const fields = BaseLib::splitString(line, delim); if (fields.empty()) @@ -246,12 +261,12 @@ bool CsvInterface::write() { if (_data.empty()) { - ERR ("CsvInterface::write() - No data to write."); + ERR("CsvInterface::write() - No data to write."); return false; } - std::size_t const n_vecs (_data.size()); - std::size_t const vec_size (getVectorSize(0)); + std::size_t const n_vecs(_data.size()); + std::size_t const vec_size(getVectorSize(0)); if (_writeCsvHeader) { @@ -263,13 +278,13 @@ bool CsvInterface::write() _out << "\n"; } - for (std::size_t j=0; j<vec_size; ++j) + for (std::size_t j = 0; j < vec_size; ++j) { - writeValue(0,j); - for (std::size_t i=1; i<n_vecs; ++i) + writeValue(0, j); + for (std::size_t i = 1; i < n_vecs; ++i) { _out << "\t"; - writeValue(i,j); + writeValue(i, j); } _out << "\n"; } @@ -297,11 +312,13 @@ void CsvInterface::writeValue(std::size_t vec_idx, std::size_t in_vec_idx) { if (_data[vec_idx].type() == typeid(std::vector<std::string>)) { - _out << boost::any_cast<std::vector<std::string>>(_data[vec_idx])[in_vec_idx]; + _out << boost::any_cast<std::vector<std::string>>( + _data[vec_idx])[in_vec_idx]; } else if (_data[vec_idx].type() == typeid(std::vector<double>)) { - _out << boost::any_cast<std::vector<double>>(_data[vec_idx])[in_vec_idx]; + _out << boost::any_cast<std::vector<double>>( + _data[vec_idx])[in_vec_idx]; } else if (_data[vec_idx].type() == typeid(std::vector<int>)) { @@ -309,4 +326,4 @@ void CsvInterface::writeValue(std::size_t vec_idx, std::size_t in_vec_idx) } } -} // end namespace FileIO +} // end namespace FileIO diff --git a/Applications/FileIO/CsvInterface.h b/Applications/FileIO/CsvInterface.h index bb057fb42f7b240dcdcd133fd736ff240e8e12aa..f9f584337c5f94bd7139b0f02276b29a3c5ff69f 100644 --- a/Applications/FileIO/CsvInterface.h +++ b/Applications/FileIO/CsvInterface.h @@ -29,18 +29,18 @@ #include "BaseLib/StringTools.h" #include "BaseLib/IO/Writer.h" -namespace GeoLib { - class Point; +namespace GeoLib +{ +class Point; } -namespace FileIO { - +namespace FileIO +{ /** * Interface for reading CSV file formats. */ -class CsvInterface : public BaseLib::IO::Writer +class CsvInterface : public BaseLib::IO::Writer { - public: /// Contructor (only needed for writing files) CsvInterface(); @@ -59,19 +59,21 @@ public: /// Stores if the CSV file to be written should include a header or not. void setCsvHeader(bool write_header) { _writeCsvHeader = write_header; } - /// Adds a data vector to the CSV file. All data vectors have to have the same size. - /// Vectors will be written in the same sequence they have been added to the interface. - template<typename T> - bool addVectorForWriting(std::string const& vec_name, std::vector<T> const& vec) + /// Adds a data vector to the CSV file. All data vectors have to have the + /// same size. Vectors will be written in the same sequence they have been + /// added to the interface. + template <typename T> + bool addVectorForWriting(std::string const& vec_name, + std::vector<T> const& vec) { - static_assert(std::is_same<T, std::string>::value - || std::is_same<T, double>::value - || std::is_same<T, int>::value, - "CsvInterface can only write vectors of strings, doubles or ints."); + static_assert( + std::is_same<T, std::string>::value || + std::is_same<T, double>::value || std::is_same<T, int>::value, + "CsvInterface can only write vectors of strings, doubles or ints."); if (!_data.empty()) { - std::size_t const vec_size (getVectorSize(0)); + std::size_t const vec_size(getVectorSize(0)); if (vec_size != vec.size()) { ERR("Vector size does not match existing data (should be " @@ -91,15 +93,15 @@ public: /** * Reads 3D points from a CSV file. It is assumed that the file has a header - * specifying a name for each of the columns. The first three columns will be - * interpreted as x-, y- and z-coordinate, respectively. - * \param fname Name of the file to be read - * \param delim Deliminator, default is ',' + * specifying a name for each of the columns. The first three columns will + * be interpreted as x-, y- and z-coordinate, respectively. \param fname + * Name of the file to be read \param delim Deliminator, default is ',' * \param points A vector containing the 3D points read from the file - * \return An error code (0 = ok, 0<i<max = number of skipped lines, -1 error reading file) + * \return An error code (0 = ok, 0<i<max = number of skipped lines, -1 + * error reading file) */ static int readPoints(std::string const& fname, char delim, - std::vector<GeoLib::Point*> &points); + std::vector<GeoLib::Point*>& points); /** * Reads 3D points from a CSV file. It is assumed that the file has a header @@ -109,14 +111,15 @@ public: * z-coordinates will be set to zero. * \param fname Name of the file to be read * \param delim Deliminator, default is ',' - * \param points A vector containing the 3D points read from the file - * \param x_column_name Name of the column to be interpreted as x-coordinate - * \param y_column_name Name of the column to be interpreted as y-coordinate - * \param z_column_name Name of the column to be interpreted as z-coordinate - * \return An error code (0 = ok, 0<i<max = number of skipped lines, -1 error reading file) + * \param points A vector containing the 3D points read from the + * file \param x_column_name Name of the column to be interpreted as + * x-coordinate \param y_column_name Name of the column to be interpreted + * as y-coordinate \param z_column_name Name of the column to be + * interpreted as z-coordinate \return An error code (0 = ok, 0<i<max = + * number of skipped lines, -1 error reading file) */ static int readPoints(std::string const& fname, char delim, - std::vector<GeoLib::Point*> &points, + std::vector<GeoLib::Point*>& points, std::string const& x_column_name, std::string const& y_column_name, std::string const& z_column_name = ""); @@ -128,17 +131,18 @@ public: * z-coordinates will be set to zero. * \param fname Name of the file to be read * \param delim Deliminator, default is ',' - * \param points A vector containing the 3D points read from the file - * \param x_column_idx Index of the column to be interpreted as x-coordinate - * \param y_column_idx Index of the column to be interpreted as y-coordinate - * \param z_column_idx Index of the column to be interpreted as z-coordinate - * \return An error code (0 = ok, 0<i<max = number of skipped lines, -1 error reading file) + * \param points A vector containing the 3D points read from the + * file \param x_column_idx Index of the column to be interpreted as + * x-coordinate \param y_column_idx Index of the column to be interpreted + * as y-coordinate \param z_column_idx Index of the column to be + * interpreted as z-coordinate \return An error code (0 = ok, 0<i<max = + * number of skipped lines, -1 error reading file) */ - static int readPoints(std::string const& fname, char delim, - std::vector<GeoLib::Point*> &points, - std::size_t x_column_idx, - std::size_t y_column_idx, - std::size_t z_column_idx = std::numeric_limits<std::size_t>::max()); + static int readPoints( + std::string const& fname, char delim, + std::vector<GeoLib::Point*>& points, std::size_t x_column_idx, + std::size_t y_column_idx, + std::size_t z_column_idx = std::numeric_limits<std::size_t>::max()); /** * Reads a column of the given name from a CSV file. @@ -146,22 +150,25 @@ public: * \param delim Deliminator, default is ',' * \param data_array A vector containing the data read from the file * \param column_name The column's name to read - * \return An error code (0 = ok, 0<i<max = number of skipped lines, -1 error reading file) + * \return An error code (0 = ok, 0<i<max = number of skipped lines, -1 + * error reading file) */ template <typename T> static int readColumn(std::string const& fname, char delim, - std::vector<T> &data_array, + std::vector<T>& data_array, std::string const& column_name) { std::ifstream in(fname.c_str()); - if (!in.is_open()) { + if (!in.is_open()) + { ERR("CsvInterface::readColumn(): Could not open file {:s}.", fname); return -1; } std::string line; getline(in, line); - std::size_t const column_idx = CsvInterface::findColumn(line, delim, column_name); + std::size_t const column_idx = + CsvInterface::findColumn(line, delim, column_name); if (column_idx == std::numeric_limits<std::size_t>::max()) { ERR("Column '{:s}' not found in file header.", column_name); @@ -172,11 +179,11 @@ public: template <typename T> static int readColumn(std::string const& fname, char delim, - std::vector<T> &data_array, - std::size_t column_idx) + std::vector<T>& data_array, std::size_t column_idx) { std::ifstream in(fname.c_str()); - if (!in.is_open()) { + if (!in.is_open()) + { ERR("CsvInterface::readColumn(): Could not open file {:s}.", fname); return -1; } @@ -185,26 +192,26 @@ public: private: /// Actual point reader for public methods - static int readPoints(std::ifstream &in, char delim, - std::vector<GeoLib::Point*> &points, + static int readPoints(std::ifstream& in, char delim, + std::vector<GeoLib::Point*>& points, std::array<std::size_t, 3> const& column_idx); /// Actual column reader for public methods template <typename T> - static int readColumn(std::ifstream &in, char delim, - std::vector<T> &data_array, - std::size_t column_idx) + static int readColumn(std::ifstream& in, char delim, + std::vector<T>& data_array, std::size_t column_idx) { std::string line; std::size_t line_count(0); std::size_t error_count(0); std::list<std::string>::const_iterator it; - while ( getline(in, line) ) + while (std::getline(in, line)) { line_count++; - std::list<std::string> const fields = BaseLib::splitString(line, delim); + std::list<std::string> const fields = + BaseLib::splitString(line, delim); - if (fields.size() < column_idx+1) + if (fields.size() < column_idx + 1) { ERR("Line {:d} contains not enough columns of data. Skipping " "line...", @@ -229,8 +236,10 @@ private: return error_count; } - /// Returns the number of the column with column_name (or std::numeric_limits::max() if no such column has been found). - static std::size_t findColumn(std::string const& line, char delim, std::string const& column_name); + /// Returns the number of the column with column_name (or + /// std::numeric_limits::max() if no such column has been found). + static std::size_t findColumn(std::string const& line, char delim, + std::string const& column_name); /// Returns the size of the vector with the given index std::size_t getVectorSize(std::size_t idx) const; @@ -244,7 +253,7 @@ private: bool _writeCsvHeader{true}; std::vector<std::string> _vec_names; - std::vector< boost::any > _data; + std::vector<boost::any> _data; }; } // namespace FileIO diff --git a/Applications/FileIO/Gmsh/GMSHInterface.h b/Applications/FileIO/Gmsh/GMSHInterface.h index e7d333c3a43b7c4a7ccec4f58850e72ef1345471..ef6b6004840a78d02563e1ecc964b3f740a66de8 100644 --- a/Applications/FileIO/Gmsh/GMSHInterface.h +++ b/Applications/FileIO/Gmsh/GMSHInterface.h @@ -18,7 +18,6 @@ #include "Applications/FileIO/Gmsh/GMSHPoint.h" #include "BaseLib/IO/Writer.h" -#include "MathLib/LinAlg/Dense/DenseMatrix.h" namespace GeoLib { diff --git a/Applications/Utils/MeshEdit/checkMesh.cpp b/Applications/Utils/MeshEdit/checkMesh.cpp index 42c8d52ea44c8828f9a24395500067df58b84801..87895d30fad3fb9ad8b9a630b610b666eb131708 100644 --- a/Applications/Utils/MeshEdit/checkMesh.cpp +++ b/Applications/Utils/MeshEdit/checkMesh.cpp @@ -28,7 +28,7 @@ #include "MeshLib/IO/readMeshFromFile.h" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Checks mesh properties.\n\n" @@ -38,18 +38,20 @@ int main(int argc, char *argv[]) "Copyright (c) 2012-2020, OpenGeoSys Community " "(http://www.opengeosys.org)", ' ', GitInfoLib::GitInfo::ogs_version); - TCLAP::UnlabeledValueArg<std::string> mesh_arg("mesh-file","input mesh file",true,"","string"); - cmd.add( mesh_arg ); - TCLAP::SwitchArg valid_arg("v","validation","validate the mesh"); - cmd.add( valid_arg ); - TCLAP::SwitchArg print_properties_arg("p","print_properties","print properties stored in the mesh"); - cmd.add( print_properties_arg ); + TCLAP::UnlabeledValueArg<std::string> mesh_arg( + "mesh-file", "input mesh file", true, "", "string"); + cmd.add(mesh_arg); + TCLAP::SwitchArg valid_arg("v", "validation", "validate the mesh"); + cmd.add(valid_arg); + TCLAP::SwitchArg print_properties_arg( + "p", "print_properties", "print properties stored in the mesh"); + cmd.add(print_properties_arg); - cmd.parse( argc, argv ); + cmd.parse(argc, argv); // read the mesh file BaseLib::MemWatch mem_watch; - const unsigned long mem_without_mesh (mem_watch.getVirtMemUsage()); + const unsigned long mem_without_mesh(mem_watch.getVirtMemUsage()); BaseLib::RunTime run_time; run_time.start(); std::unique_ptr<MeshLib::Mesh> mesh( @@ -59,8 +61,8 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - const unsigned long mem_with_mesh (mem_watch.getVirtMemUsage()); - if (mem_with_mesh>0) + const unsigned long mem_with_mesh(mem_watch.getVirtMemUsage()); + if (mem_with_mesh > 0) { INFO("Memory size: {:i} MB", (mem_with_mesh - mem_without_mesh) / (1024 * 1024)); @@ -89,7 +91,8 @@ int main(int argc, char *argv[]) MeshLib::MeshInformation::writePropertyVectorInformation(*mesh); - if (valid_arg.isSet()) { + if (valid_arg.isSet()) + { // MeshValidation outputs error messages // Remark: MeshValidation can modify the original mesh MeshLib::MeshInformation::writeMeshValidationResults(*mesh); diff --git a/Tests/GeoLib/TestSurfaceIsPointInSurface.cpp b/Tests/GeoLib/TestSurfaceIsPointInSurface.cpp index a9cf956bbe8ef8140a718fcbaaa9837e5e32c54a..8e4cc2eae795c69fead4723ff5c6d021a93fafa4 100644 --- a/Tests/GeoLib/TestSurfaceIsPointInSurface.cpp +++ b/Tests/GeoLib/TestSurfaceIsPointInSurface.cpp @@ -24,7 +24,6 @@ #include "GeoLib/Triangle.h" #include "GeoLib/AnalyticalGeometry.h" -#include "MathLib/LinAlg/Dense/DenseMatrix.h" #include "MathLib/Point3d.h" #include "MeshLib/Mesh.h" diff --git a/Tests/MeshLib/TestCoordinatesMappingLocal.cpp b/Tests/MeshLib/TestCoordinatesMappingLocal.cpp index 221694d13889b461000a3cac82178399a7f1768b..b681ccb5c81fbec9d372935b4d73b971399400ba 100644 --- a/Tests/MeshLib/TestCoordinatesMappingLocal.cpp +++ b/Tests/MeshLib/TestCoordinatesMappingLocal.cpp @@ -18,7 +18,6 @@ #include <Eigen/Eigen> #include "GeoLib/AnalyticalGeometry.h" -#include "MathLib/LinAlg/Dense/DenseMatrix.h" #include "MeshLib/CoordinateSystem.h" #include "MeshLib/Node.h"