Commit 83684cd5 by Christophe Geuzaine

allow deletMesh to delete just vertices and/or elements

parent 34b8dbee
Pipeline #946 passed with stage
in 40 minutes 6 seconds
......@@ -520,7 +520,8 @@ void gmsh::model::mesh::setVertices(const int dim, const int tag,
}
param = true;
}
ge->deleteMesh(); // this will also delete the model mesh cache
// delete vertices; this will also delete the model mesh cache
ge->deleteMesh(true, false);
for(unsigned int i = 0; i < vertexTags.size(); i++){
int n = vertexTags[i];
double x = coord[3 * i];
......@@ -546,9 +547,6 @@ template<class T>
static void _addElements(int dim, int tag, const std::vector<MElement*> &src,
std::vector<T*> &dst)
{
if(dst.size())
Msg::Warning("%s already contains mesh elements - appending the new ones",
_entityName(dim, tag).c_str());
for(unsigned int i = 0; i < src.size(); i++)
dst.push_back(static_cast<T*>(src[i]));
}
......@@ -572,6 +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);
for(unsigned int i = 0; i < types.size(); i++){
int type = types[i];
unsigned int numEle = elementTags[i].size();
......
......@@ -37,12 +37,16 @@ GEdge::~GEdge()
deleteMesh();
}
void GEdge::deleteMesh()
void GEdge::deleteMesh(bool vertices, bool elements)
{
for(unsigned int i = 0; i < mesh_vertices.size(); i++) delete mesh_vertices[i];
mesh_vertices.clear();
for(unsigned int i = 0; i < lines.size(); i++) delete lines[i];
lines.clear();
if(vertices){
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();
}
_normals.clear();
deleteVertexArrays();
model()->destroyMeshCaches();
......
......@@ -43,7 +43,7 @@ class GEdge : public GEntity {
virtual ~GEdge();
// delete mesh data
virtual void deleteMesh();
virtual void deleteMesh(bool vertices = true, bool elements = true);
// 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(){}
virtual void deleteMesh(bool vertices = true, bool elements = true){}
// delete the vertex arrays, used to to draw the mesh efficiently
void deleteVertexArrays();
......
......@@ -126,17 +126,21 @@ void GFace::replaceEdge(GEdge *e1, GEdge *e2)
l_edges = newlist;
}
void GFace::deleteMesh()
void GFace::deleteMesh(bool vertices, bool elements)
{
for(unsigned int i = 0; i < mesh_vertices.size(); i++) delete mesh_vertices[i];
mesh_vertices.clear();
transfinite_vertices.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();
if(vertices){
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();
}
deleteVertexArrays();
model()->destroyMeshCaches();
}
......
......@@ -68,7 +68,7 @@ class GFace : public GEntity {
std::set<MVertex*> constr_vertices;
// delete mesh data
virtual void deleteMesh();
virtual void deleteMesh(bool vertices = true, bool elements = true);
// 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()
void GModel::deleteMesh(bool vertices, bool elements)
{
for(riter it = firstRegion(); it != lastRegion();++it)
(*it)->deleteMesh();
(*it)->deleteMesh(vertices, elements);
for(fiter it = firstFace(); it != lastFace();++it)
(*it)->deleteMesh();
(*it)->deleteMesh(vertices, elements);
for(eiter it = firstEdge(); it != lastEdge();++it)
(*it)->deleteMesh();
(*it)->deleteMesh(vertices, elements);
for(viter it = firstVertex(); it != lastVertex();++it)
(*it)->deleteMesh();
(*it)->deleteMesh(vertices, elements);
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();
void deleteMesh(bool vertices = true, bool elements = true);
// remove all mesh vertex associations to geometrical entities and remove
// vertices from geometrical entities, then _associateEntityWithMeshVertices
......
......@@ -34,24 +34,27 @@ GRegion::~GRegion()
deleteMesh();
}
void GRegion::deleteMesh()
void GRegion::deleteMesh(bool vertices, bool elements)
{
for(unsigned int i = 0; i < mesh_vertices.size(); i++) delete mesh_vertices[i];
mesh_vertices.clear();
transfinite_vertices.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();
if(vertices){
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();
}
deleteVertexArrays();
model()->destroyMeshCaches();
}
......
......@@ -42,7 +42,7 @@ class GRegion : public GEntity {
virtual ~GRegion();
// delete mesh data
virtual void deleteMesh();
virtual void deleteMesh(bool vertices = true, bool elements = true);
// get the dimension of the region (3)
virtual int dim() const { return 3; }
......
......@@ -20,12 +20,16 @@ GVertex::~GVertex()
deleteMesh();
}
void GVertex::deleteMesh()
void GVertex::deleteMesh(bool vertices, bool elements)
{
for(unsigned int i = 0; i < mesh_vertices.size(); i++) delete mesh_vertices[i];
mesh_vertices.clear();
for(unsigned int i = 0; i < points.size(); i++) delete points[i];
points.clear();
if(vertices){
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();
}
deleteVertexArrays();
model()->destroyMeshCaches();
}
......@@ -87,7 +91,7 @@ unsigned int GVertex::getNumMeshElements()
void GVertex::getNumMeshElements(unsigned *const c) const
{
c[0] += points.size();
c[0] += points.size();
}
MElement *GVertex::getMeshElement(unsigned int index)
......
......@@ -29,7 +29,7 @@ class GVertex : public GEntity
virtual ~GVertex();
// delete mesh data
virtual void deleteMesh();
virtual void deleteMesh(bool vertices = true, bool elements = true);
// reset the mesh attributes to default values
virtual void resetMeshAttributes();
......@@ -80,7 +80,7 @@ class GVertex : public GEntity
// get number of elements in the mesh
unsigned int getNumMeshElements();
void getNumMeshElements(unsigned *const c) const;
// get the element at the given index
MElement *getMeshElement(unsigned int index);
......
......@@ -42,16 +42,13 @@ print("Entities")
entities = model.getEntities()
for e in entities :
print("entity ",e)
vertexTags,vertexCoords,_ = model.mesh.getVertices(e[0],e[1])
elemTypes,elemTags,elemVertices = model.mesh.getElements(e[0],e[1])
for i in range(len(elemTypes)):
print("type ", elemTypes[i])
print("tags : ", list(elemTags[i]))
print("vertices : ", list(elemVertices[i]))
types,tags,vertices = model.mesh.getElements(e[0],e[1])
for i in range(len(types)):
print("type ", types[i])
print("tags : ", list(tags[i]))
print("vertices : ", list(vertices[i]))
if e[0] == [2] and e[1] == 6 :
model.mesh.setVertices(e[0],e[1],vertexTags,vertexCoords)
model.mesh.setElements(e[0],e[1],elemTypes,[elemTags[0][:10]],[elemVertices[0][:30]])
model.mesh.setElements(e[0],e[1],types,[tags[0][:10]],[vertices[0][:30]])
gmsh.write("mesh_truncated.msh")
print("Vertices")
......
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