centroid.h 12.8 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
26
27
28
29
30
31
32
33
34
35
36
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef __ALGO_GEOMETRY_CENTROID_H__
#define __ALGO_GEOMETRY_CENTROID_H__

#include "Geometry/basic.h"
#include "Topology/generic/attribops.h"

namespace CGoGN
{

namespace Algo
{

37
38
39
namespace Surface
{

Pierre Kraemer's avatar
Pierre Kraemer committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
namespace Geometry
{

/**
* Compute volume centroid (generic version)
*  Pre: closed volume & embedded vertices
* Template param:
*  PFP:  as usual
*  EMBV: attributes vector type  or cell type (VertexCell, FaceCell, ...)
*  EMB:  type of attribute (Geom::Vec3f) or cell type (VertexCell, FaceCell, ...)
* @param map the map
* @param d a dart of the face
* @param attributs the vector of attribute or cell
*/
template <typename PFP, typename EMBV, typename EMB>
55
EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs, unsigned int thread = 0);
Pierre Kraemer's avatar
Pierre Kraemer committed
56

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* Compute volume centroid weighted by edge length (generic version)
*  Pre: closed volume & embedded vertices
* Template param:
*  PFP:  as usual
*  EMBV: attributes vector type  or cell type (VertexCell, FaceCell, ...)
*  EMB:  type of attribute (Geom::Vec3f) or cell type (VertexCell, FaceCell, ...)
* @param map the map
* @param d a dart of the face
* @param attributs the vector of attribute or cell
*/
template <typename PFP, typename EMBV, typename EMB>
EMB volumeCentroidELWGen(typename PFP::MAP& map, Dart d, const EMBV& attributs, unsigned int thread = 0);


Pierre Kraemer's avatar
Pierre Kraemer committed
72
73
74
75
76
77
78
79
/**
* Compute volume centroid
* Pre: closed volume & embedded vertices
 * @param map the map
 * @param d a dart of the face
 * @param position the vector of attribute
 */
template <typename PFP>
80
inline typename PFP::VEC3 volumeCentroid(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position, unsigned int thread = 0)
Pierre Kraemer's avatar
Pierre Kraemer committed
81
{
82
	return volumeCentroidGen<PFP, VertexAttribute<typename PFP::VEC3>, typename PFP::VEC3>(map, d, position, thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
83
84
}

85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* Compute volume centroid weighted by edge length
* Pre: closed volume & embedded vertices
 * @param map the map
 * @param d a dart of the face
 * @param position the vector of attribute
 */
template <typename PFP>
inline typename PFP::VEC3 volumeCentroidELW(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position, unsigned int thread = 0)
{
	return volumeCentroidELWGen<PFP, VertexAttribute<typename PFP::VEC3>, typename PFP::VEC3>(map, d, position, thread);
}


Pierre Kraemer's avatar
Pierre Kraemer committed
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
 * Compute face centroid (generic version)
 * Template param:
 *  PFP:  as usual
 *  EMBV: attributes vector type  or cell type (VertexCell, FaceCell, ...)
 *  EMB:  type of attribute (Geom::Vec3f) or cell type (VertexCell, FaceCell, ...)
 * @param map the map
 * @param d a dart of the face
 * @param attributs the vector of attribute or cell
 */
template <typename PFP, typename EMBV, typename EMB>
EMB faceCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs);

112
113
114
115
116
117
118
119
120
121
122
123
124
/**
 * Compute face centroid weighted by edge length (generic version)
 * Template param:
 *  PFP:  as usual
 *  EMBV: attributes vector type  or cell type (VertexCell, FaceCell, ...)
 *  EMB:  type of attribute (Geom::Vec3f) or cell type (VertexCell, FaceCell, ...)
 * @param map the map
 * @param d a dart of the face
 * @param attributs the vector of attribute or cell
 */
template <typename PFP, typename EMBV, typename EMB>
EMB faceCentroidELWGen(typename PFP::MAP& map, Dart d, const EMBV& attributs);

Pierre Kraemer's avatar
Pierre Kraemer committed
125
126
127
128
129
130
131
132
/**
* Compute face centroid
* Pre: closed face & embedded vertices
 * @param map the map
 * @param d a dart of the face
 * @param position the vector of attribute
 */
template <typename PFP>
133
typename PFP::VEC3 faceCentroid(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position)
Pierre Kraemer's avatar
Pierre Kraemer committed
134
{
135
	return faceCentroidGen<PFP, VertexAttribute<typename PFP::VEC3>, typename PFP::VEC3>(map, d, position);
Pierre Kraemer's avatar
Pierre Kraemer committed
136
137
}

138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
* Compute face centroid weighted by edge length
* Pre: closed face & embedded vertices
 * @param map the map
 * @param d a dart of the face
 * @param position the vector of attribute
 */
template <typename PFP>
typename PFP::VEC3 faceCentroidELW(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position)
{
	return faceCentroidELWGen<PFP, VertexAttribute<typename PFP::VEC3>, typename PFP::VEC3>(map, d, position);
}


Pierre Kraemer's avatar
Pierre Kraemer committed
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/**
 * Compute vertex neighbours centroid (generic version)
 * Template param:
 *  PFP:  as usual
 *  EMBV: attributes vector type  or cell type (VertexCell, FaceCell, ...)
 *  EMB:  type of attribute (Geom::Vec3f) or cell type (VertexCell, FaceCell, ...)
 * @param map the map
 * @param d a dart of the face
 * @param position the vector of attribute or cell
 */
template <typename PFP, typename EMBV, typename EMB>
EMB vertexNeighborhoodCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs);

/**
 * Compute  vertex neighbours centroid
 * @param map the map
 * @param d a dart of the face
 * @param position the vector of attribute
 */
template <typename PFP>
172
typename PFP::VEC3 vertexNeighborhoodCentroid(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position)
Pierre Kraemer's avatar
Pierre Kraemer committed
173
{
174
	return vertexNeighborhoodCentroidGen<PFP, VertexAttribute<typename PFP::VEC3>, typename PFP::VEC3>(map, d, position);
Pierre Kraemer's avatar
Pierre Kraemer committed
175
176
}

177
178
179
180
181
182
183
184
/**
 * Compute centroid of all faces
 * @param map the map
 * @param position position vertex attribute
 * @param face_centroid centroid face attribute
 * @param select the selector
 * @param thread the thread id (default 0)
 */
Pierre Kraemer's avatar
Pierre Kraemer committed
185
template <typename PFP>
186
187
188
void computeCentroidFaces(typename PFP::MAP& map,
		const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::VEC3>& face_centroid,
		const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
189

190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/**
 * Compute centroid of all faces (Edge Length Weighted)
 * @param map the map
 * @param position position vertex attribute
 * @param face_centroid centroid face attribute
 * @param select the selector
 * @param thread the thread id (default 0)
 */
template <typename PFP>
void computeCentroidELWFaces(typename PFP::MAP& map,
		const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::VEC3>& face_centroid,
		const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
		
		
/**
 * Compute neighborhood centroid of all vertices
 * @param map the map
 * @param position position vertex attribute
 * @param vertex_centroid centroid vertex attribute
 * @param select the selector
 * @param thread the thread id (default 0)
 */
Pierre Kraemer's avatar
Pierre Kraemer committed
212
template <typename PFP>
213
214
215
216
217
218
219
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
		const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid,
		const FunctorSelect& select = allDarts, unsigned int thread = 0) ;


namespace Parallel
{
220
221
222
223
224
225
226
227
/**
 * Compute centroid of all faces
 * @param map the map
 * @param position position vertex attribute
 * @param face_centroid centroid face attribute
 * @param select the selector
 * @param nbth the number of threads
 */
228
229
230
template <typename PFP>
void computeCentroidFaces(typename PFP::MAP& map,
		const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::VEC3>& face_centroid,
231
		const FunctorSelect& select = allDarts, unsigned int nbth = 0) ;
232

233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/**
 * Compute centroid of all faces (Edge Length Weighted)
 * @param map the map
 * @param position position vertex attribute
 * @param face_centroid centroid face attribute
 * @param select the selector
 * @param nbth the number of threads
 */
template <typename PFP>
void computeCentroidELWFaces(typename PFP::MAP& map,
		const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::VEC3>& face_centroid,
		const FunctorSelect& select = allDarts, unsigned int nbth = 0) ;

/**
 * Compute neighborhood centroid of all vertices (in parallel)
 * @param map the map
 * @param position position vertex attribute
 * @param vertex_centroid centroid vertex attribute
 * @param select the selector
 * @param nbth the number of threads
 */
254
255
256
template <typename PFP>
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
		const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid,
257
		const FunctorSelect& select = allDarts, unsigned int nbth = 0) ;
258
}
259
260
} // namespace Geometry
}
Pierre Kraemer's avatar
Pierre Kraemer committed
261

