45 #include <OpenMesh/Core/Mesh/PolyConnectivity.hh> 57 PolyConnectivity::HalfedgeHandle
63 if (to_vertex_handle(*voh_it) == _end_vh)
95 for (++vh_it; vh_it.is_valid(); ++vh_it)
108 set_halfedge_handle(_vh, *vh_it);
120 size_t i, ii, n(_vhs_size);
122 outer_next, outer_prev,
123 boundary_next, boundary_prev,
124 patch_start, patch_end;
128 if (edgeData_.size() < n)
131 next_cache_.resize(6*n);
134 size_t next_cache_count = 0;
140 for (i=0, ii=1; i<n; ++i, ++ii, ii%=n)
144 omerr() <<
"PolyMeshT::add_face: complex vertex\n";
149 edgeData_[i].halfedge_handle =
find_halfedge(_vertex_handles[i],
150 _vertex_handles[ii]);
151 edgeData_[i].is_new = !edgeData_[i].halfedge_handle.is_valid();
152 edgeData_[i].needs_adjust =
false;
154 if (!edgeData_[i].is_new && !
is_boundary(edgeData_[i].halfedge_handle))
156 omerr() <<
"PolyMeshT::add_face: complex edge\n";
162 for (i=0, ii=1; i<n; ++i, ++ii, ii%=n)
164 if (!edgeData_[i].is_new && !edgeData_[ii].is_new)
166 inner_prev = edgeData_[i].halfedge_handle;
167 inner_next = edgeData_[ii].halfedge_handle;
170 if (next_halfedge_handle(inner_prev) != inner_next)
176 outer_prev = opposite_halfedge_handle(inner_next);
177 outer_next = opposite_halfedge_handle(inner_prev);
178 boundary_prev = outer_prev;
181 opposite_halfedge_handle(next_halfedge_handle(boundary_prev));
183 boundary_next = next_halfedge_handle(boundary_prev);
186 if (boundary_prev == inner_prev)
188 omerr() <<
"PolyMeshT::add_face: patch re-linking failed\n";
196 patch_start = next_halfedge_handle(inner_prev);
197 patch_end = prev_halfedge_handle(inner_next);
207 next_cache_[next_cache_count++] = std::make_pair(boundary_prev, patch_start);
208 next_cache_[next_cache_count++] = std::make_pair(patch_end, boundary_next);
209 next_cache_[next_cache_count++] = std::make_pair(inner_prev, inner_next);
215 for (i=0, ii=1; i<n; ++i, ++ii, ii%=n)
216 if (edgeData_[i].is_new)
217 edgeData_[i].halfedge_handle = new_edge(_vertex_handles[i], _vertex_handles[ii]);
221 set_halfedge_handle(fh, edgeData_[n-1].halfedge_handle);
224 for (i=0, ii=1; i<n; ++i, ++ii, ii%=n)
226 vh = _vertex_handles[ii];
228 inner_prev = edgeData_[i].halfedge_handle;
229 inner_next = edgeData_[ii].halfedge_handle;
234 if (edgeData_[i].is_new)
id |= 1;
235 if (edgeData_[ii].is_new)
id |= 2;
240 outer_prev = opposite_halfedge_handle(inner_next);
241 outer_next = opposite_halfedge_handle(inner_prev);
249 boundary_prev = prev_halfedge_handle(inner_next);
251 next_cache_[next_cache_count++] = std::make_pair(boundary_prev, outer_next);
252 set_halfedge_handle(vh, outer_next);
256 boundary_next = next_halfedge_handle(inner_prev);
258 next_cache_[next_cache_count++] = std::make_pair(outer_prev, boundary_next);
259 set_halfedge_handle(vh, boundary_next);
263 if (!halfedge_handle(vh).is_valid())
265 set_halfedge_handle(vh, outer_next);
266 next_cache_[next_cache_count++] = std::make_pair(outer_prev, outer_next);
270 boundary_next = halfedge_handle(vh);
271 boundary_prev = prev_halfedge_handle(boundary_next);
274 next_cache_[next_cache_count++] = std::make_pair(boundary_prev, outer_next);
275 next_cache_[next_cache_count++] = std::make_pair(outer_prev, boundary_next);
281 next_cache_[next_cache_count++] = std::make_pair(inner_prev, inner_next);
283 else edgeData_[ii].needs_adjust = (halfedge_handle(vh) == inner_next);
287 set_face_handle(edgeData_[i].halfedge_handle, fh);
291 for (i = 0; i < next_cache_count; ++i)
292 set_next_halfedge_handle(next_cache_[i].first, next_cache_[i].second);
297 if (edgeData_[i].needs_adjust)
322 {
return add_face(&_vhandles.front(), _vhandles.size()); }
329 if (
status(edge_handle(v0v1)).deleted())
338 bool v0v1_triangle =
false;
339 bool v1v0_triangle =
false;
342 v0v1_triangle =
valence(face_handle(v0v1)) == 3;
345 v1v0_triangle =
valence(face_handle(v1v0)) == 3;
349 VertexHandle v_01_n = to_vertex_handle(next_halfedge_handle(v0v1));
352 VertexHandle v_10_n = to_vertex_handle(next_halfedge_handle(v1v0));
370 vl = to_vertex_handle(h1);
387 vr = to_vertex_handle(h1);
395 if ( vl.
is_valid() && (vl == vr))
return false;
403 for (vv_it =
vv_iter(v0); vv_it.is_valid(); ++vv_it)
408 for (vv_it =
vv_iter(v1); vv_it.is_valid(); ++vv_it)
413 for (vv_it =
vv_iter(v0); vv_it.is_valid(); ++vv_it)
416 !(*vv_it == v_01_n && v0v1_triangle) &&
417 !(*vv_it == v_10_n && v1v0_triangle)
428 one = next_halfedge_handle(v0v1);
429 two = next_halfedge_handle(one);
431 one = opposite_halfedge_handle(one);
432 two = opposite_halfedge_handle(two);
434 if (face_handle(one) == face_handle(two) &&
valence(face_handle(one)) != 3)
443 one = next_halfedge_handle(v1v0);
444 two = next_halfedge_handle(one);
446 one = opposite_halfedge_handle(one);
447 two = opposite_halfedge_handle(two);
449 if (face_handle(one) == face_handle(two) &&
valence(face_handle(one)) != 3)
455 if (
status(*vv_it).
tagged() && v_01_n == v_10_n && v0v1_triangle && v1v0_triangle)
469 std::vector<FaceHandle> face_handles;
470 face_handles.reserve(8);
472 face_handles.push_back(*vf_it);
476 std::vector<FaceHandle>::iterator fh_it(face_handles.begin()),
477 fh_end(face_handles.end());
479 for (; fh_it!=
fh_end; ++fh_it)
489 FaceHandle fh0(face_handle(halfedge_handle(_eh, 0)));
490 FaceHandle fh1(face_handle(halfedge_handle(_eh, 1)));
499 if ( has_edge_status() )
505 if ( has_halfedge_status() ) {
524 std::vector<EdgeHandle> deleted_edges;
525 deleted_edges.reserve(3);
530 std::vector<VertexHandle> vhandles;
546 deleted_edges.push_back(edge_handle(hh));
548 vhandles.push_back(to_vertex_handle(hh));
555 if (!deleted_edges.empty())
557 std::vector<EdgeHandle>::iterator del_it(deleted_edges.begin()),
558 del_end(deleted_edges.end());
562 for (; del_it!=del_end; ++del_it)
564 h0 = halfedge_handle(*del_it, 0);
565 v0 = to_vertex_handle(h0);
566 next0 = next_halfedge_handle(h0);
567 prev0 = prev_halfedge_handle(h0);
569 h1 = halfedge_handle(*del_it, 1);
570 v1 = to_vertex_handle(h1);
571 next1 = next_halfedge_handle(h1);
572 prev1 = prev_halfedge_handle(h1);
575 set_next_halfedge_handle(prev0, next1);
576 set_next_halfedge_handle(prev1, next0);
579 if ( has_edge_status() )
586 if ( has_halfedge_status() ) {
592 if (halfedge_handle(v0) == h1)
597 if (_delete_isolated_vertices)
601 else set_halfedge_handle(v0, next0);
605 if (halfedge_handle(v1) == h0)
610 if (_delete_isolated_vertices)
614 else set_halfedge_handle(v1, next1);
620 std::vector<VertexHandle>::iterator v_it(vhandles.begin()),
621 v_end(vhandles.end());
622 for (; v_it!=v_end; ++v_it)
734 if (next_halfedge_handle(next_halfedge_handle(h1)) == h1)
736 if (next_halfedge_handle(next_halfedge_handle(o1)) == o1)
761 set_vertex_handle(*vih_it, vh);
765 set_next_halfedge_handle(hp, hn);
766 set_next_halfedge_handle(op, on);
770 if (fh.
is_valid()) set_halfedge_handle(fh, hn);
771 if (fo.
is_valid()) set_halfedge_handle(fo, on);
775 if (halfedge_handle(vh) == o) set_halfedge_handle(vh, hn);
782 if (has_halfedge_status())
807 assert ((next_halfedge_handle(h1) == h0) && (h1 != o0));
811 set_next_halfedge_handle(h1, next_halfedge_handle(o0));
812 set_next_halfedge_handle(prev_halfedge_handle(o0), h1);
816 set_face_handle(h1, fo);
825 if (fo.
is_valid() && halfedge_handle(fo) == o0)
827 set_halfedge_handle(fo, h1);
837 if (has_halfedge_status())
854 while (next_heh != heh0)
860 next_heh = next_halfedge_handle(next_heh);
868 std::set<FaceHandle> nb_fhs;
871 if (nb_fhs.find(*cff_it) == nb_fhs.end())
873 nb_fhs.insert(*cff_it);
894 FaceHandle rem_fh = face_handle(heh0), del_fh = face_handle(heh1);
895 if (!del_fh.is_valid())
897 std::swap(del_fh, rem_fh);
899 assert(del_fh.is_valid());
911 set_next_halfedge_handle(prev_heh0, next_heh1);
912 set_next_halfedge_handle(prev_heh1, next_heh0);
917 if (halfedge_handle(vh0) == heh1)
919 set_halfedge_handle(vh0, next_heh0);
921 if (halfedge_handle(vh1) == heh0)
923 set_halfedge_handle(vh1, next_heh1);
927 if (halfedge_handle(rem_fh) == heh0)
929 set_halfedge_handle(rem_fh, prev_heh1);
931 else if (halfedge_handle(rem_fh) == heh1)
933 set_halfedge_handle(rem_fh, prev_heh0);
937 set_face_handle(*fh_it, rem_fh);
949 assert_compile(
sizeof(Halfedge) ==
sizeof(Halfedge_with_prev));
951 assert(
status(_eh).deleted());
956 FaceHandle rem_fh = face_handle(heh0), del_fh = face_handle(heh1);
957 if (!del_fh.is_valid())
959 std::swap(del_fh, rem_fh);
961 assert(
status(del_fh).deleted());
971 set_next_halfedge_handle(prev_heh0, heh0);
972 set_prev_halfedge_handle(next_heh0, heh0);
974 set_next_halfedge_handle(prev_heh1, heh1);
975 set_prev_halfedge_handle(next_heh1, heh1);
979 set_face_handle(*fh_it, del_fh);
982 if (face_handle(halfedge_handle(rem_fh)) == del_fh)
984 if (halfedge_handle(rem_fh) == prev_heh0)
986 set_halfedge_handle(rem_fh, heh1);
990 assert(halfedge_handle(rem_fh) == prev_heh1);
991 set_halfedge_handle(rem_fh, heh0);
1000 assert(face_handle(_prev_heh) == face_handle(_next_heh));
1001 assert(next_halfedge_handle(_prev_heh) != _next_heh);
1009 set_next_halfedge_handle(_prev_heh, heh0);
1010 set_next_halfedge_handle(heh0, _next_heh);
1011 set_next_halfedge_handle(prev_next_heh, heh1);
1012 set_next_halfedge_handle(heh1, next_prev_heh);
1016 set_halfedge_handle(new_fh, heh0);
1019 set_face_handle(*fh_it, new_fh);
1021 FaceHandle old_fh = face_handle(next_prev_heh);
1022 set_face_handle(heh1, old_fh);
1023 if (old_fh.
is_valid() && face_handle(halfedge_handle(old_fh)) == new_fh)
1025 set_halfedge_handle(old_fh, heh1);
1050 while (to_vertex_handle(next_halfedge_handle(next_heh)) != start_vh)
1055 set_halfedge_handle(new_fh, base_heh);
1057 HalfedgeHandle new_heh = new_edge(to_vertex_handle(next_heh), start_vh);
1059 set_next_halfedge_handle(base_heh, next_heh);
1060 set_next_halfedge_handle(next_heh, new_heh);
1061 set_next_halfedge_handle(new_heh, base_heh);
1063 set_face_handle(base_heh, new_fh);
1064 set_face_handle(next_heh, new_fh);
1065 set_face_handle(new_heh, new_fh);
1071 base_heh = opposite_halfedge_handle(new_heh);
1072 next_heh = next_next_heh;
1074 set_halfedge_handle(_fh, base_heh);
1076 set_next_halfedge_handle(base_heh, next_heh);
1077 set_next_halfedge_handle(next_halfedge_handle(next_heh), base_heh);
1079 set_face_handle(base_heh, _fh);
1090 for (; f_it!=f_end; ++f_it)
1102 set_next_halfedge_handle(hend, hold);
1103 set_face_handle(hold, fh);
1105 hold = opposite_halfedge_handle(hold);
1107 while (hh != hend) {
1112 set_halfedge_handle(fnew, hh);
1116 set_next_halfedge_handle(hnew, hold);
1117 set_next_halfedge_handle(hold, hh);
1118 set_next_halfedge_handle(hh, hnew);
1120 set_face_handle(hnew, fnew);
1121 set_face_handle(hold, fnew);
1122 set_face_handle(hh, fnew);
1124 hold = opposite_halfedge_handle(hnew);
1129 set_next_halfedge_handle(hold, hend);
1130 set_next_halfedge_handle(next_halfedge_handle(hend), hold);
1132 set_face_handle(hold, fh);
1134 set_halfedge_handle(vh, hold);
1187 set_vertex_handle(h1, _vh);
1190 set_next_halfedge_handle(new_e, h0);
1191 set_next_halfedge_handle(h1, opposite_halfedge_handle(new_e));
1193 set_next_halfedge_handle(ph0, new_e);
1194 set_next_halfedge_handle(opposite_halfedge_handle(new_e), nh1);
1204 set_face_handle(new_e, face_handle(h0));
1208 set_boundary(new_e);
1213 set_face_handle(opposite_halfedge_handle(new_e), face_handle(h1));
1217 set_boundary(opposite_halfedge_handle(new_e));
1220 set_halfedge_handle( _vh, h0 );
1223 if (halfedge_handle(vfrom) == h0)
1225 set_halfedge_handle(vfrom, new_e);
1238 EdgeHandle eh0 = edge_handle( next_halfedge_handle( halfedge_handle(_eh, 1) ) );
ConstFaceVertexIter cfv_iter(FaceHandle _fh) const
const face - vertex circulator
static const EdgeHandle InvalidEdgeHandle
Invalid handle.
void set_tagged(bool _b)
set tagged
FaceHalfedgeIter fh_iter(FaceHandle _fh)
face - halfedge circulator
EdgeIter edges_begin()
Begin iterator for edges.
Handle for a vertex entity.
bool is_boundary(HalfedgeHandle _heh) const
Check if the halfedge is at the boundary.
EdgeIter edges_end()
End iterator for edges.
VertexIter vertices_begin()
Begin iterator for vertices.
static const FaceHandle InvalidFaceHandle
Invalid handle.
ConstFaceEdgeIter cfe_iter(FaceHandle _fh) const
const face - edge circulator
ConstVertexOHalfedgeIter cvoh_iter(VertexHandle _vh) const
const vertex - outgoing halfedge circulator
void adjust_outgoing_halfedge(VertexHandle _vh)
ConstFaceFaceIter cff_iter(FaceHandle _fh) const
const face - face circulator
VertexFaceIter vf_iter(VertexHandle _vh)
vertex - face circulator
FaceHandle remove_edge(EdgeHandle _eh)
bool is_manifold(VertexHandle _vh) const
Is (the mesh at) vertex _vh two-manifold ?
void delete_face(FaceHandle _fh, bool _delete_isolated_vertices=true)
bool deleted() const
is deleted ?
VertexIter ConstVertexIter
Linear iterator.
void collapse(HalfedgeHandle _heh)
HalfedgeHandle find_halfedge(VertexHandle _start_vh, VertexHandle _end_vh) const
Find halfedge from _vh0 to _vh1. Returns invalid handle if not found.
Handle for a halfedge entity.
const StatusInfo & status(VertexHandle _vh) const
Status Query API.
FaceHalfedgeIter fh_end(FaceHandle _fh)
face - halfedge circulator
Iterators::GenericIteratorT< This, This::FaceHandle, ArrayKernel, &ArrayKernel::has_face_status, &ArrayKernel::n_faces > FaceIter
Linear iterator.
static const VertexHandle InvalidVertexHandle
Invalid handle.
void copy_all_properties(VertexHandle _vh_from, VertexHandle _vh_to, bool _copyBuildIn=false)
void collapse_loop(HalfedgeHandle _hh)
Helper for halfedge collapse.
void delete_vertex(VertexHandle _vh, bool _delete_isolated_vertices=true)
void set_deleted(bool _b)
set deleted
EdgeIter ConstEdgeIter
Linear iterator.
HalfedgeIter halfedges_begin()
Begin iterator for halfedges.
FaceIter ConstFaceIter
Linear iterator.
static const HalfedgeHandle InvalidHalfedgeHandle
Invalid handle.
bool is_collapse_ok(HalfedgeHandle _he)
uint valence(VertexHandle _vh) const
Vertex valence.
FaceHandle opposite_face_handle(HalfedgeHandle _heh) const
returns the face handle of the opposite halfedge
Handle for a face entity.
VertexVertexIter vv_iter(VertexHandle _vh)
vertex - vertex circulator
VertexIter vertices_end()
End iterator for vertices.
void triangulate()
triangulate the entire mesh
bool is_simple_link(EdgeHandle _eh) const
void split_edge_copy(EdgeHandle _eh, VertexHandle _vh)
void split(FaceHandle _fh, VertexHandle _vh)
Face split (= 1-to-n split).
void delete_edge(EdgeHandle _eh, bool _delete_isolated_vertices=true)
HalfedgeIter ConstHalfedgeIter
Linear iterator.
bool is_simply_connected(FaceHandle _fh) const
VertexIHalfedgeIter vih_iter(VertexHandle _vh)
vertex - incoming halfedge circulator
Iterators::GenericIteratorT< This, This::EdgeHandle, ArrayKernel, &ArrayKernel::has_edge_status, &ArrayKernel::n_edges > EdgeIter
Linear iterator.
Handle for a edge entity.
void collapse_edge(HalfedgeHandle _hh)
Helper for halfedge collapse.
void split_edge(EdgeHandle _eh, VertexHandle _vh)
bool is_valid() const
The handle is valid iff the index is not negative.
Iterators::GenericIteratorT< This, This::HalfedgeHandle, ArrayKernel, &ArrayKernel::has_halfedge_status, &ArrayKernel::n_halfedges > HalfedgeIter
Linear iterator.
bool tagged() const
is tagged ?
HalfedgeHandle insert_edge(HalfedgeHandle _prev_heh, HalfedgeHandle _next_heh)
FaceIter faces_end()
End iterator for faces.
FaceIter faces_begin()
Begin iterator for faces.
HalfedgeIter halfedges_end()
End iterator for halfedges.
void split_copy(FaceHandle _fh, VertexHandle _vh)
Face split (= 1-to-n split).
FaceHandle add_face(const std::vector< VertexHandle > &_vhandles)
Add and connect a new face.
void reinsert_edge(EdgeHandle _eh)
ConstVertexVertexIter cvv_iter(VertexHandle _vh) const
const vertex circulator
Iterators::GenericIteratorT< This, This::VertexHandle, ArrayKernel, &ArrayKernel::has_vertex_status, &ArrayKernel::n_vertices > VertexIter
Linear iterator.