centroid.hpp 4.36 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-2011, 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.u-strasbg.fr/                                         *
Pierre Kraemer's avatar
Pierre Kraemer committed
21 22 23 24
 * Contact information: cgogn@unistra.fr                                        *
 *                                                                              *
 *******************************************************************************/

25 26
#include "Topology/generic/traversorCell.h"
#include "Topology/generic/traversor2.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
27
#include "Topology/generic/cellmarker.h"
28 29 30
#include "Topology/generic/traversorCell.h"
#include "Topology/generic/traversor3.h"

Pierre Kraemer's avatar
Pierre Kraemer committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

namespace CGoGN
{

namespace Algo
{

namespace Geometry
{

template <typename PFP, typename EMBV, typename EMB>
EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs)
{
	EMB center = AttribOps::zero<EMB,PFP>() ;
	unsigned count = 0 ;

47 48
	Traversor3WV<typename PFP::MAP> tra(map,d);
	for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
Pierre Kraemer's avatar
Pierre Kraemer committed
49
	{
50
		center += attributs[d];
Pierre Kraemer's avatar
Pierre Kraemer committed
51 52 53 54 55 56 57 58 59 60 61 62
		++count;
	}

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

template <typename PFP, typename EMBV, typename EMB>
EMB faceCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs)
{
	EMB center = AttribOps::zero<EMB,PFP>();
	unsigned int count = 0 ;
63 64
	Traversor2FV<typename PFP::MAP> t(map, d) ;
	for(Dart it = t.begin(); it != t.end(); it = t.next())
Pierre Kraemer's avatar
Pierre Kraemer committed
65 66 67
	{
		center += attributs[it];
		++count ;
68
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
69 70 71 72 73 74 75 76 77
	center /= double(count);
	return center ;
}

template <typename PFP, typename EMBV, typename EMB>
EMB vertexNeighborhoodCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs)
{
	EMB center = AttribOps::zero<EMB,PFP>();
	unsigned int count = 0 ;
78 79
	Traversor2VVaE<typename PFP::MAP> t(map, d) ;
	for(Dart it = t.begin(); it != t.end(); it = t.next())
Pierre Kraemer's avatar
Pierre Kraemer committed
80
	{
81
		center += attributs[it];
Pierre Kraemer's avatar
Pierre Kraemer committed
82
		++count ;
83
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
84 85 86 87 88 89 90
	center /= count ;
	return center ;
}

template <typename PFP>
void computeCentroidVolumes(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& vol_centroid, const FunctorSelect& select)
{
Pierre Kraemer's avatar
Pierre Kraemer committed
91
	TraversorW<typename PFP::MAP> t(map, select) ;
92
	for(Dart d = t.begin(); d != t.end(); d = t.next())
Pierre Kraemer's avatar
Pierre Kraemer committed
93
		vol_centroid[d] = volumeCentroid<PFP>(map, d, position) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
94 95 96 97 98
}

template <typename PFP>
void computeCentroidFaces(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& face_centroid, const FunctorSelect& select)
{
Pierre Kraemer's avatar
Pierre Kraemer committed
99
	TraversorF<typename PFP::MAP> t(map, select) ;
100
	for(Dart d = t.begin(); d != t.end(); d = t.next())
Pierre Kraemer's avatar
Pierre Kraemer committed
101
		face_centroid[d] = faceCentroid<PFP>(map, d, position) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
102 103 104 105 106
}

template <typename PFP>
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& vertex_centroid, const FunctorSelect& select)
{
Pierre Kraemer's avatar
Pierre Kraemer committed
107
	TraversorV<typename PFP::MAP> t(map, select) ;
108
	for(Dart d = t.begin(); d != t.end(); d = t.next())
Pierre Kraemer's avatar
Pierre Kraemer committed
109
		vertex_centroid[d] = vertexNeighborhoodCentroid<PFP>(map, d, position) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
110 111 112 113 114 115 116
}

} // namespace Geometry

} // namespace Algo

} // namespace CGoGN