average.h 5.86 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                                        *
*                                                                              *
*******************************************************************************/

Sylvain Thery's avatar
Sylvain Thery committed
25
#include "Topology/generic/traversor/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,
Pierre Kraemer's avatar
Pierre Kraemer committed
46
47
	const VertexAttribute<T, typename PFP::MAP::IMPL>& attIn,
	VertexAttribute<T, typename PFP::MAP::IMPL>& attOut,
48
	int neigh)
49
{
Pierre Kraemer's avatar
Pierre Kraemer committed
50
	FunctorAverage<VertexAttribute<T, typename PFP::MAP::IMPL> > fa(attIn) ;
Sylvain Thery's avatar
Sylvain Thery committed
51
	Algo::Surface::Selection::Collector_OneRing<PFP> col(map) ;
52

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

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

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

101
	TraversorV<typename PFP::MAP> t(map) ;
102
	for(Dart d = t.begin(); d != t.end(); d = t.next())
103
	{
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
		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
123
		}
124
125
		else
			attOut[d] = attIn[d] ;
126
127
128
129
	}
}

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

141
	TraversorE<typename PFP::MAP> t(map) ;
142
	for(Dart d = t.begin(); d != t.end(); d = t.next())
143
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
144
145
146
147
148
149
150
151
152
		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() ;
153
154
155
156
	}
}

template <typename PFP, typename T>
157
void filterAverageFaceAttribute_WithinSphere(
158
	typename PFP::MAP& map,
Pierre Kraemer's avatar
Pierre Kraemer committed
159
160
	const FaceAttribute<T, typename PFP::MAP::IMPL>& attIn,
	FaceAttribute<T, typename PFP::MAP::IMPL>& attOut,
161
	int neigh,
Pierre Kraemer's avatar
Pierre Kraemer committed
162
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position,
163
	typename PFP::REAL radius)
164
{
Pierre Kraemer's avatar
Pierre Kraemer committed
165
	FunctorAverage<FaceAttribute<T, typename PFP::MAP::IMPL> > fa(attIn) ;
Sylvain Thery's avatar
Sylvain Thery committed
166
	Algo::Surface::Selection::Collector_WithinSphere<PFP> col(map, position, radius) ;
167

168
	TraversorF<typename PFP::MAP> t(map) ;
169
	for(Dart d = t.begin(); d != t.end(); d = t.next())
170
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
171
172
173
174
175
176
177
178
179
		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() ;
180
181
182
183
184
	}
}

} // namespace Filtering

Pierre Kraemer's avatar
Pierre Kraemer committed
185
} // namespace Surface
186

187
188
189
} // namespace Algo

} // namespace CGoGN