Skip to content
Snippets Groups Projects
Commit db0b23b5 authored by Karsten Rink's avatar Karsten Rink Committed by Dmitri Naumov
Browse files

adjusted tetgen interface to use mesh properties

parent 765b79a4
No related branches found
No related tags found
No related merge requests found
......@@ -218,7 +218,8 @@ MeshLib::Mesh* TetGenInterface::readTetGenMesh (std::string const& nodes_fname,
}
std::vector<MeshLib::Element*> elements;
if (!readElementsFromStream (ins_ele, elements, nodes)) {
std::vector<int> materials;
if (!readElementsFromStream (ins_ele, elements, materials, nodes)) {
// remove elements read until now
for (std::size_t k(0); k<elements.size(); k++) {
delete elements[k];
......@@ -230,8 +231,18 @@ MeshLib::Mesh* TetGenInterface::readTetGenMesh (std::string const& nodes_fname,
return nullptr;
}
MeshLib::Properties properties;
// remove material vector again if all mat-ids are "0"
if (*(std::max_element(materials.cbegin(), materials.cend())) > 0)
{
boost::optional<MeshLib::PropertyVector<int> &> mat_props =
properties.createNewPropertyVector<int>("MaterialIDs", MeshLib::MeshItemType::Cell);
mat_props->resize(elements.size());
std::copy(materials.cbegin(), materials.cend(), mat_props->begin());
}
const std::string mesh_name (BaseLib::extractBaseNameWithoutExtension(nodes_fname));
return new MeshLib::Mesh(mesh_name, nodes, elements);
return new MeshLib::Mesh(mesh_name, nodes, elements, properties);
}
bool TetGenInterface::readNodesFromStream (std::ifstream &ins,
......@@ -354,6 +365,7 @@ bool TetGenInterface::parseNodes(std::ifstream &ins,
bool TetGenInterface::readElementsFromStream(std::ifstream &ins,
std::vector<MeshLib::Element*> &elements,
std::vector<int> &materials,
const std::vector<MeshLib::Node*> &nodes) const
{
std::string line;
......@@ -375,7 +387,7 @@ bool TetGenInterface::readElementsFromStream(std::ifstream &ins,
bool header_okay = parseElementsFileHeader(line, n_tets, n_nodes_per_tet, region_attributes);
if (!header_okay)
return false;
if (!parseElements(ins, elements, nodes, n_tets, n_nodes_per_tet, region_attributes))
if (!parseElements(ins, elements, materials, nodes, n_tets, n_nodes_per_tet, region_attributes))
return false;
return true;
}
......@@ -417,6 +429,7 @@ bool TetGenInterface::parseElementsFileHeader(std::string &line,
bool TetGenInterface::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,
......@@ -425,6 +438,7 @@ bool TetGenInterface::parseElements(std::ifstream& ins,
std::string line;
std::size_t* ids (static_cast<std::size_t*>(alloca (sizeof (std::size_t) * n_nodes_per_tet)));
elements.reserve(n_tets);
materials.reserve(n_tets);
const unsigned offset = (_zero_based_idx) ? 0 : 1;
for (std::size_t k(0); k < n_tets && !ins.fail(); k++)
......@@ -486,8 +500,10 @@ bool TetGenInterface::parseElements(std::ifstream& ins,
for (unsigned k(0); k<4; k++) {
tet_nodes[k] = nodes[ids[k]];
}
elements.push_back (new MeshLib::Tet(tet_nodes, region));
elements.push_back (new MeshLib::Tet(tet_nodes));
materials.push_back(region);
}
return true;
}
......
......@@ -144,11 +144,13 @@ private:
* For this purpose it uses methods parseElementsFileHeader() and parseElements().
* @param input the input stream
* @param elements the elements vector to be filled
* @param materials the vector containing material ids to be filled
* @param nodes the node information needed for creating elements
* @return true, if all information is read, false if the method detects an error
*/
bool readElementsFromStream(std::ifstream &input,
std::vector<MeshLib::Element*> &elements,
std::vector<int> &materials,
const std::vector<MeshLib::Node*> &nodes) const;
/**
* Method parses the header of the elements file created by TetGen
......@@ -166,6 +168,7 @@ private:
* Method parses the tetrahedras and put them in the element vector of the mesh class.
* @param ins the input stream
* @param elements the elements vector to be filled
* @param materials the vector containing material ids to be filled
* @param nodes the node information needed for creating elements
* @param n_tets the number of tetrahedras that should be read
* @param n_nodes_per_tet the number of nodes per tetrahedron
......@@ -174,6 +177,7 @@ private:
*/
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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment