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

centroid.hpp 9.18 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
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           *
Pierre Kraemer's avatar
Pierre Kraemer committed
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/                                           *
Pierre Kraemer's avatar
Pierre Kraemer committed
21
22
23
24
25
 * Contact information: cgogn@unistra.fr                                        *
 *                                                                              *
 *******************************************************************************/

#include "Topology/generic/cellmarker.h"
26
27
28
29
#include "Topology/generic/traversor/traversorCell.h"
#include "Topology/generic/traversor/traversor2.h"
#include "Topology/generic/traversor/traversorCell.h"
#include "Topology/generic/traversor/traversor3.h"
30
#include "Algo/Parallel/parallel_foreach.h"
31

Pierre Kraemer's avatar
Pierre Kraemer committed
32
33
34
35
36
37
namespace CGoGN
{

namespace Algo
{

38
39
40
namespace Surface
{

Pierre Kraemer's avatar
Pierre Kraemer committed
41
42
43
namespace Geometry
{

44
template <typename PFP, typename V_ATT>
45
typename V_ATT::DATA_TYPE volumeCentroid(typename PFP::MAP& map, Vol d, const V_ATT& attributs, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
46
{
47
	typename V_ATT::DATA_TYPE center(0.0);
48
	unsigned int count = 0 ;
49
50
//	Traversor3WV<typename PFP::MAP> tra(map,d,false,thread);

51
	foreach_incident3<VERTEX>(map,d, [&] (Vertex v)
Pierre Kraemer's avatar
Pierre Kraemer committed
52
	{
53
		center += attributs[v];
Pierre Kraemer's avatar
Pierre Kraemer committed
54
55
		++count;
	}
56
	,false,thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
57
58
59
60
61

	center /= double(count) ;
	return center ;
}

62
template <typename PFP, typename V_ATT>
63
typename V_ATT::DATA_TYPE volumeCentroidELW(typename PFP::MAP& map, Vol d, const V_ATT& attributs, unsigned int thread)
64
{
65
	typedef typename V_ATT::DATA_TYPE EMB;
66
	EMB center(0.0);
67

68
	double count=0.0;
69
70
//	Traversor3WE<typename PFP::MAP> t(map, d,false,thread) ;

71
	foreach_incident3<EDGE>(map,d, [&] (Edge it)
72
	{
Sylvain Thery's avatar
Sylvain Thery committed
73
		EMB e1 = attributs[it.dart];
74
75
76
77
		EMB e2 = attributs[map.phi1(it)];
		double l = (e2-e1).norm();
		center += (e1+e2)*l;
		count += 2.0*l ;
78
	},false,thread);
79
80
81
82
	center /= double(count);	
	return center ;
}

83
template <typename PFP, typename V_ATT>
84
typename V_ATT::DATA_TYPE faceCentroid(typename PFP::MAP& map, Face f, const V_ATT& attributs)
Pierre Kraemer's avatar
Pierre Kraemer committed
85
{
86
	typename V_ATT::DATA_TYPE center(0.0);
Pierre Kraemer's avatar
Pierre Kraemer committed
87
	unsigned int count = 0 ;
88
89

//	Traversor2FV<typename PFP::MAP> t(map, d) ;
90
91

	foreach_incident2<VERTEX>(map, f, [&](Vertex it)
Pierre Kraemer's avatar
Pierre Kraemer committed
92
93
94
	{
		center += attributs[it];
		++count ;
95
	});
Pierre Kraemer's avatar
Pierre Kraemer committed
96
97
98
99
	center /= double(count);
	return center ;
}

100
template <typename PFP, typename V_ATT>
101
typename V_ATT::DATA_TYPE faceCentroidELW(typename PFP::MAP& map, Face f, const V_ATT& attributs)
102
{
103
104
	typedef typename V_ATT::DATA_TYPE EMB;

105
	EMB center(0.0);
106
	double count=0.0;
107
108

//	Traversor2FE<typename PFP::MAP> t(map, d) ;
109
110

	foreach_incident2<EDGE>(map, f, [&](Edge it)
111
	{
Sylvain Thery's avatar
Sylvain Thery committed
112
		EMB e1 = attributs[it.dart];
113
114
115
116
		EMB e2 = attributs[map.phi1(it)];
		double l = (e2-e1).norm();
		center += (e1+e2)*l;
		count += 2.0*l ;
117
	});
118
119
120
121
	center /= double(count);
	return center ;
}

122
template <typename PFP, typename V_ATT>
123
typename V_ATT::DATA_TYPE vertexNeighborhoodCentroid(typename PFP::MAP& map, Vertex v, const V_ATT& attributs)
Pierre Kraemer's avatar
Pierre Kraemer committed
124
{
125
126
	typename V_ATT::DATA_TYPE center(0.0);

Pierre Kraemer's avatar
Pierre Kraemer committed
127
	unsigned int count = 0 ;
128
//	Traversor2VVaE<typename PFP::MAP> t(map, d) ;
129
	foreach_adjacent2<EDGE>(map, v, [&](Vertex it)
Pierre Kraemer's avatar
Pierre Kraemer committed
130
	{
131
		center += attributs[it];
Pierre Kraemer's avatar
Pierre Kraemer committed
132
		++count ;
133
	});
Pierre Kraemer's avatar
Pierre Kraemer committed
134
135
136
137
	center /= count ;
	return center ;
}

138
139
template <typename PFP, typename V_ATT, typename F_ATT>
void computeCentroidFaces(typename PFP::MAP& map, const V_ATT& position, F_ATT& face_centroid, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
140
{
141
142
143
144
	foreach_cell<FACE>(map, [&] (Face f)
	{
		face_centroid[f] = faceCentroid<PFP,V_ATT>(map, f, position) ;
	}
145
	,AUTO,thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
146
147
}

148
149
template <typename PFP, typename V_ATT, typename F_ATT>
void computeCentroidELWFaces(typename PFP::MAP& map, const V_ATT& position, F_ATT& face_centroid, unsigned int thread)
150
{
151
152
153
154
	foreach_cell<FACE>(map, [&] (Face f)
	{
		face_centroid[f] = faceCentroidELW<PFP,V_ATT>(map, f, position) ;
	}
155
	,AUTO,thread);
156
157
}

158
159
template <typename PFP, typename V_ATT>
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const V_ATT& position, V_ATT& vertex_centroid, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
160
{
161
162
163
164
	foreach_cell<VERTEX>(map, [&] (Vertex v)
	{
		vertex_centroid[v] = vertexNeighborhoodCentroid<PFP,V_ATT>(map, v, position) ;
	}
165
	,AUTO,thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
166
167
}

168
169
170
171

namespace Parallel
{

172
173
template <typename PFP, typename V_ATT, typename F_ATT>
void computeCentroidFaces(typename PFP::MAP& map, const V_ATT& position, F_ATT& face_centroid,
Sylvain Thery's avatar
Sylvain Thery committed
174
		unsigned int nbth)
175
{
Sylvain Thery's avatar
Sylvain Thery committed
176
177
178
179
	CGoGN::Parallel::foreach_cell<FACE>(map,[&](Face f, unsigned int thr)
	{
		face_centroid[f] = faceCentroid<PFP>(map, f, position) ;
	},nbth,false,AUTO);
180
181
}

182
183
template <typename PFP, typename V_ATT, typename F_ATT>
void computeCentroidELWFaces(typename PFP::MAP& map, const V_ATT& position, F_ATT& face_centroid,
184
		unsigned int nbth, unsigned int current_thread)
185
{
Sylvain Thery's avatar
Sylvain Thery committed
186
187
188
189
190
	CGoGN::Parallel::foreach_cell<FACE>(map,[&](Face f, unsigned int thr)
	{
		face_centroid[f] = faceCentroidELW<PFP>(map, f, position) ;
	},nbth,false,AUTO);

191
192
}

193
template <typename PFP, typename V_ATT>
194
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
195
		const V_ATT& position, V_ATT& vertex_centroid,
196
		unsigned int nbth, unsigned int current_thread)
197
{
Sylvain Thery's avatar
Sylvain Thery committed
198
199
200
201
	CGoGN::Parallel::foreach_cell<VERTEX>(map,[&](Vertex v, unsigned int thr)
	{
		vertex_centroid[v] = vertexNeighborhoodCentroid<PFP>(map, v, position) ;
	},nbth,false,FORCE_CELL_MARKING);
202
203
}

Pierre Kraemer's avatar
Pierre Kraemer committed
204
205
206
207
} // namespace Parallel



208
} // namespace Geometry
Pierre Kraemer's avatar
Pierre Kraemer committed
209

210
} // namespace Surface
211

212
213
namespace Volume
{
Pierre Kraemer's avatar
Pierre Kraemer committed
214

215
namespace Geometry
Lionel Untereiner's avatar
Lionel Untereiner committed
216
{
217

218
template <typename PFP, typename V_ATT>
219
typename V_ATT::DATA_TYPE vertexNeighborhoodCentroid(typename PFP::MAP& map, Vertex v, const V_ATT& attributs, unsigned int thread)
Lionel Untereiner's avatar
Lionel Untereiner committed
220
{
221
	typename V_ATT::DATA_TYPE  center(0.0);
Lionel Untereiner's avatar
Lionel Untereiner committed
222
	unsigned int count = 0 ;
223
	foreach_adjacent3<EDGE>(map, v, [&](Vertex it)
Lionel Untereiner's avatar
Lionel Untereiner committed
224
225
226
227
	{
		center += attributs[it];
		++count ;
	}
228
	,false,thread);
Lionel Untereiner's avatar
Lionel Untereiner committed
229
230
231
	center /= count ;
	return center ;
}
232

233
234
template <typename PFP, typename V_ATT, typename W_ATT>
void computeCentroidVolumes(typename PFP::MAP& map, const V_ATT& position, W_ATT& vol_centroid, unsigned int thread)
Lionel Untereiner's avatar
Lionel Untereiner committed
235
{
236
237
238
239
	foreach_cell<VOLUME>(map, [&] (Vol v)
	{
		vol_centroid[v] = Surface::Geometry::volumeCentroid<PFP,V_ATT>(map, v, position,thread) ;
	}
240
	,AUTO,thread);
Lionel Untereiner's avatar
Lionel Untereiner committed
241
}
242

243
244
template <typename PFP, typename V_ATT, typename W_ATT>
void computeCentroidELWVolumes(typename PFP::MAP& map, const V_ATT& position, W_ATT& vol_centroid, unsigned int thread)
245
{
246
247
248
249
	foreach_cell<VOLUME>(map, [&] (Vol v)
	{
		vol_centroid[v] = Surface::Geometry::volumeCentroidELW<PFP,V_ATT>(map, v, position,thread) ;
	}
250
	,AUTO,thread);
251
252
}

253
254
template <typename PFP, typename V_ATT>
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const V_ATT& position, V_ATT& vertex_centroid, unsigned int thread)
Sylvain Thery's avatar
Sylvain Thery committed
255
{
256
257
258
259
	foreach_cell<VERTEX>(map, [&] (Vertex v)
	{
		vertex_centroid[v] = Volume::Geometry::vertexNeighborhoodCentroid<PFP,V_ATT>(map, v, position) ;
	}
260
	,AUTO,thread);
Sylvain Thery's avatar
Sylvain Thery committed
261
262
263
}


264
265
namespace Parallel
{
Pierre Kraemer's avatar
Pierre Kraemer committed
266

267
268
template <typename PFP, typename V_ATT, typename W_ATT>
void computeCentroidVolumes(typename PFP::MAP& map, const V_ATT& position, W_ATT& vol_centroid,	unsigned int nbth)
269
{
Sylvain Thery's avatar
Sylvain Thery committed
270
	CGoGN::Parallel::foreach_cell<VOLUME>(map,[&](Vol v, unsigned int thr)
271
	{
Sylvain Thery's avatar
Sylvain Thery committed
272
273
274
		vol_centroid[v] = Surface::Geometry::volumeCentroid<PFP,V_ATT,W_ATT>(map, v, position, thr) ;
	},nbth,true,AUTO);
}
275

276
277
278
template <typename PFP, typename V_ATT, typename W_ATT>
void computeCentroidELWVolumes(typename PFP::MAP& map,
		const V_ATT& position, W_ATT& vol_centroid,
Thery Sylvain's avatar
Thery Sylvain committed
279
		unsigned int nbth)
280
{
Sylvain Thery's avatar
Sylvain Thery committed
281
282
283
284
	CGoGN::Parallel::foreach_cell<VOLUME>(map,[&](Vol v, unsigned int thr)
	{
		vol_centroid[v] = Surface::Geometry::volumeCentroidELW<PFP,V_ATT>(map, v, position, thr) ;
	},nbth,true,AUTO);
285
286
}

287

288
289
290
template <typename PFP, typename V_ATT>
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const V_ATT& position, V_ATT& vertex_centroid,
		unsigned int nbth)
291
{
Sylvain Thery's avatar
Sylvain Thery committed
292
293
294
295
	CGoGN::Parallel::foreach_cell<VERTEX>(map,[&](Vertex v, unsigned int thr)
	{
		vertex_centroid[v] = Volume::Geometry::vertexNeighborhoodCentroid<PFP,V_ATT>(map, v, position,thr) ;
	},nbth,true,FORCE_CELL_MARKING);
296
}
297

untereiner's avatar
untereiner committed
298
} // namespace Parallel
Pierre Kraemer's avatar
Pierre Kraemer committed
299

300

Pierre Kraemer's avatar
Pierre Kraemer committed
301
} // namespace Geometry
302

Pierre Kraemer's avatar
Pierre Kraemer committed
303
} // namespace Volume
304

Pierre Kraemer's avatar
Pierre Kraemer committed
305
306
307
} // namespace Algo

} // namespace CGoGN