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);
66 vertex_deleted_.push_back(
false);
70 outgoing_hes_per_vertex_.resize(n_vertices_);
85 bool _allowDuplicates) {
89 assert(_fromVertex.is_valid() && (size_t)_fromVertex.idx() <
n_vertices() && !is_deleted(_fromVertex));
90 assert(_toVertex.is_valid() && (size_t)_toVertex.idx() <
n_vertices() && !is_deleted(_toVertex));
93 if(!_allowDuplicates) {
96 assert((
size_t)_fromVertex.idx() < outgoing_hes_per_vertex_.size());
97 std::vector<HalfEdgeHandle>& ohes = outgoing_hes_per_vertex_[_fromVertex.idx()];
98 for(std::vector<HalfEdgeHandle>::const_iterator he_it = ohes.begin(),
99 he_end = ohes.end(); he_it != he_end; ++he_it) {
100 if(
halfedge(*he_it).to_vertex() == _toVertex) {
105 for(
int i = 0; i < (int)edges_.size(); ++i) {
120 edge_deleted_.push_back(
false);
129 assert((
size_t)_fromVertex.idx() < outgoing_hes_per_vertex_.size());
130 assert((
size_t)_toVertex.idx() < outgoing_hes_per_vertex_.size());
132 outgoing_hes_per_vertex_[_fromVertex.idx()].push_back(
halfedge_handle(eh, 0));
133 outgoing_hes_per_vertex_[_toVertex.idx()].push_back(
halfedge_handle(eh, 1));
152 for(std::vector<HalfEdgeHandle>::const_iterator it = _halfedges.begin(),
153 end = _halfedges.end(); it != end; ++it)
154 assert(it->is_valid() && (size_t)it->idx() < edges_.size() * 2u && !is_deleted(*it));
172 std::set<VertexHandle> fromVertices;
173 std::set<VertexHandle> toVertices;
175 for(std::vector<HalfEdgeHandle>::const_iterator it = _halfedges.begin(),
176 end = _halfedges.end(); it != end; ++it) {
178 fromVertices.insert(
halfedge(*it).from_vertex());
179 toVertices.insert(
halfedge(*it).to_vertex());
182 for(std::set<VertexHandle>::const_iterator v_it = fromVertices.begin(),
183 v_end = fromVertices.end(); v_it != v_end; ++v_it) {
184 if(toVertices.count(*v_it) != 1) {
189 std::cerr <<
"add_face(): The specified halfedges are not connected!" << std::endl;
191 return InvalidFaceHandle;
201 faces_.push_back(face);
202 face_deleted_.push_back(
false);
213 for(std::vector<HalfEdgeHandle>::const_iterator it = _halfedges.begin(),
214 end = _halfedges.end(); it != end; ++it) {
216 assert((
size_t)it->idx() < incident_hfs_per_he_.size());
217 assert((
size_t)opposite_halfedge_handle(*it).idx() < incident_hfs_per_he_.size());
220 incident_hfs_per_he_[opposite_halfedge_handle(*it).idx()].push_back(
halfface_handle(fh, 1));
226 incident_cell_per_hf_.resize(
n_halffaces(), InvalidCellHandle);
241 for(std::vector<VertexHandle>::const_iterator it = _vertices.begin(),
242 end = _vertices.end(); it != end; ++it)
243 assert(it->is_valid() && (size_t)it->idx() <
n_vertices() && !is_deleted(*it));
247 std::vector<HalfEdgeHandle> halfedges;
248 std::vector<VertexHandle>::const_iterator it = _vertices.begin();
249 std::vector<VertexHandle>::const_iterator end = _vertices.end();
250 for(; (it+1) != end; ++it) {
255 char swap =
edge(e_idx).to_vertex() == *it;
260 char swap =
edge(e_idx).to_vertex() == *it;
273 void TopologyKernel::reorder_incident_halffaces(
const EdgeHandle& _eh) {
292 for(
unsigned char s = 0; s <= 1; s++) {
295 std::vector<HalfFaceHandle> new_halffaces;
300 assert((
size_t)cur_he.idx() < incident_hfs_per_he_.size());
302 if(incident_hfs_per_he_[cur_he.idx()].size() != 0) {
305 cur_hf = *incident_hfs_per_he_[cur_he.idx()].begin();
308 while(cur_hf != InvalidHalfFaceHandle) {
311 new_halffaces.push_back(cur_hf);
316 if(cur_hf != InvalidHalfFaceHandle)
320 cur_hf = opposite_halfface_handle(cur_hf);
324 if(cur_hf == start_hf)
break;
327 if(std::find(new_halffaces.begin(), new_halffaces.end(), cur_hf) != new_halffaces.end())
break;
334 if(new_halffaces.size() != incident_hfs_per_he_[cur_he.idx()].size()) {
339 while(cur_hf != InvalidHalfFaceHandle) {
341 cur_hf = opposite_halfface_handle(cur_hf);
344 if(cur_hf == start_hf)
break;
348 if(std::find(new_halffaces.begin(), new_halffaces.end(), cur_hf) != new_halffaces.end())
break;
350 if(cur_hf != InvalidHalfFaceHandle)
351 new_halffaces.insert(new_halffaces.begin(), cur_hf);
357 if(new_halffaces.size() == incident_hfs_per_he_[cur_he.idx()].size()) {
358 incident_hfs_per_he_[cur_he.idx()] = new_halffaces;
371 for(std::vector<HalfFaceHandle>::const_iterator it = _halffaces.begin(),
372 end = _halffaces.end(); it != end; ++it)
373 assert(it->is_valid() && ((size_t)it->idx() < faces_.size() * 2u) && !is_deleted(*it));
387 std::set<HalfEdgeHandle> incidentHalfedges;
388 std::set<EdgeHandle> incidentEdges;
390 for(std::vector<HalfFaceHandle>::const_iterator it = _halffaces.begin(),
391 end = _halffaces.end(); it != end; ++it) {
394 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hface.halfedges().begin(),
395 he_end = hface.halfedges().end(); he_it != he_end; ++he_it) {
396 incidentHalfedges.insert(*he_it);
401 if(incidentHalfedges.size() != (incidentEdges.size() * 2u)) {
403 std::cerr <<
"add_cell(): The specified half-faces are not connected!" << std::endl;
405 return InvalidCellHandle;
414 cells_.push_back(cell);
415 cell_deleted_.push_back(
false);
425 std::set<EdgeHandle> cell_edges;
426 for(std::vector<HalfFaceHandle>::const_iterator it = _halffaces.begin(),
427 end = _halffaces.end(); it != end; ++it) {
428 assert((
size_t)it->idx() < incident_cell_per_hf_.size());
432 if(incident_cell_per_hf_[it->idx()] != InvalidCellHandle) {
438 std::cerr <<
"add_cell(): One of the specified half-faces is already incident to another cell!" << std::endl;
444 incident_cell_per_hf_[it->idx()] = ch;
447 const std::vector<HalfEdgeHandle> hes =
halfface(*it).halfedges();
448 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin(),
449 he_end = hes.end(); he_it != he_end; ++he_it) {
460 for(std::set<EdgeHandle>::const_iterator e_it = cell_edges.begin(),
461 e_end = cell_edges.end(); e_it != e_end; ++e_it) {
462 reorder_incident_halffaces(*e_it);
476 assert(_fromVertex.is_valid() && (size_t)_fromVertex.idx() <
n_vertices() && !is_deleted(_fromVertex));
477 assert(_toVertex.is_valid() && (size_t)_toVertex.idx() <
n_vertices() && !is_deleted(_toVertex));
482 if(has_vertex_bottom_up_incidences()) {
490 std::vector<HalfEdgeHandle>::iterator h_end =
491 std::remove(outgoing_hes_per_vertex_[fv.idx()].begin(), outgoing_hes_per_vertex_[fv.idx()].end(), heh0);
492 outgoing_hes_per_vertex_[fv.idx()].resize(h_end - outgoing_hes_per_vertex_[fv.idx()].begin());
494 h_end = std::remove(outgoing_hes_per_vertex_[tv.idx()].begin(), outgoing_hes_per_vertex_[tv.idx()].end(), heh1);
495 outgoing_hes_per_vertex_[tv.idx()].resize(h_end - outgoing_hes_per_vertex_[tv.idx()].begin());
497 outgoing_hes_per_vertex_[_fromVertex.idx()].push_back(heh0);
498 outgoing_hes_per_vertex_[_toVertex.idx()].push_back(heh1);
501 e.set_from_vertex(_fromVertex);
502 e.set_to_vertex(_toVertex);
513 if(has_edge_bottom_up_incidences()) {
518 const std::vector<HalfEdgeHandle>& hes = f.halfedges();
520 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin(),
521 he_end = hes.end(); he_it != he_end; ++he_it) {
523 std::vector<HalfFaceHandle>::iterator h_end =
524 std::remove(incident_hfs_per_he_[he_it->idx()].begin(),
525 incident_hfs_per_he_[he_it->idx()].end(), hf0);
526 incident_hfs_per_he_[he_it->idx()].resize(h_end - incident_hfs_per_he_[he_it->idx()].begin());
528 h_end = std::remove(incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].begin(),
529 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].end(), hf1);
530 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].resize(h_end - incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].begin());
533 for(std::vector<HalfEdgeHandle>::const_iterator he_it = _hes.begin(),
534 he_end = _hes.end(); he_it != he_end; ++he_it) {
536 incident_hfs_per_he_[he_it->idx()].push_back(hf0);
537 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].push_back(hf1);
543 f.set_halfedges(_hes);
554 if(has_face_bottom_up_incidences()) {
556 const std::vector<HalfFaceHandle>& hfs = c.halffaces();
557 for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin(),
558 hf_end = hfs.end(); hf_it != hf_end; ++hf_it) {
560 incident_cell_per_hf_[hf_it->idx()] = InvalidCellHandle;
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->idx()] = _ch;
570 c.set_halffaces(_hfs);
589 assert(!is_deleted(_h));
591 std::vector<VertexHandle> vs;
594 std::set<EdgeHandle> incidentEdges_s;
595 get_incident_edges(vs, incidentEdges_s);
597 std::set<FaceHandle> incidentFaces_s;
598 get_incident_faces(incidentEdges_s, incidentFaces_s);
600 std::set<CellHandle> incidentCells_s;
601 get_incident_cells(incidentFaces_s, incidentCells_s);
604 for(std::set<CellHandle>::const_reverse_iterator c_it = incidentCells_s.rbegin(),
605 c_end = incidentCells_s.rend(); c_it != c_end; ++c_it) {
610 for(std::set<FaceHandle>::const_reverse_iterator f_it = incidentFaces_s.rbegin(),
611 f_end = incidentFaces_s.rend(); f_it != f_end; ++f_it) {
616 for(std::set<EdgeHandle>::const_reverse_iterator e_it = incidentEdges_s.rbegin(),
617 e_end = incidentEdges_s.rend(); e_it != e_end; ++e_it) {
641 assert(!is_deleted(_h));
643 std::vector<EdgeHandle> es;
646 std::set<FaceHandle> incidentFaces_s;
647 get_incident_faces(es, incidentFaces_s);
649 std::set<CellHandle> incidentCells_s;
650 get_incident_cells(incidentFaces_s, incidentCells_s);
653 for(std::set<CellHandle>::const_reverse_iterator c_it = incidentCells_s.rbegin(),
654 c_end = incidentCells_s.rend(); c_it != c_end; ++c_it) {
659 for(std::set<FaceHandle>::const_reverse_iterator f_it = incidentFaces_s.rbegin(),
660 f_end = incidentFaces_s.rend(); f_it != f_end; ++f_it) {
684 assert(!is_deleted(_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) {
715 assert(!is_deleted(_h));
724 if (!deferred_deletion_enabled() || !needs_garbage_collection())
727 deferred_deletion =
false;
729 for (
int i = (
int)
n_cells(); i > 0; --i) {
731 cell_deleted_[i - 1] =
false;
735 n_deleted_cells_ = 0;
737 for (
int i = (
int)
n_faces(); i > 0; --i) {
739 face_deleted_[i - 1] =
false;
743 n_deleted_faces_ = 0;
745 for (
int i = (
int)
n_edges(); i > 0; --i) {
747 edge_deleted_[i - 1] =
false;
751 n_deleted_edges_ = 0;
755 vertex_deleted_[i - 1] =
false;
759 n_deleted_vertices_ = 0;
761 deferred_deletion =
true;
767 template <
class ContainerT>
768 void TopologyKernel::get_incident_edges(
const ContainerT& _vs,
769 std::set<EdgeHandle>& _es)
const {
775 for(
typename ContainerT::const_iterator v_it = _vs.begin(),
776 v_end = _vs.end(); v_it != v_end; ++v_it) {
778 const std::vector<HalfEdgeHandle>& inc_hes = outgoing_hes_per_vertex_[v_it->idx()];
780 for(std::vector<HalfEdgeHandle>::const_iterator he_it = inc_hes.begin(),
781 he_end = inc_hes.end(); he_it != he_end; ++he_it) {
788 for(
typename ContainerT::const_iterator v_it = _vs.begin(),
789 v_end = _vs.end(); v_it != v_end; ++v_it) {
791 for(
EdgeIter e_it = edges_begin(), e_end = edges_end(); e_it != e_end; ++e_it) {
795 if(e.from_vertex() == *v_it || e.to_vertex() == *v_it) {
805 template <
class ContainerT>
806 void TopologyKernel::get_incident_faces(
const ContainerT& _es,
807 std::set<FaceHandle>& _fs)
const {
813 for(
typename ContainerT::const_iterator e_it = _es.begin(),
814 e_end = _es.end(); e_it != e_end; ++e_it) {
817 hehf_it.valid(); ++hehf_it) {
821 if(_fs.count(fh) == 0) {
828 for(
typename ContainerT::const_iterator e_it = _es.begin(),
829 e_end = _es.end(); e_it != e_end; ++e_it) {
832 f_end = faces_end(); f_it != f_end; ++f_it) {
834 const std::vector<HalfEdgeHandle>& hes =
face(*f_it).halfedges();
836 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin(),
837 he_end = hes.end(); he_it != he_end; ++he_it) {
851 template <
class ContainerT>
852 void TopologyKernel::get_incident_cells(
const ContainerT& _fs,
853 std::set<CellHandle>& _cs)
const {
859 for(
typename ContainerT::const_iterator f_it = _fs.begin(),
860 f_end = _fs.end(); f_it != f_end; ++f_it) {
868 if(c0.is_valid()) _cs.insert(c0);
869 if(c1.is_valid()) _cs.insert(c1);
873 for(
typename ContainerT::const_iterator f_it = _fs.begin(),
874 f_end = _fs.end(); f_it != f_end; ++f_it) {
876 for(
CellIter c_it = cells_begin(), c_end = cells_end();
877 c_it != c_end; ++c_it) {
879 const std::vector<HalfFaceHandle>& hfs =
cell(*c_it).halffaces();
881 for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin(),
882 hf_end = hfs.end(); hf_it != hf_end; ++hf_it) {
884 if(face_handle(*hf_it) == *f_it) {
916 assert(h.is_valid() && (size_t)h.idx() <
n_vertices());
918 if (fast_deletion_enabled() && !deferred_deletion_enabled())
921 assert(!vertex_deleted_[last_undeleted_vertex.idx()]);
923 h = last_undeleted_vertex;
926 if (deferred_deletion_enabled())
928 ++n_deleted_vertices_;
929 vertex_deleted_[h.idx()] =
true;
942 for(
int i = h.idx(), end = (int)
n_vertices(); i < end; ++i) {
943 const std::vector<HalfEdgeHandle>& hes = outgoing_hes_per_vertex_[i];
944 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin(),
945 he_end = hes.end(); he_it != he_end; ++he_it) {
948 if(e.from_vertex().idx() == i) {
951 if(e.to_vertex().idx() == i) {
960 for(
EdgeIter e_it = edges_begin(), e_end = edges_end();
961 e_it != e_end; ++e_it) {
964 if(
edge(*e_it).from_vertex() > h) {
967 if(
edge(*e_it).to_vertex() > h) {
976 assert((
size_t)h.idx() < outgoing_hes_per_vertex_.size());
977 outgoing_hes_per_vertex_.erase(outgoing_hes_per_vertex_.begin() + h.idx());
984 vertex_deleted_.erase(vertex_deleted_.begin() + h.idx());
1022 assert(h.is_valid() && (size_t)h.idx() < edges_.size());
1024 if (fast_deletion_enabled() && !deferred_deletion_enabled())
1027 assert(!edge_deleted_[last_edge.idx()]);
1038 assert(v0.is_valid() && (size_t)v0.idx() < outgoing_hes_per_vertex_.size());
1039 assert(v1.is_valid() && (size_t)v1.idx() < outgoing_hes_per_vertex_.size());
1041 outgoing_hes_per_vertex_[v0.idx()].erase(
1042 std::remove(outgoing_hes_per_vertex_[v0.idx()].begin(),
1043 outgoing_hes_per_vertex_[v0.idx()].end(),
1045 outgoing_hes_per_vertex_[v0.idx()].end());
1047 outgoing_hes_per_vertex_[v1.idx()].erase(
1048 std::remove(outgoing_hes_per_vertex_[v1.idx()].begin(),
1049 outgoing_hes_per_vertex_[v1.idx()].end(),
1051 outgoing_hes_per_vertex_[v1.idx()].end());
1054 if (deferred_deletion_enabled())
1057 edge_deleted_[h.idx()] =
true;
1067 if (!fast_deletion_enabled())
1072 assert((
size_t)
halfedge_handle(h, 0).idx() < incident_hfs_per_he_.size());
1077 std::set<FaceHandle> update_faces;
1078 for(std::vector<std::vector<HalfFaceHandle> >::const_iterator iit =
1080 iit_end = incident_hfs_per_he_.end(); iit != iit_end; ++iit) {
1081 for(std::vector<HalfFaceHandle>::const_iterator it = iit->begin(),
1082 end = iit->end(); it != end; ++it) {
1083 update_faces.insert(face_handle(*it));
1088 for(std::set<FaceHandle>::iterator f_it = update_faces.begin(),
1089 f_end = update_faces.end(); f_it != f_end; ++f_it) {
1091 std::vector<HalfEdgeHandle> hes =
face(*f_it).halfedges();
1094 hes.erase(std::remove(hes.begin(), hes.end(),
halfedge_handle(h, 0)), hes.end());
1095 hes.erase(std::remove(hes.begin(), hes.end(),
halfedge_handle(h, 1)), hes.end());
1097 #if defined(__clang_major__) && (__clang_major__ >= 5) 1098 for(std::vector<HalfEdgeHandle>::iterator it = hes.begin(), end = hes.end();
1100 cor.correctValue(*it);
1103 std::for_each(hes.begin(), hes.end(),
1104 fun::bind(&HEHandleCorrection::correctValue, &cor, fun::placeholders::_1));
1106 face(*f_it).set_halfedges(hes);
1111 for(
FaceIter f_it = faces_begin(), f_end = faces_end();
1112 f_it != f_end; ++f_it) {
1115 std::vector<HalfEdgeHandle> hes =
face(*f_it).halfedges();
1118 hes.erase(std::remove(hes.begin(), hes.end(),
halfedge_handle(h, 0)), hes.end());
1119 hes.erase(std::remove(hes.begin(), hes.end(),
halfedge_handle(h, 1)), hes.end());
1123 #if defined(__clang_major__) && (__clang_major__ >= 5) 1124 for(std::vector<HalfEdgeHandle>::iterator it = hes.begin(), end = hes.end();
1126 cor.correctValue(*it);
1129 std::for_each(hes.begin(), hes.end(),
1130 fun::bind(&HEHandleCorrection::correctValue, &cor, fun::placeholders::_1));
1132 face(*f_it).set_halfedges(hes);
1140 assert((
size_t)
halfedge_handle(h, 1).idx() < incident_hfs_per_he_.size());
1142 incident_hfs_per_he_.erase(incident_hfs_per_he_.begin() +
halfedge_handle(h, 1).idx());
1143 incident_hfs_per_he_.erase(incident_hfs_per_he_.begin() +
halfedge_handle(h, 0).idx());
1146 if (!fast_deletion_enabled())
1151 #if defined(__clang_major__) && (__clang_major__ >= 5) 1152 for(std::vector<std::vector<HalfEdgeHandle> >::iterator it = outgoing_hes_per_vertex_.begin(),
1153 end = outgoing_hes_per_vertex_.end(); it != end; ++it) {
1154 cor.correctVecValue(*it);
1157 std::for_each(outgoing_hes_per_vertex_.begin(),
1158 outgoing_hes_per_vertex_.end(),
1159 fun::bind(&HEHandleCorrection::correctVecValue, &cor, fun::placeholders::_1));
1166 edges_.erase(edges_.begin() + h.idx());
1167 edge_deleted_.erase(edge_deleted_.begin() + h.idx());
1206 assert(h.is_valid() && (size_t)h.idx() < faces_.size());
1209 if (fast_deletion_enabled() && !deferred_deletion_enabled())
1212 assert(!face_deleted_[last_face.idx()]);
1220 const std::vector<HalfEdgeHandle>& hes =
face(h).halfedges();
1221 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin(),
1222 he_end = hes.end(); he_it != he_end; ++he_it) {
1224 assert((
size_t)std::max(he_it->idx(), opposite_halfedge_handle(*he_it).idx()) < incident_hfs_per_he_.size());
1226 incident_hfs_per_he_[he_it->idx()].erase(
1227 std::remove(incident_hfs_per_he_[he_it->idx()].begin(),
1228 incident_hfs_per_he_[he_it->idx()].end(),
1232 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].erase(
1233 std::remove(incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].begin(),
1234 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].end(),
1235 halfface_handle(h, 1)), incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].end());
1241 if (deferred_deletion_enabled())
1244 face_deleted_[h.idx()] =
true;
1254 if (!fast_deletion_enabled())
1261 std::set<CellHandle> update_cells;
1262 for(std::vector<CellHandle>::const_iterator c_it = (incident_cell_per_hf_.begin() +
halfface_handle(h, 0).idx()),
1263 c_end = incident_cell_per_hf_.end(); c_it != c_end; ++c_it) {
1264 if(!c_it->is_valid())
continue;
1265 update_cells.insert(*c_it);
1267 for(std::set<CellHandle>::const_iterator c_it = update_cells.begin(),
1268 c_end = update_cells.end(); c_it != c_end; ++c_it) {
1270 std::vector<HalfFaceHandle> hfs =
cell(*c_it).halffaces();
1273 hfs.erase(std::remove(hfs.begin(), hfs.end(),
halfface_handle(h, 0)), hfs.end());
1274 hfs.erase(std::remove(hfs.begin(), hfs.end(),
halfface_handle(h, 1)), hfs.end());
1277 #if defined(__clang_major__) && (__clang_major__ >= 5) 1278 for(std::vector<HalfFaceHandle>::iterator it = hfs.begin(),
1279 end = hfs.end(); it != end; ++it) {
1280 cor.correctValue(*it);
1283 std::for_each(hfs.begin(), hfs.end(),
1284 fun::bind(&HFHandleCorrection::correctValue, &cor, fun::placeholders::_1));
1286 cell(*c_it).set_halffaces(hfs);
1292 for(
CellIter c_it = cells_begin(), c_end = cells_end(); c_it != c_end; ++c_it) {
1294 std::vector<HalfFaceHandle> hfs =
cell(*c_it).halffaces();
1297 hfs.erase(std::remove(hfs.begin(), hfs.end(),
halfface_handle(h, 0)), hfs.end());
1298 hfs.erase(std::remove(hfs.begin(), hfs.end(),
halfface_handle(h, 1)), hfs.end());
1301 #if defined(__clang_major__) && (__clang_major__ >= 5) 1302 for(std::vector<HalfFaceHandle>::iterator it = hfs.begin(),
1303 end = hfs.end(); it != end; ++it) {
1304 cor.correctValue(*it);
1307 std::for_each(hfs.begin(), hfs.end(),
1308 fun::bind(&HFHandleCorrection::correctValue, &cor, fun::placeholders::_1));
1310 cell(*c_it).set_halffaces(hfs);
1318 assert((
size_t)
halfface_handle(h, 1).idx() < incident_cell_per_hf_.size());
1320 incident_cell_per_hf_.erase(incident_cell_per_hf_.begin() +
halfface_handle(h, 1).idx());
1321 incident_cell_per_hf_.erase(incident_cell_per_hf_.begin() +
halfface_handle(h, 0).idx());
1325 if (!fast_deletion_enabled())
1330 #if defined(__clang_major__) && (__clang_major__ >= 5) 1331 for(std::vector<std::vector<HalfFaceHandle> >::iterator it = incident_hfs_per_he_.begin(), end = incident_hfs_per_he_.end(); it != end; ++it) {
1332 cor.correctVecValue(*it);
1335 std::for_each(incident_hfs_per_he_.begin(),
1336 incident_hfs_per_he_.end(),
1337 fun::bind(&HFHandleCorrection::correctVecValue, &cor, fun::placeholders::_1));
1343 faces_.erase(faces_.begin() + h.idx());
1344 face_deleted_.erase(face_deleted_.begin() + h.idx());
1377 assert(h.is_valid() && (size_t)h.idx() < cells_.size());
1380 if (fast_deletion_enabled() && !deferred_deletion_enabled())
1383 assert(!cell_deleted_[last_undeleted_cell.idx()]);
1385 h = last_undeleted_cell;
1391 const std::vector<HalfFaceHandle>& hfs =
cell(h).halffaces();
1392 for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin(),
1393 hf_end = hfs.end(); hf_it != hf_end; ++hf_it) {
1394 assert((
size_t)hf_it->idx() < incident_cell_per_hf_.size());
1395 if (incident_cell_per_hf_[hf_it->idx()] == h)
1396 incident_cell_per_hf_[hf_it->idx()] = InvalidCellHandle;
1398 std::set<EdgeHandle> edges;
1399 for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin(),
1400 hf_end = hfs.end(); hf_it != hf_end; ++hf_it) {
1402 for (
const auto& heh : hf.halfedges())
1405 for (
auto eh : edges)
1406 reorder_incident_halffaces(eh);
1409 if (deferred_deletion_enabled())
1412 cell_deleted_[h.idx()] =
true;
1422 if (!fast_deletion_enabled())
1426 #if defined(__clang_major__) && (__clang_major__ >= 5) 1427 for(std::vector<CellHandle>::iterator it = incident_cell_per_hf_.begin(),
1428 end = incident_cell_per_hf_.end(); it != end; ++it) {
1429 cor.correctValue(*it);
1432 std::for_each(incident_cell_per_hf_.begin(),
1433 incident_cell_per_hf_.end(),
1434 fun::bind(&CHandleCorrection::correctValue, &cor, fun::placeholders::_1));
1440 cells_.erase(cells_.begin() + h.idx());
1441 cell_deleted_.erase(cell_deleted_.begin() + h.idx());
1454 assert(_h1.idx() >= 0 && _h1.idx() < (int)cells_.size());
1455 assert(_h2.idx() >= 0 && _h2.idx() < (int)cells_.size());
1460 int id1 = _h1.idx();
1461 int id2 = _h2.idx();
1463 Cell c1 = cells_[id1];
1464 Cell c2 = cells_[id2];
1467 std::vector<HalfFaceHandle> hfhs1 = c1.halffaces();
1468 for (
unsigned int i = 0; i < hfhs1.size(); ++i)
1471 if (incident_cell_per_hf_[hfh.idx()] == _h1)
1472 incident_cell_per_hf_[hfh.idx()] = _h2;
1475 std::vector<HalfFaceHandle> hfhs2 = c2.halffaces();
1476 for (
unsigned int i = 0; i < hfhs2.size(); ++i)
1479 if (incident_cell_per_hf_[hfh.idx()] == _h2)
1480 incident_cell_per_hf_[hfh.idx()] = _h1;
1484 std::swap(cells_[id1], cells_[id2]);
1485 bool tmp = cell_deleted_[id1];
1486 cell_deleted_[id1] = cell_deleted_[id2];
1487 cell_deleted_[id2] = tmp;
1488 swap_cell_properties(_h1, _h2);
1493 assert(_h1.idx() >= 0 && _h1.idx() < (int)faces_.size());
1494 assert(_h2.idx() >= 0 && _h2.idx() < (int)faces_.size());
1500 std::vector<unsigned int> ids;
1501 ids.push_back(_h1.idx());
1502 ids.push_back(_h2.idx());
1504 unsigned int id1 = _h1.idx();
1505 unsigned int id2 = _h2.idx();
1510 if (has_face_bottom_up_incidences())
1512 std::set<unsigned int> processed_cells;
1513 for (
unsigned int i = 0; i < 2; ++i)
1515 unsigned int id = ids[i];
1516 for (
unsigned int j = 0; j < 2; ++j)
1519 CellHandle ch = incident_cell_per_hf_[hfh.idx()];
1525 if (processed_cells.find(ch.idx()) == processed_cells.end())
1528 Cell& c = cells_[ch.idx()];
1532 std::vector<HalfFaceHandle> new_halffaces;
1533 for (
unsigned int k = 0; k < c.halffaces().size(); ++k)
1534 if (c.halffaces()[k].idx()/2 == (int)id1)
1535 new_halffaces.push_back(
HalfFaceHandle(2 * id2 + (c.halffaces()[k].idx() % 2)));
1536 else if (c.halffaces()[k].idx()/2 == (int)id2)
1537 new_halffaces.push_back(
HalfFaceHandle(2 * id1 + (c.halffaces()[k].idx() % 2)));
1539 new_halffaces.push_back(c.halffaces()[k]);
1540 c.set_halffaces(new_halffaces);
1542 processed_cells.insert(ch.idx());
1550 for (
unsigned int i = 0; i < cells_.size(); ++i)
1552 Cell& c = cells_[i];
1555 bool contains_swapped_face =
false;
1556 for (
unsigned int k = 0; k < c.halffaces().size(); ++k)
1558 if (c.halffaces()[k].idx()/2 == (int)id1)
1559 contains_swapped_face =
true;
1560 if (c.halffaces()[k].idx()/2 == (int)id2)
1561 contains_swapped_face =
true;
1562 if (contains_swapped_face)
1566 if (contains_swapped_face)
1569 std::vector<HalfFaceHandle> new_halffaces;
1570 for (
unsigned int k = 0; k < c.halffaces().size(); ++k)
1571 if (c.halffaces()[k].idx()/2 == (int)id1)
1572 new_halffaces.push_back(
HalfFaceHandle(2 * id2 + (c.halffaces()[k].idx() % 2)));
1573 else if (c.halffaces()[k].idx()/2 == (int)id2)
1574 new_halffaces.push_back(
HalfFaceHandle(2 * id1 + (c.halffaces()[k].idx() % 2)));
1576 new_halffaces.push_back(c.halffaces()[k]);
1577 c.set_halffaces(new_halffaces);
1584 if (has_edge_bottom_up_incidences())
1586 std::set<HalfEdgeHandle> processed_halfedges;
1587 for (
unsigned int i = 0; i < 2; ++i)
1589 unsigned int id = ids[i];
1590 for (
unsigned int j = 0; j < 2; ++j)
1595 for (
unsigned int k = 0; k < hf.halfedges().size(); ++k)
1599 if (processed_halfedges.find(heh) != processed_halfedges.end())
1602 std::vector<HalfFaceHandle>& incident_halffaces = incident_hfs_per_he_[heh.idx()];
1603 for (
unsigned int l = 0; l < incident_halffaces.size(); ++l)
1607 if (hfh2.idx()/2 == (int)id1)
1609 else if (hfh2.idx()/2 == (int)id2)
1613 processed_halfedges.insert(heh);
1620 std::swap(faces_[ids[0]], faces_[ids[1]]);
1621 bool tmp = face_deleted_[ids[0]];
1622 face_deleted_[ids[0]] = face_deleted_[ids[1]];
1623 face_deleted_[ids[1]] = tmp;
1624 std::swap(incident_cell_per_hf_[2*ids[0]+0], incident_cell_per_hf_[2*ids[1]+0]);
1625 std::swap(incident_cell_per_hf_[2*ids[0]+1], incident_cell_per_hf_[2*ids[1]+1]);
1626 swap_face_properties(_h1, _h2);
1634 assert(_h1.idx() >= 0 && _h1.idx() < (int)edges_.size());
1635 assert(_h2.idx() >= 0 && _h2.idx() < (int)edges_.size());
1640 std::vector<unsigned int> ids;
1641 ids.push_back(_h1.idx());
1642 ids.push_back(_h2.idx());
1647 if (has_edge_bottom_up_incidences())
1649 std::set<unsigned int> processed_faces;
1651 for (
unsigned int i = 0; i < 2; ++i)
1656 std::vector<HalfFaceHandle>& incident_halffaces = incident_hfs_per_he_[heh.idx()];
1657 for (
unsigned int j = 0; j < incident_halffaces.size(); ++j)
1661 unsigned int f_id = hfh.idx() / 2;
1663 if (processed_faces.find(f_id) == processed_faces.end())
1666 Face& f = faces_[f_id];
1669 std::vector<HalfEdgeHandle> new_halfedges;
1670 for (
unsigned int k = 0; k < f.halfedges().size(); ++k)
1673 if (heh2.idx() / 2 == (int)ids[0])
1674 new_halfedges.push_back(
HalfEdgeHandle(2*ids[1] + (heh2.idx() % 2)));
1675 else if (heh2.idx() / 2 == (int)ids[1])
1676 new_halfedges.push_back(
HalfEdgeHandle(2*ids[0] + (heh2.idx() % 2)));
1678 new_halfedges.push_back(heh2);
1680 f.set_halfedges(new_halfedges);
1682 processed_faces.insert(f_id);
1690 for (
unsigned int i = 0; i < faces_.size(); ++i)
1692 Face& f = faces_[i];
1695 bool contains_swapped_edge =
false;
1696 for (
unsigned int k = 0; k < f.halfedges().size(); ++k)
1698 if (f.halfedges()[k].idx()/2 == (int)ids[0])
1699 contains_swapped_edge =
true;
1700 if (f.halfedges()[k].idx()/2 == (int)ids[1])
1701 contains_swapped_edge =
true;
1702 if (contains_swapped_edge)
1706 if (contains_swapped_edge)
1709 std::vector<HalfEdgeHandle> new_halfedges;
1710 for (
unsigned int k = 0; k < f.halfedges().size(); ++k)
1713 if (heh2.idx() / 2 == (int)ids[0])
1714 new_halfedges.push_back(
HalfEdgeHandle(2*ids[1] + (heh2.idx() % 2)));
1715 else if (heh2.idx() / 2 == (int)ids[1])
1716 new_halfedges.push_back(
HalfEdgeHandle(2*ids[0] + (heh2.idx() % 2)));
1718 new_halfedges.push_back(heh2);
1720 f.set_halfedges(new_halfedges);
1727 if (has_vertex_bottom_up_incidences())
1729 std::set<VertexHandle> processed_vertices;
1730 for (
unsigned int i = 0; i < 2; ++i)
1733 std::vector<VertexHandle> vhs;
1734 vhs.push_back(e.from_vertex());
1735 vhs.push_back(e.to_vertex());
1737 for (
unsigned int j = 0; j < 2; ++j)
1739 if (processed_vertices.find(vhs[j]) != processed_vertices.end())
1742 std::vector<HalfEdgeHandle>& outgoing_hes = outgoing_hes_per_vertex_[vhs[j].idx()];
1743 for (
unsigned int k = 0; k < outgoing_hes.size(); ++k)
1746 if (heh.idx() / 2 == (int)ids[0])
1748 else if (heh.idx() / 2 == (int)ids[1])
1751 processed_vertices.insert(vhs[j]);
1758 std::swap(edges_[ids[0]], edges_[ids[1]]);
1759 bool tmp = edge_deleted_[ids[0]];
1760 edge_deleted_[ids[0]] = edge_deleted_[ids[1]];
1761 edge_deleted_[ids[1]] = tmp;
1762 std::swap(incident_hfs_per_he_[2*ids[0]+0], incident_hfs_per_he_[2*ids[1]+0]);
1763 std::swap(incident_hfs_per_he_[2*ids[0]+1], incident_hfs_per_he_[2*ids[1]+1]);
1764 swap_edge_properties(_h1, _h2);
1772 assert(_h1.idx() >= 0 && _h1.idx() < (int)n_vertices_);
1773 assert(_h2.idx() >= 0 && _h2.idx() < (int)n_vertices_);
1778 std::vector<unsigned int> ids;
1779 ids.push_back(_h1.idx());
1780 ids.push_back(_h2.idx());
1785 if (has_vertex_bottom_up_incidences())
1787 for (
unsigned int i = 0; i < 2; ++i)
1789 std::set<unsigned int> processed_edges;
1790 std::vector<HalfEdgeHandle>& outgoing_hes = outgoing_hes_per_vertex_[ids[i]];
1791 for (
unsigned int k = 0; k < outgoing_hes.size(); ++k)
1793 unsigned int e_id = outgoing_hes[k].idx() / 2;
1795 if (processed_edges.find(e_id) == processed_edges.end())
1797 Edge& e = edges_[e_id];
1798 if (e.from_vertex().idx() == (int)ids[0])
1800 else if (e.from_vertex().idx() == (int)ids[1])
1803 if (e.to_vertex().idx() == (int)ids[0])
1805 else if (e.to_vertex().idx() == (int)ids[1])
1808 processed_edges.insert(e_id);
1818 for (
unsigned int i = 0; i < edges_.size(); ++i)
1820 Edge& e = edges_[i];
1821 if (e.from_vertex().idx() == (int)ids[0])
1823 else if (e.from_vertex().idx() == (int)ids[1])
1826 if (e.to_vertex().idx() == (int)ids[0])
1828 else if (e.to_vertex().idx() == (int)ids[1])
1834 bool tmp = vertex_deleted_[ids[0]];
1835 vertex_deleted_[ids[0]] = vertex_deleted_[ids[1]];
1836 vertex_deleted_[ids[1]] = tmp;
1837 std::swap(outgoing_hes_per_vertex_[ids[0]], outgoing_hes_per_vertex_[ids[1]]);
1838 swap_vertex_properties(_h1, _h2);
1843 void TopologyKernel::delete_multiple_vertices(
const std::vector<bool>& _tag) {
1847 std::vector<int> newIndices(
n_vertices(), -1);
1850 std::vector<int>::iterator idx_it = newIndices.begin();
1851 for(std::vector<bool>::const_iterator t_it = _tag.begin(),
1852 t_end = _tag.end(); t_it != t_end; ++t_it, ++idx_it) {
1864 delete_multiple_vertex_props(_tag);
1867 std::for_each(edges_.begin(), edges_.end(), corrector);
1872 void TopologyKernel::delete_multiple_edges(
const std::vector<bool>& _tag) {
1874 assert(_tag.size() ==
n_edges());
1876 std::vector<int> newIndices(
n_edges(), -1);
1879 std::vector<Edge> newEdges;
1881 std::vector<int>::iterator idx_it = newIndices.begin();
1882 std::vector<Edge>::const_iterator e_it = edges_.begin();
1884 for(std::vector<bool>::const_iterator t_it = _tag.begin(),
1885 t_end = _tag.end(); t_it != t_end; ++t_it, ++idx_it, ++e_it) {
1890 newEdges.push_back(*e_it);
1898 edges_.swap(newEdges);
1901 delete_multiple_edge_props(_tag);
1904 std::for_each(faces_.begin(), faces_.end(), corrector);
1909 void TopologyKernel::delete_multiple_faces(
const std::vector<bool>& _tag) {
1911 assert(_tag.size() ==
n_faces());
1913 std::vector<int> newIndices(
n_faces(), -1);
1916 std::vector<Face> newFaces;
1918 std::vector<int>::iterator idx_it = newIndices.begin();
1919 std::vector<Face>::const_iterator f_it = faces_.begin();
1921 for(std::vector<bool>::const_iterator t_it = _tag.begin(),
1922 t_end = _tag.end(); t_it != t_end; ++t_it, ++idx_it, ++f_it) {
1927 newFaces.push_back(*f_it);
1935 faces_.swap(newFaces);
1938 delete_multiple_face_props(_tag);
1941 std::for_each(cells_.begin(), cells_.end(), corrector);
1946 void TopologyKernel::delete_multiple_cells(
const std::vector<bool>& _tag) {
1948 assert(_tag.size() ==
n_cells());
1950 std::vector<Cell> newCells;
1952 std::vector<Cell>::const_iterator c_it = cells_.begin();
1954 for(std::vector<bool>::const_iterator t_it = _tag.begin(),
1955 t_end = _tag.end(); t_it != t_end; ++t_it, ++c_it) {
1960 newCells.push_back(*c_it);
1965 cells_.swap(newCells);
1968 delete_multiple_cell_props(_tag);
1976 assert(_first >= cells_begin());
1977 assert(_last <= cells_end());
1979 std::vector<Cell>::iterator it = cells_.erase(cells_.begin() + _first->idx(), cells_.begin() + _last->idx());
1983 f_bottom_up_ =
false;
1984 enable_face_bottom_up_incidences(
true);
1990 void TopologyKernel::enable_deferred_deletion(
bool _enable)
1992 if (deferred_deletion && !_enable)
1995 deferred_deletion = _enable;
2004 assert(_edgeHandle.is_valid() && (size_t)_edgeHandle.idx() < edges_.size());
2006 return edges_[_edgeHandle.idx()];
2015 assert(_faceHandle.is_valid() && (size_t)_faceHandle.idx() < faces_.size());
2017 return faces_[_faceHandle.idx()];
2026 assert(_cellHandle.is_valid() && (size_t)_cellHandle.idx() < cells_.size());
2028 return cells_[_cellHandle.idx()];
2037 assert(_edgeHandle.is_valid() && (size_t)_edgeHandle.idx() < edges_.size());
2039 return edges_[_edgeHandle.idx()];
2048 assert((
size_t)_faceHandle.idx() < faces_.size());
2049 assert(_faceHandle.idx() >= 0);
2051 return faces_[_faceHandle.idx()];
2060 assert((
size_t)_cellHandle.idx() < cells_.size());
2061 assert(_cellHandle.idx() >= 0);
2063 return cells_[_cellHandle.idx()];
2072 assert((
size_t)_halfEdgeHandle.idx() < (edges_.size() * 2));
2073 assert(_halfEdgeHandle.idx() >= 0);
2077 if(_halfEdgeHandle.idx() % 2 == 0)
2078 return edges_[(
int)(_halfEdgeHandle.idx() / 2)];
2089 assert((
size_t)_halfFaceHandle.idx() < (faces_.size() * 2));
2090 assert(_halfFaceHandle.idx() >= 0);
2094 if(_halfFaceHandle.idx() % 2 == 0)
2095 return faces_[(
int)(_halfFaceHandle.idx() / 2)];
2106 assert(_halfEdgeHandle.idx() >= 0);
2107 assert((
size_t)_halfEdgeHandle.idx() < (edges_.size() * 2));
2111 if(_halfEdgeHandle.idx() % 2 != 0)
2112 return edges_[(
int)(_halfEdgeHandle.idx() / 2)];
2123 assert(_halfFaceHandle.idx() >= 0);
2124 assert((
size_t)_halfFaceHandle.idx() < (faces_.size() * 2));
2128 if(_halfFaceHandle.idx() % 2 != 0)
2129 return faces_[(
int)(_halfFaceHandle.idx() / 2)];
2142 if(
halfedge(*voh_it).to_vertex() == _vh2) {
2147 return InvalidHalfEdgeHandle;
2154 assert(_vs.size() > 2);
2158 assert(v0.is_valid() && v1.is_valid() && v2.is_valid());
2161 if(!he0.is_valid())
return InvalidHalfFaceHandle;
2163 if(!he1.is_valid())
return InvalidHalfFaceHandle;
2165 std::vector<HalfEdgeHandle> hes;
2176 assert(_vs.size() > 2);
2181 assert(v0.is_valid() && v1.is_valid());
2184 if(!he0.is_valid())
return InvalidHalfFaceHandle;
2188 std::vector<HalfEdgeHandle> hes =
halfface(*hehf_it).halfedges();
2190 if (hes.size() != _vs.size())
2194 for (
unsigned int i = 0; i < hes.size(); ++i)
2198 bool all_vertices_found =
true;
2200 for (
unsigned int i = 0; i < hes.size(); ++i)
2203 if (
halfedge(heh).from_vertex() != _vs[i])
2205 all_vertices_found =
false;
2210 if (all_vertices_found)
2214 return InvalidHalfFaceHandle;
2221 assert(_hes.size() >= 2);
2225 assert(he0.is_valid() && he1.is_valid());
2229 std::vector<HalfEdgeHandle> hes =
halfface(*hehf_it).halfedges();
2230 if(std::find(hes.begin(), hes.end(), he1) != hes.end()) {
2235 return InvalidHalfFaceHandle;
2242 assert(_heh.is_valid() && (size_t)_heh.idx() < edges_.size() * 2u);
2243 assert(_hfh.is_valid() && (size_t)_hfh.idx() < faces_.size() * 2u);
2245 std::vector<HalfEdgeHandle> hes =
halfface(_hfh).halfedges();
2247 for(std::vector<HalfEdgeHandle>::const_iterator it = hes.begin();
2248 it != hes.end(); ++it) {
2250 if((it + 1) != hes.end())
return *(it + 1);
2251 else return *hes.begin();
2255 return InvalidHalfEdgeHandle;
2262 assert(_heh.is_valid() && (size_t)_heh.idx() < edges_.size() * 2u);
2263 assert(_hfh.is_valid() && (size_t)_hfh.idx() < faces_.size() * 2u);
2265 std::vector<HalfEdgeHandle> hes =
halfface(_hfh).halfedges();
2267 for(std::vector<HalfEdgeHandle>::const_iterator it = hes.begin();
2268 it != hes.end(); ++it) {
2270 if(it != hes.begin())
return *(it - 1);
2271 else return *(hes.end() - 1);
2275 return InvalidHalfEdgeHandle;
2283 assert(_halfFaceHandle.is_valid() && (size_t)_halfFaceHandle.idx() < faces_.size() * 2u);
2284 assert(_halfEdgeHandle.is_valid() && (size_t)_halfEdgeHandle.idx() < edges_.size() * 2u);
2285 assert(has_face_bottom_up_incidences());
2286 assert((
size_t)_halfFaceHandle.idx() < incident_cell_per_hf_.size());
2288 if(incident_cell_per_hf_[_halfFaceHandle.idx()] == InvalidCellHandle) {
2290 return InvalidHalfFaceHandle;
2296 bool skipped =
false;
2299 for(std::vector<HalfFaceHandle>::const_iterator hf_it = c.halffaces().begin();
2300 hf_it != c.halffaces().end(); ++hf_it) {
2302 if(*hf_it == _halfFaceHandle) {
2308 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hf.halfedges().begin();
2309 he_it != hf.halfedges().end(); ++he_it) {
2315 if(skipped && found)
break;
2317 if(skipped && found)
break;
2319 return ((skipped && found) ? idx : InvalidHalfFaceHandle);
2326 if(!has_face_bottom_up_incidences()) {
2327 return InvalidCellHandle;
2329 if((
size_t)_halfFaceHandle.idx() >= incident_cell_per_hf_.size() || _halfFaceHandle.idx() < 0) {
2330 return InvalidCellHandle;
2333 return incident_cell_per_hf_[_halfFaceHandle.idx()];
2338 void TopologyKernel::compute_vertex_bottom_up_incidences() {
2341 outgoing_hes_per_vertex_.clear();
2342 outgoing_hes_per_vertex_.resize(
n_vertices());
2345 int n_edges = (int)edges_.size();
2346 for(
int i = 0; i <
n_edges; ++i) {
2347 if (edge_deleted_[i])
2353 assert((
size_t)from.idx() < outgoing_hes_per_vertex_.size());
2358 assert((
size_t)to.idx() < outgoing_hes_per_vertex_.size());
2367 void TopologyKernel::compute_edge_bottom_up_incidences() {
2370 incident_hfs_per_he_.clear();
2371 incident_hfs_per_he_.resize(edges_.size() * 2u);
2374 int n_faces = (int)faces_.size();
2375 for(
int i = 0; i <
n_faces; ++i) {
2376 if (face_deleted_[i])
2379 std::vector<HalfEdgeHandle> halfedges = faces_[i].halfedges();
2382 for(std::vector<HalfEdgeHandle>::const_iterator he_it = halfedges.begin();
2383 he_it != halfedges.end(); ++he_it) {
2386 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].push_back(
2394 void TopologyKernel::compute_face_bottom_up_incidences() {
2397 incident_cell_per_hf_.clear();
2398 incident_cell_per_hf_.resize(faces_.size() * 2u, InvalidCellHandle);
2400 int n_cells = (int)cells_.size();
2401 for(
int i = 0; i <
n_cells; ++i) {
2402 if (cell_deleted_[i])
2405 std::vector<HalfFaceHandle> halffaces = cells_[i].halffaces();
2408 for(std::vector<HalfFaceHandle>::const_iterator hf_it = halffaces.begin();
2409 hf_it != halffaces.end(); ++hf_it) {
2411 if(incident_cell_per_hf_[hf_it->idx()] == InvalidCellHandle) {
2413 incident_cell_per_hf_[hf_it->idx()] =
CellHandle(i);
2418 std::cerr <<
"compute_face_bottom_up_incidences(): Detected non-three-manifold configuration!" << std::endl;
2419 std::cerr <<
"Connectivity probably won't work." << std::endl;
void resize_cprops(size_t _nc)
Change size of stored cell properties.
virtual VertexHandle add_vertex()
Add abstract vertex.
virtual void swap_vertex_indices(VertexHandle _h1, VertexHandle _h2)
Exchanges the indices of two vertices while keeping the mesh otherwise unaffected.
virtual FaceHandle add_face(const std::vector< HalfEdgeHandle > &_halfedges, bool _topologyCheck=false)
Add face via incident edges.
size_t n_edges() const override
Get number of edges in mesh.
const Face & face(const FaceHandle &_faceHandle) const
Get face with handle _faceHandle.
virtual CellIter delete_cell(const CellHandle &_h)
Delete cell from mesh.
size_t n_cells() const override
Get number of cells in mesh.
void resize_eprops(size_t _ne)
Change size of stored edge properties.
CellHandle incident_cell(const HalfFaceHandle &_halfFaceHandle) const
Get cell that is incident to the given halfface.
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.
FaceIter delete_face_core(const FaceHandle &_h)
Delete face from mesh.
virtual EdgeHandle add_edge(const VertexHandle &_fromVertex, const VertexHandle &_toHandle, bool _allowDuplicates=false)
Add edge.
virtual EdgeIter delete_edge(const EdgeHandle &_h)
Delete edge from mesh.
static EdgeHandle edge_handle(const HalfEdgeHandle &_h)
Handle conversion.
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.
EdgeIter delete_edge_core(const EdgeHandle &_h)
Delete edge from mesh.
static HalfFaceHandle halfface_handle(const FaceHandle &_h, const unsigned char _subIdx)
Conversion function.
HalfEdgeHandle prev_halfedge_in_halfface(const HalfEdgeHandle &_heh, const HalfFaceHandle &_hfh) const
Get previous halfedge within a halfface.
size_t n_faces() const override
Get number of faces in mesh.
HalfEdgeHandle next_halfedge_in_halfface(const HalfEdgeHandle &_heh, const HalfFaceHandle &_hfh) const
Get next halfedge within a halfface.
size_t n_vertices() const override
Get number of vertices in mesh.
Face halfface(const HalfFaceHandle &_halfFaceHandle) const
Get face that corresponds to halfface with handle _halfFaceHandle.
void set_cell(const CellHandle &_ch, const std::vector< HalfFaceHandle > &_hfs)
Set the half-faces of a cell.
virtual VertexIter delete_vertex(const VertexHandle &_h)
Delete vertex from mesh.
virtual CellHandle add_cell(const std::vector< HalfFaceHandle > &_halffaces, bool _topologyCheck=false)
Add cell via incident halffaces.
void resize_fprops(size_t _nf)
Change size of stored face properties.
Edge opposite_halfedge(const HalfEdgeHandle &_halfEdgeHandle) const
Get opposite halfedge that corresponds to halfedge with handle _halfEdgeHandle.
bool bind(osg::GeometryPtr &_geo, Mesh &_mesh)
Edge halfedge(const HalfEdgeHandle &_halfEdgeHandle) const
Get edge that corresponds to halfedge with handle _halfEdgeHandle.
virtual FaceIter delete_face(const FaceHandle &_h)
Delete face from mesh.
virtual void swap_face_indices(FaceHandle _h1, FaceHandle _h2)
Exchanges the indices of two faces while keeping the mesh otherwise unaffected.
const Cell & cell(const CellHandle &_cellHandle) const
Get cell with handle _cellHandle.
virtual void collect_garbage()
Delete all entities that are marked as deleted.
HalfFaceHandle halfface_extensive(const std::vector< VertexHandle > &_vs) const
VertexIter delete_vertex_core(const VertexHandle &_h)
Delete vertex from mesh.
virtual void swap_cell_indices(CellHandle _h1, CellHandle _h2)
Exchanges the indices of two cells while keeping the mesh otherwise unaffected.
CellIter delete_cell_range(const CellIter &_first, const CellIter &_last)
Delete range of cells.
size_t n_halffaces() const override
Get number of halffaces in mesh.
const Edge & edge(const EdgeHandle &_edgeHandle) const
Get edge with handle _edgeHandle.
Face opposite_halfface(const HalfFaceHandle &_halfFaceHandle) const
Get opposite halfface that corresponds to halfface with handle _halfFaceHandle.
void resize_vprops(size_t _nv)
Change size of stored vertex properties.
static HalfEdgeHandle halfedge_handle(const EdgeHandle &_h, const unsigned char _subIdx)
Conversion function.
size_t n_halfedges() const override
Get number of halfedges in mesh.
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.