Coupure prévue mardi 3 Août au matin pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

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

25
#include "Topology/generic/traversorCell.h"
26
27
28
29
30
31
32
33
34
#include "Algo/Filtering/functors.h"
#include "Algo/Selection/collector.h"

namespace CGoGN
{

namespace Algo
{

35
36
37
namespace Surface
{

38
39
namespace Filtering
{
40
41

enum neighborhood { INSIDE = 1, BORDER = 2 };
42
43

template <typename PFP, typename T>
44
45
void filterAverageAttribute_OneRing(
	typename PFP::MAP& map,
46
47
	const VertexAttribute<T>& attIn,
	VertexAttribute<T>& attOut,
48
	int neigh,
Pierre Kraemer's avatar
Pierre Kraemer committed
49
	const FunctorSelect& select = allDarts)
50
{
51
	FunctorAverage<T, VERTEX> fa(attIn) ;
Sylvain Thery's avatar
Sylvain Thery committed
52
	Algo::Surface::Selection::Collector_OneRing<PFP> col(map) ;
53

Pierre Kraemer's avatar
Pierre Kraemer committed
54
	TraversorV<typename PFP::MAP> t(map, select) ;
55
	for(Dart d = t.begin(); d != t.end(); d = t.next())
56
	{
57
		if(!map.isBoundaryVertex(d))
Pierre Kraemer's avatar
Pierre Kraemer committed
58
		{
59
60
61
62
63
64
65
			if (neigh & INSIDE)
				col.collectAll(d) ;
			else
				col.collectBorder(d) ;

			fa.reset() ;
			if (neigh & INSIDE)
66
			{
67
68
69
70
71
72
73
74
75
76
77
78
				switch (attIn.getOrbit())
				{
				case VERTEX :
					col.applyOnInsideVertices(fa) ;
					break;
				case EDGE :
					col.applyOnInsideEdges(fa) ;
					break;
				case FACE :
					col.applyOnInsideFaces(fa) ;
					break;
				}
79
			}
80
81
82
			if (neigh & BORDER)
				col.applyOnBorder(fa) ;
			attOut[d] = fa.getAverage() ;
83
		}
84
85
		else
			attOut[d] = attIn[d] ;
86
87
88
89
	}
}

template <typename PFP, typename T>
90
void filterAverageVertexAttribute_WithinSphere(
91
	typename PFP::MAP& map,
92
93
	const VertexAttribute<T>& attIn,
	VertexAttribute<T>& attOut,
94
	int neigh,
95
	VertexAttribute<typename PFP::VEC3>& position,
96
	typename PFP::REAL radius,
Pierre Kraemer's avatar
Pierre Kraemer committed
97
	const FunctorSelect& select = allDarts)
98
{
99
	FunctorAverage<T, VERTEX> faInside(attIn) ;
100
	FunctorAverageOnSphereBorder<PFP, T> faBorder(map, attIn, position) ;
Sylvain Thery's avatar
Sylvain Thery committed
101
	Algo::Surface::Selection::Collector_WithinSphere<PFP> col(map, position, radius) ;
102

Pierre Kraemer's avatar
Pierre Kraemer committed
103
	TraversorV<typename PFP::MAP> t(map, select) ;
104
	for(Dart d = t.begin(); d != t.end(); d = t.next())
105
	{
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
		if(!map.isBoundaryVertex(d))
		{
			if (neigh & INSIDE)
				col.collectAll(d) ;
			else
				col.collectBorder(d) ;

			attOut[d] = T(0);
			if (neigh & INSIDE){
				faInside.reset() ;
				col.applyOnInsideVertices(faInside) ;
				attOut[d] += faInside.getSum();
			}
			if (neigh & BORDER){
				faBorder.reset(position[d], radius);
				col.applyOnBorder(faBorder) ;
				attOut[d] += faBorder.getSum();
			}
			attOut[d] /= faInside.getCount() + faBorder.getCount() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
125
		}
126
127
		else
			attOut[d] = attIn[d] ;
128
129
130
131
	}
}

template <typename PFP, typename T>
132
void filterAverageEdgeAttribute_WithinSphere(
133
	typename PFP::MAP& map,
134
135
	const EdgeAttribute<T>& attIn,
	EdgeAttribute<T>& attOut,
136
	int neigh,
137
	VertexAttribute<typename PFP::VEC3>& position,
138
	typename PFP::REAL radius,
Pierre Kraemer's avatar
Pierre Kraemer committed
139
	const FunctorSelect& select = allDarts)
140
{
141
	FunctorAverage<T, EDGE> fa(attIn) ;
Sylvain Thery's avatar
Sylvain Thery committed
142
	Algo::Surface::Selection::Collector_WithinSphere<PFP> col(map, position, radius) ;
143

144
	TraversorE<typename PFP::MAP> t(map, select) ;
145
	for(Dart d = t.begin(); d != t.end(); d = t.next())
146
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
147
148
149
150
151
152
153
154
155
		if (neigh & INSIDE)
			col.collectAll(d) ;
		else
			col.collectBorder(d) ;

		fa.reset() ;
		if (neigh & INSIDE) col.applyOnInsideEdges(fa) ;
		if (neigh & BORDER) col.applyOnBorder(fa) ;
		attOut[d] = fa.getAverage() ;
156
157
158
159
	}
}

template <typename PFP, typename T>
160
void filterAverageFaceAttribute_WithinSphere(
161
	typename PFP::MAP& map,
162
163
	const FaceAttribute<T>& attIn,
	FaceAttribute<T>& attOut,
164
	int neigh,
165
	VertexAttribute<typename PFP::VEC3>& position,
166
	typename PFP::REAL radius,
Pierre Kraemer's avatar
Pierre Kraemer committed
167
	const FunctorSelect& select = allDarts)
168
{
169
	FunctorAverage<T, FACE> fa(attIn) ;
Sylvain Thery's avatar
Sylvain Thery committed
170
	Algo::Surface::Selection::Collector_WithinSphere<PFP> col(map, position, radius) ;
171

172
	TraversorF<typename PFP::MAP> t(map, select) ;
173
	for(Dart d = t.begin(); d != t.end(); d = t.next())
174
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
175
176
177
178
179
180
181
182
183
		if (neigh & INSIDE)
			col.collectAll(d) ;
		else
			col.collectBorder(d) ;

		fa.reset() ;
		if (neigh & INSIDE) col.applyOnInsideFaces(fa) ;
		if (neigh & BORDER) col.applyOnBorder(fa) ;
		attOut[d] = fa.getAverage() ;
184
185
186
187
188
	}
}

} // namespace Filtering

189
190
}

191
192
193
} // namespace Algo

} // namespace CGoGN