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);
243 for(std::vector<VertexHandle>::const_iterator it = _vertices.begin(),
244 end = _vertices.end(); it != end; ++it)
245 assert(it->is_valid() && (size_t)it->idx() <
n_vertices() && !is_deleted(*it));
249 std::vector<HalfEdgeHandle> halfedges;
250 std::vector<VertexHandle>::const_iterator it = _vertices.begin();
251 std::vector<VertexHandle>::const_iterator end = _vertices.end();
252 for(; (it+1) != end; ++it) {
257 char swap =
edge(e_idx).to_vertex() == *it;
262 char swap =
edge(e_idx).to_vertex() == *it;
275 void TopologyKernel::reorder_incident_halffaces(
const EdgeHandle& _eh) {
294 for(
unsigned char s = 0; s <= 1; s++) {
297 std::vector<HalfFaceHandle> new_halffaces;
302 assert((
size_t)cur_he.idx() < incident_hfs_per_he_.size());
304 if(incident_hfs_per_he_[cur_he.idx()].size() != 0) {
307 cur_hf = *incident_hfs_per_he_[cur_he.idx()].begin();
310 while(cur_hf != InvalidHalfFaceHandle) {
313 new_halffaces.push_back(cur_hf);
318 if(cur_hf != InvalidHalfFaceHandle)
322 cur_hf = opposite_halfface_handle(cur_hf);
326 if(cur_hf == start_hf)
break;
329 if(std::find(new_halffaces.begin(), new_halffaces.end(), cur_hf) != new_halffaces.end())
break;
336 if(new_halffaces.size() != incident_hfs_per_he_[cur_he.idx()].size()) {
341 while(cur_hf != InvalidHalfFaceHandle) {
343 cur_hf = opposite_halfface_handle(cur_hf);
346 if(cur_hf == start_hf)
break;
350 if(std::find(new_halffaces.begin(), new_halffaces.end(), cur_hf) != new_halffaces.end())
break;
352 if(cur_hf != InvalidHalfFaceHandle)
353 new_halffaces.insert(new_halffaces.begin(), cur_hf);
359 if(new_halffaces.size() == incident_hfs_per_he_[cur_he.idx()].size()) {
360 incident_hfs_per_he_[cur_he.idx()] = new_halffaces;
373 for(std::vector<HalfFaceHandle>::const_iterator it = _halffaces.begin(),
374 end = _halffaces.end(); it != end; ++it)
375 assert(it->is_valid() && ((size_t)it->idx() < faces_.size() * 2u) && !is_deleted(*it));
389 std::set<HalfEdgeHandle> incidentHalfedges;
390 std::set<EdgeHandle> incidentEdges;
392 for(std::vector<HalfFaceHandle>::const_iterator it = _halffaces.begin(),
393 end = _halffaces.end(); it != end; ++it) {
396 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hface.halfedges().begin(),
397 he_end = hface.halfedges().end(); he_it != he_end; ++he_it) {
398 incidentHalfedges.insert(*he_it);
403 if(incidentHalfedges.size() != (incidentEdges.size() * 2u)) {
405 std::cerr <<
"add_cell(): The specified half-faces are not connected!" << std::endl;
407 return InvalidCellHandle;
416 cells_.push_back(cell);
417 cell_deleted_.push_back(
false);
427 std::set<EdgeHandle> cell_edges;
428 for(std::vector<HalfFaceHandle>::const_iterator it = _halffaces.begin(),
429 end = _halffaces.end(); it != end; ++it) {
430 assert((
size_t)it->idx() < incident_cell_per_hf_.size());
434 if(incident_cell_per_hf_[it->idx()] != InvalidCellHandle) {
440 std::cerr <<
"add_cell(): One of the specified half-faces is already incident to another cell!" << std::endl;
446 incident_cell_per_hf_[it->idx()] = ch;
449 const std::vector<HalfEdgeHandle> hes =
halfface(*it).halfedges();
450 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin(),
451 he_end = hes.end(); he_it != he_end; ++he_it) {
462 for(std::set<EdgeHandle>::const_iterator e_it = cell_edges.begin(),
463 e_end = cell_edges.end(); e_it != e_end; ++e_it) {
464 reorder_incident_halffaces(*e_it);
478 assert(_fromVertex.is_valid() && (size_t)_fromVertex.idx() <
n_vertices() && !is_deleted(_fromVertex));
479 assert(_toVertex.is_valid() && (size_t)_toVertex.idx() <
n_vertices() && !is_deleted(_toVertex));
484 if(has_vertex_bottom_up_incidences()) {
492 std::vector<HalfEdgeHandle>::iterator h_end =
493 std::remove(outgoing_hes_per_vertex_[fv.idx()].begin(), outgoing_hes_per_vertex_[fv.idx()].end(), heh0);
494 outgoing_hes_per_vertex_[fv.idx()].resize(h_end - outgoing_hes_per_vertex_[fv.idx()].begin());
496 h_end = std::remove(outgoing_hes_per_vertex_[tv.idx()].begin(), outgoing_hes_per_vertex_[tv.idx()].end(), heh1);
497 outgoing_hes_per_vertex_[tv.idx()].resize(h_end - outgoing_hes_per_vertex_[tv.idx()].begin());
499 outgoing_hes_per_vertex_[_fromVertex.idx()].push_back(heh0);
500 outgoing_hes_per_vertex_[_toVertex.idx()].push_back(heh1);
503 e.set_from_vertex(_fromVertex);
504 e.set_to_vertex(_toVertex);
515 if(has_edge_bottom_up_incidences()) {
520 const std::vector<HalfEdgeHandle>& hes = f.halfedges();
522 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin(),
523 he_end = hes.end(); he_it != he_end; ++he_it) {
525 std::vector<HalfFaceHandle>::iterator h_end =
526 std::remove(incident_hfs_per_he_[he_it->idx()].begin(),
527 incident_hfs_per_he_[he_it->idx()].end(), hf0);
528 incident_hfs_per_he_[he_it->idx()].resize(h_end - incident_hfs_per_he_[he_it->idx()].begin());
530 h_end = std::remove(incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].begin(),
531 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].end(), hf1);
532 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].resize(h_end - incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].begin());
535 for(std::vector<HalfEdgeHandle>::const_iterator he_it = _hes.begin(),
536 he_end = _hes.end(); he_it != he_end; ++he_it) {
538 incident_hfs_per_he_[he_it->idx()].push_back(hf0);
539 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].push_back(hf1);
545 f.set_halfedges(_hes);
556 if(has_face_bottom_up_incidences()) {
558 const std::vector<HalfFaceHandle>& hfs = c.halffaces();
559 for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin(),
560 hf_end = hfs.end(); hf_it != hf_end; ++hf_it) {
562 incident_cell_per_hf_[hf_it->idx()] = InvalidCellHandle;
565 for(std::vector<HalfFaceHandle>::const_iterator hf_it = _hfs.begin(),
566 hf_end = _hfs.end(); hf_it != hf_end; ++hf_it) {
568 incident_cell_per_hf_[hf_it->idx()] = _ch;
572 c.set_halffaces(_hfs);
591 assert(!is_deleted(_h));
593 std::vector<VertexHandle> vs;
596 std::set<EdgeHandle> incidentEdges_s;
597 get_incident_edges(vs, incidentEdges_s);
599 std::set<FaceHandle> incidentFaces_s;
600 get_incident_faces(incidentEdges_s, incidentFaces_s);
602 std::set<CellHandle> incidentCells_s;
603 get_incident_cells(incidentFaces_s, incidentCells_s);
606 for(std::set<CellHandle>::const_reverse_iterator c_it = incidentCells_s.rbegin(),
607 c_end = incidentCells_s.rend(); c_it != c_end; ++c_it) {
612 for(std::set<FaceHandle>::const_reverse_iterator f_it = incidentFaces_s.rbegin(),
613 f_end = incidentFaces_s.rend(); f_it != f_end; ++f_it) {
618 for(std::set<EdgeHandle>::const_reverse_iterator e_it = incidentEdges_s.rbegin(),
619 e_end = incidentEdges_s.rend(); e_it != e_end; ++e_it) {
643 assert(!is_deleted(_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) {
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) {
686 assert(!is_deleted(_h));
688 std::vector<FaceHandle> fs;
691 std::set<CellHandle> incidentCells_s;
692 get_incident_cells(fs, incidentCells_s);
695 for(std::set<CellHandle>::const_reverse_iterator c_it = incidentCells_s.rbegin(),
696 c_end = incidentCells_s.rend(); c_it != c_end; ++c_it) {
717 assert(!is_deleted(_h));
726 if (!deferred_deletion_enabled() || !needs_garbage_collection())
729 deferred_deletion =
false;
731 for (
int i = (
int)
n_cells(); i > 0; --i) {
733 cell_deleted_[i - 1] =
false;
737 n_deleted_cells_ = 0;
739 for (
int i = (
int)
n_faces(); i > 0; --i) {
741 face_deleted_[i - 1] =
false;
745 n_deleted_faces_ = 0;
747 for (
int i = (
int)
n_edges(); i > 0; --i) {
749 edge_deleted_[i - 1] =
false;
753 n_deleted_edges_ = 0;
757 vertex_deleted_[i - 1] =
false;
761 n_deleted_vertices_ = 0;
763 deferred_deletion =
true;
769 template <
class ContainerT>
770 void TopologyKernel::get_incident_edges(
const ContainerT& _vs,
771 std::set<EdgeHandle>& _es)
const {
777 for(
typename ContainerT::const_iterator v_it = _vs.begin(),
778 v_end = _vs.end(); v_it != v_end; ++v_it) {
780 const std::vector<HalfEdgeHandle>& inc_hes = outgoing_hes_per_vertex_[v_it->idx()];
782 for(std::vector<HalfEdgeHandle>::const_iterator he_it = inc_hes.begin(),
783 he_end = inc_hes.end(); he_it != he_end; ++he_it) {
790 for(
typename ContainerT::const_iterator v_it = _vs.begin(),
791 v_end = _vs.end(); v_it != v_end; ++v_it) {
793 for(
EdgeIter e_it = edges_begin(), e_end = edges_end(); e_it != e_end; ++e_it) {
797 if(e.from_vertex() == *v_it || e.to_vertex() == *v_it) {
807 template <
class ContainerT>
808 void TopologyKernel::get_incident_faces(
const ContainerT& _es,
809 std::set<FaceHandle>& _fs)
const {
815 for(
typename ContainerT::const_iterator e_it = _es.begin(),
816 e_end = _es.end(); e_it != e_end; ++e_it) {
819 hehf_it.valid(); ++hehf_it) {
823 if(_fs.count(fh) == 0) {
830 for(
typename ContainerT::const_iterator e_it = _es.begin(),
831 e_end = _es.end(); e_it != e_end; ++e_it) {
834 f_end = faces_end(); f_it != f_end; ++f_it) {
836 const std::vector<HalfEdgeHandle>& hes =
face(*f_it).halfedges();
838 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin(),
839 he_end = hes.end(); he_it != he_end; ++he_it) {
853 template <
class ContainerT>
854 void TopologyKernel::get_incident_cells(
const ContainerT& _fs,
855 std::set<CellHandle>& _cs)
const {
861 for(
typename ContainerT::const_iterator f_it = _fs.begin(),
862 f_end = _fs.end(); f_it != f_end; ++f_it) {
870 if(c0.is_valid()) _cs.insert(c0);
871 if(c1.is_valid()) _cs.insert(c1);
875 for(
typename ContainerT::const_iterator f_it = _fs.begin(),
876 f_end = _fs.end(); f_it != f_end; ++f_it) {
878 for(
CellIter c_it = cells_begin(), c_end = cells_end();
879 c_it != c_end; ++c_it) {
881 const std::vector<HalfFaceHandle>& hfs =
cell(*c_it).halffaces();
883 for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin(),
884 hf_end = hfs.end(); hf_it != hf_end; ++hf_it) {
886 if(face_handle(*hf_it) == *f_it) {
918 assert(h.is_valid() && (size_t)h.idx() <
n_vertices());
920 if (fast_deletion_enabled() && !deferred_deletion_enabled())
923 assert(!vertex_deleted_[last_undeleted_vertex.idx()]);
925 h = last_undeleted_vertex;
928 if (deferred_deletion_enabled())
930 ++n_deleted_vertices_;
931 vertex_deleted_[h.idx()] =
true;
944 for(
int i = h.idx(), end = (int)
n_vertices(); i < end; ++i) {
945 const std::vector<HalfEdgeHandle>& hes = outgoing_hes_per_vertex_[i];
946 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin(),
947 he_end = hes.end(); he_it != he_end; ++he_it) {
950 if(e.from_vertex().idx() == i) {
953 if(e.to_vertex().idx() == i) {
962 for(
EdgeIter e_it = edges_begin(), e_end = edges_end();
963 e_it != e_end; ++e_it) {
966 if(
edge(*e_it).from_vertex() > h) {
969 if(
edge(*e_it).to_vertex() > h) {
978 assert((
size_t)h.idx() < outgoing_hes_per_vertex_.size());
979 outgoing_hes_per_vertex_.erase(outgoing_hes_per_vertex_.begin() + h.idx());
986 vertex_deleted_.erase(vertex_deleted_.begin() + h.idx());
1024 assert(h.is_valid() && (size_t)h.idx() < edges_.size());
1026 if (fast_deletion_enabled() && !deferred_deletion_enabled())
1029 assert(!edge_deleted_[last_edge.idx()]);
1040 assert(v0.is_valid() && (size_t)v0.idx() < outgoing_hes_per_vertex_.size());
1041 assert(v1.is_valid() && (size_t)v1.idx() < outgoing_hes_per_vertex_.size());
1043 outgoing_hes_per_vertex_[v0.idx()].erase(
1044 std::remove(outgoing_hes_per_vertex_[v0.idx()].begin(),
1045 outgoing_hes_per_vertex_[v0.idx()].end(),
1047 outgoing_hes_per_vertex_[v0.idx()].end());
1049 outgoing_hes_per_vertex_[v1.idx()].erase(
1050 std::remove(outgoing_hes_per_vertex_[v1.idx()].begin(),
1051 outgoing_hes_per_vertex_[v1.idx()].end(),
1053 outgoing_hes_per_vertex_[v1.idx()].end());
1056 if (deferred_deletion_enabled())
1059 edge_deleted_[h.idx()] =
true;
1069 if (!fast_deletion_enabled())
1074 assert((
size_t)
halfedge_handle(h, 0).idx() < incident_hfs_per_he_.size());
1079 std::set<FaceHandle> update_faces;
1080 for(std::vector<std::vector<HalfFaceHandle> >::const_iterator iit =
1082 iit_end = incident_hfs_per_he_.end(); iit != iit_end; ++iit) {
1083 for(std::vector<HalfFaceHandle>::const_iterator it = iit->begin(),
1084 end = iit->end(); it != end; ++it) {
1085 update_faces.insert(face_handle(*it));
1090 for(std::set<FaceHandle>::iterator f_it = update_faces.begin(),
1091 f_end = update_faces.end(); f_it != f_end; ++f_it) {
1093 std::vector<HalfEdgeHandle> hes =
face(*f_it).halfedges();
1096 hes.erase(std::remove(hes.begin(), hes.end(),
halfedge_handle(h, 0)), hes.end());
1097 hes.erase(std::remove(hes.begin(), hes.end(),
halfedge_handle(h, 1)), hes.end());
1099 #if defined(__clang_major__) && (__clang_major__ >= 5) 1100 for(std::vector<HalfEdgeHandle>::iterator it = hes.begin(), end = hes.end();
1102 cor.correctValue(*it);
1105 std::for_each(hes.begin(), hes.end(),
1106 fun::bind(&HEHandleCorrection::correctValue, &cor, fun::placeholders::_1));
1108 face(*f_it).set_halfedges(hes);
1113 for(
FaceIter f_it = faces_begin(), f_end = faces_end();
1114 f_it != f_end; ++f_it) {
1117 std::vector<HalfEdgeHandle> hes =
face(*f_it).halfedges();
1120 hes.erase(std::remove(hes.begin(), hes.end(),
halfedge_handle(h, 0)), hes.end());
1121 hes.erase(std::remove(hes.begin(), hes.end(),
halfedge_handle(h, 1)), hes.end());
1125 #if defined(__clang_major__) && (__clang_major__ >= 5) 1126 for(std::vector<HalfEdgeHandle>::iterator it = hes.begin(), end = hes.end();
1128 cor.correctValue(*it);
1131 std::for_each(hes.begin(), hes.end(),
1132 fun::bind(&HEHandleCorrection::correctValue, &cor, fun::placeholders::_1));
1134 face(*f_it).set_halfedges(hes);
1142 assert((
size_t)
halfedge_handle(h, 1).idx() < incident_hfs_per_he_.size());
1144 incident_hfs_per_he_.erase(incident_hfs_per_he_.begin() +
halfedge_handle(h, 1).idx());
1145 incident_hfs_per_he_.erase(incident_hfs_per_he_.begin() +
halfedge_handle(h, 0).idx());
1148 if (!fast_deletion_enabled())
1153 #if defined(__clang_major__) && (__clang_major__ >= 5) 1154 for(std::vector<std::vector<HalfEdgeHandle> >::iterator it = outgoing_hes_per_vertex_.begin(),
1155 end = outgoing_hes_per_vertex_.end(); it != end; ++it) {
1156 cor.correctVecValue(*it);
1159 std::for_each(outgoing_hes_per_vertex_.begin(),
1160 outgoing_hes_per_vertex_.end(),
1161 fun::bind(&HEHandleCorrection::correctVecValue, &cor, fun::placeholders::_1));
1168 edges_.erase(edges_.begin() + h.idx());
1169 edge_deleted_.erase(edge_deleted_.begin() + h.idx());
1208 assert(h.is_valid() && (size_t)h.idx() < faces_.size());
1211 if (fast_deletion_enabled() && !deferred_deletion_enabled())
1214 assert(!face_deleted_[last_face.idx()]);
1222 const std::vector<HalfEdgeHandle>& hes =
face(h).halfedges();
1223 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin(),
1224 he_end = hes.end(); he_it != he_end; ++he_it) {
1226 assert((
size_t)std::max(he_it->idx(), opposite_halfedge_handle(*he_it).idx()) < incident_hfs_per_he_.size());
1228 incident_hfs_per_he_[he_it->idx()].erase(
1229 std::remove(incident_hfs_per_he_[he_it->idx()].begin(),
1230 incident_hfs_per_he_[he_it->idx()].end(),
1234 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].erase(
1235 std::remove(incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].begin(),
1236 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].end(),
1237 halfface_handle(h, 1)), incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].end());
1243 if (deferred_deletion_enabled())
1246 face_deleted_[h.idx()] =
true;
1256 if (!fast_deletion_enabled())
1263 std::set<CellHandle> update_cells;
1264 for(std::vector<CellHandle>::const_iterator c_it = (incident_cell_per_hf_.begin() +
halfface_handle(h, 0).idx()),
1265 c_end = incident_cell_per_hf_.end(); c_it != c_end; ++c_it) {
1266 if(!c_it->is_valid())
continue;
1267 update_cells.insert(*c_it);
1269 for(std::set<CellHandle>::const_iterator c_it = update_cells.begin(),
1270 c_end = update_cells.end(); c_it != c_end; ++c_it) {
1272 std::vector<HalfFaceHandle> hfs =
cell(*c_it).halffaces();
1275 hfs.erase(std::remove(hfs.begin(), hfs.end(),
halfface_handle(h, 0)), hfs.end());
1276 hfs.erase(std::remove(hfs.begin(), hfs.end(),
halfface_handle(h, 1)), hfs.end());
1279 #if defined(__clang_major__) && (__clang_major__ >= 5) 1280 for(std::vector<HalfFaceHandle>::iterator it = hfs.begin(),
1281 end = hfs.end(); it != end; ++it) {
1282 cor.correctValue(*it);
1285 std::for_each(hfs.begin(), hfs.end(),
1286 fun::bind(&HFHandleCorrection::correctValue, &cor, fun::placeholders::_1));
1288 cell(*c_it).set_halffaces(hfs);
1294 for(
CellIter c_it = cells_begin(), c_end = cells_end(); c_it != c_end; ++c_it) {
1296 std::vector<HalfFaceHandle> hfs =
cell(*c_it).halffaces();
1299 hfs.erase(std::remove(hfs.begin(), hfs.end(),
halfface_handle(h, 0)), hfs.end());
1300 hfs.erase(std::remove(hfs.begin(), hfs.end(),
halfface_handle(h, 1)), hfs.end());
1303 #if defined(__clang_major__) && (__clang_major__ >= 5) 1304 for(std::vector<HalfFaceHandle>::iterator it = hfs.begin(),
1305 end = hfs.end(); it != end; ++it) {
1306 cor.correctValue(*it);
1309 std::for_each(hfs.begin(), hfs.end(),
1310 fun::bind(&HFHandleCorrection::correctValue, &cor, fun::placeholders::_1));
1312 cell(*c_it).set_halffaces(hfs);
1320 assert((
size_t)
halfface_handle(h, 1).idx() < incident_cell_per_hf_.size());
1322 incident_cell_per_hf_.erase(incident_cell_per_hf_.begin() +
halfface_handle(h, 1).idx());
1323 incident_cell_per_hf_.erase(incident_cell_per_hf_.begin() +
halfface_handle(h, 0).idx());
1327 if (!fast_deletion_enabled())
1332 #if defined(__clang_major__) && (__clang_major__ >= 5) 1333 for(std::vector<std::vector<HalfFaceHandle> >::iterator it = incident_hfs_per_he_.begin(), end = incident_hfs_per_he_.end(); it != end; ++it) {
1334 cor.correctVecValue(*it);
1337 std::for_each(incident_hfs_per_he_.begin(),
1338 incident_hfs_per_he_.end(),
1339 fun::bind(&HFHandleCorrection::correctVecValue, &cor, fun::placeholders::_1));
1345 faces_.erase(faces_.begin() + h.idx());
1346 face_deleted_.erase(face_deleted_.begin() + h.idx());
1379 assert(h.is_valid() && (size_t)h.idx() < cells_.size());
1382 if (fast_deletion_enabled() && !deferred_deletion_enabled())
1385 assert(!cell_deleted_[last_undeleted_cell.idx()]);
1387 h = last_undeleted_cell;
1393 const std::vector<HalfFaceHandle>& hfs =
cell(h).halffaces();
1394 for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin(),
1395 hf_end = hfs.end(); hf_it != hf_end; ++hf_it) {
1396 assert((
size_t)hf_it->idx() < incident_cell_per_hf_.size());
1397 if (incident_cell_per_hf_[hf_it->idx()] == h)
1398 incident_cell_per_hf_[hf_it->idx()] = InvalidCellHandle;
1400 std::set<EdgeHandle> edges;
1401 for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin(),
1402 hf_end = hfs.end(); hf_it != hf_end; ++hf_it) {
1404 for (
const auto& heh : hf.halfedges())
1407 for (
auto eh : edges)
1408 reorder_incident_halffaces(eh);
1411 if (deferred_deletion_enabled())
1414 cell_deleted_[h.idx()] =
true;
1424 if (!fast_deletion_enabled())
1428 #if defined(__clang_major__) && (__clang_major__ >= 5) 1429 for(std::vector<CellHandle>::iterator it = incident_cell_per_hf_.begin(),
1430 end = incident_cell_per_hf_.end(); it != end; ++it) {
1431 cor.correctValue(*it);
1434 std::for_each(incident_cell_per_hf_.begin(),
1435 incident_cell_per_hf_.end(),
1436 fun::bind(&CHandleCorrection::correctValue, &cor, fun::placeholders::_1));
1442 cells_.erase(cells_.begin() + h.idx());
1443 cell_deleted_.erase(cell_deleted_.begin() + h.idx());
1456 assert(_h1.idx() >= 0 && _h1.idx() < (int)cells_.size());
1457 assert(_h2.idx() >= 0 && _h2.idx() < (int)cells_.size());
1462 int id1 = _h1.idx();
1463 int id2 = _h2.idx();
1465 Cell c1 = cells_[id1];
1466 Cell c2 = cells_[id2];
1469 std::vector<HalfFaceHandle> hfhs1 = c1.halffaces();
1470 for (
unsigned int i = 0; i < hfhs1.size(); ++i)
1473 if (incident_cell_per_hf_[hfh.idx()] == _h1)
1474 incident_cell_per_hf_[hfh.idx()] = _h2;
1477 std::vector<HalfFaceHandle> hfhs2 = c2.halffaces();
1478 for (
unsigned int i = 0; i < hfhs2.size(); ++i)
1481 if (incident_cell_per_hf_[hfh.idx()] == _h2)
1482 incident_cell_per_hf_[hfh.idx()] = _h1;
1486 std::swap(cells_[id1], cells_[id2]);
1487 bool tmp = cell_deleted_[id1];
1488 cell_deleted_[id1] = cell_deleted_[id2];
1489 cell_deleted_[id2] = tmp;
1490 swap_cell_properties(_h1, _h2);
1495 assert(_h1.idx() >= 0 && _h1.idx() < (int)faces_.size());
1496 assert(_h2.idx() >= 0 && _h2.idx() < (int)faces_.size());
1502 std::vector<unsigned int> ids;
1503 ids.push_back(_h1.idx());
1504 ids.push_back(_h2.idx());
1506 unsigned int id1 = _h1.idx();
1507 unsigned int id2 = _h2.idx();
1512 if (has_face_bottom_up_incidences())
1514 std::set<unsigned int> processed_cells;
1515 for (
unsigned int i = 0; i < 2; ++i)
1517 unsigned int id = ids[i];
1518 for (
unsigned int j = 0; j < 2; ++j)
1521 CellHandle ch = incident_cell_per_hf_[hfh.idx()];
1527 if (processed_cells.find(ch.idx()) == processed_cells.end())
1530 Cell& c = cells_[ch.idx()];
1534 std::vector<HalfFaceHandle> new_halffaces;
1535 for (
unsigned int k = 0; k < c.halffaces().size(); ++k)
1536 if (c.halffaces()[k].idx()/2 == (int)id1)
1537 new_halffaces.push_back(
HalfFaceHandle(2 * id2 + (c.halffaces()[k].idx() % 2)));
1538 else if (c.halffaces()[k].idx()/2 == (int)id2)
1539 new_halffaces.push_back(
HalfFaceHandle(2 * id1 + (c.halffaces()[k].idx() % 2)));
1541 new_halffaces.push_back(c.halffaces()[k]);
1542 c.set_halffaces(new_halffaces);
1544 processed_cells.insert(ch.idx());
1552 for (
unsigned int i = 0; i < cells_.size(); ++i)
1554 Cell& c = cells_[i];
1557 bool contains_swapped_face =
false;
1558 for (
unsigned int k = 0; k < c.halffaces().size(); ++k)
1560 if (c.halffaces()[k].idx()/2 == (int)id1)
1561 contains_swapped_face =
true;
1562 if (c.halffaces()[k].idx()/2 == (int)id2)
1563 contains_swapped_face =
true;
1564 if (contains_swapped_face)
1568 if (contains_swapped_face)
1571 std::vector<HalfFaceHandle> new_halffaces;
1572 for (
unsigned int k = 0; k < c.halffaces().size(); ++k)
1573 if (c.halffaces()[k].idx()/2 == (int)id1)
1574 new_halffaces.push_back(
HalfFaceHandle(2 * id2 + (c.halffaces()[k].idx() % 2)));
1575 else if (c.halffaces()[k].idx()/2 == (int)id2)
1576 new_halffaces.push_back(
HalfFaceHandle(2 * id1 + (c.halffaces()[k].idx() % 2)));
1578 new_halffaces.push_back(c.halffaces()[k]);
1579 c.set_halffaces(new_halffaces);
1586 if (has_edge_bottom_up_incidences())
1588 std::set<HalfEdgeHandle> processed_halfedges;
1589 for (
unsigned int i = 0; i < 2; ++i)
1591 unsigned int id = ids[i];
1592 for (
unsigned int j = 0; j < 2; ++j)
1597 for (
unsigned int k = 0; k < hf.halfedges().size(); ++k)
1601 if (processed_halfedges.find(heh) != processed_halfedges.end())
1604 std::vector<HalfFaceHandle>& incident_halffaces = incident_hfs_per_he_[heh.idx()];
1605 for (
unsigned int l = 0; l < incident_halffaces.size(); ++l)
1609 if (hfh2.idx()/2 == (int)id1)
1611 else if (hfh2.idx()/2 == (int)id2)
1615 processed_halfedges.insert(heh);
1622 std::swap(faces_[ids[0]], faces_[ids[1]]);
1623 bool tmp = face_deleted_[ids[0]];
1624 face_deleted_[ids[0]] = face_deleted_[ids[1]];
1625 face_deleted_[ids[1]] = tmp;
1626 std::swap(incident_cell_per_hf_[2*ids[0]+0], incident_cell_per_hf_[2*ids[1]+0]);
1627 std::swap(incident_cell_per_hf_[2*ids[0]+1], incident_cell_per_hf_[2*ids[1]+1]);
1628 swap_face_properties(_h1, _h2);
1636 assert(_h1.idx() >= 0 && _h1.idx() < (int)edges_.size());
1637 assert(_h2.idx() >= 0 && _h2.idx() < (int)edges_.size());
1642 std::vector<unsigned int> ids;
1643 ids.push_back(_h1.idx());
1644 ids.push_back(_h2.idx());
1649 if (has_edge_bottom_up_incidences())
1651 std::set<unsigned int> processed_faces;
1653 for (
unsigned int i = 0; i < 2; ++i)
1658 std::vector<HalfFaceHandle>& incident_halffaces = incident_hfs_per_he_[heh.idx()];
1659 for (
unsigned int j = 0; j < incident_halffaces.size(); ++j)
1663 unsigned int f_id = hfh.idx() / 2;
1665 if (processed_faces.find(f_id) == processed_faces.end())
1668 Face& f = faces_[f_id];
1671 std::vector<HalfEdgeHandle> new_halfedges;
1672 for (
unsigned int k = 0; k < f.halfedges().size(); ++k)
1675 if (heh2.idx() / 2 == (int)ids[0])
1676 new_halfedges.push_back(
HalfEdgeHandle(2*ids[1] + (heh2.idx() % 2)));
1677 else if (heh2.idx() / 2 == (int)ids[1])
1678 new_halfedges.push_back(
HalfEdgeHandle(2*ids[0] + (heh2.idx() % 2)));
1680 new_halfedges.push_back(heh2);
1682 f.set_halfedges(new_halfedges);
1684 processed_faces.insert(f_id);
1692 for (
unsigned int i = 0; i < faces_.size(); ++i)
1694 Face& f = faces_[i];
1697 bool contains_swapped_edge =
false;
1698 for (
unsigned int k = 0; k < f.halfedges().size(); ++k)
1700 if (f.halfedges()[k].idx()/2 == (int)ids[0])
1701 contains_swapped_edge =
true;
1702 if (f.halfedges()[k].idx()/2 == (int)ids[1])
1703 contains_swapped_edge =
true;
1704 if (contains_swapped_edge)
1708 if (contains_swapped_edge)
1711 std::vector<HalfEdgeHandle> new_halfedges;
1712 for (
unsigned int k = 0; k < f.halfedges().size(); ++k)
1715 if (heh2.idx() / 2 == (int)ids[0])
1716 new_halfedges.push_back(
HalfEdgeHandle(2*ids[1] + (heh2.idx() % 2)));
1717 else if (heh2.idx() / 2 == (int)ids[1])
1718 new_halfedges.push_back(
HalfEdgeHandle(2*ids[0] + (heh2.idx() % 2)));
1720 new_halfedges.push_back(heh2);
1722 f.set_halfedges(new_halfedges);
1729 if (has_vertex_bottom_up_incidences())
1731 std::set<VertexHandle> processed_vertices;
1732 for (
unsigned int i = 0; i < 2; ++i)
1735 std::vector<VertexHandle> vhs;
1736 vhs.push_back(e.from_vertex());
1737 vhs.push_back(e.to_vertex());
1739 for (
unsigned int j = 0; j < 2; ++j)
1741 if (processed_vertices.find(vhs[j]) != processed_vertices.end())
1744 std::vector<HalfEdgeHandle>& outgoing_hes = outgoing_hes_per_vertex_[vhs[j].idx()];
1745 for (
unsigned int k = 0; k < outgoing_hes.size(); ++k)
1748 if (heh.idx() / 2 == (int)ids[0])
1750 else if (heh.idx() / 2 == (int)ids[1])
1753 processed_vertices.insert(vhs[j]);
1760 std::swap(edges_[ids[0]], edges_[ids[1]]);
1761 bool tmp = edge_deleted_[ids[0]];
1762 edge_deleted_[ids[0]] = edge_deleted_[ids[1]];
1763 edge_deleted_[ids[1]] = tmp;
1764 std::swap(incident_hfs_per_he_[2*ids[0]+0], incident_hfs_per_he_[2*ids[1]+0]);
1765 std::swap(incident_hfs_per_he_[2*ids[0]+1], incident_hfs_per_he_[2*ids[1]+1]);
1766 swap_edge_properties(_h1, _h2);
1774 assert(_h1.idx() >= 0 && _h1.idx() < (int)n_vertices_);
1775 assert(_h2.idx() >= 0 && _h2.idx() < (int)n_vertices_);
1780 std::vector<unsigned int> ids;
1781 ids.push_back(_h1.idx());
1782 ids.push_back(_h2.idx());
1787 if (has_vertex_bottom_up_incidences())
1789 for (
unsigned int i = 0; i < 2; ++i)
1791 std::set<unsigned int> processed_edges;
1792 std::vector<HalfEdgeHandle>& outgoing_hes = outgoing_hes_per_vertex_[ids[i]];
1793 for (
unsigned int k = 0; k < outgoing_hes.size(); ++k)
1795 unsigned int e_id = outgoing_hes[k].idx() / 2;
1797 if (processed_edges.find(e_id) == processed_edges.end())
1799 Edge& e = edges_[e_id];
1800 if (e.from_vertex().idx() == (int)ids[0])
1802 else if (e.from_vertex().idx() == (int)ids[1])
1805 if (e.to_vertex().idx() == (int)ids[0])
1807 else if (e.to_vertex().idx() == (int)ids[1])
1810 processed_edges.insert(e_id);
1820 for (
unsigned int i = 0; i < edges_.size(); ++i)
1822 Edge& e = edges_[i];
1823 if (e.from_vertex().idx() == (int)ids[0])
1825 else if (e.from_vertex().idx() == (int)ids[1])
1828 if (e.to_vertex().idx() == (int)ids[0])
1830 else if (e.to_vertex().idx() == (int)ids[1])
1836 bool tmp = vertex_deleted_[ids[0]];
1837 vertex_deleted_[ids[0]] = vertex_deleted_[ids[1]];
1838 vertex_deleted_[ids[1]] = tmp;
1839 std::swap(outgoing_hes_per_vertex_[ids[0]], outgoing_hes_per_vertex_[ids[1]]);
1840 swap_vertex_properties(_h1, _h2);
1845 void TopologyKernel::delete_multiple_vertices(
const std::vector<bool>& _tag) {
1849 std::vector<int> newIndices(
n_vertices(), -1);
1852 std::vector<int>::iterator idx_it = newIndices.begin();
1853 for(std::vector<bool>::const_iterator t_it = _tag.begin(),
1854 t_end = _tag.end(); t_it != t_end; ++t_it, ++idx_it) {
1866 delete_multiple_vertex_props(_tag);
1869 std::for_each(edges_.begin(), edges_.end(), corrector);
1874 void TopologyKernel::delete_multiple_edges(
const std::vector<bool>& _tag) {
1876 assert(_tag.size() ==
n_edges());
1878 std::vector<int> newIndices(
n_edges(), -1);
1881 std::vector<Edge> newEdges;
1883 std::vector<int>::iterator idx_it = newIndices.begin();
1884 std::vector<Edge>::const_iterator e_it = edges_.begin();
1886 for(std::vector<bool>::const_iterator t_it = _tag.begin(),
1887 t_end = _tag.end(); t_it != t_end; ++t_it, ++idx_it, ++e_it) {
1892 newEdges.push_back(*e_it);
1900 edges_.swap(newEdges);
1903 delete_multiple_edge_props(_tag);
1906 std::for_each(faces_.begin(), faces_.end(), corrector);
1911 void TopologyKernel::delete_multiple_faces(
const std::vector<bool>& _tag) {
1913 assert(_tag.size() ==
n_faces());
1915 std::vector<int> newIndices(
n_faces(), -1);
1918 std::vector<Face> newFaces;
1920 std::vector<int>::iterator idx_it = newIndices.begin();
1921 std::vector<Face>::const_iterator f_it = faces_.begin();
1923 for(std::vector<bool>::const_iterator t_it = _tag.begin(),
1924 t_end = _tag.end(); t_it != t_end; ++t_it, ++idx_it, ++f_it) {
1929 newFaces.push_back(*f_it);
1937 faces_.swap(newFaces);
1940 delete_multiple_face_props(_tag);
1943 std::for_each(cells_.begin(), cells_.end(), corrector);
1948 void TopologyKernel::delete_multiple_cells(
const std::vector<bool>& _tag) {
1950 assert(_tag.size() ==
n_cells());
1952 std::vector<Cell> newCells;
1954 std::vector<Cell>::const_iterator c_it = cells_.begin();
1956 for(std::vector<bool>::const_iterator t_it = _tag.begin(),
1957 t_end = _tag.end(); t_it != t_end; ++t_it, ++c_it) {
1962 newCells.push_back(*c_it);
1967 cells_.swap(newCells);
1970 delete_multiple_cell_props(_tag);
1978 assert(_first >= cells_begin());
1979 assert(_last <= cells_end());
1981 std::vector<Cell>::iterator it = cells_.erase(cells_.begin() + _first->idx(), cells_.begin() + _last->idx());
1985 f_bottom_up_ =
false;
1986 enable_face_bottom_up_incidences(
true);
1992 void TopologyKernel::enable_deferred_deletion(
bool _enable)
1994 if (deferred_deletion && !_enable)
1997 deferred_deletion = _enable;
2006 assert(_edgeHandle.is_valid() && (size_t)_edgeHandle.idx() < edges_.size());
2008 return edges_[_edgeHandle.idx()];
2017 assert(_faceHandle.is_valid() && (size_t)_faceHandle.idx() < faces_.size());
2019 return faces_[_faceHandle.idx()];
2028 assert(_cellHandle.is_valid() && (size_t)_cellHandle.idx() < cells_.size());
2030 return cells_[_cellHandle.idx()];
2039 assert(_edgeHandle.is_valid() && (size_t)_edgeHandle.idx() < edges_.size());
2041 return edges_[_edgeHandle.idx()];
2050 assert((
size_t)_faceHandle.idx() < faces_.size());
2051 assert(_faceHandle.idx() >= 0);
2053 return faces_[_faceHandle.idx()];
2062 assert((
size_t)_cellHandle.idx() < cells_.size());
2063 assert(_cellHandle.idx() >= 0);
2065 return cells_[_cellHandle.idx()];
2074 assert((
size_t)_halfEdgeHandle.idx() < (edges_.size() * 2));
2075 assert(_halfEdgeHandle.idx() >= 0);
2079 if(_halfEdgeHandle.idx() % 2 == 0)
2080 return edges_[(
int)(_halfEdgeHandle.idx() / 2)];
2091 assert((
size_t)_halfFaceHandle.idx() < (faces_.size() * 2));
2092 assert(_halfFaceHandle.idx() >= 0);
2096 if(_halfFaceHandle.idx() % 2 == 0)
2097 return faces_[(
int)(_halfFaceHandle.idx() / 2)];
2108 assert(_halfEdgeHandle.idx() >= 0);
2109 assert((
size_t)_halfEdgeHandle.idx() < (edges_.size() * 2));
2113 if(_halfEdgeHandle.idx() % 2 != 0)
2114 return edges_[(
int)(_halfEdgeHandle.idx() / 2)];
2125 assert(_halfFaceHandle.idx() >= 0);
2126 assert((
size_t)_halfFaceHandle.idx() < (faces_.size() * 2));
2130 if(_halfFaceHandle.idx() % 2 != 0)
2131 return faces_[(
int)(_halfFaceHandle.idx() / 2)];
2144 if(
halfedge(*voh_it).to_vertex() == _vh2) {
2149 return InvalidHalfEdgeHandle;
2156 assert(_vs.size() > 2);
2160 assert(v0.is_valid() && v1.is_valid() && v2.is_valid());
2163 if(!he0.is_valid())
return InvalidHalfFaceHandle;
2165 if(!he1.is_valid())
return InvalidHalfFaceHandle;
2167 std::vector<HalfEdgeHandle> hes;
2178 assert(_vs.size() > 2);
2183 assert(v0.is_valid() && v1.is_valid());
2186 if(!he0.is_valid())
return InvalidHalfFaceHandle;
2190 std::vector<HalfEdgeHandle> hes =
halfface(*hehf_it).halfedges();
2192 if (hes.size() != _vs.size())
2196 for (
unsigned int i = 0; i < hes.size(); ++i)
2200 bool all_vertices_found =
true;
2202 for (
unsigned int i = 0; i < hes.size(); ++i)
2205 if (
halfedge(heh).from_vertex() != _vs[i])
2207 all_vertices_found =
false;
2212 if (all_vertices_found)
2216 return InvalidHalfFaceHandle;
2223 assert(_hes.size() >= 2);
2227 assert(he0.is_valid() && he1.is_valid());
2231 std::vector<HalfEdgeHandle> hes =
halfface(*hehf_it).halfedges();
2232 if(std::find(hes.begin(), hes.end(), he1) != hes.end()) {
2237 return InvalidHalfFaceHandle;
2244 assert(_heh.is_valid() && (size_t)_heh.idx() < edges_.size() * 2u);
2245 assert(_hfh.is_valid() && (size_t)_hfh.idx() < faces_.size() * 2u);
2247 std::vector<HalfEdgeHandle> hes =
halfface(_hfh).halfedges();
2249 for(std::vector<HalfEdgeHandle>::const_iterator it = hes.begin();
2250 it != hes.end(); ++it) {
2252 if((it + 1) != hes.end())
return *(it + 1);
2253 else return *hes.begin();
2257 return InvalidHalfEdgeHandle;
2264 assert(_heh.is_valid() && (size_t)_heh.idx() < edges_.size() * 2u);
2265 assert(_hfh.is_valid() && (size_t)_hfh.idx() < faces_.size() * 2u);
2267 std::vector<HalfEdgeHandle> hes =
halfface(_hfh).halfedges();
2269 for(std::vector<HalfEdgeHandle>::const_iterator it = hes.begin();
2270 it != hes.end(); ++it) {
2272 if(it != hes.begin())
return *(it - 1);
2273 else return *(hes.end() - 1);
2277 return InvalidHalfEdgeHandle;
2285 assert(_halfFaceHandle.is_valid() && (size_t)_halfFaceHandle.idx() < faces_.size() * 2u);
2286 assert(_halfEdgeHandle.is_valid() && (size_t)_halfEdgeHandle.idx() < edges_.size() * 2u);
2287 assert(has_face_bottom_up_incidences());
2288 assert((
size_t)_halfFaceHandle.idx() < incident_cell_per_hf_.size());
2290 if(incident_cell_per_hf_[_halfFaceHandle.idx()] == InvalidCellHandle) {
2292 return InvalidHalfFaceHandle;
2298 bool skipped =
false;
2301 for(std::vector<HalfFaceHandle>::const_iterator hf_it = c.halffaces().begin();
2302 hf_it != c.halffaces().end(); ++hf_it) {
2304 if(*hf_it == _halfFaceHandle) {
2310 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hf.halfedges().begin();
2311 he_it != hf.halfedges().end(); ++he_it) {
2317 if(skipped && found)
break;
2319 if(skipped && found)
break;
2321 return ((skipped && found) ? idx : InvalidHalfFaceHandle);
2328 if(!has_face_bottom_up_incidences()) {
2329 return InvalidCellHandle;
2331 if((
size_t)_halfFaceHandle.idx() >= incident_cell_per_hf_.size() || _halfFaceHandle.idx() < 0) {
2332 return InvalidCellHandle;
2335 return incident_cell_per_hf_[_halfFaceHandle.idx()];
2340 void TopologyKernel::compute_vertex_bottom_up_incidences() {
2343 outgoing_hes_per_vertex_.clear();
2344 outgoing_hes_per_vertex_.resize(
n_vertices());
2347 int n_edges = (int)edges_.size();
2348 for(
int i = 0; i <
n_edges; ++i) {
2349 if (edge_deleted_[i])
2355 assert((
size_t)from.idx() < outgoing_hes_per_vertex_.size());
2360 assert((
size_t)to.idx() < outgoing_hes_per_vertex_.size());
2369 void TopologyKernel::compute_edge_bottom_up_incidences() {
2372 incident_hfs_per_he_.clear();
2373 incident_hfs_per_he_.resize(edges_.size() * 2u);
2376 int n_faces = (int)faces_.size();
2377 for(
int i = 0; i <
n_faces; ++i) {
2378 if (face_deleted_[i])
2381 std::vector<HalfEdgeHandle> halfedges = faces_[i].halfedges();
2384 for(std::vector<HalfEdgeHandle>::const_iterator he_it = halfedges.begin();
2385 he_it != halfedges.end(); ++he_it) {
2388 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].push_back(
2396 void TopologyKernel::compute_face_bottom_up_incidences() {
2399 incident_cell_per_hf_.clear();
2400 incident_cell_per_hf_.resize(faces_.size() * 2u, InvalidCellHandle);
2402 int n_cells = (int)cells_.size();
2403 for(
int i = 0; i <
n_cells; ++i) {
2404 if (cell_deleted_[i])
2407 std::vector<HalfFaceHandle> halffaces = cells_[i].halffaces();
2410 for(std::vector<HalfFaceHandle>::const_iterator hf_it = halffaces.begin();
2411 hf_it != halffaces.end(); ++hf_it) {
2413 if(incident_cell_per_hf_[hf_it->idx()] == InvalidCellHandle) {
2415 incident_cell_per_hf_[hf_it->idx()] =
CellHandle(i);
2420 std::cerr <<
"compute_face_bottom_up_incidences(): Detected non-three-manifold configuration!" << std::endl;
2421 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.