49 #include "TopologyKernel.hh" 54 const VertexHandle TopologyKernel::InvalidVertexHandle = VertexHandle(-1);
55 const EdgeHandle TopologyKernel::InvalidEdgeHandle = EdgeHandle(-1);
56 const HalfEdgeHandle TopologyKernel::InvalidHalfEdgeHandle = HalfEdgeHandle(-1);
57 const FaceHandle TopologyKernel::InvalidFaceHandle = FaceHandle(-1);
58 const HalfFaceHandle TopologyKernel::InvalidHalfFaceHandle = HalfFaceHandle(-1);
59 const CellHandle TopologyKernel::InvalidCellHandle = CellHandle(-1);
61 TopologyKernel::TopologyKernel() :
66 deferred_deletion(true),
68 needs_garbage_collection_(false)
72 TopologyKernel::~TopologyKernel() {
80 vertex_deleted_.push_back(
false);
84 outgoing_hes_per_vertex_.resize(n_vertices_);
88 resize_vprops(n_vertices_);
99 bool _allowDuplicates) {
103 assert(_fromVertex.is_valid() && (size_t)_fromVertex.idx() < n_vertices());
104 assert(_toVertex.is_valid() && (size_t)_toVertex.idx() < n_vertices());
107 if(!_allowDuplicates) {
110 assert((
size_t)_fromVertex.idx() < outgoing_hes_per_vertex_.size());
111 std::vector<HalfEdgeHandle>& ohes = outgoing_hes_per_vertex_[_fromVertex.idx()];
112 for(std::vector<HalfEdgeHandle>::const_iterator he_it = ohes.begin(),
113 he_end = ohes.end(); he_it != he_end; ++he_it) {
114 if(halfedge(*he_it).to_vertex() == _toVertex) {
115 return edge_handle(*he_it);
119 for(
size_t i = 0; i < edges_.size(); ++i) {
120 if(edge(
EdgeHandle(i)).from_vertex() == _fromVertex && edge(
EdgeHandle(i)).to_vertex() == _toVertex) {
122 }
else if(edge(
EdgeHandle(i)).from_vertex() == _toVertex && edge(
EdgeHandle(i)).to_vertex() == _fromVertex) {
134 edge_deleted_.push_back(
false);
137 resize_eprops(n_edges());
143 assert((
size_t)_fromVertex.idx() < outgoing_hes_per_vertex_.size());
144 assert((
size_t)_toVertex.idx() < outgoing_hes_per_vertex_.size());
146 outgoing_hes_per_vertex_[_fromVertex.idx()].push_back(halfedge_handle(eh, 0));
147 outgoing_hes_per_vertex_[_toVertex.idx()].push_back(halfedge_handle(eh, 1));
152 incident_hfs_per_he_.resize(n_halfedges());
166 for(std::vector<HalfEdgeHandle>::const_iterator it = _halfedges.begin(),
167 end = _halfedges.end(); it != end; ++it)
168 assert(it->is_valid() && (size_t)it->idx() < edges_.size() * 2u);
186 std::set<VertexHandle> fromVertices;
187 std::set<VertexHandle> toVertices;
189 for(std::vector<HalfEdgeHandle>::const_iterator it = _halfedges.begin(),
190 end = _halfedges.end(); it != end; ++it) {
192 fromVertices.insert(halfedge(*it).from_vertex());
193 toVertices.insert(halfedge(*it).to_vertex());
196 for(std::set<VertexHandle>::const_iterator v_it = fromVertices.begin(),
197 v_end = fromVertices.end(); v_it != v_end; ++v_it) {
198 if(toVertices.count(*v_it) != 1) {
203 std::cerr <<
"add_face(): The specified halfedges are not connected!" << std::endl;
205 return InvalidFaceHandle;
215 faces_.push_back(face);
216 face_deleted_.push_back(
false);
222 resize_fprops(n_faces());
227 for(std::vector<HalfEdgeHandle>::const_iterator it = _halfedges.begin(),
228 end = _halfedges.end(); it != end; ++it) {
230 assert((
size_t)it->idx() < incident_hfs_per_he_.size());
231 assert((
size_t)opposite_halfedge_handle(*it).idx() < incident_hfs_per_he_.size());
233 incident_hfs_per_he_[it->idx()].push_back(halfface_handle(fh, 0));
234 incident_hfs_per_he_[opposite_halfedge_handle(*it).idx()].push_back(halfface_handle(fh, 1));
240 incident_cell_per_hf_.resize(n_halffaces(), InvalidCellHandle);
255 for(std::vector<VertexHandle>::const_iterator it = _vertices.begin(),
256 end = _vertices.end(); it != end; ++it)
257 assert(it->is_valid() && (size_t)it->idx() < n_vertices());
261 std::vector<HalfEdgeHandle> halfedges;
262 std::vector<VertexHandle>::const_iterator it = _vertices.begin();
263 std::vector<VertexHandle>::const_iterator end = _vertices.end();
264 for(; (it+1) != end; ++it) {
270 if(edge(e_idx).to_vertex() == *it) swap = 1;
272 halfedges.push_back(halfedge_handle(e_idx, swap));
274 EdgeHandle e_idx = add_edge(*it, *_vertices.begin());
276 if(edge(e_idx).to_vertex() == *it) swap = 1;
277 halfedges.push_back(halfedge_handle(e_idx, swap));
281 return add_face(halfedges,
true);
283 return add_face(halfedges,
false);
289 void TopologyKernel::reorder_incident_halffaces(
const EdgeHandle& _eh) {
308 for(
unsigned char s = 0; s <= 1; s++) {
311 std::vector<HalfFaceHandle> new_halffaces;
316 assert((
size_t)cur_he.idx() < incident_hfs_per_he_.size());
318 if(incident_hfs_per_he_[cur_he.idx()].size() != 0) {
321 cur_hf = *incident_hfs_per_he_[cur_he.idx()].begin();
324 while(cur_hf != InvalidHalfFaceHandle) {
327 new_halffaces.push_back(cur_hf);
330 cur_hf = adjacent_halfface_in_cell(cur_hf, cur_he);
332 if(cur_hf != InvalidHalfFaceHandle)
333 cur_hf = opposite_halfface_handle(cur_hf);
336 if(cur_hf == start_hf)
break;
339 if(std::find(new_halffaces.begin(), new_halffaces.end(), cur_hf) != new_halffaces.end())
break;
346 if(new_halffaces.size() != incident_hfs_per_he_[cur_he.idx()].size()) {
351 while(cur_hf != InvalidHalfFaceHandle) {
353 cur_hf = opposite_halfface_handle(cur_hf);
354 cur_hf = adjacent_halfface_in_cell(cur_hf, cur_he);
356 if(cur_hf == start_hf)
break;
360 if(std::find(new_halffaces.begin(), new_halffaces.end(), cur_hf) != new_halffaces.end())
break;
362 if(cur_hf != InvalidHalfFaceHandle)
363 new_halffaces.insert(new_halffaces.begin(), cur_hf);
369 if(new_halffaces.size() == incident_hfs_per_he_[cur_he.idx()].size()) {
370 incident_hfs_per_he_[cur_he.idx()] = new_halffaces;
383 for(std::vector<HalfFaceHandle>::const_iterator it = _halffaces.begin(),
384 end = _halffaces.end(); it != end; ++it)
385 assert(it->is_valid() && ((size_t)it->idx() < faces_.size() * 2u));
399 std::set<HalfEdgeHandle> incidentHalfedges;
400 std::set<EdgeHandle> incidentEdges;
402 for(std::vector<HalfFaceHandle>::const_iterator it = _halffaces.begin(),
403 end = _halffaces.end(); it != end; ++it) {
406 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hface.halfedges().begin(),
407 he_end = hface.halfedges().end(); he_it != he_end; ++he_it) {
408 incidentHalfedges.insert(*he_it);
409 incidentEdges.insert(edge_handle(*he_it));
413 if(incidentHalfedges.size() != (incidentEdges.size() * 2u)) {
415 std::cerr <<
"add_cell(): The specified half-faces are not connected!" << std::endl;
417 return InvalidCellHandle;
426 cells_.push_back(cell);
427 cell_deleted_.push_back(
false);
430 resize_cprops(n_cells());
437 std::set<EdgeHandle> cell_edges;
438 for(std::vector<HalfFaceHandle>::const_iterator it = _halffaces.begin(),
439 end = _halffaces.end(); it != end; ++it) {
440 assert((
size_t)it->idx() < incident_cell_per_hf_.size());
444 if(incident_cell_per_hf_[it->idx()] != InvalidCellHandle) {
450 std::cerr <<
"add_cell(): One of the specified half-faces is already incident to another cell!" << std::endl;
456 incident_cell_per_hf_[it->idx()] = ch;
459 const std::vector<HalfEdgeHandle> hes = halfface(*it).halfedges();
460 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin(),
461 he_end = hes.end(); he_it != he_end; ++he_it) {
462 cell_edges.insert(edge_handle(*he_it));
472 for(std::set<EdgeHandle>::const_iterator e_it = cell_edges.begin(),
473 e_end = cell_edges.end(); e_it != e_end; ++e_it) {
474 reorder_incident_halffaces(*e_it);
490 if(has_vertex_bottom_up_incidences()) {
498 std::vector<HalfEdgeHandle>::iterator h_end =
499 std::remove(outgoing_hes_per_vertex_[fv.idx()].begin(), outgoing_hes_per_vertex_[fv.idx()].end(), heh0);
500 outgoing_hes_per_vertex_[fv.idx()].resize(h_end - outgoing_hes_per_vertex_[fv.idx()].begin());
502 h_end = std::remove(outgoing_hes_per_vertex_[tv.idx()].begin(), outgoing_hes_per_vertex_[tv.idx()].end(), heh1);
503 outgoing_hes_per_vertex_[tv.idx()].resize(h_end - outgoing_hes_per_vertex_[tv.idx()].begin());
505 outgoing_hes_per_vertex_[_fromVertex.idx()].push_back(heh0);
506 outgoing_hes_per_vertex_[_toVertex.idx()].push_back(heh1);
509 e.set_from_vertex(_fromVertex);
510 e.set_to_vertex(_toVertex);
520 if(has_edge_bottom_up_incidences()) {
525 const std::vector<HalfEdgeHandle>& hes = f.halfedges();
527 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin(),
528 he_end = hes.end(); he_it != he_end; ++he_it) {
530 std::vector<HalfFaceHandle>::iterator h_end =
531 std::remove(incident_hfs_per_he_[he_it->idx()].begin(),
532 incident_hfs_per_he_[he_it->idx()].end(), hf0);
533 incident_hfs_per_he_[he_it->idx()].resize(h_end - incident_hfs_per_he_[he_it->idx()].begin());
535 h_end = std::remove(incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].begin(),
536 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].end(), hf1);
537 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].resize(h_end - incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].begin());
540 for(std::vector<HalfEdgeHandle>::const_iterator he_it = _hes.begin(),
541 he_end = _hes.end(); he_it != he_end; ++he_it) {
543 incident_hfs_per_he_[he_it->idx()].push_back(hf0);
544 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].push_back(hf1);
550 f.set_halfedges(_hes);
560 if(has_face_bottom_up_incidences()) {
562 const std::vector<HalfFaceHandle>& hfs = c.halffaces();
563 for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin(),
564 hf_end = hfs.end(); hf_it != hf_end; ++hf_it) {
566 incident_cell_per_hf_[*hf_it] = InvalidCellHandle;
569 for(std::vector<HalfFaceHandle>::const_iterator hf_it = _hfs.begin(),
570 hf_end = _hfs.end(); hf_it != hf_end; ++hf_it) {
572 incident_cell_per_hf_[*hf_it] = _ch;
576 c.set_halffaces(_hfs);
595 std::vector<VertexHandle> vs;
598 std::set<EdgeHandle> incidentEdges_s;
599 get_incident_edges(vs, incidentEdges_s);
601 std::set<FaceHandle> incidentFaces_s;
602 get_incident_faces(incidentEdges_s, incidentFaces_s);
604 std::set<CellHandle> incidentCells_s;
605 get_incident_cells(incidentFaces_s, incidentCells_s);
608 for(std::set<CellHandle>::const_reverse_iterator c_it = incidentCells_s.rbegin(),
609 c_end = incidentCells_s.rend(); c_it != c_end; ++c_it) {
610 delete_cell_core(*c_it);
614 for(std::set<FaceHandle>::const_reverse_iterator f_it = incidentFaces_s.rbegin(),
615 f_end = incidentFaces_s.rend(); f_it != f_end; ++f_it) {
616 delete_face_core(*f_it);
620 for(std::set<EdgeHandle>::const_reverse_iterator e_it = incidentEdges_s.rbegin(),
621 e_end = incidentEdges_s.rend(); e_it != e_end; ++e_it) {
622 delete_edge_core(*e_it);
626 return delete_vertex_core(_h);
645 std::vector<EdgeHandle> es;
648 std::set<FaceHandle> incidentFaces_s;
649 get_incident_faces(es, incidentFaces_s);
651 std::set<CellHandle> incidentCells_s;
652 get_incident_cells(incidentFaces_s, incidentCells_s);
655 for(std::set<CellHandle>::const_reverse_iterator c_it = incidentCells_s.rbegin(),
656 c_end = incidentCells_s.rend(); c_it != c_end; ++c_it) {
657 delete_cell_core(*c_it);
661 for(std::set<FaceHandle>::const_reverse_iterator f_it = incidentFaces_s.rbegin(),
662 f_end = incidentFaces_s.rend(); f_it != f_end; ++f_it) {
663 delete_face_core(*f_it);
667 return delete_edge_core(_h);
686 std::vector<FaceHandle> fs;
689 std::set<CellHandle> incidentCells_s;
690 get_incident_cells(fs, incidentCells_s);
693 for(std::set<CellHandle>::const_reverse_iterator c_it = incidentCells_s.rbegin(),
694 c_end = incidentCells_s.rend(); c_it != c_end; ++c_it) {
695 delete_cell_core(*c_it);
699 return delete_face_core(_h);
715 return delete_cell_core(_h);
723 if (!deferred_deletion_enabled() || !needs_garbage_collection_)
726 deferred_deletion =
false;
728 for (
unsigned int i = n_cells(); i > 0; --i)
731 cell_deleted_[i-1] =
false;
735 for (
unsigned int i = n_faces(); i > 0; --i)
738 face_deleted_[i-1] =
false;
742 for (
unsigned int i = n_edges(); i > 0; --i)
745 edge_deleted_[i-1] =
false;
749 for (
unsigned int i = n_vertices(); i > 0; --i)
752 vertex_deleted_[i-1] =
false;
757 deferred_deletion =
true;
758 needs_garbage_collection_ =
false;
764 template <
class ContainerT>
765 void TopologyKernel::get_incident_edges(
const ContainerT& _vs,
766 std::set<EdgeHandle>& _es)
const {
772 for(
typename ContainerT::const_iterator v_it = _vs.begin(),
773 v_end = _vs.end(); v_it != v_end; ++v_it) {
775 const std::vector<HalfEdgeHandle>& inc_hes = outgoing_hes_per_vertex_[v_it->idx()];
777 for(std::vector<HalfEdgeHandle>::const_iterator he_it = inc_hes.begin(),
778 he_end = inc_hes.end(); he_it != he_end; ++he_it) {
780 _es.insert(edge_handle(*he_it));
785 for(
typename ContainerT::const_iterator v_it = _vs.begin(),
786 v_end = _vs.end(); v_it != v_end; ++v_it) {
788 for(
EdgeIter e_it = edges_begin(), e_end = edges_end(); e_it != e_end; ++e_it) {
790 const Edge& e = edge(*e_it);
792 if(e.from_vertex() == *v_it || e.to_vertex() == *v_it) {
802 template <
class ContainerT>
803 void TopologyKernel::get_incident_faces(
const ContainerT& _es,
804 std::set<FaceHandle>& _fs)
const {
810 for(
typename ContainerT::const_iterator e_it = _es.begin(),
811 e_end = _es.end(); e_it != e_end; ++e_it) {
814 hehf_it.valid(); ++hehf_it) {
818 if(_fs.count(fh) == 0) {
825 for(
typename ContainerT::const_iterator e_it = _es.begin(),
826 e_end = _es.end(); e_it != e_end; ++e_it) {
829 f_end = faces_end(); f_it != f_end; ++f_it) {
831 const std::vector<HalfEdgeHandle>& hes = face(*f_it).halfedges();
833 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin(),
834 he_end = hes.end(); he_it != he_end; ++he_it) {
836 if(edge_handle(*he_it) == *e_it) {
848 template <
class ContainerT>
849 void TopologyKernel::get_incident_cells(
const ContainerT& _fs,
850 std::set<CellHandle>& _cs)
const {
856 for(
typename ContainerT::const_iterator f_it = _fs.begin(),
857 f_end = _fs.end(); f_it != f_end; ++f_it) {
865 if(c0.is_valid()) _cs.insert(c0);
866 if(c1.is_valid()) _cs.insert(c1);
870 for(
typename ContainerT::const_iterator f_it = _fs.begin(),
871 f_end = _fs.end(); f_it != f_end; ++f_it) {
873 for(
CellIter c_it = cells_begin(), c_end = cells_end();
874 c_it != c_end; ++c_it) {
876 const std::vector<HalfFaceHandle>& hfs = cell(*c_it).halffaces();
878 for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin(),
879 hf_end = hfs.end(); hf_it != hf_end; ++hf_it) {
881 if(face_handle(*hf_it) == *f_it) {
913 assert(h.is_valid() && (size_t)h.idx() < n_vertices());
915 if (fast_deletion_enabled() && !deferred_deletion_enabled())
918 assert(!vertex_deleted_[last_undeleted_vertex.idx()]);
919 swap_vertices(h, last_undeleted_vertex);
920 h = last_undeleted_vertex;
923 if (deferred_deletion_enabled())
925 needs_garbage_collection_ =
true;
926 vertex_deleted_[h.idx()] =
true;
939 for(
int i = h.idx(), end = n_vertices(); i < end; ++i) {
940 const std::vector<HalfEdgeHandle>& hes = outgoing_hes_per_vertex_[i];
941 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin(),
942 he_end = hes.end(); he_it != he_end; ++he_it) {
944 Edge& e = edge(edge_handle(*he_it));
945 if(e.from_vertex().idx() == i) {
948 if(e.to_vertex().idx() == i) {
957 for(
EdgeIter e_it = edges_begin(), e_end = edges_end();
958 e_it != e_end; ++e_it) {
961 if(edge(*e_it).from_vertex() > h) {
962 edge(*e_it).set_from_vertex(
VertexHandle(edge(*e_it).from_vertex().idx() - 1));
964 if(edge(*e_it).to_vertex() > h) {
965 edge(*e_it).set_to_vertex(
VertexHandle(edge(*e_it).to_vertex().idx() - 1));
973 assert((
size_t)h.idx() < outgoing_hes_per_vertex_.size());
974 outgoing_hes_per_vertex_.erase(outgoing_hes_per_vertex_.begin() + h.idx());
981 vertex_deleted_.erase(vertex_deleted_.begin() + h.idx());
1019 assert(h.is_valid() && (size_t)h.idx() < edges_.size());
1021 if (fast_deletion_enabled() && !deferred_deletion_enabled())
1024 assert(!edge_deleted_[last_edge.idx()]);
1025 swap_edges(h, last_edge);
1035 assert(v0.is_valid() && (size_t)v0.idx() < outgoing_hes_per_vertex_.size());
1036 assert(v1.is_valid() && (size_t)v1.idx() < outgoing_hes_per_vertex_.size());
1038 outgoing_hes_per_vertex_[v0.idx()].erase(
1039 std::remove(outgoing_hes_per_vertex_[v0.idx()].begin(),
1040 outgoing_hes_per_vertex_[v0.idx()].end(),
1041 halfedge_handle(h, 0)),
1042 outgoing_hes_per_vertex_[v0.idx()].end());
1044 outgoing_hes_per_vertex_[v1.idx()].erase(
1045 std::remove(outgoing_hes_per_vertex_[v1.idx()].begin(),
1046 outgoing_hes_per_vertex_[v1.idx()].end(),
1047 halfedge_handle(h, 1)),
1048 outgoing_hes_per_vertex_[v1.idx()].end());
1051 if (deferred_deletion_enabled())
1053 needs_garbage_collection_ =
true;
1054 edge_deleted_[h.idx()] =
true;
1064 if (!fast_deletion_enabled())
1069 assert((
size_t)halfedge_handle(h, 0).idx() < incident_hfs_per_he_.size());
1074 std::set<FaceHandle> update_faces;
1075 for(std::vector<std::vector<HalfFaceHandle> >::const_iterator iit =
1076 (incident_hfs_per_he_.begin() + halfedge_handle(h, 0).idx()),
1077 iit_end = incident_hfs_per_he_.end(); iit != iit_end; ++iit) {
1078 for(std::vector<HalfFaceHandle>::const_iterator it = iit->begin(),
1079 end = iit->end(); it != end; ++it) {
1080 update_faces.insert(face_handle(*it));
1085 for(std::set<FaceHandle>::iterator f_it = update_faces.begin(),
1086 f_end = update_faces.end(); f_it != f_end; ++f_it) {
1088 std::vector<HalfEdgeHandle> hes = face(*f_it).halfedges();
1091 hes.erase(std::remove(hes.begin(), hes.end(), halfedge_handle(h, 0)), hes.end());
1092 hes.erase(std::remove(hes.begin(), hes.end(), halfedge_handle(h, 1)), hes.end());
1094 #if defined(__clang_major__) && (__clang_major__ >= 5) 1095 for(std::vector<HalfEdgeHandle>::iterator it = hes.begin(), end = hes.end();
1097 cor.correctValue(*it);
1100 std::for_each(hes.begin(), hes.end(),
1101 fun::bind(&HEHandleCorrection::correctValue, &cor, fun::placeholders::_1));
1103 face(*f_it).set_halfedges(hes);
1108 for(
FaceIter f_it = faces_begin(), f_end = faces_end();
1109 f_it != f_end; ++f_it) {
1112 std::vector<HalfEdgeHandle> hes = face(*f_it).halfedges();
1115 hes.erase(std::remove(hes.begin(), hes.end(), halfedge_handle(h, 0)), hes.end());
1116 hes.erase(std::remove(hes.begin(), hes.end(), halfedge_handle(h, 1)), hes.end());
1120 #if defined(__clang_major__) && (__clang_major__ >= 5) 1121 for(std::vector<HalfEdgeHandle>::iterator it = hes.begin(), end = hes.end();
1123 cor.correctValue(*it);
1126 std::for_each(hes.begin(), hes.end(),
1127 fun::bind(&HEHandleCorrection::correctValue, &cor, fun::placeholders::_1));
1129 face(*f_it).set_halfedges(hes);
1137 assert((
size_t)halfedge_handle(h, 1).idx() < incident_hfs_per_he_.size());
1139 incident_hfs_per_he_.erase(incident_hfs_per_he_.begin() + halfedge_handle(h, 1).idx());
1140 incident_hfs_per_he_.erase(incident_hfs_per_he_.begin() + halfedge_handle(h, 0).idx());
1143 if (!fast_deletion_enabled())
1148 #if defined(__clang_major__) && (__clang_major__ >= 5) 1149 for(std::vector<std::vector<HalfEdgeHandle> >::iterator it = outgoing_hes_per_vertex_.begin(),
1150 end = outgoing_hes_per_vertex_.end(); it != end; ++it) {
1151 cor.correctVecValue(*it);
1154 std::for_each(outgoing_hes_per_vertex_.begin(),
1155 outgoing_hes_per_vertex_.end(),
1156 fun::bind(&HEHandleCorrection::correctVecValue, &cor, fun::placeholders::_1));
1163 edges_.erase(edges_.begin() + h.idx());
1164 edge_deleted_.erase(edge_deleted_.begin() + h.idx());
1203 assert(h.is_valid() && (size_t)h.idx() < faces_.size());
1206 if (fast_deletion_enabled() && !deferred_deletion_enabled())
1209 assert(!face_deleted_[last_face.idx()]);
1210 swap_faces(h, last_face);
1217 const std::vector<HalfEdgeHandle>& hes = face(h).halfedges();
1218 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin(),
1219 he_end = hes.end(); he_it != he_end; ++he_it) {
1221 assert((
size_t)std::max(he_it->idx(), opposite_halfedge_handle(*he_it).idx()) < incident_hfs_per_he_.size());
1223 incident_hfs_per_he_[he_it->idx()].erase(
1224 std::remove(incident_hfs_per_he_[he_it->idx()].begin(),
1225 incident_hfs_per_he_[he_it->idx()].end(),
1226 halfface_handle(h, 0)), incident_hfs_per_he_[he_it->idx()].end());
1229 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].erase(
1230 std::remove(incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].begin(),
1231 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].end(),
1232 halfface_handle(h, 1)), incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].end());
1236 if (deferred_deletion_enabled())
1238 needs_garbage_collection_ =
true;
1239 face_deleted_[h.idx()] =
true;
1249 if (!fast_deletion_enabled())
1256 std::set<CellHandle> update_cells;
1257 for(std::vector<CellHandle>::const_iterator c_it = (incident_cell_per_hf_.begin() + halfface_handle(h, 0).idx()),
1258 c_end = incident_cell_per_hf_.end(); c_it != c_end; ++c_it) {
1259 if(!c_it->is_valid())
continue;
1260 update_cells.insert(*c_it);
1262 for(std::set<CellHandle>::const_iterator c_it = update_cells.begin(),
1263 c_end = update_cells.end(); c_it != c_end; ++c_it) {
1265 std::vector<HalfFaceHandle> hfs = cell(*c_it).halffaces();
1268 hfs.erase(std::remove(hfs.begin(), hfs.end(), halfface_handle(h, 0)), hfs.end());
1269 hfs.erase(std::remove(hfs.begin(), hfs.end(), halfface_handle(h, 1)), hfs.end());
1272 #if defined(__clang_major__) && (__clang_major__ >= 5) 1273 for(std::vector<HalfFaceHandle>::iterator it = hfs.begin(),
1274 end = hfs.end(); it != end; ++it) {
1275 cor.correctValue(*it);
1278 std::for_each(hfs.begin(), hfs.end(),
1279 fun::bind(&HFHandleCorrection::correctValue, &cor, fun::placeholders::_1));
1281 cell(*c_it).set_halffaces(hfs);
1287 for(
CellIter c_it = cells_begin(), c_end = cells_end(); c_it != c_end; ++c_it) {
1289 std::vector<HalfFaceHandle> hfs = cell(*c_it).halffaces();
1292 hfs.erase(std::remove(hfs.begin(), hfs.end(), halfface_handle(h, 0)), hfs.end());
1293 hfs.erase(std::remove(hfs.begin(), hfs.end(), halfface_handle(h, 1)), hfs.end());
1296 #if defined(__clang_major__) && (__clang_major__ >= 5) 1297 for(std::vector<HalfFaceHandle>::iterator it = hfs.begin(),
1298 end = hfs.end(); it != end; ++it) {
1299 cor.correctValue(*it);
1302 std::for_each(hfs.begin(), hfs.end(),
1303 fun::bind(&HFHandleCorrection::correctValue, &cor, fun::placeholders::_1));
1305 cell(*c_it).set_halffaces(hfs);
1313 assert((
size_t)halfface_handle(h, 1).idx() < incident_cell_per_hf_.size());
1315 incident_cell_per_hf_.erase(incident_cell_per_hf_.begin() + halfface_handle(h, 1).idx());
1316 incident_cell_per_hf_.erase(incident_cell_per_hf_.begin() + halfface_handle(h, 0).idx());
1320 if (!fast_deletion_enabled())
1325 #if defined(__clang_major__) && (__clang_major__ >= 5) 1326 for(std::vector<std::vector<HalfFaceHandle> >::iterator it = incident_hfs_per_he_.begin(), end = incident_hfs_per_he_.end(); it != end; ++it) {
1327 cor.correctVecValue(*it);
1330 std::for_each(incident_hfs_per_he_.begin(),
1331 incident_hfs_per_he_.end(),
1332 fun::bind(&HFHandleCorrection::correctVecValue, &cor, fun::placeholders::_1));
1338 faces_.erase(faces_.begin() + h.idx());
1339 face_deleted_.erase(face_deleted_.begin() + h.idx());
1372 assert(h.is_valid() && (size_t)h.idx() < cells_.size());
1375 if (fast_deletion_enabled() && !deferred_deletion_enabled())
1378 assert(!cell_deleted_[last_undeleted_cell.idx()]);
1379 swap_cells(h, last_undeleted_cell);
1380 h = last_undeleted_cell;
1386 const std::vector<HalfFaceHandle>& hfs = cell(h).halffaces();
1387 for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin(),
1388 hf_end = hfs.end(); hf_it != hf_end; ++hf_it) {
1389 assert((
size_t)hf_it->idx() < incident_cell_per_hf_.size());
1390 if (incident_cell_per_hf_[hf_it->idx()] == h)
1391 incident_cell_per_hf_[hf_it->idx()] = InvalidCellHandle;
1395 if (deferred_deletion_enabled())
1397 needs_garbage_collection_ =
true;
1398 cell_deleted_[h.idx()] =
true;
1408 if (!fast_deletion_enabled())
1412 #if defined(__clang_major__) && (__clang_major__ >= 5) 1413 for(std::vector<CellHandle>::iterator it = incident_cell_per_hf_.begin(),
1414 end = incident_cell_per_hf_.end(); it != end; ++it) {
1415 cor.correctValue(*it);
1418 std::for_each(incident_cell_per_hf_.begin(),
1419 incident_cell_per_hf_.end(),
1420 fun::bind(&CHandleCorrection::correctValue, &cor, fun::placeholders::_1));
1426 cells_.erase(cells_.begin() + h.idx());
1427 cell_deleted_.erase(cell_deleted_.begin() + h.idx());
1440 assert(_h1.idx() >= 0 && _h1.idx() < (int)cells_.size());
1441 assert(_h2.idx() >= 0 && _h2.idx() < (int)cells_.size());
1446 int id1 = _h1.idx();
1447 int id2 = _h2.idx();
1449 Cell c1 = cells_[id1];
1450 Cell c2 = cells_[id2];
1453 std::vector<HalfFaceHandle> hfhs1 = c1.halffaces();
1454 for (
unsigned int i = 0; i < hfhs1.size(); ++i)
1457 if (incident_cell_per_hf_[hfh.idx()] == id1)
1458 incident_cell_per_hf_[hfh.idx()] = id2;
1461 std::vector<HalfFaceHandle> hfhs2 = c2.halffaces();
1462 for (
unsigned int i = 0; i < hfhs2.size(); ++i)
1465 if (incident_cell_per_hf_[hfh.idx()] == id2)
1466 incident_cell_per_hf_[hfh.idx()] = id1;
1470 std::swap(cells_[id1], cells_[id2]);
1471 bool tmp = cell_deleted_[id1];
1472 cell_deleted_[id1] = cell_deleted_[id2];
1473 cell_deleted_[id2] = tmp;
1474 swap_cell_properties(_h1, _h2);
1479 assert(_h1.idx() >= 0 && _h1.idx() < (int)faces_.size());
1480 assert(_h2.idx() >= 0 && _h2.idx() < (int)faces_.size());
1486 std::vector<unsigned int> ids;
1487 ids.push_back(_h1.idx());
1488 ids.push_back(_h2.idx());
1490 unsigned int id1 = _h1.idx();
1491 unsigned int id2 = _h2.idx();
1496 if (has_face_bottom_up_incidences())
1498 std::set<unsigned int> processed_cells;
1499 for (
unsigned int i = 0; i < 2; ++i)
1501 unsigned int id = ids[i];
1502 for (
unsigned int j = 0; j < 2; ++j)
1511 if (processed_cells.find(ch.idx()) == processed_cells.end())
1514 Cell& c = cells_[ch.idx()];
1518 std::vector<HalfFaceHandle> new_halffaces;
1519 for (
unsigned int k = 0; k < c.halffaces().size(); ++k)
1520 if (c.halffaces()[k].idx()/2 == (int)id1)
1521 new_halffaces.push_back(
HalfFaceHandle(2 * id2 + (c.halffaces()[k].idx() % 2)));
1522 else if (c.halffaces()[k].idx()/2 == (int)id2)
1523 new_halffaces.push_back(
HalfFaceHandle(2 * id1 + (c.halffaces()[k].idx() % 2)));
1525 new_halffaces.push_back(c.halffaces()[k]);
1526 c.set_halffaces(new_halffaces);
1528 processed_cells.insert(ch.idx());
1536 for (
unsigned int i = 0; i < cells_.size(); ++i)
1538 Cell& c = cells_[i];
1541 bool contains_swapped_face =
false;
1542 for (
unsigned int k = 0; k < c.halffaces().size(); ++k)
1544 if (c.halffaces()[k].idx()/2 == (int)id1)
1545 contains_swapped_face =
true;
1546 if (c.halffaces()[k].idx()/2 == (int)id2)
1547 contains_swapped_face =
true;
1548 if (contains_swapped_face)
1552 if (contains_swapped_face)
1555 std::vector<HalfFaceHandle> new_halffaces;
1556 for (
unsigned int k = 0; k < c.halffaces().size(); ++k)
1557 if (c.halffaces()[k].idx()/2 == (int)id1)
1558 new_halffaces.push_back(
HalfFaceHandle(2 * id2 + (c.halffaces()[k].idx() % 2)));
1559 else if (c.halffaces()[k].idx()/2 == (int)id2)
1560 new_halffaces.push_back(
HalfFaceHandle(2 * id1 + (c.halffaces()[k].idx() % 2)));
1562 new_halffaces.push_back(c.halffaces()[k]);
1563 c.set_halffaces(new_halffaces);
1570 if (has_edge_bottom_up_incidences())
1572 std::set<unsigned int> processed_halfedges;
1573 for (
unsigned int i = 0; i < 2; ++i)
1575 unsigned int id = ids[i];
1576 for (
unsigned int j = 0; j < 2; ++j)
1579 Face hf = halfface(hfh);
1581 for (
unsigned int k = 0; k < hf.halfedges().size(); ++k)
1585 if (processed_halfedges.find(heh.idx()) != processed_halfedges.end())
1588 std::vector<HalfFaceHandle>& incident_halffaces = incident_hfs_per_he_[heh.idx()];
1589 for (
unsigned int l = 0; l < incident_halffaces.size(); ++l)
1593 if (hfh2.idx()/2 == (int)id1)
1595 else if (hfh2.idx()/2 == (int)id2)
1599 processed_halfedges.insert(heh);
1606 std::swap(faces_[ids[0]], faces_[ids[1]]);
1607 bool tmp = face_deleted_[ids[0]];
1608 face_deleted_[ids[0]] = face_deleted_[ids[1]];
1609 face_deleted_[ids[1]] = tmp;
1610 std::swap(incident_cell_per_hf_[2*ids[0]+0], incident_cell_per_hf_[2*ids[1]+0]);
1611 std::swap(incident_cell_per_hf_[2*ids[0]+1], incident_cell_per_hf_[2*ids[1]+1]);
1612 swap_face_properties(_h1, _h2);
1613 swap_halfface_properties(halfface_handle(_h1, 0), halfface_handle(_h2, 0));
1614 swap_halfface_properties(halfface_handle(_h1, 1), halfface_handle(_h2, 1));
1620 assert(_h1.idx() >= 0 && _h1.idx() < (int)edges_.size());
1621 assert(_h2.idx() >= 0 && _h2.idx() < (int)edges_.size());
1626 std::vector<unsigned int> ids;
1627 ids.push_back(_h1.idx());
1628 ids.push_back(_h2.idx());
1633 if (has_edge_bottom_up_incidences())
1635 std::set<unsigned int> processed_faces;
1637 for (
unsigned int i = 0; i < 2; ++i)
1642 std::vector<HalfFaceHandle>& incident_halffaces = incident_hfs_per_he_[heh.idx()];
1643 for (
unsigned int j = 0; j < incident_halffaces.size(); ++j)
1647 unsigned int f_id = hfh.idx() / 2;
1649 if (processed_faces.find(f_id) == processed_faces.end())
1652 Face& f = faces_[f_id];
1655 std::vector<HalfEdgeHandle> new_halfedges;
1656 for (
unsigned int k = 0; k < f.halfedges().size(); ++k)
1659 if (heh2.idx() / 2 == (int)ids[0])
1660 new_halfedges.push_back(
HalfEdgeHandle(2*ids[1] + (heh2.idx() % 2)));
1661 else if (heh2.idx() / 2 == (int)ids[1])
1662 new_halfedges.push_back(
HalfEdgeHandle(2*ids[0] + (heh2.idx() % 2)));
1664 new_halfedges.push_back(heh2);
1666 f.set_halfedges(new_halfedges);
1668 processed_faces.insert(f_id);
1676 for (
unsigned int i = 0; i < faces_.size(); ++i)
1678 Face& f = faces_[i];
1681 bool contains_swapped_edge =
false;
1682 for (
unsigned int k = 0; k < f.halfedges().size(); ++k)
1684 if (f.halfedges()[k].idx()/2 == (int)ids[0])
1685 contains_swapped_edge =
true;
1686 if (f.halfedges()[k].idx()/2 == (int)ids[1])
1687 contains_swapped_edge =
true;
1688 if (contains_swapped_edge)
1692 if (contains_swapped_edge)
1695 std::vector<HalfEdgeHandle> new_halfedges;
1696 for (
unsigned int k = 0; k < f.halfedges().size(); ++k)
1699 if (heh2.idx() / 2 == (int)ids[0])
1700 new_halfedges.push_back(
HalfEdgeHandle(2*ids[1] + (heh2.idx() % 2)));
1701 else if (heh2.idx() / 2 == (int)ids[1])
1702 new_halfedges.push_back(
HalfEdgeHandle(2*ids[0] + (heh2.idx() % 2)));
1704 new_halfedges.push_back(heh2);
1706 f.set_halfedges(new_halfedges);
1713 if (has_vertex_bottom_up_incidences())
1715 std::set<int> processed_vertices;
1716 for (
unsigned int i = 0; i < 2; ++i)
1719 std::vector<VertexHandle> vhs;
1720 vhs.push_back(e.from_vertex());
1721 vhs.push_back(e.to_vertex());
1723 for (
unsigned int j = 0; j < 2; ++j)
1725 if (processed_vertices.find(vhs[j].idx()) != processed_vertices.end())
1728 std::vector<HalfEdgeHandle>& outgoing_hes = outgoing_hes_per_vertex_[vhs[j].idx()];
1729 for (
unsigned int k = 0; k < outgoing_hes.size(); ++k)
1732 if (heh.idx() / 2 == (int)ids[0])
1734 else if (heh.idx() / 2 == (int)ids[1])
1737 processed_vertices.insert(vhs[j]);
1744 std::swap(edges_[ids[0]], edges_[ids[1]]);
1745 bool tmp = edge_deleted_[ids[0]];
1746 edge_deleted_[ids[0]] = edge_deleted_[ids[1]];
1747 edge_deleted_[ids[1]] = tmp;
1748 std::swap(incident_hfs_per_he_[2*ids[0]+0], incident_hfs_per_he_[2*ids[1]+0]);
1749 std::swap(incident_hfs_per_he_[2*ids[0]+1], incident_hfs_per_he_[2*ids[1]+1]);
1750 swap_edge_properties(_h1, _h2);
1751 swap_halfedge_properties(halfedge_handle(_h1, 0), halfedge_handle(_h2, 0));
1752 swap_halfedge_properties(halfedge_handle(_h1, 1), halfedge_handle(_h2, 1));
1758 assert(_h1.idx() >= 0 && _h1.idx() < (int)n_vertices_);
1759 assert(_h2.idx() >= 0 && _h2.idx() < (int)n_vertices_);
1764 std::vector<unsigned int> ids;
1765 ids.push_back(_h1.idx());
1766 ids.push_back(_h2.idx());
1771 if (has_vertex_bottom_up_incidences())
1773 for (
unsigned int i = 0; i < 2; ++i)
1775 std::set<unsigned int> processed_edges;
1776 std::vector<HalfEdgeHandle>& outgoing_hes = outgoing_hes_per_vertex_[ids[i]];
1777 for (
unsigned int k = 0; k < outgoing_hes.size(); ++k)
1779 unsigned int e_id = outgoing_hes[k].idx() / 2;
1781 if (processed_edges.find(e_id) == processed_edges.end())
1783 Edge& e = edges_[e_id];
1784 if (e.from_vertex() == (int)ids[0])
1786 else if (e.from_vertex() == (int)ids[1])
1789 if (e.to_vertex() == (int)ids[0])
1791 else if (e.to_vertex() == (int)ids[1])
1794 processed_edges.insert(e_id);
1804 for (
unsigned int i = 0; i < edges_.size(); ++i)
1806 Edge& e = edges_[i];
1807 if (e.from_vertex() == (int)ids[0])
1809 else if (e.from_vertex() == (int)ids[1])
1812 if (e.to_vertex() == (int)ids[0])
1814 else if (e.to_vertex() == (int)ids[1])
1820 bool tmp = vertex_deleted_[ids[0]];
1821 vertex_deleted_[ids[0]] = vertex_deleted_[ids[1]];
1822 vertex_deleted_[ids[1]] = tmp;
1823 std::swap(outgoing_hes_per_vertex_[ids[0]], outgoing_hes_per_vertex_[ids[1]]);
1824 swap_vertex_properties(_h1, _h2);
1829 void TopologyKernel::delete_multiple_vertices(
const std::vector<bool>& _tag) {
1831 assert(_tag.size() == n_vertices());
1833 std::vector<int> newIndices(n_vertices(), -1);
1836 std::vector<int>::iterator idx_it = newIndices.begin();
1837 for(std::vector<bool>::const_iterator t_it = _tag.begin(),
1838 t_end = _tag.end(); t_it != t_end; ++t_it, ++idx_it) {
1850 delete_multiple_vertex_props(_tag);
1853 std::for_each(edges_.begin(), edges_.end(), corrector);
1858 void TopologyKernel::delete_multiple_edges(
const std::vector<bool>& _tag) {
1860 assert(_tag.size() == n_edges());
1862 std::vector<int> newIndices(n_edges(), -1);
1865 std::vector<Edge> newEdges;
1867 std::vector<int>::iterator idx_it = newIndices.begin();
1868 std::vector<Edge>::const_iterator e_it = edges_.begin();
1870 for(std::vector<bool>::const_iterator t_it = _tag.begin(),
1871 t_end = _tag.end(); t_it != t_end; ++t_it, ++idx_it, ++e_it) {
1876 newEdges.push_back(*e_it);
1884 edges_.swap(newEdges);
1887 delete_multiple_edge_props(_tag);
1890 std::for_each(faces_.begin(), faces_.end(), corrector);
1895 void TopologyKernel::delete_multiple_faces(
const std::vector<bool>& _tag) {
1897 assert(_tag.size() == n_faces());
1899 std::vector<int> newIndices(n_faces(), -1);
1902 std::vector<Face> newFaces;
1904 std::vector<int>::iterator idx_it = newIndices.begin();
1905 std::vector<Face>::const_iterator f_it = faces_.begin();
1907 for(std::vector<bool>::const_iterator t_it = _tag.begin(),
1908 t_end = _tag.end(); t_it != t_end; ++t_it, ++idx_it, ++f_it) {
1913 newFaces.push_back(*f_it);
1921 faces_.swap(newFaces);
1924 delete_multiple_face_props(_tag);
1927 std::for_each(cells_.begin(), cells_.end(), corrector);
1932 void TopologyKernel::delete_multiple_cells(
const std::vector<bool>& _tag) {
1934 assert(_tag.size() == n_cells());
1936 std::vector<Cell> newCells;
1938 std::vector<Cell>::const_iterator c_it = cells_.begin();
1940 for(std::vector<bool>::const_iterator t_it = _tag.begin(),
1941 t_end = _tag.end(); t_it != t_end; ++t_it, ++c_it) {
1946 newCells.push_back(*c_it);
1951 cells_.swap(newCells);
1954 delete_multiple_cell_props(_tag);
1961 assert(_first >= cells_begin());
1962 assert(_last <= cells_end());
1964 std::vector<Cell>::iterator it = cells_.erase(cells_.begin() + _first->idx(), cells_.begin() + _last->idx());
1968 f_bottom_up_ =
false;
1969 enable_face_bottom_up_incidences(
true);
1975 void TopologyKernel::enable_deferred_deletion(
bool _enable)
1977 if (deferred_deletion && !_enable)
1980 deferred_deletion = _enable;
1989 assert(_edgeHandle.is_valid() && (size_t)_edgeHandle.idx() < edges_.size());
1991 return edges_[_edgeHandle.idx()];
2000 assert(_faceHandle.is_valid() && (size_t)_faceHandle.idx() < faces_.size());
2002 return faces_[_faceHandle.idx()];
2011 assert(_cellHandle.is_valid() && (size_t)_cellHandle.idx() < cells_.size());
2013 return cells_[_cellHandle.idx()];
2022 assert(_edgeHandle.is_valid() && (size_t)_edgeHandle.idx() < edges_.size());
2024 return edges_[_edgeHandle.idx()];
2033 assert((
size_t)_faceHandle.idx() < faces_.size());
2034 assert(_faceHandle.idx() >= 0);
2036 return faces_[_faceHandle.idx()];
2045 assert((
size_t)_cellHandle.idx() < cells_.size());
2046 assert(_cellHandle.idx() >= 0);
2048 return cells_[_cellHandle.idx()];
2057 assert((
size_t)_halfEdgeHandle.idx() < (edges_.size() * 2));
2058 assert(_halfEdgeHandle.idx() >= 0);
2062 if(_halfEdgeHandle.idx() % 2 == 0)
2063 return edges_[(
int)(_halfEdgeHandle.idx() / 2)];
2065 return opposite_halfedge(edges_[(
int)(_halfEdgeHandle.idx() / 2)]);
2074 assert((
size_t)_halfFaceHandle.idx() < (faces_.size() * 2));
2075 assert(_halfFaceHandle.idx() >= 0);
2079 if(_halfFaceHandle.idx() % 2 == 0)
2080 return faces_[(
int)(_halfFaceHandle.idx() / 2)];
2082 return opposite_halfface(faces_[(
int)(_halfFaceHandle.idx() / 2)]);
2091 assert(_halfEdgeHandle.idx() >= 0);
2092 assert((
size_t)_halfEdgeHandle.idx() < (edges_.size() * 2));
2096 if(_halfEdgeHandle.idx() % 2 != 0)
2097 return edges_[(
int)(_halfEdgeHandle.idx() / 2)];
2099 return opposite_halfedge(edges_[(
int)(_halfEdgeHandle.idx() / 2)]);
2108 assert(_halfFaceHandle.idx() >= 0);
2109 assert((
size_t)_halfFaceHandle.idx() < (faces_.size() * 2));
2113 if(_halfFaceHandle.idx() % 2 != 0)
2114 return faces_[(
int)(_halfFaceHandle.idx() / 2)];
2116 return opposite_halfface(faces_[(
int)(_halfFaceHandle.idx() / 2)]);
2123 assert(_vh1.idx() < (int)n_vertices());
2124 assert(_vh2.idx() < (int)n_vertices());
2127 if(halfedge(*voh_it).to_vertex() == _vh2) {
2132 return InvalidHalfEdgeHandle;
2139 assert(_vs.size() > 2);
2143 assert(v0.is_valid() && v1.is_valid() && v2.is_valid());
2146 if(!he0.is_valid())
return InvalidHalfFaceHandle;
2148 if(!he1.is_valid())
return InvalidHalfFaceHandle;
2150 std::vector<HalfEdgeHandle> hes;
2154 return halfface(hes);
2161 assert(_vs.size() > 2);
2166 assert(v0.is_valid() && v1.is_valid());
2169 if(!he0.is_valid())
return InvalidHalfFaceHandle;
2173 std::vector<HalfEdgeHandle> hes = halfface(*hehf_it).halfedges();
2175 if (hes.size() != _vs.size())
2179 for (
unsigned int i = 0; i < hes.size(); ++i)
2183 bool all_vertices_found =
true;
2185 for (
unsigned int i = 0; i < hes.size(); ++i)
2188 if (halfedge(heh).from_vertex() != _vs[i])
2190 all_vertices_found =
false;
2195 if (all_vertices_found)
2199 return InvalidHalfFaceHandle;
2206 assert(_hes.size() >= 2);
2210 assert(he0.is_valid() && he1.is_valid());
2214 std::vector<HalfEdgeHandle> hes = halfface(*hehf_it).halfedges();
2215 if(std::find(hes.begin(), hes.end(), he1) != hes.end()) {
2220 return InvalidHalfFaceHandle;
2227 assert(_heh.is_valid() && (size_t)_heh.idx() < edges_.size() * 2u);
2228 assert(_hfh.is_valid() && (size_t)_hfh.idx() < faces_.size() * 2u);
2230 std::vector<HalfEdgeHandle> hes = halfface(_hfh).halfedges();
2232 for(std::vector<HalfEdgeHandle>::const_iterator it = hes.begin();
2233 it != hes.end(); ++it) {
2235 if((it + 1) != hes.end())
return *(it + 1);
2236 else return *hes.begin();
2240 return InvalidHalfEdgeHandle;
2247 assert(_heh.is_valid() && (size_t)_heh.idx() < edges_.size() * 2u);
2248 assert(_hfh.is_valid() && (size_t)_hfh.idx() < faces_.size() * 2u);
2250 std::vector<HalfEdgeHandle> hes = halfface(_hfh).halfedges();
2252 for(std::vector<HalfEdgeHandle>::const_iterator it = hes.begin();
2253 it != hes.end(); ++it) {
2255 if(it != hes.begin())
return *(it - 1);
2256 else return *(hes.end() - 1);
2260 return InvalidHalfEdgeHandle;
2268 assert(_halfFaceHandle.is_valid() && (size_t)_halfFaceHandle.idx() < faces_.size() * 2u);
2269 assert(_halfEdgeHandle.is_valid() && (size_t)_halfEdgeHandle.idx() < edges_.size() * 2u);
2270 assert(has_face_bottom_up_incidences());
2271 assert((
size_t)_halfFaceHandle.idx() < incident_cell_per_hf_.size());
2273 if(incident_cell_per_hf_[_halfFaceHandle.idx()] == InvalidCellHandle) {
2275 return InvalidHalfFaceHandle;
2281 bool skipped =
false;
2284 for(std::vector<HalfFaceHandle>::const_iterator hf_it = c.halffaces().begin();
2285 hf_it != c.halffaces().end(); ++hf_it) {
2287 if(*hf_it == _halfFaceHandle) {
2293 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hf.halfedges().begin();
2294 he_it != hf.halfedges().end(); ++he_it) {
2296 if(edge_handle(*he_it) == edge_handle(_halfEdgeHandle)) {
2300 if(skipped && found)
break;
2302 if(skipped && found)
break;
2304 return ((skipped && found) ? idx : InvalidHalfFaceHandle);
2311 if(!has_face_bottom_up_incidences()) {
2312 return InvalidCellHandle;
2314 if((
size_t)_halfFaceHandle.idx() >= incident_cell_per_hf_.size() || _halfFaceHandle.idx() < 0) {
2315 return InvalidCellHandle;
2318 return incident_cell_per_hf_[_halfFaceHandle.idx()];
2323 void TopologyKernel::compute_vertex_bottom_up_incidences() {
2326 outgoing_hes_per_vertex_.clear();
2327 outgoing_hes_per_vertex_.resize(n_vertices());
2330 size_t n_edges = edges_.size();
2331 for(
size_t i = 0; i < n_edges; ++i) {
2332 if (edge_deleted_[i])
2338 assert((
size_t)from.idx() < outgoing_hes_per_vertex_.size());
2340 outgoing_hes_per_vertex_[from.idx()].push_back(halfedge_handle(
EdgeHandle(i), 0));
2343 assert((
size_t)to.idx() < outgoing_hes_per_vertex_.size());
2346 outgoing_hes_per_vertex_[to.idx()].push_back(halfedge_handle(
EdgeHandle(i), 1));
2352 void TopologyKernel::compute_edge_bottom_up_incidences() {
2355 incident_hfs_per_he_.clear();
2356 incident_hfs_per_he_.resize(edges_.size() * 2u);
2359 size_t n_faces = faces_.size();
2360 for(
size_t i = 0; i < n_faces; ++i) {
2361 if (face_deleted_[i])
2364 std::vector<HalfEdgeHandle> halfedges = faces_[i].halfedges();
2367 for(std::vector<HalfEdgeHandle>::const_iterator he_it = halfedges.begin();
2368 he_it != halfedges.end(); ++he_it) {
2370 incident_hfs_per_he_[he_it->idx()].push_back(halfface_handle(
FaceHandle(i), 0));
2371 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].push_back(
2379 void TopologyKernel::compute_face_bottom_up_incidences() {
2382 incident_cell_per_hf_.clear();
2383 incident_cell_per_hf_.resize(faces_.size() * 2u, InvalidCellHandle);
2385 size_t n_cells = cells_.size();
2386 for(
size_t i = 0; i < n_cells; ++i) {
2387 if (cell_deleted_[i])
2390 std::vector<HalfFaceHandle> halffaces = cells_[i].halffaces();
2393 for(std::vector<HalfFaceHandle>::const_iterator hf_it = halffaces.begin();
2394 hf_it != halffaces.end(); ++hf_it) {
2396 if(incident_cell_per_hf_[hf_it->idx()] == InvalidCellHandle) {
2398 incident_cell_per_hf_[hf_it->idx()] =
CellHandle(i);
2403 std::cerr <<
"compute_face_bottom_up_incidences(): Detected non-three-manifold configuration!" << std::endl;
2404 std::cerr <<
"Connectivity probably won't work." << std::endl;
Edge halfedge(const HalfEdgeHandle &_halfEdgeHandle) const
Get edge that corresponds to halfedge with handle _halfEdgeHandle.
virtual VertexIter delete_vertex(const VertexHandle &_h)
Delete vertex from mesh.
HalfFaceHandle halfface_extensive(const std::vector< VertexHandle > &_vs) const
HalfEdgeHandle prev_halfedge_in_halfface(const HalfEdgeHandle &_heh, const HalfFaceHandle &_hfh) const
Get previous halfedge within a halfface.
virtual CellHandle add_cell(const std::vector< HalfFaceHandle > &_halffaces, bool _topologyCheck=false)
Add cell via incident halffaces.
virtual CellIter delete_cell(const CellHandle &_h)
Delete cell from mesh.
EdgeIter delete_edge_core(const EdgeHandle &_h)
Delete edge from mesh.
virtual EdgeHandle add_edge(const VertexHandle &_fromVertex, const VertexHandle &_toHandle, bool _allowDuplicates=false)
Add edge.
const Cell & cell(const CellHandle &_cellHandle) const
Get cell with handle _cellHandle.
VertexIter delete_vertex_core(const VertexHandle &_h)
Delete vertex from mesh.
virtual VertexHandle add_vertex()
Add abstract vertex.
CellHandle incident_cell(const HalfFaceHandle &_halfFaceHandle) const
Get cell that is incident to the given halfface.
bool bind(osg::GeometryPtr &_geo, Mesh &_mesh)
const Face & face(const FaceHandle &_faceHandle) const
Get face with handle _faceHandle.
const Edge & edge(const EdgeHandle &_edgeHandle) const
Get edge with handle _edgeHandle.
FaceIter delete_face_core(const FaceHandle &_h)
Delete face from mesh.
Face halfface(const HalfFaceHandle &_halfFaceHandle) const
Get face that corresponds to halfface with handle _halfFaceHandle.
CellIter delete_cell_core(const CellHandle &_h)
Delete cell from mesh.
virtual FaceHandle add_face(const std::vector< HalfEdgeHandle > &_halfedges, bool _topologyCheck=false)
Add face via incident edges.
CellIter delete_cell_range(const CellIter &_first, const CellIter &_last)
Delete range of cells.
void set_cell(const CellHandle &_ch, const std::vector< HalfFaceHandle > &_hfs)
Set the half-faces of a cell.
virtual EdgeIter delete_edge(const EdgeHandle &_h)
Delete edge from mesh.
HalfFaceHandle adjacent_halfface_in_cell(const HalfFaceHandle &_halfFaceHandle, const HalfEdgeHandle &_halfEdgeHandle) const
Get halfface that is adjacent (w.r.t. a common halfedge) within the same cell.
Edge opposite_halfedge(const HalfEdgeHandle &_halfEdgeHandle) const
Get opposite halfedge that corresponds to halfedge with handle _halfEdgeHandle.
virtual FaceIter delete_face(const FaceHandle &_h)
Delete face from mesh.
void set_edge(const EdgeHandle &_eh, const VertexHandle &_fromVertex, const VertexHandle &_toVertex)
Set the vertices of an edge.
virtual void collect_garbage()
Delete all entities that are marked as deleted.
Face opposite_halfface(const HalfFaceHandle &_halfFaceHandle) const
Get opposite halfface that corresponds to halfface with handle _halfFaceHandle.
HalfEdgeHandle next_halfedge_in_halfface(const HalfEdgeHandle &_heh, const HalfFaceHandle &_hfh) const
Get next halfedge within a halfface.
void set_face(const FaceHandle &_fh, const std::vector< HalfEdgeHandle > &_hes)
Set the half-edges of a face.