Commit 267a04bd authored by Max Lyon's avatar Max Lyon

implemented fast and deferred deletion of entities

fast: swap deleted entity with last in vector, resize vector
deferred: only mark entity as deleted, keep deleted entity in vector
parent 4ebfee6c
......@@ -67,6 +67,8 @@ public:
virtual void delete_element(size_t _idx) = 0;
virtual void swap_elements(size_t _idx0, size_t _idx1) = 0;
virtual void serialize(std::ostream& _ostr) const = 0;
virtual void deserialize(std::istream& _istr) = 0;
......
......@@ -95,11 +95,41 @@ public:
VertexIter nV = TopologyKernelT::delete_vertex(_h);
vertices_.erase(vertices_.begin() + _h.idx());
if (TopologyKernelT::deferred_deletion_enabled())
{
}
else
vertices_.erase(vertices_.begin() + _h.idx());
return nV;
}
virtual void collect_garbage()
{
TopologyKernelT::collect_garbage();
for (unsigned int i = vertices_.size(); i > 0; --i)
if (TopologyKernelT::is_deleted(VertexHandle(i-1)))
{
vertices_.erase(vertices_.begin() + (i-1));
}
}
virtual void swap_vertices(VertexHandle _h1, VertexHandle _h2)
{
assert(_h1.idx() >= 0 && _h1.idx() < (int)vertices_.size());
assert(_h2.idx() >= 0 && _h2.idx() < (int)vertices_.size());
if (_h1 == _h2)
return;
std::swap(vertices_[_h1.idx()], vertices_[_h2.idx()]);
TopologyKernelT::swap_vertices(_h1, _h2);
}
protected:
virtual void delete_multiple_vertices(const std::vector<bool>& _tag) {
......
This diff is collapsed.
......@@ -100,7 +100,7 @@ public:
data_.reserve(_n);
}
virtual void resize(size_t _n) {
data_.resize(_n, def_);
data_.resize(_n, def_);
}
virtual void clear() {
data_.clear();
......@@ -113,9 +113,9 @@ public:
std::swap(data_[_i0], data_[_i1]);
}
void delete_element(size_t _idx) {
data_.erase(data_.begin() + _idx);
}
void delete_element(size_t _idx) {
data_.erase(data_.begin() + _idx);
}
public:
......
......@@ -83,6 +83,8 @@ public:
virtual void delete_element(size_t _idx);
virtual void swap_elements(size_t _idx0, size_t _idx1);
const_iterator begin() const { return ptr::shared_ptr<PropT>::get()->begin(); }
iterator begin() { return ptr::shared_ptr<PropT>::get()->begin(); }
......
......@@ -83,6 +83,11 @@ void PropertyPtr<PropT,HandleT>::delete_element(size_t _idx) {
ptr::shared_ptr<PropT>::get()->delete_element(_idx);
}
template <class PropT, class HandleT>
void PropertyPtr<PropT,HandleT>::swap_elements(size_t _idx0, size_t _idx1) {
ptr::shared_ptr<PropT>::get()->swap(_idx0, _idx1);
}
template <class PropT, class HandleT>
void PropertyPtr<PropT,HandleT>::set_handle(const OpenVolumeMeshHandle& _handle) {
return ptr::shared_ptr<PropT>::get()->set_handle(_handle);
......
......@@ -106,6 +106,36 @@ void ResourceManager::cell_deleted(const CellHandle& _h) {
entity_deleted(cell_props_, _h);
}
void ResourceManager::swap_cell_properties(CellHandle _h1, CellHandle _h2){
swap_property_elements(cell_props_begin(), cell_props_end(), _h1, _h2);
}
void ResourceManager::swap_face_properties(FaceHandle _h1, FaceHandle _h2){
swap_property_elements(face_props_begin(), face_props_end(), _h1, _h2);
}
void ResourceManager::swap_halfface_properties(HalfFaceHandle _h1, HalfFaceHandle _h2){
swap_property_elements(halfface_props_begin(), halfface_props_end(), _h1, _h2);
}
void ResourceManager::swap_edge_properties(EdgeHandle _h1, EdgeHandle _h2){
swap_property_elements(edge_props_begin(), edge_props_end(), _h1, _h2);
}
void ResourceManager::swap_halfedge_properties(HalfEdgeHandle _h1, HalfEdgeHandle _h2){
swap_property_elements(halfedge_props_begin(), halfedge_props_end(), _h1, _h2);
}
void ResourceManager::swap_vertex_properties(VertexHandle _h1, VertexHandle _h2){
swap_property_elements(vertex_props_begin(), vertex_props_end(), _h1, _h2);
}
void ResourceManager::release_property(VertexPropHandle _handle) {
remove_property(vertex_props_, _handle.idx());
......
......@@ -102,6 +102,27 @@ protected:
void cell_deleted(const CellHandle& _h);
void swap_cell_properties(CellHandle _h1, CellHandle _h2);
void swap_face_properties(FaceHandle _h1, FaceHandle _h2);
void swap_halfface_properties(HalfFaceHandle _h1, HalfFaceHandle _h2);
void swap_edge_properties(EdgeHandle _h1, EdgeHandle _h2);
void swap_halfedge_properties(HalfEdgeHandle _h1, HalfEdgeHandle _h2);
void swap_vertex_properties(VertexHandle _h1, VertexHandle _h2);
template <typename PropIterator, typename Handle>
void swap_property_elements(PropIterator _begin, PropIterator _end, Handle _h1, Handle _h2)
{
PropIterator p_iter = _begin;
for (; p_iter != _end; ++p_iter)
(*p_iter)->swap_elements(_h1, _h2);
}
public:
void clear_vertex_props() { clearVec(vertex_props_); }
......
This diff is collapsed.
......@@ -468,6 +468,16 @@ public:
virtual CellIter delete_cell(const CellHandle& _h);
virtual void collect_garbage();
virtual bool is_deleted(const VertexHandle& _h) const { return vertex_deleted_[_h.idx()]; }
virtual bool is_deleted(const EdgeHandle& _h) const { return edge_deleted_[_h.idx()]; }
virtual bool is_deleted(const HalfEdgeHandle& _h) const { return edge_deleted_[_h.idx()/2]; }
virtual bool is_deleted(const FaceHandle& _h) const { return face_deleted_[_h.idx()]; }
virtual bool is_deleted(const HalfFaceHandle& _h) const { return face_deleted_[_h.idx()/2]; }
virtual bool is_deleted(const CellHandle& _h) const { return cell_deleted_[_h.idx()]; }
private:
template <class ContainerT>
......@@ -489,6 +499,14 @@ private:
protected:
virtual void swap_cells(CellHandle _h1, CellHandle _h2);
virtual void swap_faces(FaceHandle _h1, FaceHandle _h2);
virtual void swap_edges(EdgeHandle _h1, EdgeHandle _h2);
virtual void swap_vertices(VertexHandle _h1, VertexHandle _h2);
virtual void delete_multiple_vertices(const std::vector<bool>& _tag);
virtual void delete_multiple_edges(const std::vector<bool>& _tag);
......@@ -570,6 +588,10 @@ public:
edges_.clear();
faces_.clear();
cells_.clear();
vertex_deleted_.clear();
edge_deleted_.clear();
face_deleted_.clear();
cell_deleted_.clear();
outgoing_hes_per_vertex_.clear();
incident_hfs_per_he_.clear();
incident_cell_per_hf_.clear();
......@@ -694,7 +716,16 @@ public:
bool has_face_bottom_up_incidences() const { return f_bottom_up_; }
private:
void enable_deferred_deletion(bool _enable = true) { deferred_deletion = _enable; }
bool deferred_deletion_enabled() const { return deferred_deletion; }
void enable_fast_deletion(bool _enable = true) { fast_deletion = _enable; }
bool fast_deletion_enabled() const { return fast_deletion; }
protected:
void compute_vertex_bottom_up_incidences();
......@@ -713,12 +744,17 @@ private:
// Incident cell (at most one) per halfface
std::vector<CellHandle> incident_cell_per_hf_;
private:
bool v_bottom_up_;
bool e_bottom_up_;
bool f_bottom_up_;
bool deferred_deletion;
bool fast_deletion;
//=====================================================================
// Connectivity
//=====================================================================
......@@ -894,6 +930,12 @@ protected:
// List of cells
std::vector<Cell> cells_;
std::vector<bool> vertex_deleted_;
std::vector<bool> edge_deleted_;
std::vector<bool> face_deleted_;
std::vector<bool> cell_deleted_;
};
}
......
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