262
namespace Volume
Lionel Untereiner's avatar
Lionel Untereiner committed
263
{
264
265
266
267
268
269
270
271
272
273
274
275
namespace Geometry
{
/**
 * Compute vertex neighbours centroid in map of dimension 3(generic version)
 * Template param:
 *  PFP:  as usual
 *  EMBV: attributes vector type  or cell type (VertexCell, FaceCell, ...)
 *  EMB:  type of attribute (Geom::Vec3f) or cell type (VertexCell, FaceCell, ...)
 * @param map the map
 * @param d a dart of the face
 * @param position the vector of attribute or cell
 */
Lionel Untereiner's avatar
Lionel Untereiner committed
276
template <typename PFP, typename EMBV, typename EMB>
277
EMB vertexNeighborhoodCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs);
Lionel Untereiner's avatar
Lionel Untereiner committed
278

279
280
281
282
283
284
/**
 * Compute  vertex neighbours centroid in map of dimension 3
 * @param map the map
 * @param d a dart of the face
 * @param position the vector of attribute
 */
Lionel Untereiner's avatar
Lionel Untereiner committed
285
286
287
template <typename PFP>
typename PFP::VEC3 vertexNeighborhoodCentroid(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position)
{
288
	return vertexNeighborhoodCentroidGen<PFP, VertexAttribute<typename PFP::VEC3>, typename PFP::VEC3>(map, d, position);
Lionel Untereiner's avatar
Lionel Untereiner committed
289
290
}

291
292
293
294
295
296
297
298
299
300
/**
 * compute centroid of all volumes
 * @param map the map
 * @param position vertex attribute of position
 * @param vol_centroid volume attribute where to store the centroids
 * @param select the selector
 */
template <typename PFP>
void computeCentroidVolumes(typename PFP::MAP& map,
		const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid,
301
		const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
302

303
304
305
306
307
template <typename PFP>
void computeCentroidELWVolumes(typename PFP::MAP& map,
		const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid,
		const FunctorSelect& select = allDarts, unsigned int thread = 0) ;

308
309
310
311
312
313
314
/**
 * compute centroid of all vertices
 * @param map the map
 * @param position vertex attribute of position
 * @param vertex_centroid vertex attribute to store the centroids
 * @param select the selector
 */
Lionel Untereiner's avatar
Lionel Untereiner committed
315
316
317
318
319
320
321
template <typename PFP>
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
		const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid,
		const FunctorSelect& select = allDarts, unsigned int thread = 0) ;



322
323
324
325
326
namespace Parallel
{
template <typename PFP>
void computeCentroidVolumes(typename PFP::MAP& map,
		const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid,
327
		const FunctorSelect& select = allDarts, unsigned int nbth = 0) ;
Lionel Untereiner's avatar
Lionel Untereiner committed
328

329
330
331
332
333
334
template <typename PFP>
void computeCentroidELWVolumes(typename PFP::MAP& map,
		const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid,
		const FunctorSelect& select = allDarts, unsigned int nbth = 0) ;

		
335
336
337
template <typename PFP>
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
		const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid,
338
		const FunctorSelect& select = allDarts, unsigned int nbth = 0) ;
339
}
Pierre Kraemer's avatar
Pierre Kraemer committed
340
} // namespace Geometry
untereiner's avatar
untereiner committed
341
} // namespace Volume
Pierre Kraemer's avatar
Pierre Kraemer committed
342
343
344
345
346
347
348
349

} // namespace Algo

} // namespace CGoGN

#include "Algo/Geometry/centroid.hpp"

#endif