changed the way status propertzies are copied.
refcount is set to 1 if it was > 0 in the original mesh fixes #48
This commit is contained in:
@@ -37,146 +37,145 @@
|
|||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
|
||||||
* *
|
* *
|
||||||
* ========================================================================= */
|
* ========================================================================= */
|
||||||
|
|
||||||
/*===========================================================================*\
|
/*===========================================================================*\
|
||||||
* *
|
* *
|
||||||
* $Revision$ *
|
* $Revision$ *
|
||||||
* $Date$ *
|
* $Date$ *
|
||||||
* *
|
* *
|
||||||
\*===========================================================================*/
|
\*===========================================================================*/
|
||||||
|
|
||||||
#include <OpenMesh/Core/Mesh/ArrayKernel.hh>
|
#include <OpenMesh/Core/Mesh/ArrayKernel.hh>
|
||||||
|
|
||||||
namespace OpenMesh
|
namespace OpenMesh
|
||||||
{
|
{
|
||||||
|
|
||||||
ArrayKernel::ArrayKernel()
|
ArrayKernel::ArrayKernel()
|
||||||
: refcount_vstatus_(0), refcount_hstatus_(0),
|
: refcount_vstatus_(0), refcount_hstatus_(0),
|
||||||
refcount_estatus_(0), refcount_fstatus_(0)
|
refcount_estatus_(0), refcount_fstatus_(0)
|
||||||
{
|
{
|
||||||
init_bit_masks(); //Status bit masks initialization
|
init_bit_masks(); //Status bit masks initialization
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayKernel::~ArrayKernel()
|
ArrayKernel::~ArrayKernel()
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ArrayKernel::ArrayKernel(const ArrayKernel& _rhs)
|
// ArrayKernel::ArrayKernel(const ArrayKernel& _rhs)
|
||||||
// : BaseKernel(_rhs),
|
// : BaseKernel(_rhs),
|
||||||
// vertices_(_rhs.vertices_), edges_(_rhs.edges_), faces_(_rhs.faces_),
|
// vertices_(_rhs.vertices_), edges_(_rhs.edges_), faces_(_rhs.faces_),
|
||||||
// vertex_status_(_rhs.vertex_status_), halfedge_status_(_rhs.halfedge_status_),
|
// vertex_status_(_rhs.vertex_status_), halfedge_status_(_rhs.halfedge_status_),
|
||||||
// edge_status_(_rhs.edge_status_), face_status_(_rhs.face_status_),
|
// edge_status_(_rhs.edge_status_), face_status_(_rhs.face_status_),
|
||||||
// refcount_vstatus_(_rhs.refcount_vstatus_), refcount_hstatus_(_rhs.refcount_hstatus_),
|
// refcount_vstatus_(_rhs.refcount_vstatus_), refcount_hstatus_(_rhs.refcount_hstatus_),
|
||||||
// refcount_estatus_(_rhs.refcount_estatus_), refcount_fstatus_(_rhs.refcount_fstatus_)
|
// refcount_estatus_(_rhs.refcount_estatus_), refcount_fstatus_(_rhs.refcount_fstatus_)
|
||||||
// {}
|
// {}
|
||||||
|
|
||||||
|
|
||||||
void ArrayKernel::assign_connectivity(const ArrayKernel& _other)
|
void ArrayKernel::assign_connectivity(const ArrayKernel& _other)
|
||||||
{
|
{
|
||||||
vertices_ = _other.vertices_;
|
vertices_ = _other.vertices_;
|
||||||
edges_ = _other.edges_;
|
edges_ = _other.edges_;
|
||||||
faces_ = _other.faces_;
|
faces_ = _other.faces_;
|
||||||
|
|
||||||
vprops_resize(n_vertices());
|
vprops_resize(n_vertices());
|
||||||
hprops_resize(n_halfedges());
|
hprops_resize(n_halfedges());
|
||||||
eprops_resize(n_edges());
|
eprops_resize(n_edges());
|
||||||
fprops_resize(n_faces());
|
fprops_resize(n_faces());
|
||||||
|
|
||||||
#define COPY_STATUS_PROPERTY(ENTITY) \
|
//just copy status properties for now,
|
||||||
if (_other.ENTITY##_status_.is_valid()) \
|
//until a proper solution for refcounted
|
||||||
{ \
|
//properties is available
|
||||||
if (!ENTITY##_status_.is_valid()) \
|
vertex_status_ = _other.vertex_status_;
|
||||||
{ \
|
halfedge_status_ = _other.halfedge_status_;
|
||||||
request_##ENTITY##_status(); \
|
edge_status_ = _other.edge_status_;
|
||||||
} \
|
face_status_ = _other.face_status_;
|
||||||
property(ENTITY##_status_) = _other.property(_other.ENTITY##_status_); \
|
|
||||||
}
|
//initialize refcounter to 1 for the new mesh,
|
||||||
COPY_STATUS_PROPERTY(vertex)
|
//if status is available.
|
||||||
COPY_STATUS_PROPERTY(halfedge)
|
refcount_estatus_ = _other.refcount_estatus_ > 0 ? 1 : 0;
|
||||||
COPY_STATUS_PROPERTY(edge)
|
refcount_vstatus_ = _other.refcount_vstatus_ > 0 ? 1 : 0;
|
||||||
COPY_STATUS_PROPERTY(face)
|
refcount_hstatus_ = _other.refcount_hstatus_ > 0 ? 1 : 0;
|
||||||
|
refcount_fstatus_ = _other.refcount_fstatus_ > 0 ? 1 : 0;
|
||||||
#undef COPY_STATUS_PROPERTY
|
}
|
||||||
}
|
|
||||||
|
// --- handle -> item ---
|
||||||
// --- handle -> item ---
|
VertexHandle ArrayKernel::handle(const Vertex& _v) const
|
||||||
VertexHandle ArrayKernel::handle(const Vertex& _v) const
|
{
|
||||||
{
|
return VertexHandle( int( &_v - &vertices_.front()));
|
||||||
return VertexHandle( int( &_v - &vertices_.front()));
|
}
|
||||||
}
|
|
||||||
|
HalfedgeHandle ArrayKernel::handle(const Halfedge& _he) const
|
||||||
HalfedgeHandle ArrayKernel::handle(const Halfedge& _he) const
|
{
|
||||||
{
|
// Calculate edge belonging to given halfedge
|
||||||
// Calculate edge belonging to given halfedge
|
// There are two halfedges stored per edge
|
||||||
// There are two halfedges stored per edge
|
// Get memory position inside edge vector and devide by size of an edge
|
||||||
// Get memory position inside edge vector and devide by size of an edge
|
// to get the corresponding edge for the requested halfedge
|
||||||
// to get the corresponding edge for the requested halfedge
|
size_t eh = ( (char*)&_he - (char*)&edges_.front() ) / sizeof(Edge) ;
|
||||||
size_t eh = ( (char*)&_he - (char*)&edges_.front() ) / sizeof(Edge) ;
|
assert((&_he == &edges_[eh].halfedges_[0]) ||
|
||||||
assert((&_he == &edges_[eh].halfedges_[0]) ||
|
(&_he == &edges_[eh].halfedges_[1]));
|
||||||
(&_he == &edges_[eh].halfedges_[1]));
|
return ((&_he == &edges_[eh].halfedges_[0]) ?
|
||||||
return ((&_he == &edges_[eh].halfedges_[0]) ?
|
HalfedgeHandle( int(eh)<<1) : HalfedgeHandle((int(eh)<<1)+1));
|
||||||
HalfedgeHandle( int(eh)<<1) : HalfedgeHandle((int(eh)<<1)+1));
|
}
|
||||||
}
|
|
||||||
|
EdgeHandle ArrayKernel::handle(const Edge& _e) const
|
||||||
EdgeHandle ArrayKernel::handle(const Edge& _e) const
|
{
|
||||||
{
|
return EdgeHandle( int(&_e - &edges_.front() ) );
|
||||||
return EdgeHandle( int(&_e - &edges_.front() ) );
|
}
|
||||||
}
|
|
||||||
|
FaceHandle ArrayKernel::handle(const Face& _f) const
|
||||||
FaceHandle ArrayKernel::handle(const Face& _f) const
|
{
|
||||||
{
|
return FaceHandle( int(&_f - &faces_.front()) );
|
||||||
return FaceHandle( int(&_f - &faces_.front()) );
|
}
|
||||||
}
|
|
||||||
|
#define SIGNED(x) signed( (x) )
|
||||||
#define SIGNED(x) signed( (x) )
|
|
||||||
|
bool ArrayKernel::is_valid_handle(VertexHandle _vh) const
|
||||||
bool ArrayKernel::is_valid_handle(VertexHandle _vh) const
|
{
|
||||||
{
|
return 0 <= _vh.idx() && _vh.idx() < SIGNED(n_vertices());
|
||||||
return 0 <= _vh.idx() && _vh.idx() < SIGNED(n_vertices());
|
}
|
||||||
}
|
|
||||||
|
bool ArrayKernel::is_valid_handle(HalfedgeHandle _heh) const
|
||||||
bool ArrayKernel::is_valid_handle(HalfedgeHandle _heh) const
|
{
|
||||||
{
|
return 0 <= _heh.idx() && _heh.idx() < SIGNED(n_edges()*2);
|
||||||
return 0 <= _heh.idx() && _heh.idx() < SIGNED(n_edges()*2);
|
}
|
||||||
}
|
|
||||||
|
bool ArrayKernel::is_valid_handle(EdgeHandle _eh) const
|
||||||
bool ArrayKernel::is_valid_handle(EdgeHandle _eh) const
|
{
|
||||||
{
|
return 0 <= _eh.idx() && _eh.idx() < SIGNED(n_edges());
|
||||||
return 0 <= _eh.idx() && _eh.idx() < SIGNED(n_edges());
|
}
|
||||||
}
|
|
||||||
|
bool ArrayKernel::is_valid_handle(FaceHandle _fh) const
|
||||||
bool ArrayKernel::is_valid_handle(FaceHandle _fh) const
|
{
|
||||||
{
|
return 0 <= _fh.idx() && _fh.idx() < SIGNED(n_faces());
|
||||||
return 0 <= _fh.idx() && _fh.idx() < SIGNED(n_faces());
|
}
|
||||||
}
|
|
||||||
|
#undef SIGNED
|
||||||
#undef SIGNED
|
|
||||||
|
unsigned int ArrayKernel::delete_isolated_vertices()
|
||||||
unsigned int ArrayKernel::delete_isolated_vertices()
|
{
|
||||||
{
|
assert(has_vertex_status());//this function requires vertex status property
|
||||||
assert(has_vertex_status());//this function requires vertex status property
|
unsigned int n_isolated = 0;
|
||||||
unsigned int n_isolated = 0;
|
for (KernelVertexIter v_it = vertices_begin(); v_it != vertices_end(); ++v_it)
|
||||||
for (KernelVertexIter v_it = vertices_begin(); v_it != vertices_end(); ++v_it)
|
{
|
||||||
{
|
if (is_isolated(handle(*v_it)))
|
||||||
if (is_isolated(handle(*v_it)))
|
{
|
||||||
{
|
status(handle(*v_it)).set_deleted(true);
|
||||||
status(handle(*v_it)).set_deleted(true);
|
n_isolated++;
|
||||||
n_isolated++;
|
}
|
||||||
}
|
}
|
||||||
}
|
return n_isolated;
|
||||||
return n_isolated;
|
}
|
||||||
}
|
|
||||||
|
void ArrayKernel::garbage_collection(bool _v, bool _e, bool _f)
|
||||||
void ArrayKernel::garbage_collection(bool _v, bool _e, bool _f)
|
{
|
||||||
{
|
std::vector<VertexHandle*> empty_vh;
|
||||||
std::vector<VertexHandle*> empty_vh;
|
std::vector<HalfedgeHandle*> empty_hh;
|
||||||
std::vector<HalfedgeHandle*> empty_hh;
|
std::vector<FaceHandle*> empty_fh;
|
||||||
std::vector<FaceHandle*> empty_fh;
|
garbage_collection( empty_vh,empty_hh,empty_fh,_v, _e, _f);
|
||||||
garbage_collection( empty_vh,empty_hh,empty_fh,_v, _e, _f);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void ArrayKernel::clean_keep_reservation()
|
void ArrayKernel::clean_keep_reservation()
|
||||||
{
|
{
|
||||||
vertices_.clear();
|
vertices_.clear();
|
||||||
@@ -187,74 +186,74 @@ void ArrayKernel::clean_keep_reservation()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArrayKernel::clean()
|
void ArrayKernel::clean()
|
||||||
{
|
{
|
||||||
|
|
||||||
vertices_.clear();
|
vertices_.clear();
|
||||||
VertexContainer().swap( vertices_ );
|
VertexContainer().swap( vertices_ );
|
||||||
|
|
||||||
edges_.clear();
|
edges_.clear();
|
||||||
EdgeContainer().swap( edges_ );
|
EdgeContainer().swap( edges_ );
|
||||||
|
|
||||||
faces_.clear();
|
faces_.clear();
|
||||||
FaceContainer().swap( faces_ );
|
FaceContainer().swap( faces_ );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ArrayKernel::clear()
|
void ArrayKernel::clear()
|
||||||
{
|
{
|
||||||
vprops_clear();
|
vprops_clear();
|
||||||
eprops_clear();
|
eprops_clear();
|
||||||
hprops_clear();
|
hprops_clear();
|
||||||
fprops_clear();
|
fprops_clear();
|
||||||
|
|
||||||
clean();
|
clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ArrayKernel::resize( size_t _n_vertices, size_t _n_edges, size_t _n_faces )
|
void ArrayKernel::resize( size_t _n_vertices, size_t _n_edges, size_t _n_faces )
|
||||||
{
|
{
|
||||||
vertices_.resize(_n_vertices);
|
vertices_.resize(_n_vertices);
|
||||||
edges_.resize(_n_edges);
|
edges_.resize(_n_edges);
|
||||||
faces_.resize(_n_faces);
|
faces_.resize(_n_faces);
|
||||||
|
|
||||||
vprops_resize(n_vertices());
|
vprops_resize(n_vertices());
|
||||||
hprops_resize(n_halfedges());
|
hprops_resize(n_halfedges());
|
||||||
eprops_resize(n_edges());
|
eprops_resize(n_edges());
|
||||||
fprops_resize(n_faces());
|
fprops_resize(n_faces());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArrayKernel::reserve(size_t _n_vertices, size_t _n_edges, size_t _n_faces )
|
void ArrayKernel::reserve(size_t _n_vertices, size_t _n_edges, size_t _n_faces )
|
||||||
{
|
{
|
||||||
vertices_.reserve(_n_vertices);
|
vertices_.reserve(_n_vertices);
|
||||||
edges_.reserve(_n_edges);
|
edges_.reserve(_n_edges);
|
||||||
faces_.reserve(_n_faces);
|
faces_.reserve(_n_faces);
|
||||||
|
|
||||||
vprops_reserve(_n_vertices);
|
vprops_reserve(_n_vertices);
|
||||||
hprops_reserve(_n_edges*2);
|
hprops_reserve(_n_edges*2);
|
||||||
eprops_reserve(_n_edges);
|
eprops_reserve(_n_edges);
|
||||||
fprops_reserve(_n_faces);
|
fprops_reserve(_n_faces);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status Sets API
|
// Status Sets API
|
||||||
void ArrayKernel::init_bit_masks(BitMaskContainer& _bmc)
|
void ArrayKernel::init_bit_masks(BitMaskContainer& _bmc)
|
||||||
{
|
{
|
||||||
for (unsigned int i = Attributes::UNUSED; i != 0; i <<= 1)
|
for (unsigned int i = Attributes::UNUSED; i != 0; i <<= 1)
|
||||||
{
|
{
|
||||||
_bmc.push_back(i);
|
_bmc.push_back(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArrayKernel::init_bit_masks()
|
void ArrayKernel::init_bit_masks()
|
||||||
{
|
{
|
||||||
init_bit_masks(vertex_bit_masks_);
|
init_bit_masks(vertex_bit_masks_);
|
||||||
edge_bit_masks_ = vertex_bit_masks_;//init_bit_masks(edge_bit_masks_);
|
edge_bit_masks_ = vertex_bit_masks_;//init_bit_masks(edge_bit_masks_);
|
||||||
face_bit_masks_ = vertex_bit_masks_;//init_bit_masks(face_bit_masks_);
|
face_bit_masks_ = vertex_bit_masks_;//init_bit_masks(face_bit_masks_);
|
||||||
halfedge_bit_masks_= vertex_bit_masks_;//init_bit_masks(halfedge_bit_masks_);
|
halfedge_bit_masks_= vertex_bit_masks_;//init_bit_masks(halfedge_bit_masks_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -879,10 +879,7 @@ private:
|
|||||||
void init_bit_masks(BitMaskContainer& _bmc);
|
void init_bit_masks(BitMaskContainer& _bmc);
|
||||||
void init_bit_masks();
|
void init_bit_masks();
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
VertexContainer vertices_;
|
|
||||||
EdgeContainer edges_;
|
|
||||||
FaceContainer faces_;
|
|
||||||
|
|
||||||
VertexStatusPropertyHandle vertex_status_;
|
VertexStatusPropertyHandle vertex_status_;
|
||||||
HalfedgeStatusPropertyHandle halfedge_status_;
|
HalfedgeStatusPropertyHandle halfedge_status_;
|
||||||
@@ -894,6 +891,11 @@ private:
|
|||||||
unsigned int refcount_estatus_;
|
unsigned int refcount_estatus_;
|
||||||
unsigned int refcount_fstatus_;
|
unsigned int refcount_fstatus_;
|
||||||
|
|
||||||
|
private:
|
||||||
|
VertexContainer vertices_;
|
||||||
|
EdgeContainer edges_;
|
||||||
|
FaceContainer faces_;
|
||||||
|
|
||||||
BitMaskContainer halfedge_bit_masks_;
|
BitMaskContainer halfedge_bit_masks_;
|
||||||
BitMaskContainer edge_bit_masks_;
|
BitMaskContainer edge_bit_masks_;
|
||||||
BitMaskContainer vertex_bit_masks_;
|
BitMaskContainer vertex_bit_masks_;
|
||||||
|
|||||||
Reference in New Issue
Block a user