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()); }
328 std::vector<VertexHandle> vhandles(_vhandles.begin(), _vhandles.end());
329 return add_face(&vhandles.front(), vhandles.size());
337 if (
status(edge_handle(v0v1)).deleted())
346 bool v0v1_triangle =
false;
347 bool v1v0_triangle =
false;
350 v0v1_triangle =
valence(face_handle(v0v1)) == 3;
353 v1v0_triangle =
valence(face_handle(v1v0)) == 3;
357 VertexHandle v_01_n = to_vertex_handle(next_halfedge_handle(v0v1));
360 VertexHandle v_10_n = to_vertex_handle(next_halfedge_handle(v1v0));
378 vl = to_vertex_handle(h1);
395 vr = to_vertex_handle(h1);
403 if ( vl.
is_valid() && (vl == vr))
return false;
411 for (vv_it =
vv_iter(v0); vv_it.is_valid(); ++vv_it)
416 for (vv_it =
vv_iter(v1); vv_it.is_valid(); ++vv_it)
421 for (vv_it =
vv_iter(v0); vv_it.is_valid(); ++vv_it)
424 !(*vv_it == v_01_n && v0v1_triangle) &&
425 !(*vv_it == v_10_n && v1v0_triangle)
436 one = next_halfedge_handle(v0v1);
437 two = next_halfedge_handle(one);
439 one = opposite_halfedge_handle(one);
440 two = opposite_halfedge_handle(two);
442 if (face_handle(one) == face_handle(two) &&
valence(face_handle(one)) != 3)
451 one = next_halfedge_handle(v1v0);
452 two = next_halfedge_handle(one);
454 one = opposite_halfedge_handle(one);
455 two = opposite_halfedge_handle(two);
457 if (face_handle(one) == face_handle(two) &&
valence(face_handle(one)) != 3)
463 if (
status(*vv_it).
tagged() && v_01_n == v_10_n && v0v1_triangle && v1v0_triangle)
477 std::vector<FaceHandle> face_handles;
478 face_handles.reserve(8);
480 face_handles.push_back(*vf_it);
484 std::vector<FaceHandle>::iterator fh_it(face_handles.begin()),
485 fh_end(face_handles.end());
487 for (; fh_it!=
fh_end; ++fh_it)
497 FaceHandle fh0(face_handle(halfedge_handle(_eh, 0)));
498 FaceHandle fh1(face_handle(halfedge_handle(_eh, 1)));
507 if ( has_edge_status() )
513 if ( has_halfedge_status() ) {
532 std::vector<EdgeHandle> deleted_edges;
533 deleted_edges.reserve(3);
538 std::vector<VertexHandle> vhandles;
554 deleted_edges.push_back(edge_handle(hh));
556 vhandles.push_back(to_vertex_handle(hh));
563 if (!deleted_edges.empty())
565 std::vector<EdgeHandle>::iterator del_it(deleted_edges.begin()),
566 del_end(deleted_edges.end());
570 for (; del_it!=del_end; ++del_it)
572 h0 = halfedge_handle(*del_it, 0);
573 v0 = to_vertex_handle(h0);
574 next0 = next_halfedge_handle(h0);
575 prev0 = prev_halfedge_handle(h0);
577 h1 = halfedge_handle(*del_it, 1);
578 v1 = to_vertex_handle(h1);
579 next1 = next_halfedge_handle(h1);
580 prev1 = prev_halfedge_handle(h1);
583 set_next_halfedge_handle(prev0, next1);
584 set_next_halfedge_handle(prev1, next0);
587 if ( has_edge_status() )
594 if ( has_halfedge_status() ) {
600 if (halfedge_handle(v0) == h1)
605 if (_delete_isolated_vertices)
609 else set_halfedge_handle(v0, next0);
613 if (halfedge_handle(v1) == h0)
618 if (_delete_isolated_vertices)
622 else set_halfedge_handle(v1, next1);
628 std::vector<VertexHandle>::iterator v_it(vhandles.begin()),
629 v_end(vhandles.end());
630 for (; v_it!=v_end; ++v_it)
647 if (next_halfedge_handle(next_halfedge_handle(h1)) == h1)
649 if (next_halfedge_handle(next_halfedge_handle(o1)) == o1)
674 set_vertex_handle(*vih_it, vh);
678 set_next_halfedge_handle(hp, hn);
679 set_next_halfedge_handle(op, on);
683 if (fh.
is_valid()) set_halfedge_handle(fh, hn);
684 if (fo.
is_valid()) set_halfedge_handle(fo, on);
688 if (halfedge_handle(vh) == o) set_halfedge_handle(vh, hn);
695 if (has_halfedge_status())
720 assert ((next_halfedge_handle(h1) == h0) && (h1 != o0));
724 set_next_halfedge_handle(h1, next_halfedge_handle(o0));
725 set_next_halfedge_handle(prev_halfedge_handle(o0), h1);
729 set_face_handle(h1, fo);
738 if (fo.
is_valid() && halfedge_handle(fo) == o0)
740 set_halfedge_handle(fo, h1);
750 if (has_halfedge_status())
767 while (next_heh != heh0)
773 next_heh = next_halfedge_handle(next_heh);
781 std::set<FaceHandle> nb_fhs;
784 if (nb_fhs.find(*cff_it) == nb_fhs.end())
786 nb_fhs.insert(*cff_it);
807 FaceHandle rem_fh = face_handle(heh0), del_fh = face_handle(heh1);
808 if (!del_fh.is_valid())
810 std::swap(del_fh, rem_fh);
812 assert(del_fh.is_valid());
824 set_next_halfedge_handle(prev_heh0, next_heh1);
825 set_next_halfedge_handle(prev_heh1, next_heh0);
830 if (halfedge_handle(vh0) == heh1)
832 set_halfedge_handle(vh0, next_heh0);
834 if (halfedge_handle(vh1) == heh0)
836 set_halfedge_handle(vh1, next_heh1);
840 if (halfedge_handle(rem_fh) == heh0)
842 set_halfedge_handle(rem_fh, prev_heh1);
844 else if (halfedge_handle(rem_fh) == heh1)
846 set_halfedge_handle(rem_fh, prev_heh0);
850 set_face_handle(*fh_it, rem_fh);
862 assert_compile(
sizeof(Halfedge) ==
sizeof(Halfedge_with_prev));
864 assert(
status(_eh).deleted());
869 FaceHandle rem_fh = face_handle(heh0), del_fh = face_handle(heh1);
870 if (!del_fh.is_valid())
872 std::swap(del_fh, rem_fh);
874 assert(
status(del_fh).deleted());
884 set_next_halfedge_handle(prev_heh0, heh0);
885 set_prev_halfedge_handle(next_heh0, heh0);
887 set_next_halfedge_handle(prev_heh1, heh1);
888 set_prev_halfedge_handle(next_heh1, heh1);
892 set_face_handle(*fh_it, del_fh);
895 if (face_handle(halfedge_handle(rem_fh)) == del_fh)
897 if (halfedge_handle(rem_fh) == prev_heh0)
899 set_halfedge_handle(rem_fh, heh1);
903 assert(halfedge_handle(rem_fh) == prev_heh1);
904 set_halfedge_handle(rem_fh, heh0);
913 assert(face_handle(_prev_heh) == face_handle(_next_heh));
914 assert(next_halfedge_handle(_prev_heh) != _next_heh);
922 set_next_halfedge_handle(_prev_heh, heh0);
923 set_next_halfedge_handle(heh0, _next_heh);
924 set_next_halfedge_handle(prev_next_heh, heh1);
925 set_next_halfedge_handle(heh1, next_prev_heh);
929 set_halfedge_handle(new_fh, heh0);
932 set_face_handle(*fh_it, new_fh);
934 FaceHandle old_fh = face_handle(next_prev_heh);
935 set_face_handle(heh1, old_fh);
936 if (old_fh.
is_valid() && face_handle(halfedge_handle(old_fh)) == new_fh)
938 set_halfedge_handle(old_fh, heh1);
963 while (to_vertex_handle(next_halfedge_handle(next_heh)) != start_vh)
968 set_halfedge_handle(new_fh, base_heh);
970 HalfedgeHandle new_heh = new_edge(to_vertex_handle(next_heh), start_vh);
972 set_next_halfedge_handle(base_heh, next_heh);
973 set_next_halfedge_handle(next_heh, new_heh);
974 set_next_halfedge_handle(new_heh, base_heh);
976 set_face_handle(base_heh, new_fh);
977 set_face_handle(next_heh, new_fh);
978 set_face_handle(new_heh, new_fh);
984 base_heh = opposite_halfedge_handle(new_heh);
985 next_heh = next_next_heh;
987 set_halfedge_handle(_fh, base_heh);
989 set_next_halfedge_handle(base_heh, next_heh);
990 set_next_halfedge_handle(next_halfedge_handle(next_heh), base_heh);
992 set_face_handle(base_heh, _fh);
1003 for (; f_it!=f_end; ++f_it)
1015 set_next_halfedge_handle(hend, hold);
1016 set_face_handle(hold, fh);
1018 hold = opposite_halfedge_handle(hold);
1020 while (hh != hend) {
1025 set_halfedge_handle(fnew, hh);
1029 set_next_halfedge_handle(hnew, hold);
1030 set_next_halfedge_handle(hold, hh);
1031 set_next_halfedge_handle(hh, hnew);
1033 set_face_handle(hnew, fnew);
1034 set_face_handle(hold, fnew);
1035 set_face_handle(hh, fnew);
1037 hold = opposite_halfedge_handle(hnew);
1042 set_next_halfedge_handle(hold, hend);
1043 set_next_halfedge_handle(next_halfedge_handle(hend), hold);
1045 set_face_handle(hold, fh);
1047 set_halfedge_handle(vh, hold);
1100 set_vertex_handle(h1, _vh);
1103 set_next_halfedge_handle(new_e, h0);
1104 set_next_halfedge_handle(h1, opposite_halfedge_handle(new_e));
1106 set_next_halfedge_handle(ph0, new_e);
1107 set_next_halfedge_handle(opposite_halfedge_handle(new_e), nh1);
1117 set_face_handle(new_e, face_handle(h0));
1121 set_boundary(new_e);
1126 set_face_handle(opposite_halfedge_handle(new_e), face_handle(h1));
1130 set_boundary(opposite_halfedge_handle(new_e));
1133 set_halfedge_handle( _vh, h0 );
1136 if (halfedge_handle(vfrom) == h0)
1138 set_halfedge_handle(vfrom, new_e);
1151 EdgeHandle eh0 = edge_handle( next_halfedge_handle( halfedge_handle(_eh, 1) ) );
Handle for a edge entity.
Handle for a face entity.
bool tagged() const
is tagged ?
bool is_manifold(VertexHandle _vh) const
Is (the mesh at) vertex _vh two-manifold ?
void split_copy(FaceHandle _fh, VertexHandle _vh)
Face split (= 1-to-n split).
void set_tagged(bool _b)
set tagged
void collapse(HalfedgeHandle _heh)
void adjust_outgoing_halfedge(VertexHandle _vh)
void delete_vertex(VertexHandle _vh, bool _delete_isolated_vertices=true)
Handle for a halfedge entity.
void split_edge(EdgeHandle _eh, VertexHandle _vh)
FaceHandle remove_edge(EdgeHandle _eh)
VertexVertexIter vv_iter(VertexHandle _vh)
vertex - vertex circulator
FaceIter faces_begin()
Begin iterator for faces.
FaceHalfedgeIter fh_iter(FaceHandle _fh)
face - halfedge circulator
ConstVertexOHalfedgeIter cvoh_iter(VertexHandle _vh) const
const vertex - outgoing halfedge circulator
VertexFaceIter vf_iter(VertexHandle _vh)
vertex - face circulator
void collapse_loop(HalfedgeHandle _hh)
Helper for halfedge collapse.
FaceIter faces_end()
End iterator for faces.
VertexIHalfedgeIter vih_iter(VertexHandle _vh)
vertex - incoming halfedge circulator
bool is_simple_link(EdgeHandle _eh) const
Handle for a vertex entity.
ConstVertexVertexIter cvv_iter(VertexHandle _vh) const
const vertex circulator
const StatusInfo & status(VertexHandle _vh) const
Status Query API.
bool is_valid() const
The handle is valid iff the index is not negative.
void split(FaceHandle _fh, VertexHandle _vh)
Face split (= 1-to-n split).
void delete_edge(EdgeHandle _eh, bool _delete_isolated_vertices=true)
HalfedgeHandle insert_edge(HalfedgeHandle _prev_heh, HalfedgeHandle _next_heh)
SmartVertexHandle make_smart(VertexHandle _vh, const PolyConnectivity *_mesh)
Creats a SmartVertexHandle from a VertexHandle and a Mesh.
void delete_face(FaceHandle _fh, bool _delete_isolated_vertices=true)
void reinsert_edge(EdgeHandle _eh)
ConstFaceFaceIter cff_iter(FaceHandle _fh) const
const face - face circulator
void set_deleted(bool _b)
set deleted
bool is_boundary(HalfedgeHandle _heh) const
Check if the halfedge is at the boundary.
void triangulate()
triangulate the entire mesh
bool is_collapse_ok(HalfedgeHandle _he)
FaceHalfedgeIter fh_end(FaceHandle _fh)
face - halfedge circulator
static const VertexHandle InvalidVertexHandle
Invalid handle.
void collapse_edge(HalfedgeHandle _hh)
Helper for halfedge collapse.
HalfedgeHandle find_halfedge(VertexHandle _start_vh, VertexHandle _end_vh) const
Find halfedge from _vh0 to _vh1. Returns invalid handle if not found.
uint valence(VertexHandle _vh) const
Vertex valence.
void split_edge_copy(EdgeHandle _eh, VertexHandle _vh)
SmartFaceHandle add_face(const std::vector< VertexHandle > &_vhandles)
Add and connect a new face.
static const HalfedgeHandle InvalidHalfedgeHandle
Invalid handle.
static const EdgeHandle InvalidEdgeHandle
Invalid handle.
bool deleted() const
is deleted ?
void copy_all_properties(VertexHandle _vh_from, VertexHandle _vh_to, bool _copyBuildIn=false)
static const FaceHandle InvalidFaceHandle
Invalid handle.
ConstFaceEdgeIter cfe_iter(FaceHandle _fh) const
const face - edge circulator
ConstFaceVertexIter cfv_iter(FaceHandle _fh) const
const face - vertex circulator
bool is_simply_connected(FaceHandle _fh) const
FaceHandle opposite_face_handle(HalfedgeHandle _heh) const
returns the face handle of the opposite halfedge