Commit 3e03bdfb authored by Jan Möbius's avatar Jan Möbius

Merge branch 'mh_refactor' into 'master'

Cleanup and small features

See merge request !54
parents bd7687fa f69d1edd
Pipeline #9315 passed with stage
in 3 minutes and 54 seconds
...@@ -55,9 +55,9 @@ class BaseProperty { ...@@ -55,9 +55,9 @@ class BaseProperty {
public: public:
friend class ResourceManager; friend class ResourceManager;
explicit BaseProperty(ResourceManager& _resMan) : resMan_(_resMan), lock_(false) {} explicit BaseProperty(ResourceManager& _resMan) : resMan_(&_resMan) {}
BaseProperty(const BaseProperty& _cpy) : resMan_(_cpy.resMan_), lock_(_cpy.lock_) {} BaseProperty(const BaseProperty& _cpy) : resMan_(_cpy.resMan_) {}
BaseProperty& operator=(const BaseProperty& _cpy) = delete; BaseProperty& operator=(const BaseProperty& _cpy) = delete;
...@@ -95,15 +95,9 @@ protected: ...@@ -95,15 +95,9 @@ protected:
virtual void set_handle(const OpenVolumeMeshHandle& /*_handle*/) = 0; virtual void set_handle(const OpenVolumeMeshHandle& /*_handle*/) = 0;
void lock() { lock_ = true; } void setResMan(ResourceManager *resMan) { resMan_ = resMan;}
void unlock() { lock_ = false; } ResourceManager* resMan_;
bool locked() const { return lock_; }
ResourceManager& resMan_;
bool lock_;
}; };
} // Namespace OpenVolumeMesh } // Namespace OpenVolumeMesh
......
...@@ -11,7 +11,7 @@ class OpenVolumeMeshPropertyT; ...@@ -11,7 +11,7 @@ class OpenVolumeMeshPropertyT;
template <class E, typename > template <class E, typename >
class PropHandleT; class PropHandleT;
template <class PropT, class HandleT> template <class PropT, typename Entity>
class PropertyPtr; class PropertyPtr;
template<typename T, typename Entity> template<typename T, typename Entity>
......
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
#include <algorithm> #include <algorithm>
#include <iosfwd> #include <iosfwd>
#include <vector> #include <vector>
#include <cassert>
#include <limits>
#include "Entities.hh" #include "Entities.hh"
#include "../System/FunctionalInclude.hh" #include "../System/FunctionalInclude.hh"
...@@ -48,17 +50,15 @@ namespace OpenVolumeMesh { ...@@ -48,17 +50,15 @@ namespace OpenVolumeMesh {
class OpenVolumeMeshHandle { class OpenVolumeMeshHandle {
public: public:
// Default constructor // Default constructor
explicit OpenVolumeMeshHandle(int _idx) : idx_(_idx) {}; explicit OpenVolumeMeshHandle(int _idx) : idx_(_idx) {}
OpenVolumeMeshHandle& operator=(int _idx) { OpenVolumeMeshHandle& operator=(int _idx) {
idx_ = _idx; idx_ = _idx;
return *this; return *this;
} }
OpenVolumeMeshHandle& operator=(const OpenVolumeMeshHandle& _idx) { OpenVolumeMeshHandle(const OpenVolumeMeshHandle& _idx) = default;
idx_ = _idx.idx_; OpenVolumeMeshHandle& operator=(const OpenVolumeMeshHandle& _idx) = default;
return *this;
}
inline bool is_valid() const { return idx_ != -1; } inline bool is_valid() const { return idx_ != -1; }
...@@ -76,6 +76,9 @@ public: ...@@ -76,6 +76,9 @@ public:
inline const int& idx() const { return idx_; } inline const int& idx() const { return idx_; }
/// return unsigned idx - handle must be valid
inline size_t uidx() const { assert(is_valid()); return static_cast<size_t>(idx_); }
void idx(const int& _idx) { idx_ = _idx; } void idx(const int& _idx) { idx_ = _idx; }
OVM_DEPRECATED("use explicit .idx() instead") OVM_DEPRECATED("use explicit .idx() instead")
...@@ -95,6 +98,17 @@ class HandleT : public OpenVolumeMeshHandle ...@@ -95,6 +98,17 @@ class HandleT : public OpenVolumeMeshHandle
public: public:
using Entity = EntityTag; using Entity = EntityTag;
explicit HandleT(int _idx = -1) : OpenVolumeMeshHandle(_idx) {} explicit HandleT(int _idx = -1) : OpenVolumeMeshHandle(_idx) {}
static HandleT<EntityTag>
from_unsigned(size_t _idx)
{
if (_idx <= std::numeric_limits<int>::max()) {
return HandleT<EntityTag>(static_cast<int>(_idx));
} else {
assert(false);
return HandleT<EntityTag>(-1);
}
}
}; };
// Default entity handles // Default entity handles
......
...@@ -82,14 +82,12 @@ template <> const std::string entityTypeName<Entity::Cell>(); ...@@ -82,14 +82,12 @@ template <> const std::string entityTypeName<Entity::Cell>();
template <> const std::string entityTypeName<Entity::Mesh>(); template <> const std::string entityTypeName<Entity::Mesh>();
template<typename T, typename Entity> template<typename T, typename Entity>
class PropertyTT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, PropHandleT<Entity>> { class PropertyTT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, Entity> {
public: public:
using PropertyHandleT = OpenVolumeMesh::PropHandleT<Entity>; using PropertyHandleT = OpenVolumeMesh::PropHandleT<Entity>;
PropertyTT(const std::string& _name, ResourceManager& _resMan, PropertyHandleT _handle, const T _def = T()); PropertyTT(const std::string& _name, ResourceManager& _resMan, PropertyHandleT _handle, const T _def = T());
virtual ~PropertyTT() = default; virtual ~PropertyTT() = default;
virtual BaseProperty* clone(ResourceManager &_resMan, OpenVolumeMeshHandle _handle) const; virtual BaseProperty* clone(ResourceManager &_resMan, OpenVolumeMeshHandle _handle) const;
virtual void serialize(std::ostream& _ostr) const;
virtual void deserialize(std::istream& _istr);
virtual const std::string entityType() const { return entityTypeName<Entity>(); } virtual const std::string entityType() const { return entityTypeName<Entity>(); }
virtual const std::string typeNameWrapper() const { return typeName<T>(); } virtual const std::string typeNameWrapper() const { return typeName<T>(); }
private: private:
......
...@@ -32,14 +32,6 @@ ...@@ -32,14 +32,6 @@
* * * *
\*===========================================================================*/ \*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $Date$ *
* $LastChangedBy$ *
* *
\*===========================================================================*/
#define PROPERTYDEFINEST_CC #define PROPERTYDEFINEST_CC
#include <istream> #include <istream>
...@@ -51,13 +43,13 @@ namespace OpenVolumeMesh { ...@@ -51,13 +43,13 @@ namespace OpenVolumeMesh {
template<typename T, typename Entity> template<typename T, typename Entity>
PropertyTT<T,Entity>::PropertyTT(const std::string& _name, ResourceManager& _resMan, PropertyHandleT _handle, const T _def) : PropertyTT<T,Entity>::PropertyTT(const std::string& _name, ResourceManager& _resMan, PropertyHandleT _handle, const T _def) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, PropertyHandleT>(new OpenVolumeMeshPropertyT<T>(_name, _def), _resMan, _handle) { PropertyPtr<OpenVolumeMeshPropertyT<T>, Entity>(new OpenVolumeMeshPropertyT<T>(_name, _def), _resMan, _handle) {
} }
template<typename T, typename Entity> template<typename T, typename Entity>
PropertyTT<T,Entity>::PropertyTT(OpenVolumeMeshPropertyT<T> *_prop, ResourceManager &_resMan, PropertyHandleT _handle) : PropertyTT<T,Entity>::PropertyTT(OpenVolumeMeshPropertyT<T> *_prop, ResourceManager &_resMan, PropertyHandleT _handle) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, PropertyHandleT>(_prop, _resMan, _handle) PropertyPtr<OpenVolumeMeshPropertyT<T>, Entity>(_prop, _resMan, _handle)
{ {
} }
...@@ -68,16 +60,6 @@ BaseProperty *PropertyTT<T,Entity>::clone(ResourceManager &_resMan, OpenVolumeMe ...@@ -68,16 +60,6 @@ BaseProperty *PropertyTT<T,Entity>::clone(ResourceManager &_resMan, OpenVolumeMe
return new PropertyTT<T, Entity>(prop_clone, _resMan, PropertyHandleT(_handle.idx())); return new PropertyTT<T, Entity>(prop_clone, _resMan, PropertyHandleT(_handle.idx()));
} }
template<typename T, typename Entity>
void PropertyTT<T,Entity>::serialize(std::ostream& _ostr) const {
PropertyPtr<OpenVolumeMeshPropertyT<T>, PropertyHandleT>::get()->serialize(_ostr);
}
template<typename T, typename Entity>
void PropertyTT<T,Entity>::deserialize(std::istream& _istr) {
PropertyPtr<OpenVolumeMeshPropertyT<T>, PropertyHandleT>::get()->deserialize(_istr);
}
template<typename T> template<typename T>
const std::string typeName() { const std::string typeName() {
throw std::runtime_error("Serialization is not supported for these data types!"); throw std::runtime_error("Serialization is not supported for these data types!");
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <string> #include <string>
#include "PropertyHandles.hh"
#include "BaseProperty.hh" #include "BaseProperty.hh"
#include "OpenVolumeMeshHandle.hh" #include "OpenVolumeMeshHandle.hh"
#include "../System/MemoryInclude.hh" #include "../System/MemoryInclude.hh"
...@@ -54,7 +55,7 @@ class ResourceManager; ...@@ -54,7 +55,7 @@ class ResourceManager;
* as soon as the object is not used anymore. * as soon as the object is not used anymore.
*/ */
template <class PropT, class HandleT> template <class PropT, typename Entity>
class PropertyPtr : protected ptr::shared_ptr<PropT>, public BaseProperty { class PropertyPtr : protected ptr::shared_ptr<PropT>, public BaseProperty {
public: public:
...@@ -66,10 +67,10 @@ public: ...@@ -66,10 +67,10 @@ public:
typedef typename PropT::reference reference; typedef typename PropT::reference reference;
typedef typename PropT::const_reference const_reference; typedef typename PropT::const_reference const_reference;
typedef OpenVolumeMesh::HandleT<typename HandleT::Entity> EntityHandleT; using EntityHandleT = HandleT<Entity>;
/// Constructor /// Constructor
PropertyPtr(PropT* _ptr, ResourceManager& _resMan, HandleT _handle); PropertyPtr(PropT* _ptr, ResourceManager& _resMan, PropHandleT<Entity> _handle);
/// Destructor /// Destructor
virtual ~PropertyPtr(); virtual ~PropertyPtr();
...@@ -98,7 +99,10 @@ public: ...@@ -98,7 +99,10 @@ public:
const_reference operator[](size_t _idx) const { return (*ptr::shared_ptr<PropT>::get())[_idx]; } const_reference operator[](size_t _idx) const { return (*ptr::shared_ptr<PropT>::get())[_idx]; }
reference operator[](const EntityHandleT& _h) { return (*ptr::shared_ptr<PropT>::get())[_h.idx()]; } reference operator[](const EntityHandleT& _h) { return (*ptr::shared_ptr<PropT>::get())[_h.idx()]; }
const_reference operator[](const EntityHandleT& _h) const { return (*ptr::shared_ptr<PropT>::get())[_h.idx()]; } const_reference operator[](const EntityHandleT& _h) const { return (*ptr::shared_ptr<PropT>::get())[_h.uidx()]; }
virtual void serialize(std::ostream& _ostr) const { ptr::shared_ptr<PropT>::get()->serialize(_ostr); }
virtual void deserialize(std::istream& _istr) { ptr::shared_ptr<PropT>::get()->deserialize(_istr); }
virtual OpenVolumeMeshHandle handle() const; virtual OpenVolumeMeshHandle handle() const;
......
...@@ -40,63 +40,62 @@ ...@@ -40,63 +40,62 @@
namespace OpenVolumeMesh { namespace OpenVolumeMesh {
template <class PropT, class HandleT> template <class PropT, typename Entity>
PropertyPtr<PropT,HandleT>::PropertyPtr(PropT* _ptr, ResourceManager& _resMan, HandleT _handle) : PropertyPtr<PropT,Entity>::PropertyPtr(PropT* _ptr, ResourceManager& _resMan, PropHandleT<Entity> _handle) :
ptr::shared_ptr<PropT>(_ptr), BaseProperty(_resMan) { ptr::shared_ptr<PropT>(_ptr), BaseProperty(_resMan) {
ptr::shared_ptr<PropT>::get()->set_handle(_handle); ptr::shared_ptr<PropT>::get()->set_handle(_handle);
} }
template <class PropT, class HandleT> template <class PropT, typename Entity>
PropertyPtr<PropT,HandleT>::~PropertyPtr() { PropertyPtr<PropT,Entity>::~PropertyPtr() {
/* /*
* If use count is 2 and prop is not set persistent, * If use count is 2 and prop is not set persistent,
* remove it, since the resource manager is the * remove it, since the resource manager is the
* only one who stores the property. * only one who stores the property.
*/ */
if(!locked() && !persistent() && ptr::shared_ptr<PropT>::use_count() == 2) { if(resMan_ && !persistent() && ptr::shared_ptr<PropT>::use_count() == 2) {
resMan_.release_property(HandleT(handle().idx())); resMan_->release_property(PropHandleT<Entity>(handle().idx()));
unlock();
} }
} }
template <class PropT, class HandleT> template <class PropT, typename Entity>
void PropertyPtr<PropT,HandleT>::resize(size_t _size) { void PropertyPtr<PropT,Entity>::resize(size_t _size) {
ptr::shared_ptr<PropT>::get()->resize(_size); ptr::shared_ptr<PropT>::get()->resize(_size);
} }
template <class PropT, class HandleT> template <class PropT, typename Entity>
const std::string& PropertyPtr<PropT,HandleT>::name() const { const std::string& PropertyPtr<PropT,Entity>::name() const {
return ptr::shared_ptr<PropT>::get()->name(); return ptr::shared_ptr<PropT>::get()->name();
} }
template <class PropT, class HandleT> template <class PropT, typename Entity>
void PropertyPtr<PropT,HandleT>::delete_element(size_t _idx) { void PropertyPtr<PropT,Entity>::delete_element(size_t _idx) {
ptr::shared_ptr<PropT>::get()->delete_element(_idx); ptr::shared_ptr<PropT>::get()->delete_element(_idx);
} }
template <class PropT, class HandleT> template <class PropT, typename Entity>
void PropertyPtr<PropT,HandleT>::swap_elements(size_t _idx0, size_t _idx1) { void PropertyPtr<PropT,Entity>::swap_elements(size_t _idx0, size_t _idx1) {
ptr::shared_ptr<PropT>::get()->swap(_idx0, _idx1); ptr::shared_ptr<PropT>::get()->swap(_idx0, _idx1);
} }
template <class PropT, class HandleT> template <class PropT, typename Entity>
void PropertyPtr<PropT,HandleT>::copy(size_t _src_idx, size_t _dst_idx) { void PropertyPtr<PropT,Entity>::copy(size_t _src_idx, size_t _dst_idx) {
ptr::shared_ptr<PropT>::get()->copy(_src_idx, _dst_idx); ptr::shared_ptr<PropT>::get()->copy(_src_idx, _dst_idx);
} }
template <class PropT, class HandleT> template <class PropT, typename Entity>
void PropertyPtr<PropT,HandleT>::set_handle(const OpenVolumeMeshHandle& _handle) { void PropertyPtr<PropT,Entity>::set_handle(const OpenVolumeMeshHandle& _handle) {
return ptr::shared_ptr<PropT>::get()->set_handle(_handle); return ptr::shared_ptr<PropT>::get()->set_handle(_handle);
} }
template <class PropT, class HandleT> template <class PropT, typename Entity>
OpenVolumeMeshHandle PropertyPtr<PropT,HandleT>::handle() const { OpenVolumeMeshHandle PropertyPtr<PropT,Entity>::handle() const {
return ptr::shared_ptr<PropT>::get()->handle(); return ptr::shared_ptr<PropT>::get()->handle();
} }
template <class PropT, class HandleT> template <class PropT, typename Entity>
void PropertyPtr<PropT,HandleT>::delete_multiple_entries(const std::vector<bool>& _tags) { void PropertyPtr<PropT,Entity>::delete_multiple_entries(const std::vector<bool>& _tags) {
ptr::shared_ptr<PropT>::get()->delete_multiple_entries(_tags); ptr::shared_ptr<PropT>::get()->delete_multiple_entries(_tags);
} }
......
...@@ -32,22 +32,25 @@ ...@@ -32,22 +32,25 @@
* * * *
\*===========================================================================*/ \*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $Date$ *
* $LastChangedBy$ *
* *
\*===========================================================================*/
#include "ResourceManager.hh" #include "ResourceManager.hh"
namespace OpenVolumeMesh { namespace OpenVolumeMesh {
ResourceManager::ResourceManager() { ResourceManager::ResourceManager(const ResourceManager &other)
{
*this = other;
}
ResourceManager::ResourceManager(ResourceManager &&other)
{
*this = std::move(other);
} }
ResourceManager::ResourceManager(const ResourceManager &other) { ResourceManager& ResourceManager::operator=(const ResourceManager &other)
{
if (this == &other)
return *this;
auto cloneProps = [this](const Properties &src, Properties &dest) { auto cloneProps = [this](const Properties &src, Properties &dest) {
dest.reserve(src.size()); dest.reserve(src.size());
for (BaseProperty *bp: src) { for (BaseProperty *bp: src) {
...@@ -61,6 +64,28 @@ ResourceManager::ResourceManager(const ResourceManager &other) { ...@@ -61,6 +64,28 @@ ResourceManager::ResourceManager(const ResourceManager &other) {
cloneProps(other.halfface_props_, halfface_props_); cloneProps(other.halfface_props_, halfface_props_);
cloneProps(other.cell_props_, cell_props_); cloneProps(other.cell_props_, cell_props_);
cloneProps(other.mesh_props_, mesh_props_); cloneProps(other.mesh_props_, mesh_props_);
return *this;
}
ResourceManager& ResourceManager::operator=(ResourceManager &&other)
{
if (this == &other)
return *this;
auto moveProps = [this](Properties &&src, Properties &dest) {
dest = std::move(src);
for (auto prop: dest) {
prop->setResMan(this);
}
};
moveProps(std::move(other.vertex_props_), vertex_props_);
moveProps(std::move(other.edge_props_), edge_props_);
moveProps(std::move(other.halfedge_props_), halfedge_props_);
moveProps(std::move(other.face_props_), face_props_);
moveProps(std::move(other.halfface_props_), halfface_props_);
moveProps(std::move(other.cell_props_), cell_props_);
moveProps(std::move(other.mesh_props_), mesh_props_);
return *this;
} }
ResourceManager::~ResourceManager() { ResourceManager::~ResourceManager() {
...@@ -153,32 +178,32 @@ void ResourceManager::swap_vertex_properties(VertexHandle _h1, VertexHandle _h2) ...@@ -153,32 +178,32 @@ void ResourceManager::swap_vertex_properties(VertexHandle _h1, VertexHandle _h2)
void ResourceManager::release_property(VertexPropHandle _handle) { void ResourceManager::release_property(VertexPropHandle _handle) {
remove_property(vertex_props_, _handle.idx()); remove_property(vertex_props_, _handle.uidx());
} }
void ResourceManager::release_property(EdgePropHandle _handle) { void ResourceManager::release_property(EdgePropHandle _handle) {
remove_property(edge_props_, _handle.idx()); remove_property(edge_props_, _handle.uidx());
} }
void ResourceManager::release_property(HalfEdgePropHandle _handle) { void ResourceManager::release_property(HalfEdgePropHandle _handle) {
remove_property(halfedge_props_, _handle.idx()); remove_property(halfedge_props_, _handle.uidx());
} }
void ResourceManager::release_property(FacePropHandle _handle) { void ResourceManager::release_property(FacePropHandle _handle) {
remove_property(face_props_, _handle.idx()); remove_property(face_props_, _handle.uidx());
} }
void ResourceManager::release_property(HalfFacePropHandle _handle) { void ResourceManager::release_property(HalfFacePropHandle _handle) {
remove_property(halfface_props_, _handle.idx()); remove_property(halfface_props_, _handle.uidx());
} }
void ResourceManager::release_property(CellPropHandle _handle) { void ResourceManager::release_property(CellPropHandle _handle) {
remove_property(cell_props_, _handle.idx()); remove_property(cell_props_, _handle.uidx());
} }
void ResourceManager::release_property(MeshPropHandle _handle) { void ResourceManager::release_property(MeshPropHandle _handle) {
......
...@@ -51,10 +51,11 @@ class BaseProperty; ...@@ -51,10 +51,11 @@ class BaseProperty;
class ResourceManager { class ResourceManager {
public: public:
ResourceManager(); ResourceManager() = default;
ResourceManager(const ResourceManager &other); ResourceManager(const ResourceManager &other);
ResourceManager& operator=(const ResourceManager &other) = delete; ResourceManager(ResourceManager &&other);
ResourceManager& operator=(const ResourceManager &other);
ResourceManager& operator=(ResourceManager &&other);
virtual ~ResourceManager(); virtual ~ResourceManager();
template <class PropT, class HandleT> friend class PropertyPtr; template <class PropT, class HandleT> friend class PropertyPtr;
...@@ -319,6 +320,9 @@ private: ...@@ -319,6 +320,9 @@ private:
template<class StdVecT> template<class StdVecT>
void clearVec(StdVecT& _vec); void clearVec(StdVecT& _vec);
template<class StdVecT>
void updatePropHandles(StdVecT& _vec);
Properties vertex_props_; Properties vertex_props_;
Properties edge_props_; Properties edge_props_;
......
...@@ -170,13 +170,11 @@ void ResourceManager::set_persistentT(PropT& _prop, bool _flag) { ...@@ -170,13 +170,11 @@ void ResourceManager::set_persistentT(PropT& _prop, bool _flag) {
template<class StdVecT> template<class StdVecT>
void ResourceManager::remove_property(StdVecT& _vec, size_t _idx) { void ResourceManager::remove_property(StdVecT& _vec, size_t _idx) {
(*(_vec.begin() + _idx))->lock(); auto prop_ptr = _vec[_idx];
delete *(_vec.begin() + _idx); prop_ptr->setResMan(nullptr);
delete prop_ptr;
_vec.erase(_vec.begin() + _idx); _vec.erase(_vec.begin() + _idx);
size_t n = _vec.size(); updatePropHandles(_vec);
for(size_t i = 0; i < n; ++i) {
_vec[i]->set_handle(OpenVolumeMeshHandle((int)i));
}
} }
template<class StdVecT> template<class StdVecT>
...@@ -200,22 +198,20 @@ void ResourceManager::entity_deleted(StdVecT& _vec, const OpenVolumeMeshHandle& ...@@ -200,22 +198,20 @@ void ResourceManager::entity_deleted(StdVecT& _vec, const OpenVolumeMeshHandle&
template<class StdVecT> template<class StdVecT>
void ResourceManager::clearVec(StdVecT& _vec) { void ResourceManager::clearVec(StdVecT& _vec) {
StdVecT newVec; for (auto prop: _vec) {
for(typename StdVecT::iterator it = _vec.begin(); prop->setResMan(nullptr);
it != _vec.end(); ++it) { delete prop;
if(!(*it)->persistent()) {
#ifndef NDEBUG
std::cerr << "Keeping property \"" << (*it)->name()
<< "\" since it is still in use!" << std::endl;
#endif
(*it)->resize(0);
newVec.push_back(*it);
}
else
delete *it;
} }
_vec.clear();
}
_vec = newVec; template<class StdVecT>
void ResourceManager::updatePropHandles(StdVecT &_vec)
{
size_t n = _vec.size();
for(size_t i = 0; i < n; ++i) {
_vec[i]->set_handle(OpenVolumeMeshHandle((int)i));
}
} }
} // Namespace OpenVolumeMesh } // Namespace OpenVolumeMesh
...@@ -99,8 +99,8 @@ EdgeHandle TopologyKernel::add_edge(const VertexHandle& _fromVertex, ...@@ -99,8 +99,8 @@ EdgeHandle TopologyKernel::add_edge(const VertexHandle& _fromVertex,
// If the conditions are not fulfilled, assert will fail (instead // If the conditions are not fulfilled, assert will fail (instead
// of returning an invalid handle) // of returning an invalid handle)
assert(_fromVertex.is_valid() && (size_t)_fromVertex.idx() < n_vertices()); assert(_fromVertex.is_valid() && (size_t)_fromVertex.idx() < n_vertices() && !is_deleted(_fromVertex));
assert(_toVertex.is_valid() && (size_t)_toVertex.idx() < n_vertices()); assert(_toVertex.is_valid() && (size_t)_toVertex.idx() < n_vertices() && !is_deleted(_toVertex));
// Test if edge does not exist, yet // Test if edge does not exist, yet
if(!_allowDuplicates) { if(!_allowDuplicates) {
...@@ -164,7 +164,7 @@ FaceHandle TopologyKernel::add_face(const std::vector<HalfEdgeHandle>& _halfedge ...@@ -164,7 +164,7 @@ FaceHandle TopologyKernel::add_face(const std::vector<HalfEdgeHandle>& _halfedge
// Assert that halfedges are valid // Assert that halfedges are valid
for(std::vector<HalfEdgeHandle>::const_iterator it = _halfedges.begin(), for(std::vector<HalfEdgeHandle>::const_iterator it = _halfedges.begin(),
end = _halfedges.end(); it != end; ++it) end = _halfedges.end(); it != end; ++it)
assert(it->is_valid() && (size_t)it->idx() < edges_.size() * 2u); assert(it->is_valid() && (size_t)it->idx() < edges_.size() * 2u && !is_deleted(*it));
#endif #endif
// Perform topology check // Perform topology check
...@@ -253,7 +253,7 @@ FaceHandle TopologyKernel::add_face(const std::vector<VertexHandle>& _vertices) ...@@ -253,7 +253,7 @@ FaceHandle TopologyKernel::add_face(const std::vector<VertexHandle>& _vertices)
// Assert that all vertices have valid indices // Assert that all vertices have valid indices
for(std::vector<VertexHandle>::const_iterator it = _vertices.begin(), for(std::vector<VertexHandle>::const_iterator it = _vertices.begin(),
end = _vertices.end(); it != end; ++it) end = _vertices.end(); it != end; ++it)
assert(it->is_valid() && (size_t)it->idx() < n_vertices()); assert(it->is_valid() && (size_t)it->idx() < n_vertices() && !is_deleted(*it));
#endif #endif
// Add edge for each pair of vertices // Add edge for each pair of vertices
...@@ -381,7 +381,7 @@ CellHandle TopologyKernel::add_cell(const std::vector<HalfFaceHandle>& _halfface