49 #include <OpenMesh/Core/Mesh/ArrayKernel.hh>
54 ArrayKernel::ArrayKernel()
55 : refcount_vstatus_(0), refcount_hstatus_(0),
56 refcount_estatus_(0), refcount_fstatus_(0)
61 ArrayKernel::~ArrayKernel()
78 vertices_ = _other.vertices_;
79 edges_ = _other.edges_;
80 faces_ = _other.faces_;
82 vprops_resize(n_vertices());
83 hprops_resize(n_halfedges());
84 eprops_resize(n_edges());
85 fprops_resize(n_faces());
87 #define COPY_STATUS_PROPERTY(ENTITY) \
88 if (_other.ENTITY##_status_.is_valid()) \
90 if (!ENTITY##_status_.is_valid()) \
92 request_##ENTITY##_status(); \
94 property(ENTITY##_status_) = _other.property(_other.ENTITY##_status_); \
96 COPY_STATUS_PROPERTY(vertex)
97 COPY_STATUS_PROPERTY(halfedge)
98 COPY_STATUS_PROPERTY(edge)
99 COPY_STATUS_PROPERTY(face)
101 #undef COPY_STATUS_PROPERTY
105 VertexHandle ArrayKernel::handle(
const Vertex& _v)
const
110 HalfedgeHandle ArrayKernel::handle(
const Halfedge& _he)
const
116 size_t eh = ( (
char*)&_he - (
char*)&edges_.front() ) /
sizeof(Edge) ;
117 assert((&_he == &edges_[eh].halfedges_[0]) ||
118 (&_he == &edges_[eh].halfedges_[1]));
119 return ((&_he == &edges_[eh].halfedges_[0]) ?
120 HalfedgeHandle(
int(eh)<<1) : HalfedgeHandle((
int(eh)<<1)+1));
123 EdgeHandle ArrayKernel::handle(
const Edge& _e)
const
125 return EdgeHandle(
int(&_e - &edges_.front() ) );
128 FaceHandle ArrayKernel::handle(
const Face& _f)
const
130 return FaceHandle(
int(&_f - &faces_.front()) );
133 #define SIGNED(x) signed( (x) )
137 return 0 <= _vh.
idx() && _vh.
idx() < SIGNED(n_vertices());
142 return 0 <= _heh.
idx() && _heh.
idx() < SIGNED(n_edges()*2);
147 return 0 <= _eh.
idx() && _eh.
idx() < SIGNED(n_edges());
152 return 0 <= _fh.
idx() && _fh.
idx() < SIGNED(n_faces());
157 unsigned int ArrayKernel::delete_isolated_vertices()
159 assert(has_vertex_status());
160 unsigned int n_isolated = 0;
161 for (KernelVertexIter v_it = vertices_begin(); v_it != vertices_end(); ++v_it)
163 if (is_isolated(handle(*v_it)))
165 status(handle(*v_it)).set_deleted(
true);
174 std::vector<VertexHandle*> empty_vh;
175 std::vector<HalfedgeHandle*> empty_hh;
176 std::vector<FaceHandle*> empty_fh;
177 garbage_collection( empty_vh,empty_hh,empty_fh,_v, _e, _f);
194 VertexContainer().swap( vertices_ );
197 EdgeContainer().swap( edges_ );
200 FaceContainer().swap( faces_ );
217 void ArrayKernel::resize(
size_t _n_vertices,
size_t _n_edges,
size_t _n_faces )
219 vertices_.resize(_n_vertices);
220 edges_.resize(_n_edges);
221 faces_.resize(_n_faces);
223 vprops_resize(n_vertices());
224 hprops_resize(n_halfedges());
225 eprops_resize(n_edges());
226 fprops_resize(n_faces());
229 void ArrayKernel::reserve(
size_t _n_vertices,
size_t _n_edges,
size_t _n_faces )
231 vertices_.reserve(_n_vertices);
232 edges_.reserve(_n_edges);
233 faces_.reserve(_n_faces);
235 vprops_reserve(_n_vertices);
236 hprops_reserve(_n_edges*2);
237 eprops_reserve(_n_edges);
238 fprops_reserve(_n_faces);
242 void ArrayKernel::init_bit_masks(BitMaskContainer& _bmc)
250 void ArrayKernel::init_bit_masks()
252 init_bit_masks(vertex_bit_masks_);
253 edge_bit_masks_ = vertex_bit_masks_;
254 face_bit_masks_ = vertex_bit_masks_;
255 halfedge_bit_masks_= vertex_bit_masks_;
void assign_connectivity(const ArrayKernel &_other)
void garbage_collection(bool _v=true, bool _e=true, bool _f=true)
garbage collection
bool is_valid_handle(VertexHandle _vh) const
checks handle validity - useful for debugging
Handle for a halfedge entity.
int idx() const
Get the underlying index of this handle.
void clean_keep_reservation()
Remove all vertices, edges and faces but keep memory allocated.
Handle for a vertex entity.
Handle for a edge entity.
void clear()
Does the same as clean() and in addition erases all properties.
void clean()
Remove all vertices, edges and faces and deallocates their memory.
Handle for a face entity.