57 #ifndef OPENMESH_ARRAY_KERNEL_HH 58 #define OPENMESH_ARRAY_KERNEL_HH 64 #include <OpenMesh/Core/System/config.h> 65 #include <OpenMesh/Core/Utils/GenProg.hh> 67 #include <OpenMesh/Core/Mesh/ArrayItems.hh> 68 #include <OpenMesh/Core/Mesh/BaseKernel.hh> 69 #include <OpenMesh/Core/Mesh/Status.hh> 119 void assign_connectivity(
const ArrayKernel& _other);
122 VertexHandle handle(
const Vertex& _v)
const;
124 HalfedgeHandle handle(
const Halfedge& _he)
const;
126 EdgeHandle handle(
const Edge& _e)
const;
128 FaceHandle handle(
const Face& _f)
const;
132 bool is_valid_handle(VertexHandle _vh)
const;
135 bool is_valid_handle(HalfedgeHandle _heh)
const;
138 bool is_valid_handle(EdgeHandle _eh)
const;
141 bool is_valid_handle(FaceHandle _fh)
const;
145 const Vertex& vertex(VertexHandle _vh)
const 147 assert(is_valid_handle(_vh));
148 return vertices_[_vh.
idx()];
151 Vertex& vertex(VertexHandle _vh)
153 assert(is_valid_handle(_vh));
154 return vertices_[_vh.
idx()];
157 const Halfedge& halfedge(HalfedgeHandle _heh)
const 159 assert(is_valid_handle(_heh));
160 return edges_[_heh.
idx() >> 1].halfedges_[_heh.
idx() & 1];
163 Halfedge& halfedge(HalfedgeHandle _heh)
165 assert(is_valid_handle(_heh));
166 return edges_[_heh.
idx() >> 1].halfedges_[_heh.
idx() & 1];
169 const Edge& edge(EdgeHandle _eh)
const 171 assert(is_valid_handle(_eh));
172 return edges_[_eh.
idx()];
175 Edge& edge(EdgeHandle _eh)
177 assert(is_valid_handle(_eh));
178 return edges_[_eh.
idx()];
181 const Face& face(FaceHandle _fh)
const 183 assert(is_valid_handle(_fh));
184 return faces_[_fh.
idx()];
187 Face& face(FaceHandle _fh)
189 assert(is_valid_handle(_fh));
190 return faces_[_fh.
idx()];
195 VertexHandle vertex_handle(
unsigned int _i)
const 196 {
return (_i < n_vertices()) ? handle( vertices_[_i] ) : VertexHandle(); }
198 HalfedgeHandle halfedge_handle(
unsigned int _i)
const 200 return (_i < n_halfedges()) ?
201 halfedge_handle(edge_handle(_i/2), _i%2) : HalfedgeHandle();
204 EdgeHandle edge_handle(
unsigned int _i)
const 205 {
return (_i < n_edges()) ? handle(edges_[_i]) : EdgeHandle(); }
207 FaceHandle face_handle(
unsigned int _i)
const 208 {
return (_i < n_faces()) ? handle(faces_[_i]) : FaceHandle(); }
212 inline VertexHandle new_vertex()
214 vertices_.push_back(Vertex());
215 vprops_resize(n_vertices());
217 return handle(vertices_.back());
220 inline HalfedgeHandle new_edge(VertexHandle _start_vh, VertexHandle _end_vh)
223 edges_.push_back(Edge());
224 eprops_resize(n_edges());
225 hprops_resize(n_halfedges());
227 EdgeHandle eh(handle(edges_.back()));
228 HalfedgeHandle heh0(halfedge_handle(eh, 0));
229 HalfedgeHandle heh1(halfedge_handle(eh, 1));
230 set_vertex_handle(heh0, _end_vh);
231 set_vertex_handle(heh1, _start_vh);
235 inline FaceHandle new_face()
237 faces_.push_back(Face());
238 fprops_resize(n_faces());
239 return handle(faces_.back());
242 inline FaceHandle new_face(
const Face& _f)
244 faces_.push_back(_f);
245 fprops_resize(n_faces());
246 return handle(faces_.back());
251 void resize(
size_t _n_vertices,
size_t _n_edges,
size_t _n_faces );
252 void reserve(
size_t _n_vertices,
size_t _n_edges,
size_t _n_faces );
270 void garbage_collection(
bool _v=
true,
bool _e=
true,
bool _f=
true);
289 template<
typename std_API_Container_VHandlePointer,
290 typename std_API_Container_HHandlePointer,
291 typename std_API_Container_FHandlePointer>
292 void garbage_collection(std_API_Container_VHandlePointer& vh_to_update,
293 std_API_Container_HHandlePointer& hh_to_update,
294 std_API_Container_FHandlePointer& fh_to_update,
295 bool _v=
true,
bool _e=
true,
bool _f=
true);
310 size_t n_vertices()
const {
return vertices_.size(); }
311 size_t n_halfedges()
const {
return 2*edges_.size(); }
312 size_t n_edges()
const {
return edges_.size(); }
313 size_t n_faces()
const {
return faces_.size(); }
315 bool vertices_empty()
const {
return vertices_.empty(); }
316 bool halfedges_empty()
const {
return edges_.empty(); }
317 bool edges_empty()
const {
return edges_.empty(); }
318 bool faces_empty()
const {
return faces_.empty(); }
322 HalfedgeHandle halfedge_handle(VertexHandle _vh)
const 323 {
return vertex(_vh).halfedge_handle_; }
325 void set_halfedge_handle(VertexHandle _vh, HalfedgeHandle _heh)
328 vertex(_vh).halfedge_handle_ = _heh;
331 bool is_isolated(VertexHandle _vh)
const 332 {
return !halfedge_handle(_vh).
is_valid(); }
334 void set_isolated(VertexHandle _vh)
335 { vertex(_vh).halfedge_handle_.invalidate(); }
337 unsigned int delete_isolated_vertices();
340 VertexHandle to_vertex_handle(HalfedgeHandle _heh)
const 341 {
return halfedge(_heh).vertex_handle_; }
343 VertexHandle from_vertex_handle(HalfedgeHandle _heh)
const 344 {
return to_vertex_handle(opposite_halfedge_handle(_heh)); }
346 void set_vertex_handle(HalfedgeHandle _heh, VertexHandle _vh)
349 halfedge(_heh).vertex_handle_ = _vh;
352 FaceHandle face_handle(HalfedgeHandle _heh)
const 353 {
return halfedge(_heh).face_handle_; }
355 void set_face_handle(HalfedgeHandle _heh, FaceHandle _fh)
358 halfedge(_heh).face_handle_ = _fh;
361 void set_boundary(HalfedgeHandle _heh)
366 {
return !face_handle(_heh).is_valid(); }
368 HalfedgeHandle next_halfedge_handle(HalfedgeHandle _heh)
const 369 {
return halfedge(_heh).next_halfedge_handle_; }
371 void set_next_halfedge_handle(HalfedgeHandle _heh, HalfedgeHandle _nheh)
373 assert(is_valid_handle(_nheh));
375 halfedge(_heh).next_halfedge_handle_ = _nheh;
376 set_prev_halfedge_handle(_nheh, _heh);
380 void set_prev_halfedge_handle(HalfedgeHandle _heh, HalfedgeHandle _pheh)
382 assert(is_valid_handle(_pheh));
383 set_prev_halfedge_handle(_heh, _pheh, HasPrevHalfedge());
386 void set_prev_halfedge_handle(HalfedgeHandle _heh, HalfedgeHandle _pheh,
388 { halfedge(_heh).prev_halfedge_handle_ = _pheh; }
390 void set_prev_halfedge_handle(HalfedgeHandle , HalfedgeHandle ,
394 HalfedgeHandle prev_halfedge_handle(HalfedgeHandle _heh)
const 395 {
return prev_halfedge_handle(_heh, HasPrevHalfedge() ); }
397 HalfedgeHandle prev_halfedge_handle(HalfedgeHandle _heh, GenProg::TrueType)
const 398 {
return halfedge(_heh).prev_halfedge_handle_; }
400 HalfedgeHandle prev_halfedge_handle(HalfedgeHandle _heh, GenProg::FalseType)
const 402 if (is_boundary(_heh))
404 HalfedgeHandle curr_heh(opposite_halfedge_handle(_heh));
405 HalfedgeHandle next_heh(next_halfedge_handle(curr_heh));
408 curr_heh = opposite_halfedge_handle(next_heh);
409 next_heh = next_halfedge_handle(curr_heh);
411 while (next_heh != _heh);
416 HalfedgeHandle heh(_heh);
417 HalfedgeHandle next_heh(next_halfedge_handle(heh));
418 while (next_heh != _heh) {
420 next_heh = next_halfedge_handle(next_heh);
427 HalfedgeHandle opposite_halfedge_handle(HalfedgeHandle _heh)
const 428 {
return HalfedgeHandle((_heh.
idx() & 1) ? _heh.
idx()-1 : _heh.
idx()+1); }
431 HalfedgeHandle ccw_rotated_halfedge_handle(HalfedgeHandle _heh)
const 432 {
return opposite_halfedge_handle(prev_halfedge_handle(_heh)); }
435 HalfedgeHandle cw_rotated_halfedge_handle(HalfedgeHandle _heh)
const 436 {
return next_halfedge_handle(opposite_halfedge_handle(_heh)); }
439 HalfedgeHandle halfedge_handle(EdgeHandle _eh,
unsigned int _i)
const 442 return HalfedgeHandle((_eh.
idx() << 1) + _i);
445 EdgeHandle edge_handle(HalfedgeHandle _heh)
const 446 {
return EdgeHandle(_heh.
idx() >> 1); }
449 HalfedgeHandle halfedge_handle(FaceHandle _fh)
const 450 {
return face(_fh).halfedge_handle_; }
452 void set_halfedge_handle(FaceHandle _fh, HalfedgeHandle _heh)
455 face(_fh).halfedge_handle_ = _heh;
460 const StatusInfo&
status(VertexHandle _vh)
const 461 {
return property(vertex_status_, _vh); }
463 StatusInfo& status(VertexHandle _vh)
464 {
return property(vertex_status_, _vh); }
467 const StatusInfo& status(HalfedgeHandle _hh)
const 468 {
return property(halfedge_status_, _hh); }
470 StatusInfo& status(HalfedgeHandle _hh)
471 {
return property(halfedge_status_, _hh); }
474 const StatusInfo& status(EdgeHandle _eh)
const 475 {
return property(edge_status_, _eh); }
477 StatusInfo& status(EdgeHandle _eh)
478 {
return property(edge_status_, _eh); }
481 const StatusInfo& status(FaceHandle _fh)
const 482 {
return property(face_status_, _fh); }
484 StatusInfo& status(FaceHandle _fh)
485 {
return property(face_status_, _fh); }
487 inline bool has_vertex_status()
const 488 {
return vertex_status_.is_valid(); }
490 inline bool has_halfedge_status()
const 491 {
return halfedge_status_.is_valid(); }
493 inline bool has_edge_status()
const 494 {
return edge_status_.is_valid(); }
496 inline bool has_face_status()
const 497 {
return face_status_.is_valid(); }
499 inline VertexStatusPropertyHandle vertex_status_pph()
const 500 {
return vertex_status_; }
502 inline HalfedgeStatusPropertyHandle halfedge_status_pph()
const 503 {
return halfedge_status_; }
505 inline EdgeStatusPropertyHandle edge_status_pph()
const 506 {
return edge_status_; }
508 inline FaceStatusPropertyHandle face_status_pph()
const 509 {
return face_status_; }
512 inline VertexStatusPropertyHandle
status_pph(VertexHandle )
const 513 {
return vertex_status_pph(); }
515 inline HalfedgeStatusPropertyHandle status_pph(HalfedgeHandle )
const 516 {
return halfedge_status_pph(); }
518 inline EdgeStatusPropertyHandle status_pph(EdgeHandle )
const 519 {
return edge_status_pph(); }
521 inline FaceStatusPropertyHandle status_pph(FaceHandle )
const 522 {
return face_status_pph(); }
527 if (!refcount_vstatus_++)
528 add_property( vertex_status_,
"v:status" );
531 void request_halfedge_status()
533 if (!refcount_hstatus_++)
534 add_property( halfedge_status_,
"h:status" );
537 void request_edge_status()
539 if (!refcount_estatus_++)
540 add_property( edge_status_,
"e:status" );
543 void request_face_status()
545 if (!refcount_fstatus_++)
546 add_property( face_status_,
"f:status" );
552 if ((refcount_vstatus_ > 0) && (! --refcount_vstatus_))
553 remove_property(vertex_status_);
556 void release_halfedge_status()
558 if ((refcount_hstatus_ > 0) && (! --refcount_hstatus_))
559 remove_property(halfedge_status_);
562 void release_edge_status()
564 if ((refcount_estatus_ > 0) && (! --refcount_estatus_))
565 remove_property(edge_status_);
568 void release_face_status()
570 if ((refcount_fstatus_ > 0) && (! --refcount_fstatus_))
571 remove_property(face_status_);
576 typedef std::vector<Vertex> VertexContainer;
577 typedef std::vector<Edge> EdgeContainer;
578 typedef std::vector<Face> FaceContainer;
579 typedef VertexContainer::iterator KernelVertexIter;
580 typedef VertexContainer::const_iterator KernelConstVertexIter;
581 typedef EdgeContainer::iterator KernelEdgeIter;
582 typedef EdgeContainer::const_iterator KernelConstEdgeIter;
583 typedef FaceContainer::iterator KernelFaceIter;
584 typedef FaceContainer::const_iterator KernelConstFaceIter;
585 typedef std::vector<unsigned int> BitMaskContainer;
588 KernelVertexIter vertices_begin() {
return vertices_.begin(); }
589 KernelConstVertexIter vertices_begin()
const {
return vertices_.begin(); }
590 KernelVertexIter vertices_end() {
return vertices_.end(); }
591 KernelConstVertexIter vertices_end()
const {
return vertices_.end(); }
593 KernelEdgeIter edges_begin() {
return edges_.begin(); }
594 KernelConstEdgeIter edges_begin()
const {
return edges_.begin(); }
595 KernelEdgeIter edges_end() {
return edges_.end(); }
596 KernelConstEdgeIter edges_end()
const {
return edges_.end(); }
598 KernelFaceIter faces_begin() {
return faces_.begin(); }
599 KernelConstFaceIter faces_begin()
const {
return faces_.begin(); }
600 KernelFaceIter faces_end() {
return faces_.end(); }
601 KernelConstFaceIter faces_end()
const {
return faces_.end(); }
604 inline BitMaskContainer& bit_masks(VertexHandle )
605 {
return vertex_bit_masks_; }
606 inline BitMaskContainer& bit_masks(EdgeHandle )
607 {
return edge_bit_masks_; }
608 inline BitMaskContainer& bit_masks(FaceHandle )
609 {
return face_bit_masks_; }
610 inline BitMaskContainer& bit_masks(HalfedgeHandle )
611 {
return halfedge_bit_masks_; }
613 template <
class Handle>
614 unsigned int pop_bit_mask(Handle _hnd)
616 assert(!bit_masks(_hnd).empty());
617 unsigned int bit_mask = bit_masks(_hnd).back();
618 bit_masks(_hnd).pop_back();
622 template <
class Handle>
623 void push_bit_mask(Handle _hnd,
unsigned int _bit_mask)
625 assert(std::find(bit_masks(_hnd).begin(), bit_masks(_hnd).end(), _bit_mask) ==
626 bit_masks(_hnd).end());
627 bit_masks(_hnd).push_back(_bit_mask);
630 void init_bit_masks(BitMaskContainer& _bmc);
631 void init_bit_masks();
634 VertexContainer vertices_;
635 EdgeContainer edges_;
636 FaceContainer faces_;
638 VertexStatusPropertyHandle vertex_status_;
639 HalfedgeStatusPropertyHandle halfedge_status_;
640 EdgeStatusPropertyHandle edge_status_;
641 FaceStatusPropertyHandle face_status_;
643 unsigned int refcount_vstatus_;
644 unsigned int refcount_hstatus_;
645 unsigned int refcount_estatus_;
646 unsigned int refcount_fstatus_;
648 BitMaskContainer halfedge_bit_masks_;
649 BitMaskContainer edge_bit_masks_;
650 BitMaskContainer vertex_bit_masks_;
651 BitMaskContainer face_bit_masks_;
658 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_ARRAY_KERNEL_C) 659 # define OPENMESH_ARRAY_KERNEL_TEMPLATES 660 # include "ArrayKernelT.cc" 663 #endif // OPENMESH_ARRAY_KERNEL_HH defined void release_vertex_status()
Status Release API.
Definition: ArrayKernel.hh:550
Handle for a halfedge entity.
Definition: Handles.hh:128
VertexStatusPropertyHandle status_pph(VertexHandle) const
status property by handle
Definition: ArrayKernel.hh:512
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
Handle for a edge entity.
Definition: Handles.hh:135
This class provides the basic property management like adding/removing properties and access to prope...
Definition: BaseKernel.hh:99
Handle for a face entity.
Definition: Handles.hh:142
bool is_valid() const
The handle is valid iff the index is not equal to -1.
Definition: Handles.hh:77
Add status information to a base class.
Definition: Status.hh:99
const StatusInfo & status(VertexHandle _vh) const
Status Query API.
Definition: ArrayKernel.hh:460
Handle for a vertex entity.
Definition: Handles.hh:121
bool is_boundary(HalfedgeHandle _heh) const
Is halfedge _heh a boundary halfedge (is its face handle invalid) ?
Definition: ArrayKernel.hh:365
int idx() const
Get the underlying index of this handle.
Definition: Handles.hh:74
void invalidate()
reset handle to be invalid
Definition: Handles.hh:82
Mesh kernel using arrays for mesh item storage.
Definition: ArrayKernel.hh:92
void request_vertex_status()
Status Request API.
Definition: ArrayKernel.hh:525