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_);
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) {
118 for(
size_t i = 0; i < edges_.size(); ++i) {
133 edge_deleted_.push_back(
false);
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));
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);
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());
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;
275 if(
edge(e_idx).to_vertex() == *it) swap = 1;
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);
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);
355 if(cur_hf == start_hf)
break;
357 if(cur_hf != InvalidHalfFaceHandle)
358 new_halffaces.insert(new_halffaces.begin(), cur_hf);
362 if(std::find(new_halffaces.begin(), new_halffaces.end(), cur_hf) != new_halffaces.end())
break;
367 if(new_halffaces.size() == incident_hfs_per_he_[cur_he.idx()].size()) {
368 incident_hfs_per_he_[cur_he.idx()] = new_halffaces;
381 for(std::vector<HalfFaceHandle>::const_iterator it = _halffaces.begin(),
382 end = _halffaces.end(); it != end; ++it)
383 assert(it->is_valid() && ((size_t)it->idx() < faces_.size() * 2u));
397 std::set<HalfEdgeHandle> incidentHalfedges;
398 std::set<EdgeHandle> incidentEdges;
400 for(std::vector<HalfFaceHandle>::const_iterator it = _halffaces.begin(),
401 end = _halffaces.end(); it != end; ++it) {
404 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hface.halfedges().begin(),
405 he_end = hface.halfedges().end(); he_it != he_end; ++he_it) {
406 incidentHalfedges.insert(*he_it);
411 if(incidentHalfedges.size() != (incidentEdges.size() * 2u)) {
413 std::cerr <<
"add_cell(): The specified half-faces are not connected!" << std::endl;
415 return InvalidCellHandle;
424 cells_.push_back(cell);
425 cell_deleted_.push_back(
false);
435 std::set<EdgeHandle> cell_edges;
436 for(std::vector<HalfFaceHandle>::const_iterator it = _halffaces.begin(),
437 end = _halffaces.end(); it != end; ++it) {
438 assert((
size_t)it->idx() < incident_cell_per_hf_.size());
442 if(incident_cell_per_hf_[it->idx()] != InvalidCellHandle) {
448 std::cerr <<
"add_cell(): One of the specified half-faces is already incident to another cell!" << std::endl;
454 incident_cell_per_hf_[it->idx()] = ch;
457 const std::vector<HalfEdgeHandle> hes =
halfface(*it).halfedges();
458 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin(),
459 he_end = hes.end(); he_it != he_end; ++he_it) {
470 for(std::set<EdgeHandle>::const_iterator e_it = cell_edges.begin(),
471 e_end = cell_edges.end(); e_it != e_end; ++e_it) {
472 reorder_incident_halffaces(*e_it);
488 if(has_vertex_bottom_up_incidences()) {
496 std::vector<HalfEdgeHandle>::iterator h_end =
497 std::remove(outgoing_hes_per_vertex_[fv.idx()].begin(), outgoing_hes_per_vertex_[fv.idx()].end(), heh0);
498 outgoing_hes_per_vertex_[fv.idx()].resize(h_end - outgoing_hes_per_vertex_[fv.idx()].begin());
500 h_end = std::remove(outgoing_hes_per_vertex_[tv.idx()].begin(), outgoing_hes_per_vertex_[tv.idx()].end(), heh1);
501 outgoing_hes_per_vertex_[tv.idx()].resize(h_end - outgoing_hes_per_vertex_[tv.idx()].begin());
503 outgoing_hes_per_vertex_[_fromVertex.idx()].push_back(heh0);
504 outgoing_hes_per_vertex_[_toVertex.idx()].push_back(heh1);
507 e.set_from_vertex(_fromVertex);
508 e.set_to_vertex(_toVertex);
518 if(has_edge_bottom_up_incidences()) {
523 const std::vector<HalfEdgeHandle>& hes = f.halfedges();
525 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin(),
526 he_end = hes.end(); he_it != he_end; ++he_it) {
528 std::vector<HalfFaceHandle>::iterator h_end =
529 std::remove(incident_hfs_per_he_[he_it->idx()].begin(),
530 incident_hfs_per_he_[he_it->idx()].end(), hf0);
531 incident_hfs_per_he_[he_it->idx()].resize(h_end - incident_hfs_per_he_[he_it->idx()].begin());
533 h_end = std::remove(incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].begin(),
534 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].end(), hf1);
535 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].resize(h_end - incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].begin());
538 for(std::vector<HalfEdgeHandle>::const_iterator he_it = _hes.begin(),
539 he_end = _hes.end(); he_it != he_end; ++he_it) {
541 incident_hfs_per_he_[he_it->idx()].push_back(hf0);
542 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].push_back(hf1);
548 f.set_halfedges(_hes);
558 if(has_face_bottom_up_incidences()) {
560 const std::vector<HalfFaceHandle>& hfs = c.halffaces();
561 for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin(),
562 hf_end = hfs.end(); hf_it != hf_end; ++hf_it) {
564 incident_cell_per_hf_[*hf_it] = InvalidCellHandle;
567 for(std::vector<HalfFaceHandle>::const_iterator hf_it = _hfs.begin(),
568 hf_end = _hfs.end(); hf_it != hf_end; ++hf_it) {
570 incident_cell_per_hf_[*hf_it] = _ch;
574 c.set_halffaces(_hfs);
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 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 std::vector<FaceHandle> fs;
687 std::set<CellHandle> incidentCells_s;
688 get_incident_cells(fs, incidentCells_s);
691 for(std::set<CellHandle>::const_reverse_iterator c_it = incidentCells_s.rbegin(),
692 c_end = incidentCells_s.rend(); c_it != c_end; ++c_it) {
721 if (!deferred_deletion_enabled())
724 deferred_deletion =
false;
726 for (
unsigned int i =
n_cells(); i > 0; --i)
729 cell_deleted_[i-1] =
false;
733 for (
unsigned int i =
n_faces(); i > 0; --i)
736 face_deleted_[i-1] =
false;
740 for (
unsigned int i =
n_edges(); i > 0; --i)
743 edge_deleted_[i-1] =
false;
747 for (
unsigned int i =
n_vertices(); i > 0; --i)
750 vertex_deleted_[i-1] =
false;
755 deferred_deletion =
true;
761 template <
class ContainerT>
762 void TopologyKernel::get_incident_edges(
const ContainerT& _vs,
763 std::set<EdgeHandle>& _es)
const {
769 for(
typename ContainerT::const_iterator v_it = _vs.begin(),
770 v_end = _vs.end(); v_it != v_end; ++v_it) {
772 const std::vector<HalfEdgeHandle>& inc_hes = outgoing_hes_per_vertex_[v_it->idx()];
774 for(std::vector<HalfEdgeHandle>::const_iterator he_it = inc_hes.begin(),
775 he_end = inc_hes.end(); he_it != he_end; ++he_it) {
782 for(
typename ContainerT::const_iterator v_it = _vs.begin(),
783 v_end = _vs.end(); v_it != v_end; ++v_it) {
785 for(EdgeIter e_it = edges_begin(), e_end = edges_end(); e_it != e_end; ++e_it) {
787 const Edge& e =
edge(*e_it);
789 if(e.from_vertex() == *v_it || e.to_vertex() == *v_it) {
799 template <
class ContainerT>
800 void TopologyKernel::get_incident_faces(
const ContainerT& _es,
801 std::set<FaceHandle>& _fs)
const {
807 for(
typename ContainerT::const_iterator e_it = _es.begin(),
808 e_end = _es.end(); e_it != e_end; ++e_it) {
810 for(HalfEdgeHalfFaceIter hehf_it = hehf_iter(
halfedge_handle(*e_it, 0));
811 hehf_it.valid(); ++hehf_it) {
813 const FaceHandle fh = face_handle(*hehf_it);
815 if(_fs.count(fh) == 0) {
822 for(
typename ContainerT::const_iterator e_it = _es.begin(),
823 e_end = _es.end(); e_it != e_end; ++e_it) {
825 for(FaceIter f_it = faces_begin(),
826 f_end = faces_end(); f_it != f_end; ++f_it) {
828 const std::vector<HalfEdgeHandle>& hes =
face(*f_it).halfedges();
830 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin(),
831 he_end = hes.end(); he_it != he_end; ++he_it) {
845 template <
class ContainerT>
846 void TopologyKernel::get_incident_cells(
const ContainerT& _fs,
847 std::set<CellHandle>& _cs)
const {
853 for(
typename ContainerT::const_iterator f_it = _fs.begin(),
854 f_end = _fs.end(); f_it != f_end; ++f_it) {
862 if(c0.is_valid()) _cs.insert(c0);
863 if(c1.is_valid()) _cs.insert(c1);
867 for(
typename ContainerT::const_iterator f_it = _fs.begin(),
868 f_end = _fs.end(); f_it != f_end; ++f_it) {
870 for(CellIter c_it = cells_begin(), c_end = cells_end();
871 c_it != c_end; ++c_it) {
873 const std::vector<HalfFaceHandle>& hfs =
cell(*c_it).halffaces();
875 for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin(),
876 hf_end = hfs.end(); hf_it != hf_end; ++hf_it) {
878 if(face_handle(*hf_it) == *f_it) {
910 assert(h.is_valid() && (size_t)h.idx() <
n_vertices());
912 if (fast_deletion_enabled() && !deferred_deletion_enabled())
915 assert(!vertex_deleted_[last_undeleted_vertex.idx()]);
916 swap_vertices(h, last_undeleted_vertex);
917 h = last_undeleted_vertex;
920 if (deferred_deletion_enabled())
922 vertex_deleted_[h.idx()] =
true;
935 for(
int i = h.idx(), end =
n_vertices(); i < end; ++i) {
936 const std::vector<HalfEdgeHandle>& hes = outgoing_hes_per_vertex_[i];
937 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin(),
938 he_end = hes.end(); he_it != he_end; ++he_it) {
941 if(e.from_vertex().idx() == i) {
944 if(e.to_vertex().idx() == i) {
953 for(
EdgeIter e_it = edges_begin(), e_end = edges_end();
954 e_it != e_end; ++e_it) {
957 if(
edge(*e_it).from_vertex() > h) {
960 if(
edge(*e_it).to_vertex() > h) {
969 assert((
size_t)h.idx() < outgoing_hes_per_vertex_.size());
970 outgoing_hes_per_vertex_.erase(outgoing_hes_per_vertex_.begin() + h.idx());
977 vertex_deleted_.erase(vertex_deleted_.begin() + h.idx());
1015 assert(h.is_valid() && (size_t)h.idx() < edges_.size());
1017 if (fast_deletion_enabled() && !deferred_deletion_enabled())
1020 assert(!edge_deleted_[last_edge.idx()]);
1021 swap_edges(h, last_edge);
1031 assert(v0.is_valid() && (size_t)v0.idx() < outgoing_hes_per_vertex_.size());
1032 assert(v1.is_valid() && (size_t)v1.idx() < outgoing_hes_per_vertex_.size());
1034 outgoing_hes_per_vertex_[v0.idx()].erase(
1035 std::remove(outgoing_hes_per_vertex_[v0.idx()].begin(),
1036 outgoing_hes_per_vertex_[v0.idx()].end(),
1038 outgoing_hes_per_vertex_[v0.idx()].end());
1040 outgoing_hes_per_vertex_[v1.idx()].erase(
1041 std::remove(outgoing_hes_per_vertex_[v1.idx()].begin(),
1042 outgoing_hes_per_vertex_[v1.idx()].end(),
1044 outgoing_hes_per_vertex_[v1.idx()].end());
1047 if (deferred_deletion_enabled())
1049 edge_deleted_[h.idx()] =
true;
1059 if (!fast_deletion_enabled())
1064 assert((
size_t)
halfedge_handle(h, 0).idx() < incident_hfs_per_he_.size());
1069 std::set<FaceHandle> update_faces;
1070 for(std::vector<std::vector<HalfFaceHandle> >::const_iterator iit =
1072 iit_end = incident_hfs_per_he_.end(); iit != iit_end; ++iit) {
1073 for(std::vector<HalfFaceHandle>::const_iterator it = iit->begin(),
1074 end = iit->end(); it != end; ++it) {
1075 update_faces.insert(face_handle(*it));
1080 for(std::set<FaceHandle>::iterator f_it = update_faces.begin(),
1081 f_end = update_faces.end(); f_it != f_end; ++f_it) {
1083 std::vector<HalfEdgeHandle> hes =
face(*f_it).halfedges();
1086 hes.erase(std::remove(hes.begin(), hes.end(),
halfedge_handle(h, 0)), hes.end());
1087 hes.erase(std::remove(hes.begin(), hes.end(),
halfedge_handle(h, 1)), hes.end());
1089 #if defined(__clang_major__) && (__clang_major__ >= 5)
1090 for(std::vector<HalfEdgeHandle>::iterator it = hes.begin(), end = hes.end();
1092 cor.correctValue(*it);
1095 std::for_each(hes.begin(), hes.end(),
1096 fun::bind(&HEHandleCorrection::correctValue, &cor, fun::placeholders::_1));
1098 face(*f_it).set_halfedges(hes);
1103 for(
FaceIter f_it = faces_begin(), f_end = faces_end();
1104 f_it != f_end; ++f_it) {
1107 std::vector<HalfEdgeHandle> hes =
face(*f_it).halfedges();
1110 hes.erase(std::remove(hes.begin(), hes.end(),
halfedge_handle(h, 0)), hes.end());
1111 hes.erase(std::remove(hes.begin(), hes.end(),
halfedge_handle(h, 1)), hes.end());
1115 #if defined(__clang_major__) && (__clang_major__ >= 5)
1116 for(std::vector<HalfEdgeHandle>::iterator it = hes.begin(), end = hes.end();
1118 cor.correctValue(*it);
1121 std::for_each(hes.begin(), hes.end(),
1122 fun::bind(&HEHandleCorrection::correctValue, &cor, fun::placeholders::_1));
1124 face(*f_it).set_halfedges(hes);
1132 assert((
size_t)
halfedge_handle(h, 1).idx() < incident_hfs_per_he_.size());
1134 incident_hfs_per_he_.erase(incident_hfs_per_he_.begin() +
halfedge_handle(h, 1).idx());
1135 incident_hfs_per_he_.erase(incident_hfs_per_he_.begin() +
halfedge_handle(h, 0).idx());
1138 if (!fast_deletion_enabled())
1143 #if defined(__clang_major__) && (__clang_major__ >= 5)
1144 for(std::vector<std::vector<HalfEdgeHandle> >::iterator it = outgoing_hes_per_vertex_.begin(),
1145 end = outgoing_hes_per_vertex_.end(); it != end; ++it) {
1146 cor.correctVecValue(*it);
1149 std::for_each(outgoing_hes_per_vertex_.begin(),
1150 outgoing_hes_per_vertex_.end(),
1151 fun::bind(&HEHandleCorrection::correctVecValue, &cor, fun::placeholders::_1));
1158 edges_.erase(edges_.begin() + h.idx());
1159 edge_deleted_.erase(edge_deleted_.begin() + h.idx());
1198 assert(h.is_valid() && (size_t)h.idx() < faces_.size());
1201 if (fast_deletion_enabled() && !deferred_deletion_enabled())
1204 assert(!face_deleted_[last_face.idx()]);
1205 swap_faces(h, last_face);
1212 const std::vector<HalfEdgeHandle>& hes =
face(h).halfedges();
1213 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin(),
1214 he_end = hes.end(); he_it != he_end; ++he_it) {
1216 assert((
size_t)std::max(he_it->idx(), opposite_halfedge_handle(*he_it).idx()) < incident_hfs_per_he_.size());
1218 incident_hfs_per_he_[he_it->idx()].erase(
1219 std::remove(incident_hfs_per_he_[he_it->idx()].begin(),
1220 incident_hfs_per_he_[he_it->idx()].end(),
1224 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].erase(
1225 std::remove(incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].begin(),
1226 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].end(),
1227 halfface_handle(h, 1)), incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].end());
1231 if (deferred_deletion_enabled())
1233 face_deleted_[h.idx()] =
true;
1243 if (!fast_deletion_enabled())
1250 std::set<CellHandle> update_cells;
1251 for(std::vector<CellHandle>::const_iterator c_it = (incident_cell_per_hf_.begin() +
halfface_handle(h, 0).idx()),
1252 c_end = incident_cell_per_hf_.end(); c_it != c_end; ++c_it) {
1253 if(!c_it->is_valid())
continue;
1254 update_cells.insert(*c_it);
1256 for(std::set<CellHandle>::const_iterator c_it = update_cells.begin(),
1257 c_end = update_cells.end(); c_it != c_end; ++c_it) {
1259 std::vector<HalfFaceHandle> hfs =
cell(*c_it).halffaces();
1262 hfs.erase(std::remove(hfs.begin(), hfs.end(),
halfface_handle(h, 0)), hfs.end());
1263 hfs.erase(std::remove(hfs.begin(), hfs.end(),
halfface_handle(h, 1)), hfs.end());
1266 #if defined(__clang_major__) && (__clang_major__ >= 5)
1267 for(std::vector<HalfFaceHandle>::iterator it = hfs.begin(),
1268 end = hfs.end(); it != end; ++it) {
1269 cor.correctValue(*it);
1272 std::for_each(hfs.begin(), hfs.end(),
1273 fun::bind(&HFHandleCorrection::correctValue, &cor, fun::placeholders::_1));
1275 cell(*c_it).set_halffaces(hfs);
1281 for(
CellIter c_it = cells_begin(), c_end = cells_end(); c_it != c_end; ++c_it) {
1283 std::vector<HalfFaceHandle> hfs =
cell(*c_it).halffaces();
1286 hfs.erase(std::remove(hfs.begin(), hfs.end(),
halfface_handle(h, 0)), hfs.end());
1287 hfs.erase(std::remove(hfs.begin(), hfs.end(),
halfface_handle(h, 1)), hfs.end());
1290 #if defined(__clang_major__) && (__clang_major__ >= 5)
1291 for(std::vector<HalfFaceHandle>::iterator it = hfs.begin(),
1292 end = hfs.end(); it != end; ++it) {
1293 cor.correctValue(*it);
1296 std::for_each(hfs.begin(), hfs.end(),
1297 fun::bind(&HFHandleCorrection::correctValue, &cor, fun::placeholders::_1));
1299 cell(*c_it).set_halffaces(hfs);
1307 assert((
size_t)
halfface_handle(h, 1).idx() < incident_cell_per_hf_.size());
1309 incident_cell_per_hf_.erase(incident_cell_per_hf_.begin() +
halfface_handle(h, 1).idx());
1310 incident_cell_per_hf_.erase(incident_cell_per_hf_.begin() +
halfface_handle(h, 0).idx());
1314 if (!fast_deletion_enabled())
1319 #if defined(__clang_major__) && (__clang_major__ >= 5)
1320 for(std::vector<std::vector<HalfFaceHandle> >::iterator it = incident_hfs_per_he_.begin(), end = incident_hfs_per_he_.end(); it != end; ++it) {
1321 cor.correctVecValue(*it);
1324 std::for_each(incident_hfs_per_he_.begin(),
1325 incident_hfs_per_he_.end(),
1326 fun::bind(&HFHandleCorrection::correctVecValue, &cor, fun::placeholders::_1));
1332 faces_.erase(faces_.begin() + h.idx());
1333 face_deleted_.erase(face_deleted_.begin() + h.idx());
1366 assert(h.is_valid() && (size_t)h.idx() < cells_.size());
1369 if (fast_deletion_enabled() && !deferred_deletion_enabled())
1372 assert(!cell_deleted_[last_undeleted_cell.idx()]);
1373 swap_cells(h, last_undeleted_cell);
1374 h = last_undeleted_cell;
1380 const std::vector<HalfFaceHandle>& hfs =
cell(h).halffaces();
1381 for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin(),
1382 hf_end = hfs.end(); hf_it != hf_end; ++hf_it) {
1383 assert((
size_t)hf_it->idx() < incident_cell_per_hf_.size());
1384 if (incident_cell_per_hf_[hf_it->idx()] == h)
1385 incident_cell_per_hf_[hf_it->idx()] = InvalidCellHandle;
1389 if (deferred_deletion_enabled())
1391 cell_deleted_[h.idx()] =
true;
1401 if (!fast_deletion_enabled())
1405 #if defined(__clang_major__) && (__clang_major__ >= 5)
1406 for(std::vector<CellHandle>::iterator it = incident_cell_per_hf_.begin(),
1407 end = incident_cell_per_hf_.end(); it != end; ++it) {
1408 cor.correctValue(*it);
1411 std::for_each(incident_cell_per_hf_.begin(),
1412 incident_cell_per_hf_.end(),
1413 fun::bind(&CHandleCorrection::correctValue, &cor, fun::placeholders::_1));
1419 cells_.erase(cells_.begin() + h.idx());
1420 cell_deleted_.erase(cell_deleted_.begin() + h.idx());
1433 assert(_h1.idx() >= 0 && _h1.idx() < (int)cells_.size());
1434 assert(_h2.idx() >= 0 && _h2.idx() < (int)cells_.size());
1439 int id1 = _h1.idx();
1440 int id2 = _h2.idx();
1442 Cell c1 = cells_[id1];
1443 Cell c2 = cells_[id2];
1446 std::vector<HalfFaceHandle> hfhs1 = c1.halffaces();
1447 for (
unsigned int i = 0; i < hfhs1.size(); ++i)
1450 if (incident_cell_per_hf_[hfh.idx()] == id1)
1451 incident_cell_per_hf_[hfh.idx()] = id2;
1454 std::vector<HalfFaceHandle> hfhs2 = c2.halffaces();
1455 for (
unsigned int i = 0; i < hfhs2.size(); ++i)
1457 HalfFaceHandle hfh = hfhs2[i];
1458 if (incident_cell_per_hf_[hfh.idx()] == id2)
1459 incident_cell_per_hf_[hfh.idx()] = id1;
1463 std::swap(cells_[id1], cells_[id2]);
1464 bool tmp = cell_deleted_[id1];
1465 cell_deleted_[id1] = cell_deleted_[id2];
1466 cell_deleted_[id2] = tmp;
1467 swap_cell_properties(_h1, _h2);
1470 void TopologyKernel::swap_faces(FaceHandle _h1, FaceHandle _h2)
1472 assert(_h1.idx() >= 0 && _h1.idx() < (int)faces_.size());
1473 assert(_h2.idx() >= 0 && _h2.idx() < (int)faces_.size());
1479 std::vector<unsigned int> ids;
1480 ids.push_back(_h1.idx());
1481 ids.push_back(_h2.idx());
1483 unsigned int id1 = _h1.idx();
1484 unsigned int id2 = _h2.idx();
1489 if (has_face_bottom_up_incidences())
1491 std::set<unsigned int> processed_cells;
1492 for (
unsigned int i = 0; i < 2; ++i)
1494 unsigned int id = ids[i];
1495 for (
unsigned int j = 0; j < 2; ++j)
1497 HalfFaceHandle hfh = HalfFaceHandle(2*
id+j);
1498 CellHandle ch = incident_cell_per_hf_[hfh];
1504 if (processed_cells.find(ch.idx()) == processed_cells.end())
1507 Cell& c = cells_[ch.idx()];
1511 std::vector<HalfFaceHandle> new_halffaces;
1512 for (
unsigned int k = 0; k < c.halffaces().size(); ++k)
1513 if (c.halffaces()[k].idx()/2 == (int)id1)
1514 new_halffaces.push_back(HalfFaceHandle(2 * id2 + (c.halffaces()[k].idx() % 2)));
1515 else if (c.halffaces()[k].idx()/2 == (int)id2)
1516 new_halffaces.push_back(HalfFaceHandle(2 * id1 + (c.halffaces()[k].idx() % 2)));
1518 new_halffaces.push_back(c.halffaces()[k]);
1519 c.set_halffaces(new_halffaces);
1521 processed_cells.insert(ch.idx());
1529 for (
unsigned int i = 0; i < cells_.size(); ++i)
1531 Cell& c = cells_[i];
1534 bool contains_swapped_face =
false;
1535 for (
unsigned int k = 0; k < c.halffaces().size(); ++k)
1537 if (c.halffaces()[k].idx()/2 == (int)id1)
1538 contains_swapped_face =
true;
1539 if (c.halffaces()[k].idx()/2 == (int)id2)
1540 contains_swapped_face =
true;
1541 if (contains_swapped_face)
1545 if (contains_swapped_face)
1548 std::vector<HalfFaceHandle> new_halffaces;
1549 for (
unsigned int k = 0; k < c.halffaces().size(); ++k)
1550 if (c.halffaces()[k].idx()/2 == (int)id1)
1551 new_halffaces.push_back(HalfFaceHandle(2 * id2 + (c.halffaces()[k].idx() % 2)));
1552 else if (c.halffaces()[k].idx()/2 == (int)id2)
1553 new_halffaces.push_back(HalfFaceHandle(2 * id1 + (c.halffaces()[k].idx() % 2)));
1555 new_halffaces.push_back(c.halffaces()[k]);
1556 c.set_halffaces(new_halffaces);
1563 if (has_edge_bottom_up_incidences())
1565 std::set<unsigned int> processed_halfedges;
1566 for (
unsigned int i = 0; i < 2; ++i)
1568 unsigned int id = ids[i];
1569 for (
unsigned int j = 0; j < 2; ++j)
1571 HalfFaceHandle hfh = HalfFaceHandle(2*
id+j);
1574 for (
unsigned int k = 0; k < hf.halfedges().size(); ++k)
1576 HalfEdgeHandle heh = hf.halfedges()[k];
1578 if (processed_halfedges.find(heh.idx()) != processed_halfedges.end())
1581 std::vector<HalfFaceHandle>& incident_halffaces = incident_hfs_per_he_[heh.idx()];
1582 for (
unsigned int l = 0; l < incident_halffaces.size(); ++l)
1584 HalfFaceHandle& hfh2 = incident_halffaces[l];
1586 if (hfh2.idx()/2 == (int)id1)
1587 hfh2 = HalfFaceHandle(2 * id2 + (hfh2.idx() % 2));
1588 else if (hfh2.idx()/2 == (int)id2)
1589 hfh2 = HalfFaceHandle(2 * id1 + (hfh2.idx() % 2));
1592 processed_halfedges.insert(heh);
1599 std::swap(faces_[ids[0]], faces_[ids[1]]);
1600 bool tmp = face_deleted_[ids[0]];
1601 face_deleted_[ids[0]] = face_deleted_[ids[1]];
1602 face_deleted_[ids[1]] = tmp;
1603 std::swap(incident_cell_per_hf_[2*ids[0]+0], incident_cell_per_hf_[2*ids[1]+0]);
1604 std::swap(incident_cell_per_hf_[2*ids[0]+1], incident_cell_per_hf_[2*ids[1]+1]);
1605 swap_face_properties(_h1, _h2);
1611 void TopologyKernel::swap_edges(EdgeHandle _h1, EdgeHandle _h2)
1613 assert(_h1.idx() >= 0 && _h1.idx() < (int)edges_.size());
1614 assert(_h2.idx() >= 0 && _h2.idx() < (int)edges_.size());
1619 std::vector<unsigned int> ids;
1620 ids.push_back(_h1.idx());
1621 ids.push_back(_h2.idx());
1626 if (has_edge_bottom_up_incidences())
1628 std::set<unsigned int> processed_faces;
1630 for (
unsigned int i = 0; i < 2; ++i)
1632 HalfEdgeHandle heh = HalfEdgeHandle(2*ids[i]);
1635 std::vector<HalfFaceHandle>& incident_halffaces = incident_hfs_per_he_[heh.idx()];
1636 for (
unsigned int j = 0; j < incident_halffaces.size(); ++j)
1638 HalfFaceHandle hfh = incident_halffaces[j];
1640 unsigned int f_id = hfh.idx() / 2;
1642 if (processed_faces.find(f_id) == processed_faces.end())
1645 Face& f = faces_[f_id];
1648 std::vector<HalfEdgeHandle> new_halfedges;
1649 for (
unsigned int k = 0; k < f.halfedges().size(); ++k)
1651 HalfEdgeHandle heh2 = f.halfedges()[k];
1652 if (heh2.idx() / 2 == (int)ids[0])
1653 new_halfedges.push_back(HalfEdgeHandle(2*ids[1] + (heh2.idx() % 2)));
1654 else if (heh2.idx() / 2 == (int)ids[1])
1655 new_halfedges.push_back(HalfEdgeHandle(2*ids[0] + (heh2.idx() % 2)));
1657 new_halfedges.push_back(heh2);
1659 f.set_halfedges(new_halfedges);
1661 processed_faces.insert(f_id);
1669 for (
unsigned int i = 0; i < faces_.size(); ++i)
1671 Face& f = faces_[i];
1674 bool contains_swapped_edge =
false;
1675 for (
unsigned int k = 0; k < f.halfedges().size(); ++k)
1677 if (f.halfedges()[k].idx()/2 == (int)ids[0])
1678 contains_swapped_edge =
true;
1679 if (f.halfedges()[k].idx()/2 == (int)ids[1])
1680 contains_swapped_edge =
true;
1681 if (contains_swapped_edge)
1685 if (contains_swapped_edge)
1688 std::vector<HalfEdgeHandle> new_halfedges;
1689 for (
unsigned int k = 0; k < f.halfedges().size(); ++k)
1691 HalfEdgeHandle heh2 = f.halfedges()[k];
1692 if (heh2.idx() / 2 == (int)ids[0])
1693 new_halfedges.push_back(HalfEdgeHandle(2*ids[1] + (heh2.idx() % 2)));
1694 else if (heh2.idx() / 2 == (int)ids[1])
1695 new_halfedges.push_back(HalfEdgeHandle(2*ids[0] + (heh2.idx() % 2)));
1697 new_halfedges.push_back(heh2);
1699 f.set_halfedges(new_halfedges);
1706 if (has_vertex_bottom_up_incidences())
1708 std::set<int> processed_vertices;
1709 for (
unsigned int i = 0; i < 2; ++i)
1711 Edge e =
edge(EdgeHandle(ids[i]));
1712 std::vector<VertexHandle> vhs;
1713 vhs.push_back(e.from_vertex());
1714 vhs.push_back(e.to_vertex());
1716 for (
unsigned int j = 0; j < 2; ++j)
1718 if (processed_vertices.find(vhs[j].idx()) != processed_vertices.end())
1721 std::vector<HalfEdgeHandle>& outgoing_hes = outgoing_hes_per_vertex_[vhs[j].idx()];
1722 for (
unsigned int k = 0; k < outgoing_hes.size(); ++k)
1724 HalfEdgeHandle& heh = outgoing_hes[k];
1725 if (heh.idx() / 2 == (int)ids[0])
1726 heh = HalfEdgeHandle(2 * ids[1] + (heh.idx() % 2));
1727 else if (heh.idx() / 2 == (int)ids[1])
1728 heh = HalfEdgeHandle(2 * ids[0] + (heh.idx() % 2));
1730 processed_vertices.insert(vhs[j]);
1737 std::swap(edges_[ids[0]], edges_[ids[1]]);
1738 bool tmp = edge_deleted_[ids[0]];
1739 edge_deleted_[ids[0]] = edge_deleted_[ids[1]];
1740 edge_deleted_[ids[1]] = tmp;
1741 std::swap(incident_hfs_per_he_[2*ids[0]+0], incident_hfs_per_he_[2*ids[1]+0]);
1742 std::swap(incident_hfs_per_he_[2*ids[0]+1], incident_hfs_per_he_[2*ids[1]+1]);
1743 swap_edge_properties(_h1, _h2);
1749 void TopologyKernel::swap_vertices(VertexHandle _h1, VertexHandle _h2)
1751 assert(_h1.idx() >= 0 && _h1.idx() < (int)n_vertices_);
1752 assert(_h2.idx() >= 0 && _h2.idx() < (int)n_vertices_);
1757 std::vector<unsigned int> ids;
1758 ids.push_back(_h1.idx());
1759 ids.push_back(_h2.idx());
1764 if (has_vertex_bottom_up_incidences())
1766 for (
unsigned int i = 0; i < 2; ++i)
1768 std::set<unsigned int> processed_edges;
1769 std::vector<HalfEdgeHandle>& outgoing_hes = outgoing_hes_per_vertex_[ids[i]];
1770 for (
unsigned int k = 0; k < outgoing_hes.size(); ++k)
1772 unsigned int e_id = outgoing_hes[k].idx() / 2;
1774 if (processed_edges.find(e_id) == processed_edges.end())
1776 Edge& e = edges_[e_id];
1777 if (e.from_vertex() == (int)ids[0])
1778 e.set_from_vertex(VertexHandle(ids[1]));
1779 else if (e.from_vertex() == (int)ids[1])
1780 e.set_from_vertex(VertexHandle(ids[0]));
1782 if (e.to_vertex() == (int)ids[0])
1783 e.set_to_vertex(VertexHandle(ids[1]));
1784 else if (e.to_vertex() == (int)ids[1])
1785 e.set_to_vertex(VertexHandle(ids[0]));
1787 processed_edges.insert(e_id);
1797 for (
unsigned int i = 0; i < edges_.size(); ++i)
1799 Edge& e = edges_[i];
1800 if (e.from_vertex() == (int)ids[0])
1801 e.set_from_vertex(VertexHandle(ids[1]));
1802 else if (e.from_vertex() == (int)ids[1])
1803 e.set_from_vertex(VertexHandle(ids[0]));
1805 if (e.to_vertex() == (int)ids[0])
1806 e.set_to_vertex(VertexHandle(ids[1]));
1807 else if (e.to_vertex() == (int)ids[1])
1808 e.set_to_vertex(VertexHandle(ids[0]));
1813 bool tmp = vertex_deleted_[ids[0]];
1814 vertex_deleted_[ids[0]] = vertex_deleted_[ids[1]];
1815 vertex_deleted_[ids[1]] = tmp;
1816 std::swap(outgoing_hes_per_vertex_[ids[0]], outgoing_hes_per_vertex_[ids[1]]);
1817 swap_vertex_properties(_h1, _h2);
1822 void TopologyKernel::delete_multiple_vertices(
const std::vector<bool>& _tag) {
1826 std::vector<int> newIndices(
n_vertices(), -1);
1829 std::vector<int>::iterator idx_it = newIndices.begin();
1830 for(std::vector<bool>::const_iterator t_it = _tag.begin(),
1831 t_end = _tag.end(); t_it != t_end; ++t_it, ++idx_it) {
1843 delete_multiple_vertex_props(_tag);
1845 EdgeCorrector corrector(newIndices);
1846 std::for_each(edges_.begin(), edges_.end(), corrector);
1851 void TopologyKernel::delete_multiple_edges(
const std::vector<bool>& _tag) {
1853 assert(_tag.size() ==
n_edges());
1855 std::vector<int> newIndices(
n_edges(), -1);
1858 std::vector<Edge> newEdges;
1860 std::vector<int>::iterator idx_it = newIndices.begin();
1861 std::vector<Edge>::const_iterator e_it = edges_.begin();
1863 for(std::vector<bool>::const_iterator t_it = _tag.begin(),
1864 t_end = _tag.end(); t_it != t_end; ++t_it, ++idx_it, ++e_it) {
1869 newEdges.push_back(*e_it);
1877 edges_.swap(newEdges);
1880 delete_multiple_edge_props(_tag);
1882 FaceCorrector corrector(newIndices);
1883 std::for_each(faces_.begin(), faces_.end(), corrector);
1888 void TopologyKernel::delete_multiple_faces(
const std::vector<bool>& _tag) {
1890 assert(_tag.size() ==
n_faces());
1892 std::vector<int> newIndices(
n_faces(), -1);
1895 std::vector<Face> newFaces;
1897 std::vector<int>::iterator idx_it = newIndices.begin();
1898 std::vector<Face>::const_iterator f_it = faces_.begin();
1900 for(std::vector<bool>::const_iterator t_it = _tag.begin(),
1901 t_end = _tag.end(); t_it != t_end; ++t_it, ++idx_it, ++f_it) {
1906 newFaces.push_back(*f_it);
1914 faces_.swap(newFaces);
1917 delete_multiple_face_props(_tag);
1919 CellCorrector corrector(newIndices);
1920 std::for_each(cells_.begin(), cells_.end(), corrector);
1925 void TopologyKernel::delete_multiple_cells(
const std::vector<bool>& _tag) {
1927 assert(_tag.size() ==
n_cells());
1929 std::vector<Cell> newCells;
1931 std::vector<Cell>::const_iterator c_it = cells_.begin();
1933 for(std::vector<bool>::const_iterator t_it = _tag.begin(),
1934 t_end = _tag.end(); t_it != t_end; ++t_it, ++c_it) {
1939 newCells.push_back(*c_it);
1944 cells_.swap(newCells);
1947 delete_multiple_cell_props(_tag);
1954 assert(_first >= cells_begin());
1955 assert(_last <= cells_end());
1957 std::vector<Cell>::iterator it = cells_.erase(cells_.begin() + _first->idx(), cells_.begin() + _last->idx());
1961 f_bottom_up_ =
false;
1962 enable_face_bottom_up_incidences(
true);
1968 void TopologyKernel::enable_deferred_deletion(
bool _enable)
1970 if (deferred_deletion && !_enable)
1973 deferred_deletion = _enable;
1982 assert(_edgeHandle.is_valid() && (size_t)_edgeHandle.idx() < edges_.size());
1984 return edges_[_edgeHandle.idx()];
1993 assert(_faceHandle.is_valid() && (size_t)_faceHandle.idx() < faces_.size());
1995 return faces_[_faceHandle.idx()];
2004 assert(_cellHandle.is_valid() && (size_t)_cellHandle.idx() < cells_.size());
2006 return cells_[_cellHandle.idx()];
2015 assert(_edgeHandle.is_valid() && (size_t)_edgeHandle.idx() < edges_.size());
2017 return edges_[_edgeHandle.idx()];
2026 assert((
size_t)_faceHandle.idx() < faces_.size());
2027 assert(_faceHandle.idx() >= 0);
2029 return faces_[_faceHandle.idx()];
2038 assert((
size_t)_cellHandle.idx() < cells_.size());
2039 assert(_cellHandle.idx() >= 0);
2041 return cells_[_cellHandle.idx()];
2050 assert((
size_t)_halfEdgeHandle.idx() < (edges_.size() * 2));
2051 assert(_halfEdgeHandle.idx() >= 0);
2055 if(_halfEdgeHandle.idx() % 2 == 0)
2056 return edges_[(
int)(_halfEdgeHandle.idx() / 2)];
2067 assert((
size_t)_halfFaceHandle.idx() < (faces_.size() * 2));
2068 assert(_halfFaceHandle.idx() >= 0);
2072 if(_halfFaceHandle.idx() % 2 == 0)
2073 return faces_[(
int)(_halfFaceHandle.idx() / 2)];
2084 assert(_halfEdgeHandle.idx() >= 0);
2085 assert((
size_t)_halfEdgeHandle.idx() < (edges_.size() * 2));
2089 if(_halfEdgeHandle.idx() % 2 != 0)
2090 return edges_[(
int)(_halfEdgeHandle.idx() / 2)];
2101 assert(_halfFaceHandle.idx() >= 0);
2102 assert((
size_t)_halfFaceHandle.idx() < (faces_.size() * 2));
2106 if(_halfFaceHandle.idx() % 2 != 0)
2107 return faces_[(
int)(_halfFaceHandle.idx() / 2)];
2120 if(
halfedge(*voh_it).to_vertex() == _vh2) {
2125 return InvalidHalfEdgeHandle;
2132 assert(_vs.size() > 2);
2136 assert(v0.is_valid() && v1.is_valid() && v2.is_valid());
2139 if(!he0.is_valid())
return InvalidHalfFaceHandle;
2141 if(!he1.is_valid())
return InvalidHalfFaceHandle;
2143 std::vector<HalfEdgeHandle> hes;
2154 assert(_vs.size() > 2);
2159 assert(v0.is_valid() && v1.is_valid());
2162 if(!he0.is_valid())
return InvalidHalfFaceHandle;
2166 std::vector<HalfEdgeHandle> hes =
halfface(*hehf_it).halfedges();
2168 if (hes.size() != _vs.size())
2172 for (
unsigned int i = 0; i < hes.size(); ++i)
2176 bool all_vertices_found =
true;
2178 for (
unsigned int i = 0; i < hes.size(); ++i)
2181 if (
halfedge(heh).from_vertex() != _vs[i])
2183 all_vertices_found =
false;
2188 if (all_vertices_found)
2192 return InvalidHalfFaceHandle;
2199 assert(_hes.size() >= 2);
2203 assert(he0.is_valid() && he1.is_valid());
2207 std::vector<HalfEdgeHandle> hes =
halfface(*hehf_it).halfedges();
2208 if(std::find(hes.begin(), hes.end(), he1) != hes.end()) {
2213 return InvalidHalfFaceHandle;
2220 assert(_heh.is_valid() && (size_t)_heh.idx() < edges_.size() * 2u);
2221 assert(_hfh.is_valid() && (size_t)_hfh.idx() < faces_.size() * 2u);
2223 std::vector<HalfEdgeHandle> hes =
halfface(_hfh).halfedges();
2225 for(std::vector<HalfEdgeHandle>::const_iterator it = hes.begin();
2226 it != hes.end(); ++it) {
2228 if((it + 1) != hes.end())
return *(it + 1);
2229 else return *hes.begin();
2233 return InvalidHalfEdgeHandle;
2240 assert(_heh.is_valid() && (size_t)_heh.idx() < edges_.size() * 2u);
2241 assert(_hfh.is_valid() && (size_t)_hfh.idx() < faces_.size() * 2u);
2243 std::vector<HalfEdgeHandle> hes =
halfface(_hfh).halfedges();
2245 for(std::vector<HalfEdgeHandle>::const_iterator it = hes.begin();
2246 it != hes.end(); ++it) {
2248 if(it != hes.begin())
return *(it - 1);
2249 else return *(hes.end() - 1);
2253 return InvalidHalfEdgeHandle;
2261 assert(_halfFaceHandle.is_valid() && (size_t)_halfFaceHandle.idx() < faces_.size() * 2u);
2262 assert(_halfEdgeHandle.is_valid() && (size_t)_halfEdgeHandle.idx() < edges_.size() * 2u);
2263 assert(has_face_bottom_up_incidences());
2264 assert((
size_t)_halfFaceHandle.idx() < incident_cell_per_hf_.size());
2266 if(incident_cell_per_hf_[_halfFaceHandle.idx()] == InvalidCellHandle) {
2268 return InvalidHalfFaceHandle;
2274 bool skipped =
false;
2277 for(std::vector<HalfFaceHandle>::const_iterator hf_it = c.halffaces().begin();
2278 hf_it != c.halffaces().end(); ++hf_it) {
2280 if(*hf_it == _halfFaceHandle) {
2286 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hf.halfedges().begin();
2287 he_it != hf.halfedges().end(); ++he_it) {
2293 if(skipped && found)
break;
2295 if(skipped && found)
break;
2297 return ((skipped && found) ? idx : InvalidHalfFaceHandle);
2304 if(!has_face_bottom_up_incidences()) {
2305 return InvalidCellHandle;
2307 if((
size_t)_halfFaceHandle.idx() >= incident_cell_per_hf_.size() || _halfFaceHandle.idx() < 0) {
2308 return InvalidCellHandle;
2311 return incident_cell_per_hf_[_halfFaceHandle.idx()];
2316 void TopologyKernel::compute_vertex_bottom_up_incidences() {
2319 outgoing_hes_per_vertex_.clear();
2320 outgoing_hes_per_vertex_.resize(
n_vertices());
2323 size_t n_edges = edges_.size();
2324 for(
size_t i = 0; i <
n_edges; ++i) {
2325 if (edge_deleted_[i])
2331 assert((
size_t)from.idx() < outgoing_hes_per_vertex_.size());
2336 assert((
size_t)to.idx() < outgoing_hes_per_vertex_.size());
2345 void TopologyKernel::compute_edge_bottom_up_incidences() {
2348 incident_hfs_per_he_.clear();
2349 incident_hfs_per_he_.resize(edges_.size() * 2u);
2352 size_t n_faces = faces_.size();
2353 for(
size_t i = 0; i <
n_faces; ++i) {
2354 if (face_deleted_[i])
2357 std::vector<HalfEdgeHandle> halfedges = faces_[i].halfedges();
2360 for(std::vector<HalfEdgeHandle>::const_iterator he_it = halfedges.begin();
2361 he_it != halfedges.end(); ++he_it) {
2363 incident_hfs_per_he_[he_it->idx()].push_back(
halfface_handle(FaceHandle(i), 0));
2364 incident_hfs_per_he_[opposite_halfedge_handle(*he_it).idx()].push_back(
2372 void TopologyKernel::compute_face_bottom_up_incidences() {
2375 incident_cell_per_hf_.clear();
2376 incident_cell_per_hf_.resize(faces_.size() * 2u, InvalidCellHandle);
2378 size_t n_cells = cells_.size();
2379 for(
size_t i = 0; i <
n_cells; ++i) {
2380 if (cell_deleted_[i])
2383 std::vector<HalfFaceHandle> halffaces = cells_[i].halffaces();
2386 for(std::vector<HalfFaceHandle>::const_iterator hf_it = halffaces.begin();
2387 hf_it != halffaces.end(); ++hf_it) {
2389 if(incident_cell_per_hf_[hf_it->idx()] == InvalidCellHandle) {
2391 incident_cell_per_hf_[hf_it->idx()] = CellHandle(i);
2396 std::cerr <<
"compute_face_bottom_up_incidences(): Detected non-three-manifold configuration!" << std::endl;
2397 std::cerr <<
"Connectivity probably won't work." << std::endl;
void set_cell(const CellHandle &_ch, const std::vector< HalfFaceHandle > &_hfs)
Set the half-faces of a cell.
virtual size_t n_cells() const
Get number of cells in mesh.
HalfFaceHandle adjacent_halfface_in_cell(const HalfFaceHandle &_halfFaceHandle, const HalfEdgeHandle &_halfEdgeHandle) const
Get halfface that is adjacent (w.r.t. a common halfedge) within the same cell.
FaceIter delete_face_core(const FaceHandle &_h)
Delete face from mesh.
virtual VertexHandle add_vertex()
Add abstract vertex.
const Face & face(const FaceHandle &_faceHandle) const
Get face with handle _faceHandle.
void resize_cprops(size_t _nc)
Change size of stored cell properties.
Edge halfedge(const HalfEdgeHandle &_halfEdgeHandle) const
Get edge that corresponds to halfedge with handle _halfEdgeHandle.
virtual size_t n_vertices() const
Get number of vertices in mesh.
virtual EdgeHandle add_edge(const VertexHandle &_fromVertex, const VertexHandle &_toHandle, bool _allowDuplicates=false)
Add edge.
void resize_eprops(size_t _ne)
Change size of stored edge properties.
virtual CellIter delete_cell(const CellHandle &_h)
Delete cell from mesh.
CellHandle incident_cell(const HalfFaceHandle &_halfFaceHandle) const
Get cell that is incident to the given halfface.
virtual void collect_garbage()
Delete all entities that are marked as deleted.
virtual CellHandle add_cell(const std::vector< HalfFaceHandle > &_halffaces, bool _topologyCheck=false)
Add cell via incident halffaces.
EdgeIter delete_edge_core(const EdgeHandle &_h)
Delete edge from mesh.
CellIter delete_cell_range(const CellIter &_first, const CellIter &_last)
Delete range of cells.
const Cell & cell(const CellHandle &_cellHandle) const
Get cell with handle _cellHandle.
Face halfface(const HalfFaceHandle &_halfFaceHandle) const
Get face that corresponds to halfface with handle _halfFaceHandle.
const Edge & edge(const EdgeHandle &_edgeHandle) const
Get edge with handle _edgeHandle.
virtual size_t n_edges() const
Get number of edges in mesh.
virtual EdgeIter delete_edge(const EdgeHandle &_h)
Delete edge from mesh.
static HalfEdgeHandle halfedge_handle(const EdgeHandle &_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.
HalfFaceHandle halfface_extensive(const std::vector< VertexHandle > &_vs) const
void set_face(const FaceHandle &_fh, const std::vector< HalfEdgeHandle > &_hes)
Set the half-edges of a face.
static HalfFaceHandle halfface_handle(const FaceHandle &_h, const unsigned char _subIdx)
Conversion function.
static EdgeHandle edge_handle(const HalfEdgeHandle &_h)
Handle conversion.
Face opposite_halfface(const HalfFaceHandle &_halfFaceHandle) const
Get opposite halfface that corresponds to halfface with handle _halfFaceHandle.
virtual FaceHandle add_face(const std::vector< HalfEdgeHandle > &_halfedges, bool _topologyCheck=false)
Add face via incident edges.
virtual FaceIter delete_face(const FaceHandle &_h)
Delete face from mesh.
void resize_fprops(size_t _nf)
Change size of stored face properties.
HalfEdgeHandle next_halfedge_in_halfface(const HalfEdgeHandle &_heh, const HalfFaceHandle &_hfh) const
Get next halfedge within a halfface.
void set_edge(const EdgeHandle &_eh, const VertexHandle &_fromVertex, const VertexHandle &_toVertex)
Set the vertices of an edge.
bool bind(osg::GeometryPtr &_geo, Mesh &_mesh)
CellIter delete_cell_core(const CellHandle &_h)
Delete cell from mesh.
virtual size_t n_halffaces() const
Get number of halffaces in mesh.
Edge opposite_halfedge(const HalfEdgeHandle &_halfEdgeHandle) const
Get opposite halfedge that corresponds to halfedge with handle _halfEdgeHandle.
virtual VertexIter delete_vertex(const VertexHandle &_h)
Delete vertex from mesh.
VertexIter delete_vertex_core(const VertexHandle &_h)
Delete vertex from mesh.
void resize_vprops(size_t _nv)
Change size of stored vertex properties.
virtual size_t n_faces() const
Get number of faces in mesh.
virtual size_t n_halfedges() const
Get number of halfedges in mesh.