From 514ef6620b5399ca10abbab3b1e30adbe9a03142 Mon Sep 17 00:00:00 2001 From: Karsten Rink <karsten.rink@ufz.de> Date: Tue, 4 Sep 2012 14:59:55 +0200 Subject: [PATCH] added check if nodes belong to any elements; reworked legacy mesh input to use getline command so that linux coding will hopefully be no longer a problem --- FileIO/Legacy/MeshIO.cpp | 26 +++++++++++++------------- MeshLib/Mesh.cpp | 7 +++++++ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/FileIO/Legacy/MeshIO.cpp b/FileIO/Legacy/MeshIO.cpp index fd822d5eeeb..93d9aed5cee 100644 --- a/FileIO/Legacy/MeshIO.cpp +++ b/FileIO/Legacy/MeshIO.cpp @@ -64,28 +64,28 @@ MeshLib::Mesh* MeshIO::loadMeshFromFile(const std::string& file_name) else if (line_string.find("$NODES") != std::string::npos) { double x, y, z, double_dummy; - unsigned nNodes, idx; - in >> nNodes >> std::ws; + unsigned idx; + getline(in, line_string); + trim(line_string); + unsigned nNodes = atoi(line_string.c_str()); std::string s; - std::ios::pos_type position = in.tellg(); for (unsigned i = 0; i < nNodes; i++) { - in >> idx >> x >> y >> z; - MeshLib::Node* node(new MeshLib::Node(x, y, z, nodes.size())); + getline(in, line_string); + std::stringstream iss(line_string); + iss >> idx >> x >> y >> z; + MeshLib::Node* node(new MeshLib::Node(x, y, z, idx)); nodes.push_back(node); - position = in.tellg(); - in >> s; + iss >> s; if (s.find("$AREA") != std::string::npos) - in >> double_dummy; - else - in.seekg(position, std::ios::beg); - in >> std::ws; + iss >> double_dummy; } } else if (line_string.find("$ELEMENTS") != std::string::npos) { - unsigned nElements; - in >> nElements >> std::ws; + getline(in, line_string); + trim(line_string); + unsigned nElements = atoi(line_string.c_str()); for (unsigned i = 0; i < nElements; i++) { getline(in, line_string); diff --git a/MeshLib/Mesh.cpp b/MeshLib/Mesh.cpp index c332dc66b73..e6117acb8ae 100644 --- a/MeshLib/Mesh.cpp +++ b/MeshLib/Mesh.cpp @@ -125,6 +125,13 @@ void Mesh::setElementInformationForNodes() for (unsigned j=0; j<nNodes; j++) _elements[i]->_nodes[j]->addElement(_elements[i]); } +#ifdef NDEBUG + // search for nodes that are not part of any element + const size_t nNodes (_nodes.size()); + for (unsigned i=0; i<nNodes; i++) + if (_nodes[i]->getNElements() == 0) + std::cout << "Warning: Node " << i << " is not part of any element." << std::endl; +#endif } void Mesh::setEdgeLengthRange(const double &min_length, const double &max_length) -- GitLab