OpenMesh
HoleFillerT.hh
1/* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2023, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openmesh.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenMesh. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 * ========================================================================= */
41
42#pragma once
43
44#include <vector>
45#include <OpenMesh/Core/Mesh/PolyConnectivity.hh>
46
47//=============================================================================
48
49namespace OpenMesh {
50namespace HoleFiller {
51
52template< class MeshT >
54{
55 typedef typename MeshT::Point Point;
56 typedef typename MeshT::Scalar Scalar;
57
58public:
59
60 // Ctors
61 explicit HoleFillerT( MeshT & _mesh );
63
67 void fill_all_holes( int _stages = 3 );
68
69
76 void fill_hole( typename MeshT::EdgeHandle _eh, int _stages = 3 );
77
78private:
79
80
81 void fairing( std::vector< OpenMesh::SmartFaceHandle >& _faceHandles );
82
83 // Remove degenerated faces from the filling
84 void removeDegeneratedFaces( std::vector< typename MeshT::FaceHandle >& _faceHandles );
85
86 // A weight is a tuple of area and maximum dihedral angle
87 //
88
89 class Weight {
90 public:
91
92 Weight() : angle_( 180 ), area_( FLT_MAX ) {}
93 Weight( Scalar _angle, Scalar _area ) : angle_( _angle ), area_( _area ) {}
94 ~Weight() {}
95
96 Scalar angle() const { return angle_; }
97 Scalar area() const { return area_; }
98
99 Weight operator+( const Weight & _other ) const {
100 return Weight( std::max( angle(), _other.angle() ),
101 area() + _other.area() );
102 }
103
104 bool operator<( const Weight & _rhs ) const {
105 return ( angle() < _rhs.angle() ||
106 ( angle() == _rhs.angle() && area() < _rhs.area() ) );
107 }
108
109 private:
110 Scalar angle_;
111 Scalar area_;
112 };
113
114 // Refine a face
115 bool refine( typename MeshT::FaceHandle _fh );
116
117 // Relax an edge
118 bool relax_edge( OpenMesh::SmartEdgeHandle _eh );
119
120 // Test whether a point _x lies in the circumsphere of _a,_b,_c.
121 bool in_circumsphere( const Point & _x,
122 const Point & _a,
123 const Point & _b,
124 const Point & _c ) const;
125
126 // Create the triangulation for polygon (_i,...,_j).
127 bool fill( int _i, int _j );
128
129 // Compute the weight of the triangle (_i,_j,_k).
130 Weight weight( int _i, int _j, int _k );
131
132 // Does edge (_u,_v) already exist?
133 bool exists_edge( OpenMesh::SmartVertexHandle _u, typename MeshT::VertexHandle _w );
134
135 // Compute the area of the triangle (_a,_b,_c).
136 Scalar area( typename MeshT::VertexHandle _a, typename MeshT::VertexHandle _b, typename MeshT::VertexHandle _c );
137
138 // Compute the dihedral angle (in degrees) between triangle
139 // (_u,_v,_a) and triangle (_v,_u,_b).
140 Scalar dihedral_angle( typename MeshT::VertexHandle _u, typename MeshT::VertexHandle _v, typename MeshT::VertexHandle _a, typename MeshT::VertexHandle _b );
141
142
143 // The mesh, with each vertex we associate a scale factor that is
144 // needed for remeshing
145
146 MeshT & mesh_;
148
149 /*
150 HOLE
151
152 boundary_vertex_
153 |
154 V
155 ==*=======*=======*== BOUNDARY
156 / \ / \ / \
157 / \ / \ / \
158 \ / \ /
159 * * <- opposite_vertex_
160 */
161
162
163 typedef std::vector< typename MeshT::VertexHandle > VHVec;
164 typedef typename std::vector< typename MeshT::VertexHandle >::iterator VHVecIter;
165 typedef typename std::vector< typename MeshT::VertexHandle >::const_iterator CVHVecIter;
166
167 typedef std::vector< typename MeshT::FaceHandle > FHVec;
168 typedef typename std::vector< typename MeshT::FaceHandle >::iterator FHVecIter;
169 typedef typename std::vector< typename MeshT::FaceHandle >::const_iterator CFHVecIter;
170
171
172 // This vector contains all vertices of the hole (in order)
173 std::vector< OpenMesh::SmartVertexHandle > boundary_vertex_;
174
175 // This vector contains all vertices that are opposite to an edge of the hole
176 VHVec opposite_vertex_;
177
178 // This vector contains all edges of the hole (in order)
179 std::vector< OpenMesh::SmartEdgeHandle > hole_edge_;
180
181 // This vector stores handles to all triangles of the current hole
182 std::vector< OpenMesh::SmartFaceHandle > hole_triangle_;
183
184 // These are the two central arrays that are needed for the dynamic
185 // programming approach to hole filling.
186 // w_[i][j] : stores the minimal weight that can be achieved
187 // for a triangulation of the polygon
188 // boundary_vertex_[i],...,boundary_vertex_[j]
189 // l_[i][j] : stores the third index of the triangle
190 // <boundary_vertex_[i],boundary_vertex_[l_[i][j]],
191 // boundary_vertex_[j]>
192 // that is needed for reconstructing the minimal triangulation
193
194 std::vector< std::vector< Weight > > w_;
195 std::vector< std::vector< int > > l_;
196};
197
198} // namespace HoleFiller
199} // namespace OpenMesh
200
201//=============================================================================
202#ifndef HOLEFILLER_CC
203 #include "HoleFillerT_impl.hh"
204#endif
205//=============================================================================
206
207
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
T angle(T _cos_angle, T _sin_angle)
returns the angle determined by its cos and the sign of its sin result is positive if the angle is in...
Definition: MathDefs.hh:140
Smart version of VertexHandle contains a pointer to the corresponding mesh and allows easier access t...
Definition: SmartHandles.hh:110
Definition: SmartHandles.hh:197
Definition: HoleFillerT.hh:54
void fill_hole(typename MeshT::EdgeHandle _eh, int _stages=3)
Fill a hole which is identified by one of its boundary edges.
Definition: HoleFillerT_impl.hh:137
void fill_all_holes(int _stages=3)
Identify and fill all holes of the mesh.
Definition: HoleFillerT_impl.hh:91

Project OpenMesh, ©  Visual Computing Institute, RWTH Aachen. Documentation generated using doxygen .