OGS
TetGenInterface.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include <vector>
7
8// GeoLib
9#include "GeoLib/GEOObjects.h"
10#include "GeoLib/Point.h"
11
12// forward declaration of class Node and Element
13namespace MeshLib
14{
15class Node;
16class Element;
17class Mesh;
18} // namespace MeshLib
19
20namespace FileIO
21{
22// clang-format off
30// clang-format on
31class TetGenInterface final
32{
33public:
35
42 bool readTetGenGeometry(std::string const& geo_fname,
43 GeoLib::GEOObjects& geo_objects);
44
52 MeshLib::Mesh* readTetGenMesh(std::string const& nodes_fname,
53 std::string const& ele_fname);
54
65 static bool writeTetGenSmesh(
66 const std::string& file_name,
67 const GeoLib::GEOObjects& geo_objects,
68 const std::string& geo_name,
69 const std::vector<GeoLib::Point>& attribute_points);
70
80 bool writeTetGenSmesh(const std::string& file_name,
81 const MeshLib::Mesh& mesh,
82 std::vector<MeshLib::Node>& attribute_points) const;
83
84private:
86 std::size_t getNFacets(std::ifstream& input);
87
98 bool parseSmeshFacets(std::ifstream& input,
99 std::vector<GeoLib::Surface*>& surfaces,
100 const std::vector<GeoLib::Point*>& points,
101 const std::vector<std::size_t>& pnt_id_map);
102
111 bool readNodesFromStream(std::ifstream& ins,
112 std::vector<MeshLib::Node*>& nodes);
113
124 static bool parseNodesFileHeader(std::string const& line,
125 std::size_t& n_nodes,
126 std::size_t& dim,
127 std::size_t& n_attributes,
128 bool& boundary_markers);
137 bool parseNodes(std::ifstream& ins,
138 std::vector<MeshLib::Node*>& nodes,
139 std::size_t n_nodes,
140 std::size_t dim);
141
153 bool readElementsFromStream(std::ifstream& ins,
154 std::vector<MeshLib::Element*>& elements,
155 std::vector<int>& materials,
156 const std::vector<MeshLib::Node*>& nodes) const;
165 static bool parseElementsFileHeader(std::string& line,
166 std::size_t& n_tets,
167 std::size_t& n_nodes_per_tet,
168 bool& region_attribute);
184 bool parseElements(std::ifstream& ins,
185 std::vector<MeshLib::Element*>& elements,
186 std::vector<int>& materials,
187 const std::vector<MeshLib::Node*>& nodes,
188 std::size_t n_tets,
189 std::size_t n_nodes_per_tet,
190 bool region_attribute) const;
191
198 void write2dElements(std::ofstream& out, const MeshLib::Mesh& mesh) const;
199
207 void write3dElements(std::ofstream& out,
208 const MeshLib::Mesh& mesh,
209 std::vector<MeshLib::Node>& attribute_points) const;
210
213 static void writeElementToFacets(std::ofstream& out,
214 const MeshLib::Element& element,
215 unsigned& element_count,
216 std::string const& matId);
217
219 bool _zero_based_idx{false};
220
222 bool _boundary_markers{false};
223};
224} // namespace FileIO
bool readElementsFromStream(std::ifstream &ins, std::vector< MeshLib::Element * > &elements, std::vector< int > &materials, const std::vector< MeshLib::Node * > &nodes) const
bool _boundary_markers
true if boundary markers are set, false otherwise
MeshLib::Mesh * readTetGenMesh(std::string const &nodes_fname, std::string const &ele_fname)
bool parseNodes(std::ifstream &ins, std::vector< MeshLib::Node * > &nodes, std::size_t n_nodes, std::size_t dim)
static bool parseElementsFileHeader(std::string &line, std::size_t &n_tets, std::size_t &n_nodes_per_tet, bool &region_attribute)
void write3dElements(std::ofstream &out, const MeshLib::Mesh &mesh, std::vector< MeshLib::Node > &attribute_points) const
bool readNodesFromStream(std::ifstream &ins, std::vector< MeshLib::Node * > &nodes)
static bool parseNodesFileHeader(std::string const &line, std::size_t &n_nodes, std::size_t &dim, std::size_t &n_attributes, bool &boundary_markers)
bool _zero_based_idx
the value is true if the indexing is zero based, else false
bool readTetGenGeometry(std::string const &geo_fname, GeoLib::GEOObjects &geo_objects)
void write2dElements(std::ofstream &out, const MeshLib::Mesh &mesh) const
bool parseElements(std::ifstream &ins, std::vector< MeshLib::Element * > &elements, std::vector< int > &materials, const std::vector< MeshLib::Node * > &nodes, std::size_t n_tets, std::size_t n_nodes_per_tet, bool region_attribute) const
static bool writeTetGenSmesh(const std::string &file_name, const GeoLib::GEOObjects &geo_objects, const std::string &geo_name, const std::vector< GeoLib::Point > &attribute_points)
static void writeElementToFacets(std::ofstream &out, const MeshLib::Element &element, unsigned &element_count, std::string const &matId)
bool parseSmeshFacets(std::ifstream &input, std::vector< GeoLib::Surface * > &surfaces, const std::vector< GeoLib::Point * > &points, const std::vector< std::size_t > &pnt_id_map)
std::size_t getNFacets(std::ifstream &input)
Returns the declared number of facets in the poly file.
Container class for geometric objects.
Definition GEOObjects.h:46