diff --git a/FileIO/TetGenInterface.cpp b/FileIO/TetGenInterface.cpp index 23e4b9590de691d82ac3cdb0d9c1ea89c4c979ff..dc8f094649aa23a8ce9599d6037aa529a5787966 100644 --- a/FileIO/TetGenInterface.cpp +++ b/FileIO/TetGenInterface.cpp @@ -657,9 +657,9 @@ bool TetGenInterface::writeTetGenSmesh(const std::string &file_name, out << i << " " << (*nodes[i])[0] << " " << (*nodes[i])[1] << " " << (*nodes[i])[2] << "\n"; if (mesh.getDimension() == 2) - smeshFrom2D(out, mesh, attribute_points); + write2dElements(out, mesh, attribute_points); else - smeshFrom3D(out, mesh, attribute_points); + write3dElements(out, mesh, attribute_points); out << "0\n"; // the polygon holes list @@ -679,9 +679,9 @@ bool TetGenInterface::writeTetGenSmesh(const std::string &file_name, return true; } -void TetGenInterface::smeshFrom2D(std::ofstream &out, - const MeshLib::Mesh &mesh, - std::vector<MeshLib::Node> &attribute_points) const +void TetGenInterface::write2dElements(std::ofstream &out, + const MeshLib::Mesh &mesh, + std::vector<MeshLib::Node> &attribute_points) const { // the surfaces header const std::array<unsigned,7> types = MeshInformation::getNumberOfElementTypes(mesh); @@ -695,12 +695,14 @@ void TetGenInterface::smeshFrom2D(std::ofstream &out, this->writeElementToFacets(out, *elements[i], element_count); } -void TetGenInterface::smeshFrom3D(std::ofstream &out, - const MeshLib::Mesh &mesh, - std::vector<MeshLib::Node> &attribute_points) const +void TetGenInterface::write3dElements(std::ofstream &out, + const MeshLib::Mesh &mesh, + std::vector<MeshLib::Node> &attribute_points) const { const std::vector<MeshLib::Element*> &elements = mesh.getElements(); const std::size_t nElements (elements.size()); + if (!attribute_points.empty()) + attribute_points.clear(); // get position where number of facets need to be written and figure out worst case of chars that are needed std::streamoff before_elems_pos (out.tellp()); diff --git a/FileIO/TetGenInterface.h b/FileIO/TetGenInterface.h index f1c2754381cd8607800842b3ba30e745dba47bf8..2d9d0565beeab77a1c2692e84aa9e2b3c5e8ef89 100644 --- a/FileIO/TetGenInterface.h +++ b/FileIO/TetGenInterface.h @@ -190,14 +190,29 @@ private: std::size_t n_nodes_per_tet, bool region_attribute) const; - void smeshFrom2D(std::ofstream &out, - const MeshLib::Mesh &mesh, - std::vector<MeshLib::Node> &attribute_points) const; + /** + * Writes the elements from a 2D mesh to a TetGen smesh-file. + * @param out the output stream the information is written to. + * @param mesh mesh containing the subsurface boundary representation used for meshing. + * @param attribute_points attribute points containing material IDs (if the vector is empty no attributes are written). + * @return returns true on success and false otherwise. + */ + void write2dElements(std::ofstream &out, + const MeshLib::Mesh &mesh, + std::vector<MeshLib::Node> &attribute_points) const; - void smeshFrom3D(std::ofstream &out, - const MeshLib::Mesh &mesh, - std::vector<MeshLib::Node> &attribute_points) const; + /** + * Writes the elements from a 3D mesh to a TetGen smesh-file. + * @param out the output stream the information is written to. + * @param mesh the 3D mesh. + * @param attribute_points attribute points containing material IDs (emptied when called and then filled with correct values). + * @return returns true on success and false otherwise. + */ + void write3dElements(std::ofstream &out, + const MeshLib::Mesh &mesh, + std::vector<MeshLib::Node> &attribute_points) const; + /// Writes facet information from a 2D element to the stream and increments the total element count accordingly void writeElementToFacets(std::ofstream &out, const MeshLib::Element &element, unsigned &element_count) const; /// the value is true if the indexing is zero based, else false