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),
71 TopologyKernel::~TopologyKernel() {
79 vertex_deleted_.push_back(
false);
83 outgoing_hes_per_vertex_.resize(n_vertices_);
87 resize_vprops(n_vertices_);
98 bool _allowDuplicates) {
102 assert(_fromVertex.is_valid() && (size_t)_fromVertex.idx() < n_vertices());
103 assert(_toVertex.is_valid() && (size_t)_toVertex.idx() < n_vertices());
106 if(!_allowDuplicates) {
109 assert((
size_t)_fromVertex.idx() < outgoing_hes_per_vertex_.size());
110 std::vector<HalfEdgeHandle>& ohes = outgoing_hes_per_vertex_[_fromVertex.idx()];
111 for(std::vector<HalfEdgeHandle>::const_iterator he_it = ohes.begin(),
112 he_end = ohes.end(); he_it != he_end; ++he_it) {
113 if(halfedge(*he_it).to_vertex() == _toVertex) {
114 return edge_handle(*he_it);
118 for(
int i = 0; i < (int)edges_.size(); ++i) {
119 if(edge(
EdgeHandle(i)).from_vertex() == _fromVertex && edge(
EdgeHandle(i)).to_vertex() == _toVertex) {
121 }
else if(edge(
EdgeHandle(i)).from_vertex() == _toVertex && edge(
EdgeHandle(i)).to_vertex() == _fromVertex) {
133 edge_deleted_.push_back(
false);
136 resize_eprops(n_edges());
142 assert((
size_t)_fromVertex.idx() < outgoing_hes_per_vertex_.size());
143 assert((
size_t)_toVertex.idx() < outgoing_hes_per_vertex_.size());
145 outgoing_hes_per_vertex_[_fromVertex.idx()].push_back(halfedge_handle(eh, 0));
146 outgoing_hes_per_vertex_[_toVertex.idx()].push_back(halfedge_handle(eh, 1));
151 incident_hfs_per_he_.resize(n_halfedges());
165 for(std::vector<HalfEdgeHandle>::const_iterator it = _halfedges.begin(),
166 end = _halfedges.end(); it != end; ++it)
167 assert(it->is_valid() && (size_t)it->idx() < edges_.size() * 2u);
185 std::set<VertexHandle> fromVertices;
186 std::set<VertexHandle> toVertices;
188 for(std::vector<HalfEdgeHandle>::const_iterator it = _halfedges.begin(),
189 end = _halfedges.end(); it != end; ++it) {
191 fromVertices.insert(halfedge(*it).from_vertex());
192 toVertices.insert(halfedge(*it).to_vertex());
195 for(std::set<VertexHandle>::const_iterator v_it = fromVertices.begin(),
196 v_end = fromVertices.end(); v_it != v_end; ++v_it) {
197 if(toVertices.count(*v_it) != 1) {
202 std::cerr <<
"add_face(): The specified halfedges are not connected!" << std::endl;
204 return InvalidFaceHandle;
214 faces_.push_back(face);
215 face_deleted_.push_back(
false);
221 resize_fprops(n_faces());
226 for(std::vector<HalfEdgeHandle>::const_iterator it = _halfedges.begin(),
227 end = _halfedges.end(); it != end; ++it) {
229 assert((
size_t)it->idx() < incident_hfs_per_he_.size());
230 assert((
size_t)opposite_halfedge_handle(*it).idx() < incident_hfs_per_he_.size());
232 incident_hfs_per_he_[it->idx()].push_back(halfface_handle(fh, 0));
233 incident_hfs_per_he_[opposite_halfedge_handle(*it).idx()].push_back(halfface_handle(fh, 1));
239 incident_cell_per_hf_.resize(n_halffaces(), InvalidCellHandle);
254 for(std::vector<VertexHandle>::const_iterator it = _vertices.begin(),
255 end = _vertices.end(); it != end; ++it)
256 assert(it->is_valid() && (size_t)it->idx() < n_vertices());
260 std::vector<HalfEdgeHandle> halfedges;
261 std::vector<VertexHandle>::const_iterator it = _vertices.begin();
262 std::vector<VertexHandle>::const_iterator end = _vertices.end();
263 for(; (it+1) != end; ++it) {
269 if(edge(e_idx).to_vertex() == *it) swap = 1;
271 halfedges.push_back(halfedge_handle(e_idx, swap));
273 EdgeHandle e_idx = add_edge(*it, *_vertices.begin());
275 if(edge(e_idx).to_vertex() == *it) swap = 1;
276 halfedges.push_back(halfedge_handle(e_idx, swap));
280 return add_face(halfedges,
true);
282 return add_face(halfedges,
false);
288 void TopologyKernel::reorder_incident_halffaces(
const EdgeHandle& _eh) {
307 for(
unsigned char s = 0; s <= 1; s++) {
310 std::vector<HalfFaceHandle> new_halffaces;
315 assert((
size_t)cur_he.idx() < incident_hfs_per_he_.size());
317 if(incident_hfs_per_he_[cur_he.idx()].size() != 0) {
320 cur_hf = *incident_hfs_per_he_[cur_he.idx()].begin();
323 while(cur_hf != InvalidHalfFaceHandle) {
326 new_halffaces.push_back(cur_hf);
329 cur_hf = adjacent_halfface_in_cell(cur_hf, cur_he);
331 if(cur_hf != InvalidHalfFaceHandle)
332 cur_hf = opposite_halfface_handle(cur_hf);
335 if(cur_hf == start_hf)
break;
338 if(std::find(new_halffaces.begin(), new_halffaces.end(), cur_hf) != new_halffaces.end())
break;
345 if(new_halffaces.size() != incident_hfs_per_he_[cur_he.idx()].size()) {
350 while(cur_hf != InvalidHalfFaceHandle) {
352 cur_hf = opposite_halfface_handle(cur_hf);
353 cur_hf = adjacent_halfface_in_cell(cur_hf, cur_he);
355 if(cur_hf == start_hf)
break;
359 if(std::find(new_halffaces.begin(), new_halffaces.end(), cur_hf) != new_halffaces.end())
break;
361 if(cur_hf != InvalidHalfFaceHandle)
362 new_halffaces.insert(new_halffaces.begin(), cur_hf);
368 if(new_halffaces.size() == incident_hfs_per_he_[cur_he.idx()].size()) {
369 incident_hfs_per_he_[cur_he.idx()] = new_halffaces;
382 for(std::vector<HalfFaceHandle>::const_iterator it = _halffaces.begin(),
383 end = _halffaces.end(); it != end; ++it)
384 assert(it->is_valid() && ((size_t)it->idx() < faces_.size() * 2u));
398 std::set<HalfEdgeHandle> incidentHalfedges;
399 std::set<EdgeHandle> incidentEdges;
401 for(std::vector<HalfFaceHandle>::const_iterator it = _halffaces.begin(),
402 end = _halffaces.end(); it != end; ++it) {
405 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hface.halfedges().begin(),
406 he_end = hface.halfedges().end(); he_it != he_end; ++he_it) {
407 incidentHalfedges.insert(*he_it);
408 incidentEdges.insert(edge_handle(*he_it));
412 if(incidentHalfedges.size() != (incidentEdges.size() * 2u)) {
414 std::cerr <<
"add_cell(): The specified half-faces are not connected!" << std::endl;
416 return InvalidCellHandle;
425 cells_.push_back(cell);
426 cell_deleted_.push_back(
false);
429 resize_cprops(n_cells());
436 std::set<EdgeHandle> cell_edges;
437 for(std::vector<HalfFaceHandle>::const_iterator it = _halffaces.begin(),
438 end = _halffaces.end(); it != end; ++it) {
439 assert((
size_t)it->idx() < incident_cell_per_hf_.size());
443 if(incident_cell_per_hf_[it->idx()] != InvalidCellHandle) {
449 std::cerr <<
"add_cell(): One of the specified half-faces is already incident to another cell!" << std::endl;
455 incident_cell_per_hf_[it->idx()] = ch;
458 const std::vector<HalfEdgeHandle> hes = halfface(*it).halfedges();
459 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin(),
460 he_end = hes.end(); he_it != he_end; ++he_it) {
461 cell_edges.insert(edge_handle(*he_it));
471 for(std::set<EdgeHandle>::const_iterator e_it = cell_edges.begin(),
472 e_end = cell_edges.end(); e_it != e_end; ++e_it) {
473 reorder_incident_halffaces(*e_it);
489 if(has_vertex_bottom_up_incidences()) {
497 std::vector<HalfEdgeHandle>::iterator h_end =
498 std::remove(outgoing_hes_per_vertex_[fv.idx()].begin(), outgoing_hes_per_vertex_[fv.idx()].end(), heh0);
499 outgoing_hes_per_vertex_[fv.idx()].resize(h_end - outgoing_hes_per_vertex_[fv.idx()].begin());
501 h_end = std::remove(outgoing_hes_per_vertex_[tv.idx()].begin(), outgoing_hes_per_vertex_[tv.idx()].end(), heh1);
502 outgoing_hes_per_vertex_[tv.idx()].resize(h_end - outgoing_hes_per_vertex_[tv.idx()].begin());
504 outgoing_hes_per_vertex_[_fromVertex.idx()].push_back(heh0);
505 outgoing_hes_per_vertex_[_toVertex.idx()].push_back(heh1);
508 e.set_from_vertex(_fromVertex);
509 e.set_to_vertex(_toVertex);
519 if(has_edge_bottom_up_incidences()) {
524 const std::vector<HalfEdgeHandle>& hes = f.halfedges();
526 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin(),
527 he_end = hes.end(); he_it != he_end; ++he_it) {
529 std::vector<HalfFaceHandle>::iterator h_end =
530 std::remove(incident_hfs_per_he_[he_it->idx()].begin(),
531 incident_hfs_per_he_[he_it->idx()].end(), hf0);
532 incident_hfs_per_he_[he_it->idx()].resize(h_end - incident_hfs_per_he_[he_it->idx()].begin());
534 h_end = std::remove(incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].begin(),
535 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].end(), hf1);
536 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].resize(h_end - incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].begin());
539 for(std::vector<HalfEdgeHandle>::const_iterator he_it = _hes.begin(),
540 he_end = _hes.end(); he_it != he_end; ++he_it) {
542 incident_hfs_per_he_[he_it->idx()].push_back(hf0);
543 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].push_back(hf1);
549 f.set_halfedges(_hes);
559 if(has_face_bottom_up_incidences()) {
561 const std::vector<HalfFaceHandle>& hfs = c.halffaces();
562 for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin(),
563 hf_end = hfs.end(); hf_it != hf_end; ++hf_it) {
565 incident_cell_per_hf_[hf_it->idx()] = InvalidCellHandle;
568 for(std::vector<HalfFaceHandle>::const_iterator hf_it = _hfs.begin(),
569 hf_end = _hfs.end(); hf_it != hf_end; ++hf_it) {
571 incident_cell_per_hf_[hf_it->idx()] = _ch;
575 c.set_halffaces(_hfs);
594 std::vector<VertexHandle> vs;
597 std::set<EdgeHandle> incidentEdges_s;
598 get_incident_edges(vs, incidentEdges_s);
600 std::set<FaceHandle> incidentFaces_s;
601 get_incident_faces(incidentEdges_s, incidentFaces_s);
603 std::set<CellHandle> incidentCells_s;
604 get_incident_cells(incidentFaces_s, incidentCells_s);
607 for(std::set<CellHandle>::const_reverse_iterator c_it = incidentCells_s.rbegin(),
608 c_end = incidentCells_s.rend(); c_it != c_end; ++c_it) {
609 delete_cell_core(*c_it);
613 for(std::set<FaceHandle>::const_reverse_iterator f_it = incidentFaces_s.rbegin(),
614 f_end = incidentFaces_s.rend(); f_it != f_end; ++f_it) {
615 delete_face_core(*f_it);
619 for(std::set<EdgeHandle>::const_reverse_iterator e_it = incidentEdges_s.rbegin(),
620 e_end = incidentEdges_s.rend(); e_it != e_end; ++e_it) {
621 delete_edge_core(*e_it);
625 return delete_vertex_core(_h);
644 std::vector<EdgeHandle> es;
647 std::set<FaceHandle> incidentFaces_s;
648 get_incident_faces(es, incidentFaces_s);
650 std::set<CellHandle> incidentCells_s;
651 get_incident_cells(incidentFaces_s, incidentCells_s);
654 for(std::set<CellHandle>::const_reverse_iterator c_it = incidentCells_s.rbegin(),
655 c_end = incidentCells_s.rend(); c_it != c_end; ++c_it) {
656 delete_cell_core(*c_it);
660 for(std::set<FaceHandle>::const_reverse_iterator f_it = incidentFaces_s.rbegin(),
661 f_end = incidentFaces_s.rend(); f_it != f_end; ++f_it) {
662 delete_face_core(*f_it);
666 return delete_edge_core(_h);
685 std::vector<FaceHandle> fs;
688 std::set<CellHandle> incidentCells_s;
689 get_incident_cells(fs, incidentCells_s);
692 for(std::set<CellHandle>::const_reverse_iterator c_it = incidentCells_s.rbegin(),
693 c_end = incidentCells_s.rend(); c_it != c_end; ++c_it) {
694 delete_cell_core(*c_it);
698 return delete_face_core(_h);
714 return delete_cell_core(_h);
722 if (!deferred_deletion_enabled() || !needs_garbage_collection())
725 deferred_deletion =
false;
727 for (
int i = (
int)n_cells(); i > 0; --i) {
729 cell_deleted_[i - 1] =
false;
733 n_deleted_cells_ = 0;
735 for (
int i = (
int)n_faces(); i > 0; --i) {
737 face_deleted_[i - 1] =
false;
741 n_deleted_faces_ = 0;
743 for (
int i = (
int)n_edges(); i > 0; --i) {
745 edge_deleted_[i - 1] =
false;
749 n_deleted_edges_ = 0;
751 for (
int i = (
int)n_vertices(); i > 0; --i) {
753 vertex_deleted_[i - 1] =
false;
757 n_deleted_vertices_ = 0;
759 deferred_deletion =
true;
765 template <
class ContainerT>
766 void TopologyKernel::get_incident_edges(
const ContainerT& _vs,
767 std::set<EdgeHandle>& _es)
const {
773 for(
typename ContainerT::const_iterator v_it = _vs.begin(),
774 v_end = _vs.end(); v_it != v_end; ++v_it) {
776 const std::vector<HalfEdgeHandle>& inc_hes = outgoing_hes_per_vertex_[v_it->idx()];
778 for(std::vector<HalfEdgeHandle>::const_iterator he_it = inc_hes.begin(),
779 he_end = inc_hes.end(); he_it != he_end; ++he_it) {
781 _es.insert(edge_handle(*he_it));
786 for(
typename ContainerT::const_iterator v_it = _vs.begin(),
787 v_end = _vs.end(); v_it != v_end; ++v_it) {
789 for(
EdgeIter e_it = edges_begin(), e_end = edges_end(); e_it != e_end; ++e_it) {
791 const Edge& e = edge(*e_it);
793 if(e.from_vertex() == *v_it || e.to_vertex() == *v_it) {
803 template <
class ContainerT>
804 void TopologyKernel::get_incident_faces(
const ContainerT& _es,
805 std::set<FaceHandle>& _fs)
const {
811 for(
typename ContainerT::const_iterator e_it = _es.begin(),
812 e_end = _es.end(); e_it != e_end; ++e_it) {
815 hehf_it.valid(); ++hehf_it) {
819 if(_fs.count(fh) == 0) {
826 for(
typename ContainerT::const_iterator e_it = _es.begin(),
827 e_end = _es.end(); e_it != e_end; ++e_it) {
830 f_end = faces_end(); f_it != f_end; ++f_it) {
832 const std::vector<HalfEdgeHandle>& hes = face(*f_it).halfedges();
834 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin(),
835 he_end = hes.end(); he_it != he_end; ++he_it) {
837 if(edge_handle(*he_it) == *e_it) {
849 template <
class ContainerT>
850 void TopologyKernel::get_incident_cells(
const ContainerT& _fs,
851 std::set<CellHandle>& _cs)
const {
857 for(
typename ContainerT::const_iterator f_it = _fs.begin(),
858 f_end = _fs.end(); f_it != f_end; ++f_it) {
866 if(c0.is_valid()) _cs.insert(c0);
867 if(c1.is_valid()) _cs.insert(c1);
871 for(
typename ContainerT::const_iterator f_it = _fs.begin(),
872 f_end = _fs.end(); f_it != f_end; ++f_it) {
874 for(
CellIter c_it = cells_begin(), c_end = cells_end();
875 c_it != c_end; ++c_it) {
877 const std::vector<HalfFaceHandle>& hfs = cell(*c_it).halffaces();
879 for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin(),
880 hf_end = hfs.end(); hf_it != hf_end; ++hf_it) {
882 if(face_handle(*hf_it) == *f_it) {
914 assert(h.is_valid() && (size_t)h.idx() < n_vertices());
916 if (fast_deletion_enabled() && !deferred_deletion_enabled())
919 assert(!vertex_deleted_[last_undeleted_vertex.idx()]);
920 swap_vertex_indices(h, last_undeleted_vertex);
921 h = last_undeleted_vertex;
924 if (deferred_deletion_enabled())
926 ++n_deleted_vertices_;
927 vertex_deleted_[h.idx()] =
true;
940 for(
int i = h.idx(), end = (int)n_vertices(); i < end; ++i) {
941 const std::vector<HalfEdgeHandle>& hes = outgoing_hes_per_vertex_[i];
942 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin(),
943 he_end = hes.end(); he_it != he_end; ++he_it) {
945 Edge& e = edge(edge_handle(*he_it));
946 if(e.from_vertex().idx() == i) {
949 if(e.to_vertex().idx() == i) {
958 for(
EdgeIter e_it = edges_begin(), e_end = edges_end();
959 e_it != e_end; ++e_it) {
962 if(edge(*e_it).from_vertex() > h) {
963 edge(*e_it).set_from_vertex(
VertexHandle(edge(*e_it).from_vertex().idx() - 1));
965 if(edge(*e_it).to_vertex() > h) {
966 edge(*e_it).set_to_vertex(
VertexHandle(edge(*e_it).to_vertex().idx() - 1));
974 assert((
size_t)h.idx() < outgoing_hes_per_vertex_.size());
975 outgoing_hes_per_vertex_.erase(outgoing_hes_per_vertex_.begin() + h.idx());
982 vertex_deleted_.erase(vertex_deleted_.begin() + h.idx());
1020 assert(h.is_valid() && (size_t)h.idx() < edges_.size());
1022 if (fast_deletion_enabled() && !deferred_deletion_enabled())
1025 assert(!edge_deleted_[last_edge.idx()]);
1026 swap_edge_indices(h, last_edge);
1036 assert(v0.is_valid() && (size_t)v0.idx() < outgoing_hes_per_vertex_.size());
1037 assert(v1.is_valid() && (size_t)v1.idx() < outgoing_hes_per_vertex_.size());
1039 outgoing_hes_per_vertex_[v0.idx()].erase(
1040 std::remove(outgoing_hes_per_vertex_[v0.idx()].begin(),
1041 outgoing_hes_per_vertex_[v0.idx()].end(),
1042 halfedge_handle(h, 0)),
1043 outgoing_hes_per_vertex_[v0.idx()].end());
1045 outgoing_hes_per_vertex_[v1.idx()].erase(
1046 std::remove(outgoing_hes_per_vertex_[v1.idx()].begin(),
1047 outgoing_hes_per_vertex_[v1.idx()].end(),
1048 halfedge_handle(h, 1)),
1049 outgoing_hes_per_vertex_[v1.idx()].end());
1052 if (deferred_deletion_enabled())
1055 edge_deleted_[h.idx()] =
true;
1065 if (!fast_deletion_enabled())
1070 assert((
size_t)halfedge_handle(h, 0).idx() < incident_hfs_per_he_.size());
1075 std::set<FaceHandle> update_faces;
1076 for(std::vector<std::vector<HalfFaceHandle> >::const_iterator iit =
1077 (incident_hfs_per_he_.begin() + halfedge_handle(h, 0).idx()),
1078 iit_end = incident_hfs_per_he_.end(); iit != iit_end; ++iit) {
1079 for(std::vector<HalfFaceHandle>::const_iterator it = iit->begin(),
1080 end = iit->end(); it != end; ++it) {
1081 update_faces.insert(face_handle(*it));
1086 for(std::set<FaceHandle>::iterator f_it = update_faces.begin(),
1087 f_end = update_faces.end(); f_it != f_end; ++f_it) {
1089 std::vector<HalfEdgeHandle> hes = face(*f_it).halfedges();
1092 hes.erase(std::remove(hes.begin(), hes.end(), halfedge_handle(h, 0)), hes.end());
1093 hes.erase(std::remove(hes.begin(), hes.end(), halfedge_handle(h, 1)), hes.end());
1095 #if defined(__clang_major__) && (__clang_major__ >= 5) 1096 for(std::vector<HalfEdgeHandle>::iterator it = hes.begin(), end = hes.end();
1098 cor.correctValue(*it);
1101 std::for_each(hes.begin(), hes.end(),
1102 fun::bind(&HEHandleCorrection::correctValue, &cor, fun::placeholders::_1));
1104 face(*f_it).set_halfedges(hes);
1109 for(
FaceIter f_it = faces_begin(), f_end = faces_end();
1110 f_it != f_end; ++f_it) {
1113 std::vector<HalfEdgeHandle> hes = face(*f_it).halfedges();
1116 hes.erase(std::remove(hes.begin(), hes.end(), halfedge_handle(h, 0)), hes.end());
1117 hes.erase(std::remove(hes.begin(), hes.end(), halfedge_handle(h, 1)), hes.end());
1121 #if defined(__clang_major__) && (__clang_major__ >= 5) 1122 for(std::vector<HalfEdgeHandle>::iterator it = hes.begin(), end = hes.end();
1124 cor.correctValue(*it);
1127 std::for_each(hes.begin(), hes.end(),
1128 fun::bind(&HEHandleCorrection::correctValue, &cor, fun::placeholders::_1));
1130 face(*f_it).set_halfedges(hes);
1138 assert((
size_t)halfedge_handle(h, 1).idx() < incident_hfs_per_he_.size());
1140 incident_hfs_per_he_.erase(incident_hfs_per_he_.begin() + halfedge_handle(h, 1).idx());
1141 incident_hfs_per_he_.erase(incident_hfs_per_he_.begin() + halfedge_handle(h, 0).idx());
1144 if (!fast_deletion_enabled())
1149 #if defined(__clang_major__) && (__clang_major__ >= 5) 1150 for(std::vector<std::vector<HalfEdgeHandle> >::iterator it = outgoing_hes_per_vertex_.begin(),
1151 end = outgoing_hes_per_vertex_.end(); it != end; ++it) {
1152 cor.correctVecValue(*it);
1155 std::for_each(outgoing_hes_per_vertex_.begin(),
1156 outgoing_hes_per_vertex_.end(),
1157 fun::bind(&HEHandleCorrection::correctVecValue, &cor, fun::placeholders::_1));
1164 edges_.erase(edges_.begin() + h.idx());
1165 edge_deleted_.erase(edge_deleted_.begin() + h.idx());
1204 assert(h.is_valid() && (size_t)h.idx() < faces_.size());
1207 if (fast_deletion_enabled() && !deferred_deletion_enabled())
1210 assert(!face_deleted_[last_face.idx()]);
1211 swap_face_indices(h, last_face);
1218 const std::vector<HalfEdgeHandle>& hes = face(h).halfedges();
1219 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin(),
1220 he_end = hes.end(); he_it != he_end; ++he_it) {
1222 assert((
size_t)std::max(he_it->idx(), opposite_halfedge_handle(*he_it).idx()) < incident_hfs_per_he_.size());
1224 incident_hfs_per_he_[he_it->idx()].erase(
1225 std::remove(incident_hfs_per_he_[he_it->idx()].begin(),
1226 incident_hfs_per_he_[he_it->idx()].end(),
1227 halfface_handle(h, 0)), incident_hfs_per_he_[he_it->idx()].end());
1230 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].erase(
1231 std::remove(incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].begin(),
1232 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].end(),
1233 halfface_handle(h, 1)), incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].end());
1237 if (deferred_deletion_enabled())
1240 face_deleted_[h.idx()] =
true;
1250 if (!fast_deletion_enabled())
1257 std::set<CellHandle> update_cells;
1258 for(std::vector<CellHandle>::const_iterator c_it = (incident_cell_per_hf_.begin() + halfface_handle(h, 0).idx()),
1259 c_end = incident_cell_per_hf_.end(); c_it != c_end; ++c_it) {
1260 if(!c_it->is_valid())
continue;
1261 update_cells.insert(*c_it);
1263 for(std::set<CellHandle>::const_iterator c_it = update_cells.begin(),
1264 c_end = update_cells.end(); c_it != c_end; ++c_it) {
1266 std::vector<HalfFaceHandle> hfs = cell(*c_it).halffaces();
1269 hfs.erase(std::remove(hfs.begin(), hfs.end(), halfface_handle(h, 0)), hfs.end());
1270 hfs.erase(std::remove(hfs.begin(), hfs.end(), halfface_handle(h, 1)), hfs.end());
1273 #if defined(__clang_major__) && (__clang_major__ >= 5) 1274 for(std::vector<HalfFaceHandle>::iterator it = hfs.begin(),
1275 end = hfs.end(); it != end; ++it) {
1276 cor.correctValue(*it);
1279 std::for_each(hfs.begin(), hfs.end(),
1280 fun::bind(&HFHandleCorrection::correctValue, &cor, fun::placeholders::_1));
1282 cell(*c_it).set_halffaces(hfs);
1288 for(
CellIter c_it = cells_begin(), c_end = cells_end(); c_it != c_end; ++c_it) {
1290 std::vector<HalfFaceHandle> hfs = cell(*c_it).halffaces();
1293 hfs.erase(std::remove(hfs.begin(), hfs.end(), halfface_handle(h, 0)), hfs.end());
1294 hfs.erase(std::remove(hfs.begin(), hfs.end(), halfface_handle(h, 1)), hfs.end());
1297 #if defined(__clang_major__) && (__clang_major__ >= 5) 1298 for(std::vector<HalfFaceHandle>::iterator it = hfs.begin(),
1299 end = hfs.end(); it != end; ++it) {
1300 cor.correctValue(*it);
1303 std::for_each(hfs.begin(), hfs.end(),
1304 fun::bind(&HFHandleCorrection::correctValue, &cor, fun::placeholders::_1));
1306 cell(*c_it).set_halffaces(hfs);
1314 assert((
size_t)halfface_handle(h, 1).idx() < incident_cell_per_hf_.size());
1316 incident_cell_per_hf_.erase(incident_cell_per_hf_.begin() + halfface_handle(h, 1).idx());
1317 incident_cell_per_hf_.erase(incident_cell_per_hf_.begin() + halfface_handle(h, 0).idx());
1321 if (!fast_deletion_enabled())
1326 #if defined(__clang_major__) && (__clang_major__ >= 5) 1327 for(std::vector<std::vector<HalfFaceHandle> >::iterator it = incident_hfs_per_he_.begin(), end = incident_hfs_per_he_.end(); it != end; ++it) {
1328 cor.correctVecValue(*it);
1331 std::for_each(incident_hfs_per_he_.begin(),
1332 incident_hfs_per_he_.end(),
1333 fun::bind(&HFHandleCorrection::correctVecValue, &cor, fun::placeholders::_1));
1339 faces_.erase(faces_.begin() + h.idx());
1340 face_deleted_.erase(face_deleted_.begin() + h.idx());
1373 assert(h.is_valid() && (size_t)h.idx() < cells_.size());
1376 if (fast_deletion_enabled() && !deferred_deletion_enabled())
1379 assert(!cell_deleted_[last_undeleted_cell.idx()]);
1380 swap_cell_indices(h, last_undeleted_cell);
1381 h = last_undeleted_cell;
1387 const std::vector<HalfFaceHandle>& hfs = cell(h).halffaces();
1388 for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin(),
1389 hf_end = hfs.end(); hf_it != hf_end; ++hf_it) {
1390 assert((
size_t)hf_it->idx() < incident_cell_per_hf_.size());
1391 if (incident_cell_per_hf_[hf_it->idx()] == h)
1392 incident_cell_per_hf_[hf_it->idx()] = InvalidCellHandle;
1396 if (deferred_deletion_enabled())
1399 cell_deleted_[h.idx()] =
true;
1409 if (!fast_deletion_enabled())
1413 #if defined(__clang_major__) && (__clang_major__ >= 5) 1414 for(std::vector<CellHandle>::iterator it = incident_cell_per_hf_.begin(),
1415 end = incident_cell_per_hf_.end(); it != end; ++it) {
1416 cor.correctValue(*it);
1419 std::for_each(incident_cell_per_hf_.begin(),
1420 incident_cell_per_hf_.end(),
1421 fun::bind(&CHandleCorrection::correctValue, &cor, fun::placeholders::_1));
1427 cells_.erase(cells_.begin() + h.idx());
1428 cell_deleted_.erase(cell_deleted_.begin() + h.idx());
1441 assert(_h1.idx() >= 0 && _h1.idx() < (int)cells_.size());
1442 assert(_h2.idx() >= 0 && _h2.idx() < (int)cells_.size());
1447 int id1 = _h1.idx();
1448 int id2 = _h2.idx();
1450 Cell c1 = cells_[id1];
1451 Cell c2 = cells_[id2];
1454 std::vector<HalfFaceHandle> hfhs1 = c1.halffaces();
1455 for (
unsigned int i = 0; i < hfhs1.size(); ++i)
1458 if (incident_cell_per_hf_[hfh.idx()] == _h1)
1459 incident_cell_per_hf_[hfh.idx()] = _h2;
1462 std::vector<HalfFaceHandle> hfhs2 = c2.halffaces();
1463 for (
unsigned int i = 0; i < hfhs2.size(); ++i)
1466 if (incident_cell_per_hf_[hfh.idx()] == _h2)
1467 incident_cell_per_hf_[hfh.idx()] = _h1;
1471 std::swap(cells_[id1], cells_[id2]);
1472 bool tmp = cell_deleted_[id1];
1473 cell_deleted_[id1] = cell_deleted_[id2];
1474 cell_deleted_[id2] = tmp;
1475 swap_cell_properties(_h1, _h2);
1480 assert(_h1.idx() >= 0 && _h1.idx() < (int)faces_.size());
1481 assert(_h2.idx() >= 0 && _h2.idx() < (int)faces_.size());
1487 std::vector<unsigned int> ids;
1488 ids.push_back(_h1.idx());
1489 ids.push_back(_h2.idx());
1491 unsigned int id1 = _h1.idx();
1492 unsigned int id2 = _h2.idx();
1497 if (has_face_bottom_up_incidences())
1499 std::set<unsigned int> processed_cells;
1500 for (
unsigned int i = 0; i < 2; ++i)
1502 unsigned int id = ids[i];
1503 for (
unsigned int j = 0; j < 2; ++j)
1506 CellHandle ch = incident_cell_per_hf_[hfh.idx()];
1512 if (processed_cells.find(ch.idx()) == processed_cells.end())
1515 Cell& c = cells_[ch.idx()];
1519 std::vector<HalfFaceHandle> new_halffaces;
1520 for (
unsigned int k = 0; k < c.halffaces().size(); ++k)
1521 if (c.halffaces()[k].idx()/2 == (int)id1)
1522 new_halffaces.push_back(
HalfFaceHandle(2 * id2 + (c.halffaces()[k].idx() % 2)));
1523 else if (c.halffaces()[k].idx()/2 == (int)id2)
1524 new_halffaces.push_back(
HalfFaceHandle(2 * id1 + (c.halffaces()[k].idx() % 2)));
1526 new_halffaces.push_back(c.halffaces()[k]);
1527 c.set_halffaces(new_halffaces);
1529 processed_cells.insert(ch.idx());
1537 for (
unsigned int i = 0; i < cells_.size(); ++i)
1539 Cell& c = cells_[i];
1542 bool contains_swapped_face =
false;
1543 for (
unsigned int k = 0; k < c.halffaces().size(); ++k)
1545 if (c.halffaces()[k].idx()/2 == (int)id1)
1546 contains_swapped_face =
true;
1547 if (c.halffaces()[k].idx()/2 == (int)id2)
1548 contains_swapped_face =
true;
1549 if (contains_swapped_face)
1553 if (contains_swapped_face)
1556 std::vector<HalfFaceHandle> new_halffaces;
1557 for (
unsigned int k = 0; k < c.halffaces().size(); ++k)
1558 if (c.halffaces()[k].idx()/2 == (int)id1)
1559 new_halffaces.push_back(
HalfFaceHandle(2 * id2 + (c.halffaces()[k].idx() % 2)));
1560 else if (c.halffaces()[k].idx()/2 == (int)id2)
1561 new_halffaces.push_back(
HalfFaceHandle(2 * id1 + (c.halffaces()[k].idx() % 2)));
1563 new_halffaces.push_back(c.halffaces()[k]);
1564 c.set_halffaces(new_halffaces);
1571 if (has_edge_bottom_up_incidences())
1573 std::set<HalfEdgeHandle> processed_halfedges;
1574 for (
unsigned int i = 0; i < 2; ++i)
1576 unsigned int id = ids[i];
1577 for (
unsigned int j = 0; j < 2; ++j)
1580 Face hf = halfface(hfh);
1582 for (
unsigned int k = 0; k < hf.halfedges().size(); ++k)
1586 if (processed_halfedges.find(heh) != processed_halfedges.end())
1589 std::vector<HalfFaceHandle>& incident_halffaces = incident_hfs_per_he_[heh.idx()];
1590 for (
unsigned int l = 0; l < incident_halffaces.size(); ++l)
1594 if (hfh2.idx()/2 == (int)id1)
1596 else if (hfh2.idx()/2 == (int)id2)
1600 processed_halfedges.insert(heh);
1607 std::swap(faces_[ids[0]], faces_[ids[1]]);
1608 bool tmp = face_deleted_[ids[0]];
1609 face_deleted_[ids[0]] = face_deleted_[ids[1]];
1610 face_deleted_[ids[1]] = tmp;
1611 std::swap(incident_cell_per_hf_[2*ids[0]+0], incident_cell_per_hf_[2*ids[1]+0]);
1612 std::swap(incident_cell_per_hf_[2*ids[0]+1], incident_cell_per_hf_[2*ids[1]+1]);
1613 swap_face_properties(_h1, _h2);
1614 swap_halfface_properties(halfface_handle(_h1, 0), halfface_handle(_h2, 0));
1615 swap_halfface_properties(halfface_handle(_h1, 1), halfface_handle(_h2, 1));
1621 assert(_h1.idx() >= 0 && _h1.idx() < (int)edges_.size());
1622 assert(_h2.idx() >= 0 && _h2.idx() < (int)edges_.size());
1627 std::vector<unsigned int> ids;
1628 ids.push_back(_h1.idx());
1629 ids.push_back(_h2.idx());
1634 if (has_edge_bottom_up_incidences())
1636 std::set<unsigned int> processed_faces;
1638 for (
unsigned int i = 0; i < 2; ++i)
1643 std::vector<HalfFaceHandle>& incident_halffaces = incident_hfs_per_he_[heh.idx()];
1644 for (
unsigned int j = 0; j < incident_halffaces.size(); ++j)
1648 unsigned int f_id = hfh.idx() / 2;
1650 if (processed_faces.find(f_id) == processed_faces.end())
1653 Face& f = faces_[f_id];
1656 std::vector<HalfEdgeHandle> new_halfedges;
1657 for (
unsigned int k = 0; k < f.halfedges().size(); ++k)
1660 if (heh2.idx() / 2 == (int)ids[0])
1661 new_halfedges.push_back(
HalfEdgeHandle(2*ids[1] + (heh2.idx() % 2)));
1662 else if (heh2.idx() / 2 == (int)ids[1])
1663 new_halfedges.push_back(
HalfEdgeHandle(2*ids[0] + (heh2.idx() % 2)));
1665 new_halfedges.push_back(heh2);
1667 f.set_halfedges(new_halfedges);
1669 processed_faces.insert(f_id);
1677 for (
unsigned int i = 0; i < faces_.size(); ++i)
1679 Face& f = faces_[i];
1682 bool contains_swapped_edge =
false;
1683 for (
unsigned int k = 0; k < f.halfedges().size(); ++k)
1685 if (f.halfedges()[k].idx()/2 == (int)ids[0])
1686 contains_swapped_edge =
true;
1687 if (f.halfedges()[k].idx()/2 == (int)ids[1])
1688 contains_swapped_edge =
true;
1689 if (contains_swapped_edge)
1693 if (contains_swapped_edge)
1696 std::vector<HalfEdgeHandle> new_halfedges;
1697 for (
unsigned int k = 0; k < f.halfedges().size(); ++k)
1700 if (heh2.idx() / 2 == (int)ids[0])
1701 new_halfedges.push_back(
HalfEdgeHandle(2*ids[1] + (heh2.idx() % 2)));
1702 else if (heh2.idx() / 2 == (int)ids[1])
1703 new_halfedges.push_back(
HalfEdgeHandle(2*ids[0] + (heh2.idx() % 2)));
1705 new_halfedges.push_back(heh2);
1707 f.set_halfedges(new_halfedges);
1714 if (has_vertex_bottom_up_incidences())
1716 std::set<VertexHandle> processed_vertices;
1717 for (
unsigned int i = 0; i < 2; ++i)
1720 std::vector<VertexHandle> vhs;
1721 vhs.push_back(e.from_vertex());
1722 vhs.push_back(e.to_vertex());
1724 for (
unsigned int j = 0; j < 2; ++j)
1726 if (processed_vertices.find(vhs[j]) != processed_vertices.end())
1729 std::vector<HalfEdgeHandle>& outgoing_hes = outgoing_hes_per_vertex_[vhs[j].idx()];
1730 for (
unsigned int k = 0; k < outgoing_hes.size(); ++k)
1733 if (heh.idx() / 2 == (int)ids[0])
1735 else if (heh.idx() / 2 == (int)ids[1])
1738 processed_vertices.insert(vhs[j]);
1745 std::swap(edges_[ids[0]], edges_[ids[1]]);
1746 bool tmp = edge_deleted_[ids[0]];
1747 edge_deleted_[ids[0]] = edge_deleted_[ids[1]];
1748 edge_deleted_[ids[1]] = tmp;
1749 std::swap(incident_hfs_per_he_[2*ids[0]+0], incident_hfs_per_he_[2*ids[1]+0]);
1750 std::swap(incident_hfs_per_he_[2*ids[0]+1], incident_hfs_per_he_[2*ids[1]+1]);
1751 swap_edge_properties(_h1, _h2);
1752 swap_halfedge_properties(halfedge_handle(_h1, 0), halfedge_handle(_h2, 0));
1753 swap_halfedge_properties(halfedge_handle(_h1, 1), halfedge_handle(_h2, 1));
1759 assert(_h1.idx() >= 0 && _h1.idx() < (int)n_vertices_);
1760 assert(_h2.idx() >= 0 && _h2.idx() < (int)n_vertices_);
1765 std::vector<unsigned int> ids;
1766 ids.push_back(_h1.idx());
1767 ids.push_back(_h2.idx());
1772 if (has_vertex_bottom_up_incidences())
1774 for (
unsigned int i = 0; i < 2; ++i)
1776 std::set<unsigned int> processed_edges;
1777 std::vector<HalfEdgeHandle>& outgoing_hes = outgoing_hes_per_vertex_[ids[i]];
1778 for (
unsigned int k = 0; k < outgoing_hes.size(); ++k)
1780 unsigned int e_id = outgoing_hes[k].idx() / 2;
1782 if (processed_edges.find(e_id) == processed_edges.end())
1784 Edge& e = edges_[e_id];
1785 if (e.from_vertex().idx() == (int)ids[0])
1787 else if (e.from_vertex().idx() == (int)ids[1])
1790 if (e.to_vertex().idx() == (int)ids[0])
1792 else if (e.to_vertex().idx() == (int)ids[1])
1795 processed_edges.insert(e_id);
1805 for (
unsigned int i = 0; i < edges_.size(); ++i)
1807 Edge& e = edges_[i];
1808 if (e.from_vertex().idx() == (int)ids[0])
1810 else if (e.from_vertex().idx() == (int)ids[1])
1813 if (e.to_vertex().idx() == (int)ids[0])
1815 else if (e.to_vertex().idx() == (int)ids[1])
1821 bool tmp = vertex_deleted_[ids[0]];
1822 vertex_deleted_[ids[0]] = vertex_deleted_[ids[1]];
1823 vertex_deleted_[ids[1]] = tmp;
1824 std::swap(outgoing_hes_per_vertex_[ids[0]], outgoing_hes_per_vertex_[ids[1]]);
1825 swap_vertex_properties(_h1, _h2);
1830 void TopologyKernel::delete_multiple_vertices(
const std::vector<bool>& _tag) {
1832 assert(_tag.size() == n_vertices());
1834 std::vector<int> newIndices(n_vertices(), -1);
1837 std::vector<int>::iterator idx_it = newIndices.begin();
1838 for(std::vector<bool>::const_iterator t_it = _tag.begin(),
1839 t_end = _tag.end(); t_it != t_end; ++t_it, ++idx_it) {
1851 delete_multiple_vertex_props(_tag);
1854 std::for_each(edges_.begin(), edges_.end(), corrector);
1859 void TopologyKernel::delete_multiple_edges(
const std::vector<bool>& _tag) {
1861 assert(_tag.size() == n_edges());
1863 std::vector<int> newIndices(n_edges(), -1);
1866 std::vector<Edge> newEdges;
1868 std::vector<int>::iterator idx_it = newIndices.begin();
1869 std::vector<Edge>::const_iterator e_it = edges_.begin();
1871 for(std::vector<bool>::const_iterator t_it = _tag.begin(),
1872 t_end = _tag.end(); t_it != t_end; ++t_it, ++idx_it, ++e_it) {
1877 newEdges.push_back(*e_it);
1885 edges_.swap(newEdges);
1888 delete_multiple_edge_props(_tag);
1891 std::for_each(faces_.begin(), faces_.end(), corrector);
1896 void TopologyKernel::delete_multiple_faces(
const std::vector<bool>& _tag) {
1898 assert(_tag.size() == n_faces());
1900 std::vector<int> newIndices(n_faces(), -1);
1903 std::vector<Face> newFaces;
1905 std::vector<int>::iterator idx_it = newIndices.begin();
1906 std::vector<Face>::const_iterator f_it = faces_.begin();
1908 for(std::vector<bool>::const_iterator t_it = _tag.begin(),
1909 t_end = _tag.end(); t_it != t_end; ++t_it, ++idx_it, ++f_it) {
1914 newFaces.push_back(*f_it);
1922 faces_.swap(newFaces);
1925 delete_multiple_face_props(_tag);
1928 std::for_each(cells_.begin(), cells_.end(), corrector);
1933 void TopologyKernel::delete_multiple_cells(
const std::vector<bool>& _tag) {
1935 assert(_tag.size() == n_cells());
1937 std::vector<Cell> newCells;
1939 std::vector<Cell>::const_iterator c_it = cells_.begin();
1941 for(std::vector<bool>::const_iterator t_it = _tag.begin(),
1942 t_end = _tag.end(); t_it != t_end; ++t_it, ++c_it) {
1947 newCells.push_back(*c_it);
1952 cells_.swap(newCells);
1955 delete_multiple_cell_props(_tag);
1962 assert(_first >= cells_begin());
1963 assert(_last <= cells_end());
1965 std::vector<Cell>::iterator it = cells_.erase(cells_.begin() + _first->idx(), cells_.begin() + _last->idx());
1969 f_bottom_up_ =
false;
1970 enable_face_bottom_up_incidences(
true);
1976 void TopologyKernel::enable_deferred_deletion(
bool _enable)
1978 if (deferred_deletion && !_enable)
1981 deferred_deletion = _enable;
1990 assert(_edgeHandle.is_valid() && (size_t)_edgeHandle.idx() < edges_.size());
1992 return edges_[_edgeHandle.idx()];
2001 assert(_faceHandle.is_valid() && (size_t)_faceHandle.idx() < faces_.size());
2003 return faces_[_faceHandle.idx()];
2012 assert(_cellHandle.is_valid() && (size_t)_cellHandle.idx() < cells_.size());
2014 return cells_[_cellHandle.idx()];
2023 assert(_edgeHandle.is_valid() && (size_t)_edgeHandle.idx() < edges_.size());
2025 return edges_[_edgeHandle.idx()];
2034 assert((
size_t)_faceHandle.idx() < faces_.size());
2035 assert(_faceHandle.idx() >= 0);
2037 return faces_[_faceHandle.idx()];
2046 assert((
size_t)_cellHandle.idx() < cells_.size());
2047 assert(_cellHandle.idx() >= 0);
2049 return cells_[_cellHandle.idx()];
2058 assert((
size_t)_halfEdgeHandle.idx() < (edges_.size() * 2));
2059 assert(_halfEdgeHandle.idx() >= 0);
2063 if(_halfEdgeHandle.idx() % 2 == 0)
2064 return edges_[(
int)(_halfEdgeHandle.idx() / 2)];
2066 return opposite_halfedge(edges_[(
int)(_halfEdgeHandle.idx() / 2)]);
2075 assert((
size_t)_halfFaceHandle.idx() < (faces_.size() * 2));
2076 assert(_halfFaceHandle.idx() >= 0);
2080 if(_halfFaceHandle.idx() % 2 == 0)
2081 return faces_[(
int)(_halfFaceHandle.idx() / 2)];
2083 return opposite_halfface(faces_[(
int)(_halfFaceHandle.idx() / 2)]);
2092 assert(_halfEdgeHandle.idx() >= 0);
2093 assert((
size_t)_halfEdgeHandle.idx() < (edges_.size() * 2));
2097 if(_halfEdgeHandle.idx() % 2 != 0)
2098 return edges_[(
int)(_halfEdgeHandle.idx() / 2)];
2100 return opposite_halfedge(edges_[(
int)(_halfEdgeHandle.idx() / 2)]);
2109 assert(_halfFaceHandle.idx() >= 0);
2110 assert((
size_t)_halfFaceHandle.idx() < (faces_.size() * 2));
2114 if(_halfFaceHandle.idx() % 2 != 0)
2115 return faces_[(
int)(_halfFaceHandle.idx() / 2)];
2117 return opposite_halfface(faces_[(
int)(_halfFaceHandle.idx() / 2)]);
2124 assert(_vh1.idx() < (int)n_vertices());
2125 assert(_vh2.idx() < (int)n_vertices());
2128 if(halfedge(*voh_it).to_vertex() == _vh2) {
2133 return InvalidHalfEdgeHandle;
2140 assert(_vs.size() > 2);
2144 assert(v0.is_valid() && v1.is_valid() && v2.is_valid());
2147 if(!he0.is_valid())
return InvalidHalfFaceHandle;
2149 if(!he1.is_valid())
return InvalidHalfFaceHandle;
2151 std::vector<HalfEdgeHandle> hes;
2155 return halfface(hes);
2162 assert(_vs.size() > 2);
2167 assert(v0.is_valid() && v1.is_valid());
2170 if(!he0.is_valid())
return InvalidHalfFaceHandle;
2174 std::vector<HalfEdgeHandle> hes = halfface(*hehf_it).halfedges();
2176 if (hes.size() != _vs.size())
2180 for (
unsigned int i = 0; i < hes.size(); ++i)
2184 bool all_vertices_found =
true;
2186 for (
unsigned int i = 0; i < hes.size(); ++i)
2189 if (halfedge(heh).from_vertex() != _vs[i])
2191 all_vertices_found =
false;
2196 if (all_vertices_found)
2200 return InvalidHalfFaceHandle;
2207 assert(_hes.size() >= 2);
2211 assert(he0.is_valid() && he1.is_valid());
2215 std::vector<HalfEdgeHandle> hes = halfface(*hehf_it).halfedges();
2216 if(std::find(hes.begin(), hes.end(), he1) != hes.end()) {
2221 return InvalidHalfFaceHandle;
2228 assert(_heh.is_valid() && (size_t)_heh.idx() < edges_.size() * 2u);
2229 assert(_hfh.is_valid() && (size_t)_hfh.idx() < faces_.size() * 2u);
2231 std::vector<HalfEdgeHandle> hes = halfface(_hfh).halfedges();
2233 for(std::vector<HalfEdgeHandle>::const_iterator it = hes.begin();
2234 it != hes.end(); ++it) {
2236 if((it + 1) != hes.end())
return *(it + 1);
2237 else return *hes.begin();
2241 return InvalidHalfEdgeHandle;
2248 assert(_heh.is_valid() && (size_t)_heh.idx() < edges_.size() * 2u);
2249 assert(_hfh.is_valid() && (size_t)_hfh.idx() < faces_.size() * 2u);
2251 std::vector<HalfEdgeHandle> hes = halfface(_hfh).halfedges();
2253 for(std::vector<HalfEdgeHandle>::const_iterator it = hes.begin();
2254 it != hes.end(); ++it) {
2256 if(it != hes.begin())
return *(it - 1);
2257 else return *(hes.end() - 1);
2261 return InvalidHalfEdgeHandle;
2269 assert(_halfFaceHandle.is_valid() && (size_t)_halfFaceHandle.idx() < faces_.size() * 2u);
2270 assert(_halfEdgeHandle.is_valid() && (size_t)_halfEdgeHandle.idx() < edges_.size() * 2u);
2271 assert(has_face_bottom_up_incidences());
2272 assert((
size_t)_halfFaceHandle.idx() < incident_cell_per_hf_.size());
2274 if(incident_cell_per_hf_[_halfFaceHandle.idx()] == InvalidCellHandle) {
2276 return InvalidHalfFaceHandle;
2282 bool skipped =
false;
2285 for(std::vector<HalfFaceHandle>::const_iterator hf_it = c.halffaces().begin();
2286 hf_it != c.halffaces().end(); ++hf_it) {
2288 if(*hf_it == _halfFaceHandle) {
2294 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hf.halfedges().begin();
2295 he_it != hf.halfedges().end(); ++he_it) {
2297 if(edge_handle(*he_it) == edge_handle(_halfEdgeHandle)) {
2301 if(skipped && found)
break;
2303 if(skipped && found)
break;
2305 return ((skipped && found) ? idx : InvalidHalfFaceHandle);
2312 if(!has_face_bottom_up_incidences()) {
2313 return InvalidCellHandle;
2315 if((
size_t)_halfFaceHandle.idx() >= incident_cell_per_hf_.size() || _halfFaceHandle.idx() < 0) {
2316 return InvalidCellHandle;
2319 return incident_cell_per_hf_[_halfFaceHandle.idx()];
2324 void TopologyKernel::compute_vertex_bottom_up_incidences() {
2327 outgoing_hes_per_vertex_.clear();
2328 outgoing_hes_per_vertex_.resize(n_vertices());
2331 int n_edges = (int)edges_.size();
2332 for(
int i = 0; i < n_edges; ++i) {
2333 if (edge_deleted_[i])
2339 assert((
size_t)from.idx() < outgoing_hes_per_vertex_.size());
2341 outgoing_hes_per_vertex_[from.idx()].push_back(halfedge_handle(
EdgeHandle(i), 0));
2344 assert((
size_t)to.idx() < outgoing_hes_per_vertex_.size());
2347 outgoing_hes_per_vertex_[to.idx()].push_back(halfedge_handle(
EdgeHandle(i), 1));
2353 void TopologyKernel::compute_edge_bottom_up_incidences() {
2356 incident_hfs_per_he_.clear();
2357 incident_hfs_per_he_.resize(edges_.size() * 2u);
2360 int n_faces = (int)faces_.size();
2361 for(
int i = 0; i < n_faces; ++i) {
2362 if (face_deleted_[i])
2365 std::vector<HalfEdgeHandle> halfedges = faces_[i].halfedges();
2368 for(std::vector<HalfEdgeHandle>::const_iterator he_it = halfedges.begin();
2369 he_it != halfedges.end(); ++he_it) {
2371 incident_hfs_per_he_[he_it->idx()].push_back(halfface_handle(
FaceHandle(i), 0));
2372 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].push_back(
2380 void TopologyKernel::compute_face_bottom_up_incidences() {
2383 incident_cell_per_hf_.clear();
2384 incident_cell_per_hf_.resize(faces_.size() * 2u, InvalidCellHandle);
2386 int n_cells = (int)cells_.size();
2387 for(
int i = 0; i < n_cells; ++i) {
2388 if (cell_deleted_[i])
2391 std::vector<HalfFaceHandle> halffaces = cells_[i].halffaces();
2394 for(std::vector<HalfFaceHandle>::const_iterator hf_it = halffaces.begin();
2395 hf_it != halffaces.end(); ++hf_it) {
2397 if(incident_cell_per_hf_[hf_it->idx()] == InvalidCellHandle) {
2399 incident_cell_per_hf_[hf_it->idx()] =
CellHandle(i);
2404 std::cerr <<
"compute_face_bottom_up_incidences(): Detected non-three-manifold configuration!" << std::endl;
2405 std::cerr <<
"Connectivity probably won't work." << std::endl;
bool bind(osg::GeometryPtr &_geo, Mesh &_mesh)
virtual void swap_vertex_indices(VertexHandle _h1, VertexHandle _h2)
Exchanges the indices of two vertices while keeping the mesh otherwise unaffected.
const Edge & edge(const EdgeHandle &_edgeHandle) const
Get edge with handle _edgeHandle.
CellIter delete_cell_range(const CellIter &_first, const CellIter &_last)
Delete range of cells.
FaceIter delete_face_core(const FaceHandle &_h)
Delete face from mesh.
virtual VertexIter delete_vertex(const VertexHandle &_h)
Delete vertex from mesh.
const Cell & cell(const CellHandle &_cellHandle) const
Get cell with handle _cellHandle.
Edge opposite_halfedge(const HalfEdgeHandle &_halfEdgeHandle) const
Get opposite halfedge that corresponds to halfedge with handle _halfEdgeHandle.
VertexIter delete_vertex_core(const VertexHandle &_h)
Delete vertex from mesh.
virtual FaceHandle add_face(const std::vector< HalfEdgeHandle > &_halfedges, bool _topologyCheck=false)
Add face via incident edges.
virtual EdgeHandle add_edge(const VertexHandle &_fromVertex, const VertexHandle &_toHandle, bool _allowDuplicates=false)
Add edge.
virtual FaceIter delete_face(const FaceHandle &_h)
Delete face from mesh.
virtual void swap_cell_indices(CellHandle _h1, CellHandle _h2)
Exchanges the indices of two cells while keeping the mesh otherwise unaffected.
Face opposite_halfface(const HalfFaceHandle &_halfFaceHandle) const
Get opposite halfface that corresponds to halfface with handle _halfFaceHandle.
EdgeIter delete_edge_core(const EdgeHandle &_h)
Delete edge from mesh.
Face halfface(const HalfFaceHandle &_halfFaceHandle) const
Get face that corresponds to halfface with handle _halfFaceHandle.
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.
virtual CellHandle add_cell(const std::vector< HalfFaceHandle > &_halffaces, bool _topologyCheck=false)
Add cell via incident halffaces.
void set_cell(const CellHandle &_ch, const std::vector< HalfFaceHandle > &_hfs)
Set the half-faces of a cell.
virtual void collect_garbage()
Delete all entities that are marked as deleted.
HalfEdgeHandle prev_halfedge_in_halfface(const HalfEdgeHandle &_heh, const HalfFaceHandle &_hfh) const
Get previous halfedge within a halfface.
const Face & face(const FaceHandle &_faceHandle) const
Get face with handle _faceHandle.
void set_face(const FaceHandle &_fh, const std::vector< HalfEdgeHandle > &_hes)
Set the half-edges of a face.
void set_edge(const EdgeHandle &_eh, const VertexHandle &_fromVertex, const VertexHandle &_toVertex)
Set the vertices of an edge.
CellHandle incident_cell(const HalfFaceHandle &_halfFaceHandle) const
Get cell that is incident to the given halfface.
Edge halfedge(const HalfEdgeHandle &_halfEdgeHandle) const
Get edge that corresponds to halfedge with handle _halfEdgeHandle.
virtual void swap_edge_indices(EdgeHandle _h1, EdgeHandle _h2)
Exchanges the indices of two edges while keeping the mesh otherwise unaffected.
CellIter delete_cell_core(const CellHandle &_h)
Delete cell from mesh.
HalfEdgeHandle next_halfedge_in_halfface(const HalfEdgeHandle &_heh, const HalfFaceHandle &_hfh) const
Get next halfedge within a halfface.
virtual void swap_face_indices(FaceHandle _h1, FaceHandle _h2)
Exchanges the indices of two faces while keeping the mesh otherwise unaffected.
virtual CellIter delete_cell(const CellHandle &_h)
Delete cell from mesh.
HalfFaceHandle halfface_extensive(const std::vector< VertexHandle > &_vs) const
virtual EdgeIter delete_edge(const EdgeHandle &_h)
Delete edge from mesh.
virtual VertexHandle add_vertex()
Add abstract vertex.