00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef OPENMESH_POLYMESHT_HH
00040 #define OPENMESH_POLYMESHT_HH
00041
00042
00043
00044
00045
00046 #include <OpenMesh/Core/System/config.h>
00047 #include <OpenMesh/Core/Mesh/BaseMesh.hh>
00048 #include <OpenMesh/Core/Mesh/Iterators/IteratorsT.hh>
00049 #include <OpenMesh/Core/Mesh/Iterators/CirculatorsT.hh>
00050 #include <OpenMesh/Core/Attributes/Attributes.hh>
00051 #include <vector>
00052
00053
00054
00055
00056
00057 namespace OpenMesh {
00058
00059
00060
00061
00062
00077 template <class Kernel>
00078 class PolyMeshT : public Kernel, public BaseMesh
00079 {
00080
00081 public:
00082
00083
00084
00085
00087 typedef PolyMeshT<Kernel> This;
00088
00089
00090
00091
00092
00094
00095
00096 typedef typename Kernel::Scalar Scalar;
00098 typedef typename Kernel::Point Point;
00099
00101 typedef typename Kernel::Normal Normal;
00102
00104 typedef typename Kernel::Color Color;
00105
00107 typedef typename Kernel::TexCoord TexCoord;
00108
00110 typedef typename Kernel::Vertex Vertex;
00112 typedef typename Kernel::Halfedge Halfedge;
00114 typedef typename Kernel::Edge Edge;
00116 typedef typename Kernel::Face Face;
00118
00119
00120
00121
00122
00124
00125
00126 typedef typename Kernel::VertexHandle VertexHandle;
00127 typedef typename Kernel::HalfedgeHandle HalfedgeHandle;
00128 typedef typename Kernel::EdgeHandle EdgeHandle;
00129 typedef typename Kernel::FaceHandle FaceHandle;
00130
00132 static const VertexHandle InvalidVertexHandle;
00134 static const HalfedgeHandle InvalidHalfedgeHandle;
00136 static const EdgeHandle InvalidEdgeHandle;
00138 static const FaceHandle InvalidFaceHandle;
00140
00141
00142
00143
00144
00150
00151 typedef Iterators::VertexIterT<This> VertexIter;
00152 typedef Iterators::HalfedgeIterT<This> HalfedgeIter;
00153 typedef Iterators::EdgeIterT<This> EdgeIter;
00154 typedef Iterators::FaceIterT<This> FaceIter;
00155
00156 typedef Iterators::ConstVertexIterT<This> ConstVertexIter;
00157 typedef Iterators::ConstHalfedgeIterT<This> ConstHalfedgeIter;
00158 typedef Iterators::ConstEdgeIterT<This> ConstEdgeIter;
00159 typedef Iterators::ConstFaceIterT<This> ConstFaceIter;
00161
00162
00163
00164
00165
00171
00172 typedef Iterators::VertexVertexIterT<This> VertexVertexIter;
00173 typedef Iterators::VertexOHalfedgeIterT<This> VertexOHalfedgeIter;
00174 typedef Iterators::VertexIHalfedgeIterT<This> VertexIHalfedgeIter;
00175 typedef Iterators::VertexEdgeIterT<This> VertexEdgeIter;
00176 typedef Iterators::VertexFaceIterT<This> VertexFaceIter;
00177 typedef Iterators::FaceVertexIterT<This> FaceVertexIter;
00178 typedef Iterators::FaceHalfedgeIterT<This> FaceHalfedgeIter;
00179 typedef Iterators::FaceEdgeIterT<This> FaceEdgeIter;
00180 typedef Iterators::FaceFaceIterT<This> FaceFaceIter;
00181
00182 typedef Iterators::ConstVertexVertexIterT<This> ConstVertexVertexIter;
00183 typedef Iterators::ConstVertexOHalfedgeIterT<This> ConstVertexOHalfedgeIter;
00184 typedef Iterators::ConstVertexIHalfedgeIterT<This> ConstVertexIHalfedgeIter;
00185 typedef Iterators::ConstVertexEdgeIterT<This> ConstVertexEdgeIter;
00186 typedef Iterators::ConstVertexFaceIterT<This> ConstVertexFaceIter;
00187 typedef Iterators::ConstFaceVertexIterT<This> ConstFaceVertexIter;
00188 typedef Iterators::ConstFaceHalfedgeIterT<This> ConstFaceHalfedgeIter;
00189 typedef Iterators::ConstFaceEdgeIterT<This> ConstFaceEdgeIter;
00190 typedef Iterators::ConstFaceFaceIterT<This> ConstFaceFaceIter;
00192
00193
00194
00195
00196
00197
00202
00203 typedef VertexHandle VHandle;
00204 typedef HalfedgeHandle HHandle;
00205 typedef EdgeHandle EHandle;
00206 typedef FaceHandle FHandle;
00207
00208 typedef VertexIter VIter;
00209 typedef HalfedgeIter HIter;
00210 typedef EdgeIter EIter;
00211 typedef FaceIter FIter;
00212
00213 typedef ConstVertexIter CVIter;
00214 typedef ConstHalfedgeIter CHIter;
00215 typedef ConstEdgeIter CEIter;
00216 typedef ConstFaceIter CFIter;
00217
00218 typedef VertexVertexIter VVIter;
00219 typedef VertexOHalfedgeIter VOHIter;
00220 typedef VertexIHalfedgeIter VIHIter;
00221 typedef VertexEdgeIter VEIter;
00222 typedef VertexFaceIter VFIter;
00223 typedef FaceVertexIter FVIter;
00224 typedef FaceHalfedgeIter FHIter;
00225 typedef FaceEdgeIter FEIter;
00226 typedef FaceFaceIter FFIter;
00227
00228 typedef ConstVertexVertexIter CVVIter;
00229 typedef ConstVertexOHalfedgeIter CVOHIter;
00230 typedef ConstVertexIHalfedgeIter CVIHIter;
00231 typedef ConstVertexEdgeIter CVEIter;
00232 typedef ConstVertexFaceIter CVFIter;
00233 typedef ConstFaceVertexIter CFVIter;
00234 typedef ConstFaceHalfedgeIter CFHIter;
00235 typedef ConstFaceEdgeIter CFEIter;
00236 typedef ConstFaceFaceIter CFFIter;
00238
00239
00240
00241
00242
00244 PolyMeshT() {}
00245
00247 ~PolyMeshT() {}
00248
00254 PolyMeshT& operator=(const PolyMeshT& _rhs) {
00255 Kernel::operator=(_rhs); return *this;
00256 }
00257
00258
00259
00260
00261
00262
00263
00267
00269 VertexHandle add_vertex(const Point& _p) {
00270 return new_vertex(_p);
00271 }
00272
00274 FaceHandle add_face(const std::vector<VertexHandle>& _vhandles);
00275
00290 template <class OtherMesh>
00291 PolyMeshT& assign(const OtherMesh& _rhs)
00292 #if OM_OUT_OF_CLASS_TEMPLATE || defined(DOXYGEN)
00293 ;
00294 #else
00295 # include "PolyMeshT_assign.hh"
00296 #endif
00297
00299
00300
00301
00302
00303
00304
00305
00307
00308
00314 void delete_vertex(VertexHandle _vh, bool _delete_isolated_vertices = true);
00315
00324 void delete_edge(EdgeHandle _eh, bool _delete_isolated_vertices=true);
00325
00336 void delete_face(FaceHandle _fh, bool _delete_isolated_vertices=true);
00337
00339
00340
00341
00342
00343
00344
00345
00349
00351 VertexIter vertices_begin()
00352 { return VertexIter(*this, VertexHandle(0)); }
00354 ConstVertexIter vertices_begin() const
00355 { return ConstVertexIter(*this, VertexHandle(0)); }
00357 VertexIter vertices_end()
00358 { return VertexIter(*this, VertexHandle(n_vertices())); }
00360 ConstVertexIter vertices_end() const
00361 { return ConstVertexIter(*this, VertexHandle(n_vertices())); }
00362
00364 HalfedgeIter halfedges_begin()
00365 { return HalfedgeIter(*this, HalfedgeHandle(0)); }
00367 ConstHalfedgeIter halfedges_begin() const
00368 { return ConstHalfedgeIter(*this, HalfedgeHandle(0)); }
00370 HalfedgeIter halfedges_end()
00371 { return HalfedgeIter(*this, HalfedgeHandle(n_halfedges())); }
00373 ConstHalfedgeIter halfedges_end() const
00374 { return ConstHalfedgeIter(*this, HalfedgeHandle(n_halfedges())); }
00375
00377 EdgeIter edges_begin()
00378 { return EdgeIter(*this, EdgeHandle(0)); }
00380 ConstEdgeIter edges_begin() const
00381 { return ConstEdgeIter(*this, EdgeHandle(0)); }
00383 EdgeIter edges_end()
00384 { return EdgeIter(*this, EdgeHandle(n_edges())); }
00386 ConstEdgeIter edges_end() const
00387 { return ConstEdgeIter(*this, EdgeHandle(n_edges())); }
00388
00390 FaceIter faces_begin()
00391 { return FaceIter(*this, FaceHandle(0)); }
00393 ConstFaceIter faces_begin() const
00394 { return ConstFaceIter(*this, FaceHandle(0)); }
00396 FaceIter faces_end()
00397 { return FaceIter(*this, FaceHandle(n_faces())); }
00399 ConstFaceIter faces_end() const
00400 { return ConstFaceIter(*this, FaceHandle(n_faces())); }
00401
00403
00404
00405
00409
00411 VertexIter vertices_sbegin()
00412 { return VertexIter(*this, VertexHandle(0), true); }
00414 ConstVertexIter vertices_sbegin() const
00415 { return ConstVertexIter(*this, VertexHandle(0), true); }
00416
00418 HalfedgeIter halfedges_sbegin()
00419 { return HalfedgeIter(*this, HalfedgeHandle(0), true); }
00421 ConstHalfedgeIter halfedges_sbegin() const
00422 { return ConstHalfedgeIter(*this, HalfedgeHandle(0), true); }
00423
00425 EdgeIter edges_sbegin()
00426 { return EdgeIter(*this, EdgeHandle(0), true); }
00428 ConstEdgeIter edges_sbegin() const
00429 { return ConstEdgeIter(*this, EdgeHandle(0), true); }
00430
00432 FaceIter faces_sbegin()
00433 { return FaceIter(*this, FaceHandle(0), true); }
00435 ConstFaceIter faces_sbegin() const
00436 { return ConstFaceIter(*this, FaceHandle(0), true); }
00437
00439
00440
00441
00442
00443
00444
00448
00450 VertexVertexIter vv_iter(VertexHandle _vh) {
00451 return VertexVertexIter(*this, _vh); }
00453 VertexIHalfedgeIter vih_iter(VertexHandle _vh) {
00454 return VertexIHalfedgeIter(*this, _vh); }
00456 VertexOHalfedgeIter voh_iter(VertexHandle _vh) {
00457 return VertexOHalfedgeIter(*this, _vh); }
00459 VertexEdgeIter ve_iter(VertexHandle _vh) {
00460 return VertexEdgeIter(*this, _vh); }
00462 VertexFaceIter vf_iter(VertexHandle _vh) {
00463 return VertexFaceIter(*this, _vh); }
00464
00466 ConstVertexVertexIter cvv_iter(VertexHandle _vh) const {
00467 return ConstVertexVertexIter(*this, _vh); }
00469 ConstVertexIHalfedgeIter cvih_iter(VertexHandle _vh) const {
00470 return ConstVertexIHalfedgeIter(*this, _vh); }
00472 ConstVertexOHalfedgeIter cvoh_iter(VertexHandle _vh) const {
00473 return ConstVertexOHalfedgeIter(*this, _vh); }
00475 ConstVertexEdgeIter cve_iter(VertexHandle _vh) const {
00476 return ConstVertexEdgeIter(*this, _vh); }
00478 ConstVertexFaceIter cvf_iter(VertexHandle _vh) const {
00479 return ConstVertexFaceIter(*this, _vh); }
00480
00482 FaceVertexIter fv_iter(FaceHandle _fh) {
00483 return FaceVertexIter(*this, _fh); }
00485 FaceHalfedgeIter fh_iter(FaceHandle _fh) {
00486 return FaceHalfedgeIter(*this, _fh); }
00488 FaceEdgeIter fe_iter(FaceHandle _fh) {
00489 return FaceEdgeIter(*this, _fh); }
00491 FaceFaceIter ff_iter(FaceHandle _fh) {
00492 return FaceFaceIter(*this, _fh); }
00493
00495 ConstFaceVertexIter cfv_iter(FaceHandle _fh) const {
00496 return ConstFaceVertexIter(*this, _fh); }
00498 ConstFaceHalfedgeIter cfh_iter(FaceHandle _fh) const {
00499 return ConstFaceHalfedgeIter(*this, _fh); }
00501 ConstFaceEdgeIter cfe_iter(FaceHandle _fh) const {
00502 return ConstFaceEdgeIter(*this, _fh); }
00504 ConstFaceFaceIter cff_iter(FaceHandle _fh) const {
00505 return ConstFaceFaceIter(*this, _fh); }
00507
00508
00509
00510
00511
00512
00516
00518 bool is_boundary(HalfedgeHandle _heh) const {
00519 return ! face_handle(_heh).is_valid();
00520 }
00523 bool is_boundary(EdgeHandle _eh) const {
00524 return (is_boundary(halfedge_handle(_eh, 0)) ||
00525 is_boundary(halfedge_handle(_eh, 1)));
00526 }
00528 bool is_boundary(VertexHandle _vh) const {
00529 HalfedgeHandle heh(halfedge_handle(_vh));
00530 return (!(heh.is_valid() && face_handle(heh).is_valid()));
00531 }
00532
00539 bool is_boundary(FaceHandle _fh, bool _check_vertex=false) const {
00540 for (ConstFaceEdgeIter cfeit = cfe_iter( _fh ); cfeit; ++cfeit)
00541 if (is_boundary( cfeit.handle() ) )
00542 return true;
00543
00544 if (_check_vertex)
00545 {
00546 for (ConstFaceVertexIter cfvit = cfv_iter( _fh ); cfvit; ++cfvit)
00547 if (is_boundary( cfvit.handle() ) )
00548 return true;
00549 }
00550 return false;
00551 }
00552
00554 bool is_manifold(VertexHandle _vh) const {
00555
00556
00557
00558
00559
00560
00561
00562 ConstVertexOHalfedgeIter vh_it(*this, _vh);
00563 if (vh_it)
00564 for (++vh_it; vh_it; ++vh_it)
00565 if (is_boundary(vh_it.handle()))
00566 return false;
00567
00568 return true;
00569 }
00570
00572
00573
00574
00575
00576
00577
00581
00584 void update_normals();
00585
00587 Normal calc_face_normal(FaceHandle _fh) const;
00588
00590 Normal calc_face_normal(const Point& _p0,
00591 const Point& _p1,
00592 const Point& _p2) const;
00593
00595 void update_normal(FaceHandle _fh)
00596 { set_normal(_fh, calc_face_normal(_fh)); }
00597
00601 void update_face_normals();
00602
00607 Normal calc_vertex_normal(VertexHandle _vh) const;
00608
00610 void update_normal(VertexHandle _vh)
00611 { set_normal(_vh, calc_vertex_normal(_vh)); }
00612
00616 void update_vertex_normals();
00617
00619
00620
00621
00622
00623
00624
00626 HalfedgeHandle find_halfedge(VertexHandle _start_vertex_handle,
00627 VertexHandle _end_vertex_habdle) const;
00628
00629
00631 void split(FaceHandle _fh, VertexHandle _vh);
00633 void split(FaceHandle _fh, const Point& _p) { split(_fh, add_vertex(_p)); }
00634
00636 void triangulate(FaceHandle _fh);
00637
00639 void triangulate();
00640
00641
00643 unsigned int valence(VertexHandle _vh) const;
00644
00646 unsigned int valence(FaceHandle _fh) const;
00647
00648
00654
00655 const Vertex& deref(VertexHandle _h) const { return vertex(_h); }
00656 Vertex& deref(VertexHandle _h) { return vertex(_h); }
00657 const Halfedge& deref(HalfedgeHandle _h) const { return halfedge(_h); }
00658 Halfedge& deref(HalfedgeHandle _h) { return halfedge(_h); }
00659 const Edge& deref(EdgeHandle _h) const { return edge(_h); }
00660 Edge& deref(EdgeHandle _h) { return edge(_h); }
00661 const Face& deref(FaceHandle _h) const { return face(_h); }
00662 Face& deref(FaceHandle _h) { return face(_h); }
00664
00665
00666 public:
00667
00670 void adjust_outgoing_halfedge(VertexHandle _vh);
00671 };
00672
00673
00674
00675
00676 }
00677
00678 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_POLYMESH_C)
00679 # define OPENMESH_POLYMESH_TEMPLATES
00680 # include "PolyMeshT.cc"
00681 #endif
00682
00683 #endif // OPENMESH_POLYMESHT_HH defined
00684