Developer Documentation
TetrahedralMeshTopologyKernel.hh
1 #pragma once
2 /*===========================================================================*\
3  * *
4  * OpenVolumeMesh *
5  * Copyright (C) 2011 by Computer Graphics Group, RWTH Aachen *
6  * www.openvolumemesh.org *
7  * *
8  *---------------------------------------------------------------------------*
9  * This file is part of OpenVolumeMesh. *
10  * *
11  * OpenVolumeMesh is free software: you can redistribute it and/or modify *
12  * it under the terms of the GNU Lesser General Public License as *
13  * published by the Free Software Foundation, either version 3 of *
14  * the License, or (at your option) any later version with the *
15  * following exceptions: *
16  * *
17  * If other files instantiate templates or use macros *
18  * or inline functions from this file, or you compile this file and *
19  * link it with other files to produce an executable, this file does *
20  * not by itself cause the resulting executable to be covered by the *
21  * GNU Lesser General Public License. This exception does not however *
22  * invalidate any other reasons why the executable file might be *
23  * covered by the GNU Lesser General Public License. *
24  * *
25  * OpenVolumeMesh is distributed in the hope that it will be useful, *
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
28  * GNU Lesser General Public License for more details. *
29  * *
30  * You should have received a copy of the GNU LesserGeneral Public *
31  * License along with OpenVolumeMesh. If not, *
32  * see <http://www.gnu.org/licenses/>. *
33  * *
34 \*===========================================================================*/
35 
36 
37 #ifndef NDEBUG
38 #include <iostream>
39 #endif
40 #include <set>
41 
42 #include "../Core/TopologyKernel.hh"
43 #include "TetrahedralMeshIterators.hh"
44 #include "OpenVolumeMesh/Config/Export.hh"
45 
46 namespace OpenVolumeMesh {
47 
55 class OVM_EXPORT TetrahedralMeshTopologyKernel : public TopologyKernel {
56 public:
57 
59  ~TetrahedralMeshTopologyKernel() override = default;
60 
61  FaceHandle add_face(const std::vector<HalfEdgeHandle>& _halfedges, bool _topologyCheck = false) override;
62 
63  FaceHandle add_face(const std::vector<VertexHandle>& _vertices) override;
64 
65  CellHandle add_cell(const std::vector<HalfFaceHandle>& _halffaces, bool _topologyCheck = false) override;
66 
67  CellHandle add_cell(const std::vector<VertexHandle>& _vertices, bool _topologyCheck = false);
68 
69  CellHandle add_cell(VertexHandle _vh0, VertexHandle _vh1, VertexHandle _vh2, VertexHandle _vh3, bool _topologyCheck = false);
70 
71  HalfFaceHandle add_halfface(const std::vector<HalfEdgeHandle>& _halfedges, bool _topologyCheck = false);
72  HalfFaceHandle add_halfface(VertexHandle _vh0, VertexHandle _vh1, VertexHandle _vh2, bool _topologyCheck = false);
73 
74  HalfEdgeHandle add_halfedge(const VertexHandle& _fromVertex, const VertexHandle& _toVertex);
75 
76  std::vector<VertexHandle> get_cell_vertices(CellHandle ch) const;
77  std::vector<VertexHandle> get_cell_vertices(CellHandle ch, VertexHandle vh) const;
78  std::vector<VertexHandle> get_cell_vertices(HalfFaceHandle hfh) const;
79  std::vector<VertexHandle> get_cell_vertices(HalfFaceHandle hfh, HalfEdgeHandle heh) const;
80 
81  std::vector<VertexHandle> get_halfface_vertices(HalfFaceHandle hfh) const;
82  std::vector<VertexHandle> get_halfface_vertices(HalfFaceHandle hfh, VertexHandle vh) const;
83  std::vector<VertexHandle> get_halfface_vertices(HalfFaceHandle hfh, HalfEdgeHandle heh) const;
84 
85  VertexHandle halfface_opposite_vertex(HalfFaceHandle hfh) const;
86 
87 
88  VertexHandle collapse_edge(HalfEdgeHandle _heh);
89 protected:
90  void split_edge(HalfEdgeHandle _heh, VertexHandle _vh);
91  void split_face(FaceHandle _fh, VertexHandle _vh);
92 
93 public:
94 
95 
96  // ======================= Specialized Iterators =============================
97 
98  friend class TetVertexIter;
99 
100  typedef class TetVertexIter TetVertexIter;
101 
102  TetVertexIter tv_iter(const CellHandle& _ref_h, int _max_laps = 1) const {
103  return TetVertexIter(_ref_h, this, _max_laps);
104  }
105 
106  std::pair<TetVertexIter,TetVertexIter> tet_vertices(const CellHandle& _ref_h, int _max_laps = 1) const {
107  TetVertexIter begin = tv_iter(_ref_h, _max_laps);
108  TetVertexIter end = make_end_circulator(begin);
109  return std::make_pair(begin, end);
110  }
111 
112 private:
113  // void replaceHalfFace(CellHandle ch, HalfFaceHandle hf_del, HalfFaceHandle hf_ins);
114  // void replaceHalfEdge(HalfFaceHandle hfh, HalfEdgeHandle he_del, HalfEdgeHandle he_ins);
115 
116  template <typename PropIterator, typename Handle>
117  void swapPropertyElements(PropIterator begin, PropIterator end, Handle source, Handle destination)
118  {
119  PropIterator p_iter = begin;
120  for (; p_iter != end; ++p_iter)
121  (*p_iter)->swap_elements(source, destination);
122  }
123 };
124 
125 } // Namespace OpenVolumeMesh
126 
A data structure based on PolyhedralMesh with specializations for tetrahedra.