Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

pliant.hpp 6.35 KB
Newer Older
1
2
3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
*                                                                              *
* This library is free software; you can redistribute it and/or modify it      *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library is distributed in the hope that it will be useful, but WITHOUT  *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License  *
* for more details.                                                            *
*                                                                              *
* You should have received a copy of the GNU Lesser General Public License     *
* along with this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
20
* Web site: http://cgogn.unistra.fr/                                           *
21
22
23
24
25
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#include "Algo/Geometry/basic.h"
26
#include "Algo/Geometry/feature.h"
27
28
29
30
31
32
33

namespace CGoGN
{

namespace Algo
{

34
35
36
namespace Surface
{

37
38
39
40
namespace Remeshing
{

template <typename PFP>
41
void pliantRemeshing(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& normal)
42
43
44
45
{
	typedef typename PFP::VEC3 VEC3 ;
	typedef typename PFP::REAL REAL ;

46
47
	// compute the mean edge length
	DartMarker m1(map) ;
48
49
50
51
	REAL meanEdgeLength = 0 ;
	unsigned int nbEdges = 0 ;
	for(Dart d = map.begin(); d != map.end(); map.next(d))
	{
52
		if(!m1.isMarked(d))
53
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
54
			m1.markOrbit<EDGE>(d) ;
55
			meanEdgeLength += Geometry::edgeLength<PFP>(map, d, position) ;
56
57
58
59
60
			++nbEdges ;
		}
	}
	meanEdgeLength /= REAL(nbEdges) ;

61
62
	// compute the min and max edge lengths
	REAL edgeLengthInf = REAL(3) / REAL(4) * meanEdgeLength ;
63
64
	REAL edgeLengthSup = REAL(4) / REAL(3) * meanEdgeLength ;

65
66
	// split long edges
	DartMarker m2(map) ;
67
68
	for(Dart d = map.begin(); d != map.end(); map.next(d))
	{
69
		if(!m2.isMarked(d))
70
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
71
			m2.markOrbit<EDGE>(d) ;
72
			REAL length = Geometry::edgeLength<PFP>(map, d, position) ;
73
74
75
76
77
78
79
			if(length > edgeLengthSup)
			{
				Dart dd = map.phi2(d) ;
				VEC3 p = REAL(0.5) * (position[d] + position[dd]) ;
				map.cutEdge(d) ;
				position[map.phi1(d)] = p ;
				map.splitFace(map.phi1(d), map.phi_1(d)) ;
80
81
				if(dd != d)
					map.splitFace(map.phi1(dd), map.phi_1(dd)) ;
82
83
84
85
			}
		}
	}

86
	// compute feature edges
87
	CellMarker<EDGE> featureEdge(map) ;
88
	Geometry::featureEdgeDetection<PFP>(map, position, featureEdge) ;
89
90

	// compute feature vertices
91
92
	CellMarker<VERTEX> featureVertex(map) ;
	CellMarker<VERTEX> cornerVertex(map) ;
93
	DartMarker m3(map) ;
94
95
	for(Dart d = map.begin(); d != map.end(); map.next(d))
	{
96
		if(!m3.isMarked(d))
97
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
98
			m3.markOrbit<VERTEX>(d) ;
99
100
101
			unsigned int nbFeatureEdges = 0 ;
			Dart vit = d ;
			do
102
			{
103
104
				if(featureEdge.isMarked(vit))
					++nbFeatureEdges ;
105
				vit = map.phi2_1(vit) ;
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
			} while(vit != d) ;
			if(nbFeatureEdges > 0)
			{
				if(nbFeatureEdges == 2)
					featureVertex.mark(d) ;
				else
					cornerVertex.mark(d) ;
			}
		}
	}

	// collapse short
	for(Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if(m3.isMarked(d))
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
122
			m3.unmarkOrbit<EDGE>(d) ;
123
124
125
126
			Dart d1 = map.phi1(d) ;
			if(!cornerVertex.isMarked(d) && !cornerVertex.isMarked(d1) &&
				( (featureVertex.isMarked(d) && featureVertex.isMarked(d1)) || (!featureVertex.isMarked(d) && !featureVertex.isMarked(d1)) ))
			{
127
				REAL length = Geometry::edgeLength<PFP>(map, d, position) ;
128
				if(length < edgeLengthInf && map.edgeCanCollapse(d))
129
				{
130
131
					bool collapse = true ;
					VEC3 p = position[d1] ;
132
					Dart vit = map.phi2_1(d) ;
133
134
135
136
137
					do
					{
						VEC3 vec = position[d1] - position[map.phi1(vit)] ;
						if(vec.norm() > edgeLengthSup)
							collapse = false ;
138
						vit = map.phi2_1(vit) ;
139
140
141
142
143
144
					} while(vit != d && collapse) ;
					if(collapse)
					{
						Dart v = map.collapseEdge(d) ;
						position[v] = p ;
					}
145
146
147
148
				}
			}
		}
	}
149
150
151
152

	// equalize valences with edge flips
	for(Dart d = map.begin(); d != map.end(); map.next(d))
	{
153
		if(!m3.isMarked(d))
154
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
155
			m3.markOrbit<EDGE>(d) ;
156
			Dart e = map.phi2(d) ;
157
			if(!featureEdge.isMarked(d) && e != d)
158
			{
159
160
161
162
163
164
165
166
167
168
169
170
				unsigned int w = map.vertexDegree(d) ;
				unsigned int x = map.vertexDegree(e) ;
				unsigned int y = map.vertexDegree(map.phi1(map.phi1(d))) ;
				unsigned int z = map.vertexDegree(map.phi1(map.phi1(e))) ;
				int flip = 0 ;
				flip += w > 6 ? 1 : (w < 6 ? -1 : 0) ;
				flip += x > 6 ? 1 : (x < 6 ? -1 : 0) ;
				flip += y < 6 ? 1 : (y > 6 ? -1 : 0) ;
				flip += z < 6 ? 1 : (z > 6 ? -1 : 0) ;
				if(flip > 1)
				{
					map.flipEdge(d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
171
172
173
174
					m3.markOrbit<EDGE>(map.phi1(d)) ;
					m3.markOrbit<EDGE>(map.phi_1(d)) ;
					m3.markOrbit<EDGE>(map.phi1(e)) ;
					m3.markOrbit<EDGE>(map.phi_1(e)) ;
175
				}
176
177
178
179
180
			}
		}
	}

	// update vertices normals
Sylvain Thery's avatar
Sylvain Thery committed
181
	Algo::Surface::Geometry::computeNormalVertices<PFP>(map, position, normal) ;
182
183

	// tangential relaxation
184
	VertexAttribute<VEC3> centroid = map.template addAttribute<VEC3, VERTEX>("centroid") ;
Sylvain Thery's avatar
Sylvain Thery committed
185
	Surface::Geometry::computeNeighborhoodCentroidVertices<PFP>(map, position, centroid) ;
186

187
	CellMarker<VERTEX> vm(map) ;
188
189
190
191
192
	for(Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if(!vm.isMarked(d))
		{
			vm.mark(d) ;
193
194
195
196
197
198
199
			if(!cornerVertex.isMarked(d) && !featureVertex.isMarked(d) && !map.isBoundaryVertex(d))
			{
				VEC3 l = position[d] - centroid[d] ;
				REAL e = l * normal[d] ;
				VEC3 displ = e * normal[d] ;
				position[d] = centroid[d] + displ ;
			}
200
201
		}
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
202

203
	map.removeAttribute(centroid) ;
204
205
206
207
}

} // namespace Remeshing

208
209
}

210
211
212
} // namespace Algo

} // namespace CGoGN