Commit 2016417a authored by Jan Möbius's avatar Jan Möbius
Browse files

Merge branch 'feature/track-deleted-entities' into 'master'

Track number of deleted entities and add n_logical_*() methods as proposed in #8

See merge request !38
parents 687c4e76 3ee92228
Pipeline #7559 passed with stage
in 5 minutes and 39 seconds
...@@ -64,8 +64,7 @@ TopologyKernel::TopologyKernel() : ...@@ -64,8 +64,7 @@ TopologyKernel::TopologyKernel() :
e_bottom_up_(true), e_bottom_up_(true),
f_bottom_up_(true), f_bottom_up_(true),
deferred_deletion(true), deferred_deletion(true),
fast_deletion(true), fast_deletion(true)
needs_garbage_collection_(false)
{ {
} }
...@@ -720,42 +719,44 @@ CellIter TopologyKernel::delete_cell(const CellHandle& _h) { ...@@ -720,42 +719,44 @@ CellIter TopologyKernel::delete_cell(const CellHandle& _h) {
*/ */
void TopologyKernel::collect_garbage() void TopologyKernel::collect_garbage()
{ {
if (!deferred_deletion_enabled() || !needs_garbage_collection_) if (!deferred_deletion_enabled() || !needs_garbage_collection())
return; // nothing todo return; // nothing todo
deferred_deletion = false; deferred_deletion = false;
for (int i = (int)n_cells(); i > 0; --i) for (int i = (int)n_cells(); i > 0; --i) {
if (is_deleted(CellHandle(i-1))) if (is_deleted(CellHandle(i - 1))) {
{ cell_deleted_[i - 1] = false;
cell_deleted_[i-1] = false; delete_cell_core(CellHandle(i - 1));
delete_cell_core(CellHandle(i-1));
} }
}
n_deleted_cells_ = 0;
for (int i = (int)n_faces(); i > 0; --i) for (int i = (int)n_faces(); i > 0; --i) {
if (is_deleted(FaceHandle(i-1))) if (is_deleted(FaceHandle(i - 1))) {
{ face_deleted_[i - 1] = false;
face_deleted_[i-1] = false; delete_face_core(FaceHandle(i - 1));
delete_face_core(FaceHandle(i-1));
} }
}
n_deleted_faces_ = 0;
for (int i = (int)n_edges(); i > 0; --i) for (int i = (int)n_edges(); i > 0; --i) {
if (is_deleted(EdgeHandle(i-1))) if (is_deleted(EdgeHandle(i - 1))) {
{ edge_deleted_[i - 1] = false;
edge_deleted_[i-1] = false; delete_edge_core(EdgeHandle(i - 1));
delete_edge_core(EdgeHandle(i-1));
} }
}
n_deleted_edges_ = 0;
for (int i = (int)n_vertices(); i > 0; --i) for (int i = (int)n_vertices(); i > 0; --i) {
if (is_deleted(VertexHandle(i-1))) if (is_deleted(VertexHandle(i - 1))) {
{ vertex_deleted_[i - 1] = false;
vertex_deleted_[i-1] = false; delete_vertex_core(VertexHandle(i - 1));
delete_vertex_core(VertexHandle(i-1));
} }
}
n_deleted_vertices_ = 0;
deferred_deletion = true; deferred_deletion = true;
needs_garbage_collection_ = false;
} }
...@@ -922,7 +923,7 @@ VertexIter TopologyKernel::delete_vertex_core(const VertexHandle& _h) { ...@@ -922,7 +923,7 @@ VertexIter TopologyKernel::delete_vertex_core(const VertexHandle& _h) {
if (deferred_deletion_enabled()) if (deferred_deletion_enabled())
{ {
needs_garbage_collection_ = true; ++n_deleted_vertices_;
vertex_deleted_[h.idx()] = true; vertex_deleted_[h.idx()] = true;
// deleted_vertices_.push_back(h); // deleted_vertices_.push_back(h);
...@@ -1050,7 +1051,7 @@ EdgeIter TopologyKernel::delete_edge_core(const EdgeHandle& _h) { ...@@ -1050,7 +1051,7 @@ EdgeIter TopologyKernel::delete_edge_core(const EdgeHandle& _h) {
if (deferred_deletion_enabled()) if (deferred_deletion_enabled())
{ {
needs_garbage_collection_ = true; ++n_deleted_edges_;
edge_deleted_[h.idx()] = true; edge_deleted_[h.idx()] = true;
// deleted_edges_.push_back(h); // deleted_edges_.push_back(h);
...@@ -1235,7 +1236,7 @@ FaceIter TopologyKernel::delete_face_core(const FaceHandle& _h) { ...@@ -1235,7 +1236,7 @@ FaceIter TopologyKernel::delete_face_core(const FaceHandle& _h) {
if (deferred_deletion_enabled()) if (deferred_deletion_enabled())
{ {
needs_garbage_collection_ = true; ++n_deleted_faces_;
face_deleted_[h.idx()] = true; face_deleted_[h.idx()] = true;
// deleted_faces_.push_back(h); // deleted_faces_.push_back(h);
...@@ -1394,7 +1395,7 @@ CellIter TopologyKernel::delete_cell_core(const CellHandle& _h) { ...@@ -1394,7 +1395,7 @@ CellIter TopologyKernel::delete_cell_core(const CellHandle& _h) {
if (deferred_deletion_enabled()) if (deferred_deletion_enabled())
{ {
needs_garbage_collection_ = true; ++n_deleted_cells_;
cell_deleted_[h.idx()] = true; cell_deleted_[h.idx()] = true;
// deleted_cells_.push_back(h); // deleted_cells_.push_back(h);
// deleted_cells_set.insert(h); // deleted_cells_set.insert(h);
......
...@@ -331,6 +331,19 @@ public: ...@@ -331,6 +331,19 @@ public:
/// Get number of cells in mesh /// Get number of cells in mesh
virtual size_t n_cells() const { return cells_.size(); } virtual size_t n_cells() const { return cells_.size(); }
/// Get number of undeleted vertices in mesh
size_t n_logical_vertices() const { return n_vertices_ - n_deleted_vertices_; }
/// Get number of undeleted edges in mesh
size_t n_logical_edges() const { return edges_.size() - n_deleted_edges_; }
/// Get number of undeleted halfedges in mesh
size_t n_logical_halfedges() const { return n_logical_edges() * 2u; }
/// Get number of undeleted faces in mesh
size_t n_logical_faces() const { return faces_.size() - n_deleted_faces_; }
/// Get number of undeleted halffaces in mesh
size_t n_logical_halffaces() const { return n_faces() * 2u; }
/// Get number of undeleted cells in mesh
size_t n_logical_cells() const { return cells_.size() - n_deleted_cells_; }
int genus() const { int genus() const {
int g = (1 - (int)(n_vertices() - int g = (1 - (int)(n_vertices() -
...@@ -623,6 +636,10 @@ public: ...@@ -623,6 +636,10 @@ public:
edge_deleted_.clear(); edge_deleted_.clear();
face_deleted_.clear(); face_deleted_.clear();
cell_deleted_.clear(); cell_deleted_.clear();
n_deleted_vertices_ = 0;
n_deleted_edges_ = 0;
n_deleted_faces_ = 0;
n_deleted_cells_ = 0;
outgoing_hes_per_vertex_.clear(); outgoing_hes_per_vertex_.clear();
incident_hfs_per_he_.clear(); incident_hfs_per_he_.clear();
incident_cell_per_hf_.clear(); incident_cell_per_hf_.clear();
...@@ -952,7 +969,7 @@ public: ...@@ -952,7 +969,7 @@ public:
} }
bool inline needs_garbage_collection() const { bool inline needs_garbage_collection() const {
return needs_garbage_collection_; return n_deleted_vertices_ > 0 || n_deleted_edges_ > 0 || n_deleted_faces_ > 0 || n_deleted_cells_ > 0;
} }
protected: protected:
...@@ -970,7 +987,12 @@ protected: ...@@ -970,7 +987,12 @@ protected:
std::vector<bool> edge_deleted_; std::vector<bool> edge_deleted_;
std::vector<bool> face_deleted_; std::vector<bool> face_deleted_;
std::vector<bool> cell_deleted_; std::vector<bool> cell_deleted_;
bool needs_garbage_collection_;
// number of elements deleted, but not yet garbage collected
size_t n_deleted_vertices_ = 0;
size_t n_deleted_edges_ = 0;
size_t n_deleted_faces_ = 0;
size_t n_deleted_cells_ = 0;
}; };
......
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