Commit ace0bb67 by Christophe Geuzaine

better deleteMesh() (to avoid potential mistakes)

parent c011f9e7
Pipeline #951 passed with stage
in 36 minutes 4 seconds
......@@ -520,8 +520,8 @@ void gmsh::model::mesh::setVertices(const int dim, const int tag,
}
param = true;
}
// delete vertices; this will also delete the model mesh cache
ge->deleteMesh(true, false);
// delete vertices and elements; this will also delete the model mesh cache
ge->deleteMesh();
for(unsigned int i = 0; i < vertexTags.size(); i++){
int n = vertexTags[i];
double x = coord[3 * i];
......@@ -570,8 +570,8 @@ void gmsh::model::mesh::setElements(const int dim, const int tag,
Msg::Error("Wrong number of vertex tags");
throw 2;
}
// delete elements; this will also delete the model mesh cache
ge->deleteMesh(false, true);
// delete only elements; this will also delete the model mesh cache
ge->deleteMesh(true);
for(unsigned int i = 0; i < types.size(); i++){
int type = types[i];
unsigned int numEle = elementTags[i].size();
......
......@@ -37,16 +37,14 @@ GEdge::~GEdge()
deleteMesh();
}
void GEdge::deleteMesh(bool vertices, bool elements)
void GEdge::deleteMesh(bool onlyDeleteElements)
{
if(vertices){
if(!onlyDeleteElements){
for(unsigned int i = 0; i < mesh_vertices.size(); i++) delete mesh_vertices[i];
mesh_vertices.clear();
}
if(elements){
for(unsigned int i = 0; i < lines.size(); i++) delete lines[i];
lines.clear();
}
for(unsigned int i = 0; i < lines.size(); i++) delete lines[i];
lines.clear();
_normals.clear();
deleteVertexArrays();
model()->destroyMeshCaches();
......
......@@ -43,7 +43,7 @@ class GEdge : public GEntity {
virtual ~GEdge();
// delete mesh data
virtual void deleteMesh(bool vertices = true, bool elements = true);
virtual void deleteMesh(bool onlyDeleteElements = false);
// get the start/end vertices of the edge
void setBeginVertex(GVertex *gv) { v0=gv; }
......
......@@ -189,7 +189,7 @@ class GEntity {
virtual void mesh(bool verbose) {}
// delete the mesh data
virtual void deleteMesh(bool vertices = true, bool elements = true){}
virtual void deleteMesh(bool onlyDeleteElements = false){}
// delete the vertex arrays, used to to draw the mesh efficiently
void deleteVertexArrays();
......
......@@ -126,21 +126,19 @@ void GFace::replaceEdge(GEdge *e1, GEdge *e2)
l_edges = newlist;
}
void GFace::deleteMesh(bool vertices, bool elements)
void GFace::deleteMesh(bool onlyDeleteElements)
{
if(vertices){
if(!onlyDeleteElements){
for(unsigned int i = 0; i < mesh_vertices.size(); i++) delete mesh_vertices[i];
mesh_vertices.clear();
transfinite_vertices.clear();
}
if(elements){
for(unsigned int i = 0; i < triangles.size(); i++) delete triangles[i];
triangles.clear();
for(unsigned int i = 0; i < quadrangles.size(); i++) delete quadrangles[i];
quadrangles.clear();
for(unsigned int i = 0; i < polygons.size(); i++) delete polygons[i];
polygons.clear();
}
for(unsigned int i = 0; i < triangles.size(); i++) delete triangles[i];
triangles.clear();
for(unsigned int i = 0; i < quadrangles.size(); i++) delete quadrangles[i];
quadrangles.clear();
for(unsigned int i = 0; i < polygons.size(); i++) delete polygons[i];
polygons.clear();
deleteVertexArrays();
model()->destroyMeshCaches();
}
......
......@@ -68,7 +68,7 @@ class GFace : public GEntity {
std::set<MVertex*> constr_vertices;
// delete mesh data
virtual void deleteMesh(bool vertices = true, bool elements = true);
virtual void deleteMesh(bool onlyDeleteElements = false);
// add/delete regions that are bounded by the face
void addRegion(GRegion *r)
......
......@@ -227,16 +227,16 @@ void GModel::destroyMeshCaches()
_octree = 0;
}
void GModel::deleteMesh(bool vertices, bool elements)
void GModel::deleteMesh(bool deleteOnlyElements)
{
for(riter it = firstRegion(); it != lastRegion();++it)
(*it)->deleteMesh(vertices, elements);
(*it)->deleteMesh(deleteOnlyElements);
for(fiter it = firstFace(); it != lastFace();++it)
(*it)->deleteMesh(vertices, elements);
(*it)->deleteMesh(deleteOnlyElements);
for(eiter it = firstEdge(); it != lastEdge();++it)
(*it)->deleteMesh(vertices, elements);
(*it)->deleteMesh(deleteOnlyElements);
for(viter it = firstVertex(); it != lastVertex();++it)
(*it)->deleteMesh(vertices, elements);
(*it)->deleteMesh(deleteOnlyElements);
destroyMeshCaches();
_currentMeshEntity = 0;
_lastMeshEntityError.clear();
......
......@@ -198,7 +198,7 @@ class GModel {
// mesh is changed)
void destroyMeshCaches();
//delete the mesh stored in entities and call destroMeshCaches
void deleteMesh(bool vertices = true, bool elements = true);
void deleteMesh(bool onlyDeleteElements = false);
// remove all mesh vertex associations to geometrical entities and remove
// vertices from geometrical entities, then _associateEntityWithMeshVertices
......
......@@ -34,27 +34,25 @@ GRegion::~GRegion()
deleteMesh();
}
void GRegion::deleteMesh(bool vertices, bool elements)
void GRegion::deleteMesh(bool onlyDeleteElements)
{
if(vertices){
if(!onlyDeleteElements){
for(unsigned int i = 0; i < mesh_vertices.size(); i++) delete mesh_vertices[i];
mesh_vertices.clear();
transfinite_vertices.clear();
}
if(elements){
for(unsigned int i = 0; i < tetrahedra.size(); i++) delete tetrahedra[i];
tetrahedra.clear();
for(unsigned int i = 0; i < hexahedra.size(); i++) delete hexahedra[i];
hexahedra.clear();
for(unsigned int i = 0; i < prisms.size(); i++) delete prisms[i];
prisms.clear();
for(unsigned int i = 0; i < pyramids.size(); i++) delete pyramids[i];
pyramids.clear();
for(unsigned int i = 0; i < trihedra.size(); i++) delete trihedra[i];
trihedra.clear();
for(unsigned int i = 0; i < polyhedra.size(); i++) delete polyhedra[i];
polyhedra.clear();
}
for(unsigned int i = 0; i < tetrahedra.size(); i++) delete tetrahedra[i];
tetrahedra.clear();
for(unsigned int i = 0; i < hexahedra.size(); i++) delete hexahedra[i];
hexahedra.clear();
for(unsigned int i = 0; i < prisms.size(); i++) delete prisms[i];
prisms.clear();
for(unsigned int i = 0; i < pyramids.size(); i++) delete pyramids[i];
pyramids.clear();
for(unsigned int i = 0; i < trihedra.size(); i++) delete trihedra[i];
trihedra.clear();
for(unsigned int i = 0; i < polyhedra.size(); i++) delete polyhedra[i];
polyhedra.clear();
deleteVertexArrays();
model()->destroyMeshCaches();
}
......
......@@ -42,7 +42,7 @@ class GRegion : public GEntity {
virtual ~GRegion();
// delete mesh data
virtual void deleteMesh(bool vertices = true, bool elements = true);
virtual void deleteMesh(bool onlyDeleteElements = false);
// get the dimension of the region (3)
virtual int dim() const { return 3; }
......
......@@ -20,16 +20,14 @@ GVertex::~GVertex()
deleteMesh();
}
void GVertex::deleteMesh(bool vertices, bool elements)
void GVertex::deleteMesh(bool onlyDeleteElements)
{
if(vertices){
if(!onlyDeleteElements){
for(unsigned int i = 0; i < mesh_vertices.size(); i++) delete mesh_vertices[i];
mesh_vertices.clear();
}
if(elements){
for(unsigned int i = 0; i < points.size(); i++) delete points[i];
points.clear();
}
for(unsigned int i = 0; i < points.size(); i++) delete points[i];
points.clear();
deleteVertexArrays();
model()->destroyMeshCaches();
}
......
......@@ -29,7 +29,7 @@ class GVertex : public GEntity
virtual ~GVertex();
// delete mesh data
virtual void deleteMesh(bool vertices = true, bool elements = true);
virtual void deleteMesh(bool onlyDeleteElements = false);
// reset the mesh attributes to default values
virtual void resetMeshAttributes();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment