centroid.h 12.1 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
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef __ALGO_GEOMETRY_CENTROID_H__
#define __ALGO_GEOMETRY_CENTROID_H__

#include "Geometry/basic.h"

namespace CGoGN
{

namespace Algo
{

36 37 38
namespace Surface
{

Pierre Kraemer's avatar
Pierre Kraemer committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
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>
54
EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs, unsigned int thread = 0);
Pierre Kraemer's avatar
Pierre Kraemer committed
55

56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
/**
* 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
71 72 73 74 75 76 77 78
/**
* 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>
79
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
80
{
81
	return volumeCentroidGen<PFP, VertexAttribute<typename PFP::VEC3>, typename PFP::VEC3>(map, d, position, thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
82 83
}

84 85 86 87 88 89 90 91 92 93 94 95 96 97
/**
* 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
98 99 100 101 102 103 104 105 106 107 108 109 110
/**
 * 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);

111 112 113 114 115 116 117 118 119 120 121 122 123
/**
 * 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
124 125 126 127 128 129 130 131
/**
* 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>
132
typename PFP::VEC3 faceCentroid(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position)
Pierre Kraemer's avatar
Pierre Kraemer committed
133
{
134
	return faceCentroidGen<PFP, VertexAttribute<typename PFP::VEC3>, typename PFP::VEC3>(map, d, position);
Pierre Kraemer's avatar
Pierre Kraemer committed
135 136
}

137 138 139 140 141 142 143 144 145 146 147 148 149 150
/**
* 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
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
/**
 * 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>
171
typename PFP::VEC3 vertexNeighborhoodCentroid(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position)
Pierre Kraemer's avatar
Pierre Kraemer committed
172
{
173
	return vertexNeighborhoodCentroidGen<PFP, VertexAttribute<typename PFP::VEC3>, typename PFP::VEC3>(map, d, position);
Pierre Kraemer's avatar
Pierre Kraemer committed
174 175
}

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

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


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

228 229 230 231 232 233 234 235 236 237
/**
 * Compute centroid of all faces (Edge Length Weighted)
 * @param map the map
 * @param position position vertex attribute
 * @param face_centroid centroid face attribute
 * @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,
238
		unsigned int nbth = 0) ;
239 240 241 242 243 244 245 246

/**
 * Compute neighborhood centroid of all vertices (in parallel)
 * @param map the map
 * @param position position vertex attribute
 * @param vertex_centroid centroid vertex attribute
 * @param nbth the number of threads
 */
247 248 249
template <typename PFP>
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
		const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid,
250
		unsigned int nbth = 0) ;
251
}
252 253
} // namespace Geometry
}
Pierre Kraemer's avatar
Pierre Kraemer committed
254

255
namespace Volume
Lionel Untereiner's avatar
Lionel Untereiner committed
256
{
257 258 259 260 261 262 263 264 265 266 267 268
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
269
template <typename PFP, typename EMBV, typename EMB>
270
EMB vertexNeighborhoodCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs);
Lionel Untereiner's avatar
Lionel Untereiner committed
271

272 273 274 275 276 277
/**
 * 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
278 279 280
template <typename PFP>
typename PFP::VEC3 vertexNeighborhoodCentroid(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position)
{
281
	return vertexNeighborhoodCentroidGen<PFP, VertexAttribute<typename PFP::VEC3>, typename PFP::VEC3>(map, d, position);
Lionel Untereiner's avatar
Lionel Untereiner committed
282 283
}

284 285 286 287 288 289 290 291 292
/**
 * 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
 */
template <typename PFP>
void computeCentroidVolumes(typename PFP::MAP& map,
		const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid,
293
		unsigned int thread = 0) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
294

295 296 297
template <typename PFP>
void computeCentroidELWVolumes(typename PFP::MAP& map,
		const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid,
298
		unsigned int thread = 0) ;
299

300 301 302 303 304 305
/**
 * compute centroid of all vertices
 * @param map the map
 * @param position vertex attribute of position
 * @param vertex_centroid vertex attribute to store the centroids
 */
Lionel Untereiner's avatar
Lionel Untereiner committed
306 307 308
template <typename PFP>
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
		const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid,
309
		unsigned int thread = 0) ;
Lionel Untereiner's avatar
Lionel Untereiner committed
310 311 312



313 314 315 316 317
namespace Parallel
{
template <typename PFP>
void computeCentroidVolumes(typename PFP::MAP& map,
		const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid,
318
		unsigned int nbth = 0) ;
Lionel Untereiner's avatar
Lionel Untereiner committed
319

320 321 322
template <typename PFP>
void computeCentroidELWVolumes(typename PFP::MAP& map,
		const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid,
323
		unsigned int nbth = 0) ;
324 325

		
326 327 328
template <typename PFP>
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
		const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid,
329
		unsigned int nbth = 0) ;
330
}
Pierre Kraemer's avatar
Pierre Kraemer committed
331
} // namespace Geometry
untereiner's avatar
untereiner committed
332
} // namespace Volume
Pierre Kraemer's avatar
Pierre Kraemer committed
333 334 335 336 337 338 339 340

} // namespace Algo

} // namespace CGoGN

#include "Algo/Geometry/centroid.hpp"

#endif