From d439ce72dd4ad35b300fa25f6e3559c75590ca55 Mon Sep 17 00:00:00 2001 From: Karsten Rink <karsten.rink@ufz.de> Date: Tue, 15 Apr 2014 16:50:54 +0200 Subject: [PATCH] region attributes are now written to tetgen smesh file --- FileIO/TetGenInterface.cpp | 31 +++++++++++++++++++++++++++---- FileIO/TetGenInterface.h | 6 ++++-- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/FileIO/TetGenInterface.cpp b/FileIO/TetGenInterface.cpp index a3cdf0e91c4..013b9074d59 100644 --- a/FileIO/TetGenInterface.cpp +++ b/FileIO/TetGenInterface.cpp @@ -578,7 +578,8 @@ bool TetGenInterface::parseElements(std::ifstream& ins, bool TetGenInterface::writeTetGenSmesh(const std::string &file_name, const GeoLib::GEOObjects &geo_objects, - const std::string &geo_name) const + const std::string &geo_name, + const std::vector<GeoLib::PointWithID> &attribute_points) const { std::vector<GeoLib::Point*> const*const points = geo_objects.getPointVec(geo_name); std::vector<GeoLib::Surface*> const*const surfaces = geo_objects.getSurfaceVec(geo_name); @@ -592,6 +593,7 @@ bool TetGenInterface::writeTetGenSmesh(const std::string &file_name, WARN ("No surfaces found for geometry %s. Writing points only.", geo_name.c_str()); std::ofstream out( file_name.c_str(), std::ios::out ); + out.precision(std::numeric_limits<double>::digits10); // the points header const std::size_t nPoints (points->size()); out << nPoints << " 3\n"; @@ -617,14 +619,24 @@ bool TetGenInterface::writeTetGenSmesh(const std::string &file_name, } } out << "0\n"; // the polygon holes list - out << "0\n"; // the region attribues list + // the region attributes list + if (attribute_points.empty()) + out << "0\n"; + else + { + const std::size_t nAttributePoints (attribute_points.size()); + out << nAttributePoints << "\n"; + for (std::size_t i=0; i<nAttributePoints; ++i) + out << i+1 << " " << attribute_points[i][0] << " " << attribute_points[i][1] << " " << attribute_points[i][2] << " " << 10*attribute_points[i].getID() << "\n"; + } INFO ("TetGenInterface::writeTetGenPoly() - %d points and %d surfaces successfully written.", nPoints, nSurfaces); out.close(); return true; } bool TetGenInterface::writeTetGenSmesh(const std::string &file_name, - const MeshLib::Mesh &mesh) const + const MeshLib::Mesh &mesh, + const std::vector<MeshLib::Node> &attribute_points) const { if (mesh.getDimension() != 2) return false; @@ -633,6 +645,7 @@ bool TetGenInterface::writeTetGenSmesh(const std::string &file_name, const std::vector<MeshLib::Element*> &elements = mesh.getElements(); std::ofstream out( file_name.c_str(), std::ios::out ); + out.precision(std::numeric_limits<double>::digits10); // the points header const std::size_t nPoints (nodes.size()); out << nPoints << " 3\n"; @@ -657,7 +670,17 @@ bool TetGenInterface::writeTetGenSmesh(const std::string &file_name, } } out << "0\n"; // the polygon holes list - out << "0\n"; // the region attribues list + + // the region attributes list + if (attribute_points.empty()) + out << "0\n"; + else + { + const std::size_t nAttributePoints (attribute_points.size()); + out << nAttributePoints << "\n"; + for (std::size_t i=0; i<nAttributePoints; ++i) + out << i+1 << " " << attribute_points[i][0] << " " << attribute_points[i][1] << " " << attribute_points[i][2] << " " << 10*attribute_points[i].getID() << "\n"; + } INFO ("TetGenInterface::writeTetGenPoly() - %d points and %d surfaces successfully written.", nPoints, nElements); out.close(); return true; diff --git a/FileIO/TetGenInterface.h b/FileIO/TetGenInterface.h index b89faa54332..ed6abfe6f1d 100644 --- a/FileIO/TetGenInterface.h +++ b/FileIO/TetGenInterface.h @@ -69,10 +69,12 @@ public: */ bool writeTetGenSmesh(const std::string &file_name, const GeoLib::GEOObjects &geo_objects, - const std::string &geo_name) const; + const std::string &geo_name, + const std::vector<GeoLib::PointWithID> &attribute_points) const; bool writeTetGenSmesh(const std::string &file_name, - const MeshLib::Mesh &mesh) const; + const MeshLib::Mesh &mesh, + const std::vector<MeshLib::Node> &attribute_points) const; private: /// Returns the declared number of facets in the poly file. -- GitLab