Easy3D 2.6.1
Loading...
Searching...
No Matches
poly_mesh.h
1/********************************************************************
2 * Copyright (C) 2015 Liangliang Nan <liangliang.nan@gmail.com>
3 * https://3d.bk.tudelft.nl/liangliang/
4 *
5 * This file is part of Easy3D. If it is useful in your research/work,
6 * I would be grateful if you show your appreciation by citing it:
7 * ------------------------------------------------------------------
8 * Liangliang Nan.
9 * Easy3D: a lightweight, easy-to-use, and efficient C++ library
10 * for processing and rendering 3D data.
11 * Journal of Open Source Software, 6(64), 3255, 2021.
12 * ------------------------------------------------------------------
13 *
14 * Easy3D is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License Version 3
16 * as published by the Free Software Foundation.
17 *
18 * Easy3D is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ********************************************************************/
26
27#ifndef EASY3D_CORE_POLYHEDRAL_MESH_H
28#define EASY3D_CORE_POLYHEDRAL_MESH_H
29
30#include <easy3d/core/model.h>
31
32#include <set>
33
34#include <easy3d/core/types.h>
35#include <easy3d/core/property.h>
36
37
38namespace easy3d {
39
48 class PolyMesh : public Model
49 {
50
51 public: //------------------------------------------------------ topology types
52
58 {
59 public:
64 explicit BaseHandle(int _idx=-1) : idx_(_idx) {}
65
70 int idx() const { return idx_; }
71
75 void reset() { idx_=-1; }
76
81 bool is_valid() const { return idx_ != -1; }
82
88 bool operator==(const BaseHandle& _rhs) const {
89 return idx_ == _rhs.idx_;
90 }
91
97 bool operator!=(const BaseHandle& _rhs) const {
98 return idx_ != _rhs.idx_;
99 }
100
106 bool operator<(const BaseHandle& _rhs) const {
107 return idx_ < _rhs.idx_;
108 }
109
113 struct Hash {
119 std::size_t operator()(const BaseHandle& h) const { return h.idx(); }
120 };
121
122 private:
123 friend class PolyMesh;
124 int idx_;
125 };
126
136 explicit Vertex(int _idx=-1) : BaseHandle(_idx) {}
142 std::ostream& operator<<(std::ostream& os) const { return os << 'v' << idx(); }
143 };
144
149 struct Edge : BaseHandle {
154 explicit Edge(int _idx=-1) : BaseHandle(_idx) {}
160 std::ostream& operator<<(std::ostream& os) const { return os << 'e' << idx(); }
161 };
162
172 explicit HalfFace(int _idx=-1) : BaseHandle(_idx) {}
178 std::ostream& operator<<(std::ostream& os) const { return os << 'h' << idx(); }
179 };
180
185 struct Face : BaseHandle {
190 explicit Face(int _idx=-1) : BaseHandle(_idx) {}
196 std::ostream& operator<<(std::ostream& os) const { return os << 'f' << idx(); }
197 };
198
203 struct Cell : BaseHandle {
208 explicit Cell(int _idx=-1) : BaseHandle(_idx) {}
214 std::ostream& operator<<(std::ostream& os) const { return os << 'c' << idx(); }
215 };
216
217
218 public: //-------------------------------------------------- connectivity types
219
225 std::set<Vertex> vertices_;
226 std::set<Edge> edges_;
227 std::set<HalfFace> halffaces_;
228 std::set<Cell> cells_;
233 void read(std::istream& in);
238 void write(std::ostream& out) const;
239 };
240
246 std::vector<Vertex> vertices_;
247 std::set<HalfFace> halffaces_;
248 std::set<Cell> cells_;
253 void read(std::istream& in);
258 void write(std::ostream& out) const;
259 };
260
266 std::vector<Vertex> vertices_;
267 std::set<Edge> edges_;
274 void read(std::istream& in);
279 void write(std::ostream& out) const;
280 };
281
287 std::set<Vertex> vertices_;
288 std::set<Edge> edges_;
289 std::vector<HalfFace> halffaces_;
294 void read(std::istream& in);
299 void write(std::ostream& out) const;
300 };
301
302
303 public: //------------------------------------------------------ property types
304
309 template <class T> class VertexProperty : public Property<T>
310 {
311 public:
315 VertexProperty() = default;
320 explicit VertexProperty(Property<T> p) : Property<T>(p) {}
321
330
339 };
340
345 template <class T> class EdgeProperty : public Property<T>
346 {
347 public:
351 EdgeProperty() = default;
356 explicit EdgeProperty(Property<T> p) : Property<T>(p) {}
357
366
373 return Property<T>::operator[](e.idx());
374 }
375 };
376
381 template <class T> class HalfFaceProperty : public Property<T>
382 {
383 public:
387 HalfFaceProperty() = default;
392 explicit HalfFaceProperty(Property<T> p) : Property<T>(p) {}
393
402
411 };
412
417 template <class T> class FaceProperty : public Property<T>
418 {
419 public:
423 FaceProperty() = default;
428 explicit FaceProperty(Property<T> p) : Property<T>(p) {}
429
438
445 return Property<T>::operator[](f.idx());
446 }
447 };
448
453 template <class T> class CellProperty : public Property<T>
454 {
455 public:
459 CellProperty() = default;
464 explicit CellProperty(Property<T> p) : Property<T>(p) {}
465
474
481 return Property<T>::operator[](c.idx());
482 }
483 };
484
485
490 template <class T> class ModelProperty : public Property<T>
491 {
492 public:
496 ModelProperty() = default;
501 explicit ModelProperty(Property<T> p) : Property<T>(p) {}
502
508 typename Property<T>::reference operator[](size_t idx) {
509 return Property<T>::operator[](idx);
510 }
511
517 typename Property<T>::const_reference operator[](size_t idx) const {
518 return Property<T>::operator[](idx);
519 }
520 };
521
522
523 public: //------------------------------------------------------ iterator types
530 {
531 public:
537 explicit VertexIterator(Vertex v=Vertex(), const PolyMesh* m=nullptr) : hnd_(v), mesh_(m) { }
538
543 Vertex operator*() const { return hnd_; }
544
550 bool operator==(const VertexIterator& rhs) const {
551 return (hnd_==rhs.hnd_);
552 }
553
559 bool operator!=(const VertexIterator& rhs) const {
560 return !operator==(rhs);
561 }
562
568 ++hnd_.idx_;
569 assert(mesh_);
570 return *this;
571 }
572
578 --hnd_.idx_;
579 assert(mesh_);
580 return *this;
581 }
582
583 private:
584 Vertex hnd_;
585 const PolyMesh* mesh_;
586 };
587
594 {
595 public:
601 explicit EdgeIterator(Edge e=Edge(), const PolyMesh* m=nullptr) : hnd_(e), mesh_(m) { }
602
607 Edge operator*() const { return hnd_; }
608
614 bool operator==(const EdgeIterator& rhs) const {
615 return (hnd_==rhs.hnd_);
616 }
617
623 bool operator!=(const EdgeIterator& rhs) const {
624 return !operator==(rhs);
625 }
626
632 ++hnd_.idx_;
633 assert(mesh_);
634 return *this;
635 }
636
642 --hnd_.idx_;
643 assert(mesh_);
644 return *this;
645 }
646
647 private:
648 Edge hnd_;
649 const PolyMesh* mesh_;
650 };
651
652
659 {
660 public:
666 explicit HalfFaceIterator(HalfFace h=HalfFace(), const PolyMesh* m=nullptr) : hnd_(h), mesh_(m) { }
667
672 HalfFace operator*() const { return hnd_; }
673
679 bool operator==(const HalfFaceIterator& rhs) const {
680 return (hnd_==rhs.hnd_);
681 }
682
688 bool operator!=(const HalfFaceIterator& rhs) const {
689 return !operator==(rhs);
690 }
691
697 ++hnd_.idx_;
698 assert(mesh_);
699 return *this;
700 }
701
707 --hnd_.idx_;
708 assert(mesh_);
709 return *this;
710 }
711
712 private:
713 HalfFace hnd_;
714 const PolyMesh* mesh_;
715 };
716
717
724 {
725 public:
731 explicit FaceIterator(Face f=Face(), const PolyMesh* m=nullptr) : hnd_(f), mesh_(m) { }
732
737 Face operator*() const { return hnd_; }
738
744 bool operator==(const FaceIterator& rhs) const {
745 return (hnd_==rhs.hnd_);
746 }
747
753 bool operator!=(const FaceIterator& rhs) const {
754 return !operator==(rhs);
755 }
756
762 ++hnd_.idx_;
763 assert(mesh_);
764 return *this;
765 }
766
772 --hnd_.idx_;
773 assert(mesh_);
774 return *this;
775 }
776
777 private:
778 Face hnd_;
779 const PolyMesh* mesh_;
780 };
781
782
789 {
790 public:
796 explicit CellIterator(Cell c=Cell(), const PolyMesh* m=nullptr) : hnd_(c), mesh_(m) { }
797
802 Cell operator*() const { return hnd_; }
803
809 bool operator==(const CellIterator& rhs) const {
810 return (hnd_==rhs.hnd_);
811 }
812
818 bool operator!=(const CellIterator& rhs) const {
819 return !operator==(rhs);
820 }
821
827 ++hnd_.idx_;
828 assert(mesh_);
829 return *this;
830 }
831
837 --hnd_.idx_;
838 assert(mesh_);
839 return *this;
840 }
841
842 private:
843 Cell hnd_;
844 const PolyMesh* mesh_;
845 };
846
847
848 public: //-------------------------- containers for C++11 range-based for loops
849
855 {
856 public:
862 VertexContainer(VertexIterator _begin, VertexIterator _end) : begin_(_begin), end_(_end) {}
867 VertexIterator begin() const { return begin_; }
872 VertexIterator end() const { return end_; }
873 private:
874 VertexIterator begin_, end_;
875 };
876
877
883 {
884 public:
890 EdgeContainer(EdgeIterator _begin, EdgeIterator _end) : begin_(_begin), end_(_end) {}
895 EdgeIterator begin() const { return begin_; }
900 EdgeIterator end() const { return end_; }
901 private:
902 EdgeIterator begin_, end_;
903 };
904
905
911 {
912 public:
918 HalffaceContainer(HalfFaceIterator _begin, HalfFaceIterator _end) : begin_(_begin), end_(_end) {}
923 HalfFaceIterator begin() const { return begin_; }
928 HalfFaceIterator end() const { return end_; }
929 private:
930 HalfFaceIterator begin_, end_;
931 };
932
933
939 {
940 public:
946 FaceContainer(FaceIterator _begin, FaceIterator _end) : begin_(_begin), end_(_end) {}
951 FaceIterator begin() const { return begin_; }
956 FaceIterator end() const { return end_; }
957 private:
958 FaceIterator begin_, end_;
959 };
960
961
967 {
968 public:
974 CellContainer(CellIterator _begin, CellIterator _end) : begin_(_begin), end_(_end) {}
979 CellIterator begin() const { return begin_; }
984 CellIterator end() const { return end_; }
985 private:
986 CellIterator begin_, end_;
987 };
988
989
990 public: //-------------------------------------------- constructor / destructor
991
993
994
998 PolyMesh();
999
1003 ~PolyMesh() override = default;
1004
1009 PolyMesh(const PolyMesh& rhs) { operator=(rhs); }
1010
1016 PolyMesh& operator=(const PolyMesh& rhs);
1017
1023 PolyMesh& assign(const PolyMesh& rhs);
1025
1028
1036 bool read(const std::string& filename);
1044 bool write(const std::string& filename) const;
1046
1047 public: //----------------------------------------------- add new vertex / face / cell
1048
1050
1051
1057 Vertex add_vertex(const vec3& p) { Vertex v = new_vertex(); vpoint_[v] = p; return v; }
1064 Cell add_cell(const std::vector<HalfFace>& faces);
1074 Cell add_tetra(HalfFace f0, HalfFace f1, HalfFace f2, HalfFace f3) { return add_cell({f0, f1, f2, f3}); }
1085 Cell add_tetra(Vertex v0, Vertex v1, Vertex v2, Vertex v3);
1112 Cell add_hexa(Vertex v0, Vertex v1, Vertex v2, Vertex v3, Vertex v4, Vertex v5, Vertex v6, Vertex v7);
1119 HalfFace add_face(const std::vector<Vertex>& vertices);
1128 HalfFace add_triangle(Vertex v0, Vertex v1, Vertex v2) { return add_face({ v0, v1, v2 }); }
1138 HalfFace add_quad(Vertex v0, Vertex v1, Vertex v2, Vertex v3) { return add_face({ v0, v1, v2, v3}); }
1139
1141
1142 public: //--------------------------------------------------- memory management
1143
1145
1146
1151 unsigned int n_vertices() const { return (unsigned int) vprops_.size(); }
1156 unsigned int n_edges() const { return (unsigned int) eprops_.size(); }
1161 unsigned int n_halffaces() const { return (unsigned int) hprops_.size(); }
1166 unsigned int n_faces() const { return (unsigned int) fprops_.size(); }
1171 unsigned int n_cells() const { return (unsigned int) cprops_.size(); }
1172
1178 void clear();
1179
1188 void resize(unsigned int nv, unsigned int ne, unsigned int nf, unsigned int nc) {
1189 vprops_.resize(nv);
1190 eprops_.resize(ne);
1191 hprops_.resize(2 * nf);
1192 fprops_.resize(nf);
1193 cprops_.resize(nc);
1194 }
1195
1201 bool is_valid(Vertex v) const {
1202 return (0 <= v.idx()) && (v.idx() < (int)n_vertices());
1203 }
1204
1209 bool is_valid(Edge e) const {
1210 return (0 <= e.idx()) && (e.idx() < (int)n_edges());
1211 }
1212
1217 bool is_valid(HalfFace h) const {
1218 return (0 <= h.idx()) && (h.idx() < (int)n_halffaces());
1219 }
1220
1225 bool is_valid(Face f) const {
1226 return (0 <= f.idx()) && (f.idx() < (int)n_faces());
1227 }
1228
1233 bool is_valid(Cell c) const {
1234 return (0 <= c.idx()) && (c.idx() < (int)n_cells());
1235 }
1236
1238
1239
1240 public: //--------------------------------------------------- property handling
1241
1243
1244
1253 template <class T> VertexProperty<T> add_vertex_property(const std::string& name, const T t=T()) {
1254 return VertexProperty<T>(vprops_.add<T>(name, t));
1255 }
1256
1264 template <class T> EdgeProperty<T> add_edge_property(const std::string& name, const T t=T()) {
1265 return EdgeProperty<T>(eprops_.add<T>(name, t));
1266 }
1267
1275 template <class T> HalfFaceProperty<T> add_halfface_property(const std::string& name, const T t=T()) {
1276 return HalfFaceProperty<T>(hprops_.add<T>(name, t));
1277 }
1278
1286 template <class T> FaceProperty<T> add_face_property(const std::string& name, const T t=T()) {
1287 return FaceProperty<T>(fprops_.add<T>(name, t));
1288 }
1289
1297 template <class T> CellProperty<T> add_cell_property(const std::string& name, const T t=T()) {
1298 return CellProperty<T>(cprops_.add<T>(name, t));
1299 }
1300
1312 template <class T> ModelProperty<T> add_model_property(const std::string& name, const T t=T()) {
1313 return ModelProperty<T>(mprops_.add<T>(name, t));
1314 }
1315
1322 template <class T> VertexProperty<T> get_vertex_property(const std::string& name) const {
1323 return VertexProperty<T>(vprops_.get<T>(name));
1324 }
1325
1331 template <class T> EdgeProperty<T> get_edge_property(const std::string& name) const {
1332 return EdgeProperty<T>(eprops_.get<T>(name));
1333 }
1334
1340 template <class T> HalfFaceProperty<T> get_halfface_property(const std::string& name) const {
1341 return HalfFaceProperty<T>(hprops_.get<T>(name));
1342 }
1343
1349 template <class T> FaceProperty<T> get_face_property(const std::string& name) const {
1350 return FaceProperty<T>(fprops_.get<T>(name));
1351 }
1352
1358 template <class T> CellProperty<T> get_cell_property(const std::string& name) const {
1359 return CellProperty<T>(cprops_.get<T>(name));
1360 }
1361
1372 template <class T> ModelProperty<T> get_model_property(const std::string& name) const {
1373 return ModelProperty<T>(mprops_.get<T>(name));
1374 }
1375
1384 template <class T> VertexProperty<T> vertex_property(const std::string& name, const T t=T()) {
1385 return VertexProperty<T>(vprops_.get_or_add<T>(name, t));
1386 }
1387
1395 template <class T> EdgeProperty<T> edge_property(const std::string& name, const T t=T()) {
1396 return EdgeProperty<T>(eprops_.get_or_add<T>(name, t));
1397 }
1398
1406 template <class T> HalfFaceProperty<T> halfface_property(const std::string& name, const T t=T()) {
1407 return HalfFaceProperty<T>(hprops_.get_or_add<T>(name, t));
1408 }
1409
1417 template <class T> FaceProperty<T> face_property(const std::string& name, const T t=T()) {
1418 return FaceProperty<T>(fprops_.get_or_add<T>(name, t));
1419 }
1420
1428 template <class T> CellProperty<T> cell_property(const std::string& name, const T t=T()) {
1429 return CellProperty<T>(cprops_.get_or_add<T>(name, t));
1430 }
1431
1439 template <class T> ModelProperty<T> model_property(const std::string& name, const T t=T()) {
1440 return ModelProperty<T>(mprops_.get_or_add<T>(name, t));
1441 }
1442
1443
1449 template<class T>
1450 bool remove_vertex_property(VertexProperty<T> &p) { return vprops_.remove(p); }
1456 bool remove_vertex_property(const std::string &n) { return vprops_.remove(n); }
1462 template<class T>
1463 bool remove_edge_property(EdgeProperty<T> &p) { return eprops_.remove(p); }
1469 bool remove_edge_property(const std::string &n) { return eprops_.remove(n); }
1475 template<class T>
1476 bool remove_halfface_property(HalfFaceProperty<T> &p) { return hprops_.remove(p); }
1482 bool remove_halfface_property(const std::string &n) { return hprops_.remove(n); }
1488 template<class T>
1489 bool remove_face_property(FaceProperty<T> &p) { return fprops_.remove(p); }
1495 bool remove_face_property(const std::string &n) { return fprops_.remove(n); }
1501 template<class T>
1502 bool remove_cell_property(CellProperty<T> &p) { return cprops_.remove(p); }
1508 bool remove_cell_property(const std::string &n) { return cprops_.remove(n); }
1514 template<class T>
1515 bool remove_model_property(ModelProperty<T> &p) { return mprops_.remove(p); }
1521 bool remove_model_property(const std::string &n) { return mprops_.remove(n); }
1522
1529 bool rename_vertex_property(const std::string &old_name, const std::string &new_name) {
1530 return vprops_.rename(old_name, new_name);
1531 }
1532
1538 bool rename_halfface_property(const std::string &old_name, const std::string &new_name) {
1539 return hprops_.rename(old_name, new_name);
1540 }
1541
1547 bool rename_face_property(const std::string &old_name, const std::string &new_name) {
1548 return fprops_.rename(old_name, new_name);
1549 }
1550
1556 bool rename_edge_property(const std::string &old_name, const std::string &new_name) {
1557 return eprops_.rename(old_name, new_name);
1558 }
1559
1565 bool rename_cell_property(const std::string &old_name, const std::string &new_name) {
1566 return cprops_.rename(old_name, new_name);
1567 }
1568
1574 bool rename_model_property(const std::string &old_name, const std::string &new_name) {
1575 return mprops_.rename(old_name, new_name);
1576 }
1577
1583 const std::type_info& get_vertex_property_type(const std::string& name) const {
1584 return vprops_.get_type(name);
1585 }
1586
1591 const std::type_info& get_edge_property_type(const std::string& name) const {
1592 return eprops_.get_type(name);
1593 }
1594
1599 const std::type_info& get_halfface_property_type(const std::string& name) const {
1600 return hprops_.get_type(name);
1601 }
1602
1607 const std::type_info& get_face_property_type(const std::string& name) const {
1608 return fprops_.get_type(name);
1609 }
1610
1615 const std::type_info& get_cell_property_type(const std::string& name) const {
1616 return cprops_.get_type(name);
1617 }
1618
1623 const std::type_info& get_model_property_type(const std::string& name) const {
1624 return mprops_.get_type(name);
1625 }
1626
1627
1632 std::vector<std::string> vertex_properties() const {
1633 return vprops_.properties();
1634 }
1635
1639 std::vector<std::string> edge_properties() const {
1640 return eprops_.properties();
1641 }
1642
1646 std::vector<std::string> halfface_properties() const {
1647 return hprops_.properties();
1648 }
1649
1653 std::vector<std::string> face_properties() const {
1654 return fprops_.properties();
1655 }
1656
1660 std::vector<std::string> cell_properties() const {
1661 return cprops_.properties();
1662 }
1663
1667 std::vector<std::string> model_properties() const {
1668 return mprops_.properties();
1669 }
1670
1675 void property_stats(std::ostream &output) const override;
1676
1678
1679
1680 public: //--------------------------------------------- iterators & circulators
1681
1683
1684
1690 return VertexIterator(Vertex(0), this);
1691 }
1692
1698 return VertexIterator(Vertex(static_cast<int>(n_vertices())), this);
1699 }
1700
1707
1713 return EdgeIterator(Edge(0), this);
1714 }
1715
1721 return EdgeIterator(Edge(static_cast<int>(n_edges())), this);
1722 }
1723
1729 return EdgeContainer(edges_begin(), edges_end());
1730 }
1731
1737 return HalfFaceIterator(HalfFace(0), this);
1738 }
1739
1745 return HalfFaceIterator(HalfFace(static_cast<int>(n_halffaces())), this);
1746 }
1747
1755
1761 return FaceIterator(Face(0), this);
1762 }
1763
1769 return FaceIterator(Face(static_cast<int>(n_faces())), this);
1770 }
1771
1777 return FaceContainer(faces_begin(), faces_end());
1778 }
1779
1785 return CellIterator(Cell(0), this);
1786 }
1787
1793 return CellIterator(Cell(static_cast<int>(n_cells())), this);
1794 }
1795
1801 return CellContainer(cells_begin(), cells_end());
1802 }
1803
1804
1805 public: //--------------------------------------------- adjacency access
1806
1808
1809
1815 const std::set<Vertex>& vertices(Vertex v) const {
1816 return vconn_[v].vertices_;
1817 }
1818
1825 HalfFace halfface(Face f, unsigned int i) const {
1826 assert(i<=1);
1827 return HalfFace(static_cast<int>((f.idx() << 1) + i));
1828 }
1829
1835 Face face(HalfFace h) const {
1836 return Face((h.idx() >> 1));
1837 }
1838
1845 return hconn_[h].opposite_;
1846 }
1847
1854 Vertex vertex(Edge e, unsigned int i) const {
1855 assert(i<=1);
1856 return econn_[e].vertices_[i];
1857 }
1858
1865 const std::vector<Vertex>& vertices(HalfFace h) const {
1866 return hconn_[h].vertices_;
1867 }
1868
1874 const std::vector<Vertex>& vertices(Face f) const {
1875 return vertices(halfface(f, 0));
1876 }
1877
1883 const std::set<Vertex>& vertices(Cell c) const {
1884 return cconn_[c].vertices_;
1885 }
1886
1892 const std::set<Edge>& edges(Vertex v) const {
1893 return vconn_[v].edges_;
1894 }
1895
1901 const std::set<Edge>& edges(HalfFace h) const {
1902 return hconn_[h].edges_;
1903 }
1904
1910 const std::set<Edge>& edges(Cell c) const {
1911 return cconn_[c].edges_;
1912 }
1913
1919 const std::set<HalfFace>& halffaces(Vertex v) const {
1920 return vconn_[v].halffaces_;
1921 }
1922
1928 const std::set<HalfFace>& halffaces(Edge e) const {
1929 return econn_[e].halffaces_;
1930 }
1931
1937 const std::vector<HalfFace>& halffaces(Cell c) const {
1938 return cconn_[c].halffaces_;
1939 }
1940
1946 const std::set<Cell>& cells(Vertex v) const {
1947 return vconn_[v].cells_;
1948 }
1949
1955 const std::set<Cell>& cells(Edge e) const {
1956 return econn_[e].cells_;
1957 }
1958
1964 Cell cell(HalfFace h) const {
1965 return hconn_[h].cell_;
1966 }
1967
1968
1969 public: //--------------------------------------------- higher-level operations
1970
1972
1973
1978 bool is_tetraheral_mesh() const;
1979
1986 bool is_border(Vertex v) const {
1987 for (auto h : halffaces(v)) { if (is_border(h)) return true; }
1988 return false;
1989 }
1990
1997 bool is_border(Edge e) const {
1998 for (auto h : halffaces(e)) { if (is_border(h)) return true; }
1999 return false;
2000 }
2001
2007 bool is_border(HalfFace h) const {
2008 return (!cell(h).is_valid());
2009 }
2010
2016 bool is_border(Face f) const {
2017 return is_border(halfface(f, 0)) || is_border(halfface(f, 1));
2018 }
2019
2026 Edge find_edge(Vertex a, Vertex b) const;
2027
2033 HalfFace find_half_face(const std::vector<Vertex>& vertices) const;
2034
2040 bool is_degenerate(Face f) const;
2041
2046 void extract_boundary(std::vector< std::vector<Vertex> >& faces) const;
2048
2049 public: //------------------------------------------ geometry-related functions
2050
2052
2053
2059 const vec3& position(Vertex v) const { return vpoint_[v]; }
2060
2065 const std::vector<vec3>& points() const override { return vpoint_.vector(); }
2066
2071 std::vector<vec3>& points() override { return vpoint_.vector(); }
2072
2076 void update_face_normals();
2077
2083 vec3 compute_face_normal(Face f) const;
2084
2091 void update_vertex_normals();
2092
2098 float edge_length(Edge e) const;
2099
2101
2102
2103 private: //---------------------------------------------- allocate new elements
2104
2106 Vertex new_vertex()
2107 {
2108 vprops_.push_back();
2109 return Vertex(static_cast<int>(n_vertices()-1));
2110 }
2111
2113 Edge new_edge(Vertex s, Vertex t)
2114 {
2115 assert(s != t);
2116 eprops_.push_back();
2117 Edge e = Edge(static_cast<int>(n_edges() - 1));
2118 econn_[e].vertices_ = {s, t};
2119 vconn_[s].edges_.insert(e);
2120 vconn_[t].edges_.insert(e);
2121 vconn_[s].vertices_.insert(t);
2122 vconn_[t].vertices_.insert(s);
2123 return e;
2124 }
2125
2127 HalfFace new_face()
2128 {
2129 fprops_.push_back();
2130 hprops_.push_back();
2131 hprops_.push_back();
2132 HalfFace h0(static_cast<int>(n_halffaces()-2));
2133 HalfFace h1(static_cast<int>(n_halffaces()-1));
2134
2135 hconn_[h0].opposite_ = h1;
2136 hconn_[h1].opposite_ = h0;
2137
2138 return h0;
2139 }
2140
2142 Cell new_cell()
2143 {
2144 cprops_.push_back();
2145 return Cell(static_cast<int>(n_cells()-1));
2146 }
2147
2148 private: //------------------------------------------------------- private data
2149
2150 PropertyContainer vprops_;
2151 PropertyContainer eprops_;
2152 PropertyContainer hprops_;
2153 PropertyContainer fprops_;
2154 PropertyContainer cprops_;
2155 PropertyContainer mprops_;
2156
2161
2162 VertexProperty<vec3> vpoint_;
2163 };
2164
2165
2166 //------------------------------------------------------------ output operators
2167
2169 inline std::ostream& operator<<(std::ostream& os, PolyMesh::Vertex v)
2170 {
2171 return (os << 'v' << v.idx());
2172 }
2173
2175 inline std::ostream& operator<<(std::ostream& os, PolyMesh::Edge e)
2176 {
2177 return (os << 'e' << e.idx());
2178 }
2179
2181 inline std::ostream& operator<<(std::ostream& os, PolyMesh::HalfFace h)
2182 {
2183 return (os << 'h' << h.idx());
2184 }
2185
2187 inline std::ostream& operator<<(std::ostream& os, PolyMesh::Face f)
2188 {
2189 return (os << 'f' << f.idx());
2190 }
2191
2193 inline std::ostream& operator<<(std::ostream& os, PolyMesh::Cell c)
2194 {
2195 return (os << 'c' << c.idx());
2196 }
2197
2198} // namespace easy3d
2199
2200#endif // EASY3D_CORE_POLYHEDRAL_MESH_H
const std::string & name() const
The name of a model.
Definition model.h:61
Model(const std::string &name="unknown")
Default constructor. The parameter name is optional, but it is useful for handling multiple models wi...
Definition model.cpp:33
bool operator!=(const BaseHandle &_rhs) const
Are two handles different?
Definition poly_mesh.h:97
bool is_valid() const
Return whether the handle is valid, i.e., the index is not equal to -1.
Definition poly_mesh.h:81
int idx() const
Return the index of the handle.
Definition poly_mesh.h:70
bool operator<(const BaseHandle &_rhs) const
Compare operator useful for sorting handles.
Definition poly_mesh.h:106
bool operator==(const BaseHandle &_rhs) const
Are two handles equal?
Definition poly_mesh.h:88
void reset()
Reset handle to be invalid (index = -1).
Definition poly_mesh.h:75
BaseHandle(int _idx=-1)
Constructor.
Definition poly_mesh.h:64
This helper class is a container for iterating through all cells using C++11 range-based for-loops.
Definition poly_mesh.h:967
CellIterator begin() const
Get the beginning iterator.
Definition poly_mesh.h:979
CellIterator end() const
Get the ending iterator.
Definition poly_mesh.h:984
CellContainer(CellIterator _begin, CellIterator _end)
Constructor.
Definition poly_mesh.h:974
Cell iterator for PolyMesh. This class iterates linearly over all cells.
Definition poly_mesh.h:789
bool operator==(const CellIterator &rhs) const
Are two iterators equal?
Definition poly_mesh.h:809
bool operator!=(const CellIterator &rhs) const
Are two iterators different?
Definition poly_mesh.h:818
CellIterator & operator--()
Pre-decrement iterator.
Definition poly_mesh.h:836
Cell operator*() const
Get the cell the iterator refers to.
Definition poly_mesh.h:802
CellIterator & operator++()
Pre-increment iterator.
Definition poly_mesh.h:826
CellIterator(Cell c=Cell(), const PolyMesh *m=nullptr)
Default constructor.
Definition poly_mesh.h:796
Cell property of type T.
Definition poly_mesh.h:454
Property< T >::const_reference operator[](Cell c) const
Access the data stored for cell c.
Definition poly_mesh.h:480
CellProperty(Property< T > p)
Constructor with property.
Definition poly_mesh.h:464
Property< T >::reference operator[](Cell c)
Access the data stored for cell c.
Definition poly_mesh.h:471
CellProperty()=default
Default constructor.
This helper class is a container for iterating through all edges using C++11 range-based for-loops.
Definition poly_mesh.h:883
EdgeIterator begin() const
Get the beginning iterator.
Definition poly_mesh.h:895
EdgeIterator end() const
Get the ending iterator.
Definition poly_mesh.h:900
EdgeContainer(EdgeIterator _begin, EdgeIterator _end)
Constructor.
Definition poly_mesh.h:890
Edge iterator for PolyMesh. This class iterates linearly over all edges.
Definition poly_mesh.h:594
bool operator!=(const EdgeIterator &rhs) const
Are two iterators different?
Definition poly_mesh.h:623
EdgeIterator & operator++()
Pre-increment iterator.
Definition poly_mesh.h:631
Edge operator*() const
Get the edge the iterator refers to.
Definition poly_mesh.h:607
bool operator==(const EdgeIterator &rhs) const
Are two iterators equal?
Definition poly_mesh.h:614
EdgeIterator(Edge e=Edge(), const PolyMesh *m=nullptr)
Default constructor.
Definition poly_mesh.h:601
EdgeIterator & operator--()
Pre-decrement iterator.
Definition poly_mesh.h:641
Edge property of type T.
Definition poly_mesh.h:346
EdgeProperty()=default
Default constructor.
Property< T >::reference operator[](Edge e)
Access the data stored for edge e.
Definition poly_mesh.h:363
Property< T >::const_reference operator[](Edge e) const
Access the data stored for edge e.
Definition poly_mesh.h:372
EdgeProperty(Property< T > p)
Constructor with property.
Definition poly_mesh.h:356
This helper class is a container for iterating through all faces using C++11 range-based for-loops.
Definition poly_mesh.h:939
FaceContainer(FaceIterator _begin, FaceIterator _end)
Constructor.
Definition poly_mesh.h:946
FaceIterator begin() const
Get the beginning iterator.
Definition poly_mesh.h:951
FaceIterator end() const
Get the ending iterator.
Definition poly_mesh.h:956
Face iterator for PolyMesh. This class iterates linearly over all faces.
Definition poly_mesh.h:724
bool operator!=(const FaceIterator &rhs) const
Are two iterators different?
Definition poly_mesh.h:753
bool operator==(const FaceIterator &rhs) const
Are two iterators equal?
Definition poly_mesh.h:744
FaceIterator & operator--()
Pre-decrement iterator.
Definition poly_mesh.h:771
FaceIterator(Face f=Face(), const PolyMesh *m=nullptr)
Default constructor.
Definition poly_mesh.h:731
Face operator*() const
Get the face the iterator refers to.
Definition poly_mesh.h:737
FaceIterator & operator++()
Pre-increment iterator.
Definition poly_mesh.h:761
Face property of type T.
Definition poly_mesh.h:418
Property< T >::reference operator[](Face f)
Access the data stored for face f.
Definition poly_mesh.h:435
FaceProperty(Property< T > p)
Constructor with property.
Definition poly_mesh.h:428
FaceProperty()=default
Default constructor.
Property< T >::const_reference operator[](Face f) const
Access the data stored for face f.
Definition poly_mesh.h:444
HalfFace iterator for PolyMesh. This class iterates linearly over all halffaces.
Definition poly_mesh.h:659
HalfFaceIterator & operator++()
Pre-increment iterator.
Definition poly_mesh.h:696
HalfFaceIterator(HalfFace h=HalfFace(), const PolyMesh *m=nullptr)
Default constructor.
Definition poly_mesh.h:666
HalfFaceIterator & operator--()
Pre-decrement iterator.
Definition poly_mesh.h:706
bool operator!=(const HalfFaceIterator &rhs) const
Are two iterators different?
Definition poly_mesh.h:688
HalfFace operator*() const
Get the halfface the iterator refers to.
Definition poly_mesh.h:672
bool operator==(const HalfFaceIterator &rhs) const
Are two iterators equal?
Definition poly_mesh.h:679
HalfFace property of type T.
Definition poly_mesh.h:382
Property< T >::const_reference operator[](HalfFace h) const
Access the data stored for halfface h.
Definition poly_mesh.h:408
HalfFaceProperty(Property< T > p)
Constructor with property.
Definition poly_mesh.h:392
Property< T >::reference operator[](HalfFace h)
Access the data stored for halfface h.
Definition poly_mesh.h:399
HalfFaceProperty()=default
Default constructor.
This helper class is a container for iterating through all halffaces using C++11 range-based for-loop...
Definition poly_mesh.h:911
HalfFaceIterator end() const
Get the ending iterator.
Definition poly_mesh.h:928
HalfFaceIterator begin() const
Get the beginning iterator.
Definition poly_mesh.h:923
HalffaceContainer(HalfFaceIterator _begin, HalfFaceIterator _end)
Constructor.
Definition poly_mesh.h:918
Model property of type T.
Definition poly_mesh.h:491
ModelProperty()=default
Default constructor.
ModelProperty(Property< T > p)
Constructor with property.
Definition poly_mesh.h:501
Property< T >::const_reference operator[](size_t idx) const
Access the data stored for the mesh.
Definition poly_mesh.h:517
Property< T >::reference operator[](size_t idx)
Access the data stored for the mesh.
Definition poly_mesh.h:508
This helper class is a container for iterating through all vertices using C++11 range-based for-loops...
Definition poly_mesh.h:855
VertexContainer(VertexIterator _begin, VertexIterator _end)
Constructor.
Definition poly_mesh.h:862
VertexIterator begin() const
Get the beginning iterator.
Definition poly_mesh.h:867
VertexIterator end() const
Get the ending iterator.
Definition poly_mesh.h:872
Vertex iterator for PolyMesh. This class iterates linearly over all vertices.
Definition poly_mesh.h:530
VertexIterator(Vertex v=Vertex(), const PolyMesh *m=nullptr)
Default constructor.
Definition poly_mesh.h:537
Vertex operator*() const
Get the vertex the iterator refers to.
Definition poly_mesh.h:543
bool operator==(const VertexIterator &rhs) const
Are two iterators equal?
Definition poly_mesh.h:550
VertexIterator & operator--()
Pre-decrement iterator.
Definition poly_mesh.h:577
bool operator!=(const VertexIterator &rhs) const
Are two iterators different?
Definition poly_mesh.h:559
VertexIterator & operator++()
Pre-increment iterator.
Definition poly_mesh.h:567
Vertex property of type T.
Definition poly_mesh.h:310
VertexProperty(Property< T > p)
Constructor with property.
Definition poly_mesh.h:320
Property< T >::const_reference operator[](Vertex v) const
Access the data stored for vertex v.
Definition poly_mesh.h:336
Property< T >::reference operator[](Vertex v)
Access the data stored for vertex v.
Definition poly_mesh.h:327
VertexProperty()=default
Default constructor.
Data structure representing a polyhedral mesh.
Definition poly_mesh.h:49
const vec3 & position(Vertex v) const
Returns the position of a vertex.
Definition poly_mesh.h:2059
const std::set< HalfFace > & halffaces(Edge e) const
Returns the set of halffaces around edge e.
Definition poly_mesh.h:1928
HalfFace opposite(HalfFace h) const
Returns the twin halfface of halfface h.
Definition poly_mesh.h:1844
bool is_border(Vertex v) const
Returns whether v is a boundary vertex, i.e., at least one of its incident halffaces is not associate...
Definition poly_mesh.h:1986
EdgeContainer edges() const
Returns a container for range-based iteration over edges.
Definition poly_mesh.h:1728
HalfFace find_half_face(const std::vector< Vertex > &vertices) const
Definition poly_mesh.cpp:417
const std::type_info & get_vertex_property_type(const std::string &name) const
Get the type information of the vertex property name.
Definition poly_mesh.h:1583
unsigned int n_faces() const
Returns number of faces in the mesh.
Definition poly_mesh.h:1166
void extract_boundary(std::vector< std::vector< Vertex > > &faces) const
Definition poly_mesh.cpp:686
const std::vector< Vertex > & vertices(Face f) const
Returns the set of vertices around face f.
Definition poly_mesh.h:1874
bool remove_vertex_property(const std::string &n)
Remove the vertex property named n.
Definition poly_mesh.h:1456
const std::set< Edge > & edges(Cell c) const
Returns the set of edges around cell c.
Definition poly_mesh.h:1910
EdgeIterator edges_end() const
Returns an iterator to the end of the edges.
Definition poly_mesh.h:1720
HalfFace add_triangle(Vertex v0, Vertex v1, Vertex v2)
Add a new triangle face connecting vertices v0, v1, v2.
Definition poly_mesh.h:1128
CellIterator cells_begin() const
Returns an iterator to the beginning of the cells.
Definition poly_mesh.h:1784
unsigned int n_edges() const
Returns number of edges in the mesh.
Definition poly_mesh.h:1156
bool is_valid(Edge e) const
Return whether edge e is valid, i.e. the index is stored within the array bounds.
Definition poly_mesh.h:1209
bool rename_vertex_property(const std::string &old_name, const std::string &new_name)
Rename a vertex property given its name.
Definition poly_mesh.h:1529
const std::vector< Vertex > & vertices(HalfFace h) const
Returns the set of vertices around halfface h. The vertices are ordered in a way such that its normal...
Definition poly_mesh.h:1865
std::vector< std::string > halfface_properties() const
Get the names of all halfface properties.
Definition poly_mesh.h:1646
HalfFaceProperty< T > add_halfface_property(const std::string &name, const T t=T())
Add a halfface property of type T with name name and default value t.
Definition poly_mesh.h:1275
const std::set< Cell > & cells(Vertex v) const
Returns the set of cells around vertex v.
Definition poly_mesh.h:1946
PolyMesh()
Default constructor.
Definition poly_mesh.cpp:133
HalfFaceIterator halffaces_begin() const
Returns an iterator to the beginning of the halffaces.
Definition poly_mesh.h:1736
VertexContainer vertices() const
Returns a container for range-based iteration over vertices.
Definition poly_mesh.h:1704
FaceProperty< T > get_face_property(const std::string &name) const
Get the face property with name name of type T.
Definition poly_mesh.h:1349
const std::set< Cell > & cells(Edge e) const
Returns the set of cells around edge e.
Definition poly_mesh.h:1955
const std::type_info & get_edge_property_type(const std::string &name) const
Get the type information of the edge property name.
Definition poly_mesh.h:1591
bool remove_halfface_property(HalfFaceProperty< T > &p)
Remove the halfface property p.
Definition poly_mesh.h:1476
HalfFace add_quad(Vertex v0, Vertex v1, Vertex v2, Vertex v3)
Add a new quad face connecting vertices v0, v1, v2, v3.
Definition poly_mesh.h:1138
bool rename_face_property(const std::string &old_name, const std::string &new_name)
Rename a face property given its name.
Definition poly_mesh.h:1547
const std::vector< HalfFace > & halffaces(Cell c) const
Returns the set of halffaces around cell c.
Definition poly_mesh.h:1937
VertexProperty< T > vertex_property(const std::string &name, const T t=T())
If a vertex property of type T with name name exists, it is returned. Otherwise, this property is add...
Definition poly_mesh.h:1384
const std::set< Vertex > & vertices(Vertex v) const
Returns the vertices around vertex v.
Definition poly_mesh.h:1815
std::vector< std::string > face_properties() const
Get the names of all face properties.
Definition poly_mesh.h:1653
const std::set< Edge > & edges(HalfFace h) const
Returns the set of edges around halfface h.
Definition poly_mesh.h:1901
const std::set< Vertex > & vertices(Cell c) const
Returns the set of vertices around cell c.
Definition poly_mesh.h:1883
FaceContainer faces() const
Returns a container for range-based iteration over faces.
Definition poly_mesh.h:1776
ModelProperty< T > get_model_property(const std::string &name) const
Gets the model property named name of type T.
Definition poly_mesh.h:1372
std::vector< std::string > vertex_properties() const
Get the names of all vertex properties.
Definition poly_mesh.h:1632
void update_face_normals()
Computes face normals by calling compute_face_normal(HalfFace) for each face.
Definition poly_mesh.cpp:549
vec3 compute_face_normal(Face f) const
Computes the normal vector of face f.
Definition poly_mesh.cpp:572
EdgeProperty< T > get_edge_property(const std::string &name) const
Get the edge property with name name of type T.
Definition poly_mesh.h:1331
const std::type_info & get_face_property_type(const std::string &name) const
Get the type information of the face property name.
Definition poly_mesh.h:1607
Cell add_hexa(Vertex v0, Vertex v1, Vertex v2, Vertex v3, Vertex v4, Vertex v5, Vertex v6, Vertex v7)
Add a new hexahedron connecting vertices v0, v1, v2, v3, v4, v5, v6, v7.
Definition poly_mesh.cpp:519
EdgeIterator edges_begin() const
Returns an iterator to the beginning of the edges.
Definition poly_mesh.h:1712
HalfFaceIterator halffaces_end() const
Returns an iterator to the end of the halffaces.
Definition poly_mesh.h:1744
FaceIterator faces_begin() const
Returns an iterator to the beginning of the faces.
Definition poly_mesh.h:1760
Cell add_cell(const std::vector< HalfFace > &faces)
Add a new cell defined by faces.
Definition poly_mesh.cpp:479
VertexProperty< T > get_vertex_property(const std::string &name) const
Get the vertex property with name name of type T.
Definition poly_mesh.h:1322
bool remove_face_property(const std::string &n)
Remove the face property named n.
Definition poly_mesh.h:1495
void resize(unsigned int nv, unsigned int ne, unsigned int nf, unsigned int nc)
Resizes space for vertices, edges, halffaces, and their currently associated properties.
Definition poly_mesh.h:1188
const std::set< Edge > & edges(Vertex v) const
Returns the set of edges around vertex v.
Definition poly_mesh.h:1892
Edge find_edge(Vertex a, Vertex b) const
Definition poly_mesh.cpp:408
std::vector< std::string > edge_properties() const
Get the names of all edge properties.
Definition poly_mesh.h:1639
bool read(const std::string &filename)
Read mesh from a PM file filename.
Definition poly_mesh.cpp:220
std::vector< std::string > model_properties() const
Get the names of all model properties.
Definition poly_mesh.h:1667
bool is_tetraheral_mesh() const
Returns whether the mesh is a tetrahedral mesh, i.e., every cell is a tetrahedron.
Definition poly_mesh.cpp:670
CellContainer cells() const
Returns a container for range-based iteration over cells.
Definition poly_mesh.h:1800
bool is_border(HalfFace h) const
Returns whether h is a boundary halfface, i.e., it is not associated with a cell.
Definition poly_mesh.h:2007
bool rename_edge_property(const std::string &old_name, const std::string &new_name)
Rename an edge property given its name.
Definition poly_mesh.h:1556
HalffaceContainer halffaces() const
Returns a container for range-based iteration over halffaces.
Definition poly_mesh.h:1752
bool remove_halfface_property(const std::string &n)
Remove the halfface property named n.
Definition poly_mesh.h:1482
const std::type_info & get_model_property_type(const std::string &name) const
Get the type information of the model property name.
Definition poly_mesh.h:1623
std::vector< vec3 > & points() override
Returns a modifiable vector of all vertex positions.
Definition poly_mesh.h:2071
CellProperty< T > cell_property(const std::string &name, const T t=T())
If a cell property of type T with name name exists, it is returned. Otherwise, this property is added...
Definition poly_mesh.h:1428
bool remove_face_property(FaceProperty< T > &p)
Remove the face property p.
Definition poly_mesh.h:1489
const std::type_info & get_halfface_property_type(const std::string &name) const
Get the type information of the halfface property name.
Definition poly_mesh.h:1599
bool remove_edge_property(const std::string &n)
Remove the edge property named n.
Definition poly_mesh.h:1469
ModelProperty< T > model_property(const std::string &name, const T t=T())
If a model property of type T with name name exists, it is returned. Otherwise, this property is adde...
Definition poly_mesh.h:1439
bool remove_cell_property(const std::string &n)
Remove the cell property named n.
Definition poly_mesh.h:1508
Cell cell(HalfFace h) const
Returns the cell associated with halfface h.
Definition poly_mesh.h:1964
VertexProperty< T > add_vertex_property(const std::string &name, const T t=T())
Add a vertex property of type T with name name and default value t.
Definition poly_mesh.h:1253
bool remove_model_property(ModelProperty< T > &p)
Remove the model property p.
Definition poly_mesh.h:1515
PolyMesh & assign(const PolyMesh &rhs)
Assign rhs to *this. Does not copy custom properties.
Definition poly_mesh.cpp:179
FaceProperty< T > face_property(const std::string &name, const T t=T())
If a face property of type T with name name exists, it is returned. Otherwise, this property is added...
Definition poly_mesh.h:1417
PolyMesh & operator=(const PolyMesh &rhs)
Assign rhs to *this. Performs a deep copy of all properties.
Definition poly_mesh.cpp:151
FaceProperty< T > add_face_property(const std::string &name, const T t=T())
Add a face property of type T with name name and default value t.
Definition poly_mesh.h:1286
bool is_valid(HalfFace h) const
Return whether halfface h is valid, i.e. the index is stored within the array bounds.
Definition poly_mesh.h:1217
bool remove_cell_property(CellProperty< T > &p)
Remove the cell property p.
Definition poly_mesh.h:1502
bool rename_model_property(const std::string &old_name, const std::string &new_name)
Rename a model property given its name.
Definition poly_mesh.h:1574
unsigned int n_halffaces() const
Returns number of halffaces in the mesh.
Definition poly_mesh.h:1161
ModelProperty< T > add_model_property(const std::string &name, const T t=T())
Adds a model property of type T with name name and default value t.
Definition poly_mesh.h:1312
HalfFace add_face(const std::vector< Vertex > &vertices)
Add a new face connecting vertices.
Definition poly_mesh.cpp:450
CellProperty< T > get_cell_property(const std::string &name) const
Get the cell property with name name of type T.
Definition poly_mesh.h:1358
CellProperty< T > add_cell_property(const std::string &name, const T t=T())
Add a cell property of type T with name name and default value t.
Definition poly_mesh.h:1297
PolyMesh(const PolyMesh &rhs)
Copy constructor: copies rhs to *this. Performs a deep copy of all properties.
Definition poly_mesh.h:1009
HalfFaceProperty< T > get_halfface_property(const std::string &name) const
Get the halfface property with name name of type T.
Definition poly_mesh.h:1340
bool write(const std::string &filename) const
Write mesh to a PM file filename.
Definition poly_mesh.cpp:263
Vertex add_vertex(const vec3 &p)
Add a new vertex.
Definition poly_mesh.h:1057
bool is_valid(Face f) const
Return whether face f is valid, i.e. the index is stored within the array bounds.
Definition poly_mesh.h:1225
CellIterator cells_end() const
Returns an iterator to the end of the cells.
Definition poly_mesh.h:1792
Face face(HalfFace h) const
Returns the face of HalfFace h.
Definition poly_mesh.h:1835
bool is_border(Face f) const
Returns whether f is a boundary face, i.e., it is incident to only one cell.
Definition poly_mesh.h:2016
EdgeProperty< T > edge_property(const std::string &name, const T t=T())
If an edge property of type T with name name exists, it is returned. Otherwise, this property is adde...
Definition poly_mesh.h:1395
bool remove_edge_property(EdgeProperty< T > &p)
Remove the edge property p.
Definition poly_mesh.h:1463
HalfFaceProperty< T > halfface_property(const std::string &name, const T t=T())
If a halfface property of type T with name name exists, it is returned. Otherwise,...
Definition poly_mesh.h:1406
void property_stats(std::ostream &output) const override
Prints the names of all properties to an output stream (e.g., std::cout).
Definition poly_mesh.cpp:343
void update_vertex_normals()
Computes vertex normals for each vertex.
Definition poly_mesh.cpp:599
FaceIterator faces_end() const
Returns an iterator to the end of the faces.
Definition poly_mesh.h:1768
const std::type_info & get_cell_property_type(const std::string &name) const
Get the type information of the cell property name.
Definition poly_mesh.h:1615
HalfFace halfface(Face f, unsigned int i) const
Returns the i'th halfface of face f. i has to be 0 or 1.
Definition poly_mesh.h:1825
void clear()
Removes all vertices, edges, halffaces, faces, cells and properties.
Definition poly_mesh.cpp:311
bool rename_halfface_property(const std::string &old_name, const std::string &new_name)
Rename a halfface property given its name.
Definition poly_mesh.h:1538
bool rename_cell_property(const std::string &old_name, const std::string &new_name)
Rename a cell property given its name.
Definition poly_mesh.h:1565
bool remove_model_property(const std::string &n)
Remove the model property named n.
Definition poly_mesh.h:1521
float edge_length(Edge e) const
Computes the length of edge e.
Definition poly_mesh.cpp:633
EdgeProperty< T > add_edge_property(const std::string &name, const T t=T())
Add an edge property of type T with name name and default value t.
Definition poly_mesh.h:1264
bool is_border(Edge e) const
Returns whether e is a boundary edge, i.e., at least one of its incident halffaces is not associated ...
Definition poly_mesh.h:1997
VertexIterator vertices_begin() const
Returns an iterator to the beginning of the vertices.
Definition poly_mesh.h:1689
std::vector< std::string > cell_properties() const
Get the names of all cell properties.
Definition poly_mesh.h:1660
bool remove_vertex_property(VertexProperty< T > &p)
Remove the vertex property p.
Definition poly_mesh.h:1450
bool is_degenerate(Face f) const
Returns whether face f is degenerate, i.e., if it has collinear or coincident vertices.
Definition poly_mesh.cpp:642
VertexIterator vertices_end() const
Returns an iterator to the end of the vertices.
Definition poly_mesh.h:1697
bool is_valid(Vertex v) const
Return whether vertex v is valid, i.e. the index is stored within the array bounds.
Definition poly_mesh.h:1201
Vertex vertex(Edge e, unsigned int i) const
Returns the i'th vertex of edge e. i has to be 0 or 1.
Definition poly_mesh.h:1854
Cell add_tetra(HalfFace f0, HalfFace f1, HalfFace f2, HalfFace f3)
Add a new tetrahedron defined by its faces.
Definition poly_mesh.h:1074
unsigned int n_cells() const
Returns number of cells in the mesh.
Definition poly_mesh.h:1171
bool is_valid(Cell c) const
Return whether cell c is valid, i.e. the index is stored within the array bounds.
Definition poly_mesh.h:1233
~PolyMesh() override=default
Destructor.
const std::vector< vec3 > & points() const override
Returns a read-only vector of all vertex positions.
Definition poly_mesh.h:2065
unsigned int n_vertices() const
Returns number of vertices in the mesh.
Definition poly_mesh.h:1151
const std::set< HalfFace > & halffaces(Vertex v) const
Returns the set of halffaces around vertex v.
Definition poly_mesh.h:1919
void push_back()
Adds a new element to each vector.
Definition property.h:771
PropertyArray< T >::const_reference const_reference
The const reference type of the property.
Definition property.h:329
virtual reference operator[](size_t i)
Accesses the i-th element.
Definition property.h:365
Property(PropertyArray< T > *p=nullptr)
Constructor.
Definition property.h:338
PropertyArray< T >::reference reference
The reference type of the property.
Definition property.h:328
Definition collider.cpp:182
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition types.h:44
std::ostream & operator<<(std::ostream &os, Graph::Vertex v)
Output stream support for Graph::Vertex.
Definition graph.h:1300
Helper structure to be able to use std::unordered_map.
Definition poly_mesh.h:113
std::size_t operator()(const BaseHandle &h) const
Hash function for BaseHandle.
Definition poly_mesh.h:119
Definition poly_mesh.h:286
std::set< Edge > edges_
The edges incident to this cell.
Definition poly_mesh.h:288
std::vector< HalfFace > halffaces_
The halffaces incident to this cell.
Definition poly_mesh.h:289
void write(std::ostream &out) const
Writes the cell connectivity to an output stream.
Definition poly_mesh.cpp:126
void read(std::istream &in)
Reads the cell connectivity from an input stream.
Definition poly_mesh.cpp:119
std::set< Vertex > vertices_
The vertices connected to this cell.
Definition poly_mesh.h:287
Definition poly_mesh.h:203
std::ostream & operator<<(std::ostream &os) const
Output stream support for Cell.
Definition poly_mesh.h:214
Cell(int _idx=-1)
Default constructor (with invalid index).
Definition poly_mesh.h:208
Definition poly_mesh.h:245
std::set< Cell > cells_
The cells incident to this edge.
Definition poly_mesh.h:248
std::vector< Vertex > vertices_
The vertices connected to this edge.
Definition poly_mesh.h:246
void write(std::ostream &out) const
Writes the edge connectivity to an output stream.
Definition poly_mesh.cpp:96
void read(std::istream &in)
Reads the edge connectivity from an input stream.
Definition poly_mesh.cpp:89
std::set< HalfFace > halffaces_
The halffaces incident to this edge.
Definition poly_mesh.h:247
Definition poly_mesh.h:149
std::ostream & operator<<(std::ostream &os) const
Output stream support for Edge.
Definition poly_mesh.h:160
Edge(int _idx=-1)
Default constructor (with invalid index).
Definition poly_mesh.h:154
Definition poly_mesh.h:185
Face(int _idx=-1)
Default constructor (with invalid index).
Definition poly_mesh.h:190
std::ostream & operator<<(std::ostream &os) const
Output stream support for Face.
Definition poly_mesh.h:196
Definition poly_mesh.h:265
std::set< Edge > edges_
The edges incident to this halfface.
Definition poly_mesh.h:267
HalfFace opposite_
The opposite halfface.
Definition poly_mesh.h:269
Cell cell_
The cell incident to this halfface.
Definition poly_mesh.h:268
std::vector< Vertex > vertices_
The vertices connected to this halfface.
Definition poly_mesh.h:266
void write(std::ostream &out) const
Writes the halfface connectivity to an output stream.
Definition poly_mesh.cpp:111
void read(std::istream &in)
Reads the halfface connectivity from an input stream.
Definition poly_mesh.cpp:103
Definition poly_mesh.h:167
std::ostream & operator<<(std::ostream &os) const
Output stream support for HalfFace.
Definition poly_mesh.h:178
HalfFace(int _idx=-1)
Default constructor (with invalid index).
Definition poly_mesh.h:172
Definition poly_mesh.h:224
std::set< Cell > cells_
The cells incident to this vertex.
Definition poly_mesh.h:228
std::set< Edge > edges_
The edges incident to this vertex.
Definition poly_mesh.h:226
void write(std::ostream &out) const
Writes the edge connectivity to an output stream.
Definition poly_mesh.cpp:81
void read(std::istream &in)
Definition poly_mesh.cpp:73
std::set< Vertex > vertices_
The vertices connected to this vertex.
Definition poly_mesh.h:225
std::set< HalfFace > halffaces_
The halffaces incident to this vertex.
Definition poly_mesh.h:227
Definition poly_mesh.h:131
std::ostream & operator<<(std::ostream &os) const
Output stream support for Vertex.
Definition poly_mesh.h:142
Vertex(int _idx=-1)
Default constructor (with invalid index).
Definition poly_mesh.h:136