average.h 5.57 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009-2011, IGG Team, LSIIT, University of Strasbourg           *
*                                                                              *
* 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.           *
*                                                                              *
* Web site: http://cgogn.u-strasbg.fr/                                         *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#include "Algo/Filtering/functors.h"
#include "Algo/Selection/collector.h"

namespace CGoGN
{

namespace Algo
{

namespace Filtering
{
36
37

enum neighborhood { INSIDE = 1, BORDER = 2 };
38
39

template <typename PFP, typename T>
40
41
42
43
void filterAverageAttribute_OneRing(
	typename PFP::MAP& map,
	const AttributeHandler<T>& attIn,
	AttributeHandler<T>& attOut,
44
	int neigh,
45
	const FunctorSelect& select = SelectorTrue())
46
{
47
	FunctorAverage<T> fa(attIn) ;
48
49
	Algo::Selection::Collector_OneRing<PFP> col(map) ;

50
	CellMarker markV(map, VERTEX) ;
51
52
53
54
	for(Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if(select(d) && !markV.isMarked(d))
		{
55
			markV.mark(d) ;
56
57
58
59
60
61
62

			if (neigh & INSIDE)
				col.collectAll(d) ;
			else
				col.collectBorder(d) ;

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

template <typename PFP, typename T>
85
86
87
88
void filterAverageEdgesAttribute_WithinSphere(
	typename PFP::MAP& map,
	const AttributeHandler<T>& attIn,
	AttributeHandler<T>& attOut,
89
	int neigh,
90
91
92
	typename PFP::TVEC3 & position,
	typename PFP::REAL radius,
	const FunctorSelect& select = SelectorTrue())
93
{
94
	FunctorAverage<T> fa(attIn) ;
95
96
	Algo::Selection::Collector_WithinSphere<PFP> col(map, position, radius) ;

97
	CellMarker markV(map, VERTEX) ;
98
99
100
101
	for(Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if(select(d) && !markV.isMarked(d))
		{
102
			markV.mark(d) ;
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

			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() ;
		}
	}
}

template <typename PFP, typename T>
118
119
120
121
void filterAverageFacesAttribute_WithinSphere(
	typename PFP::MAP& map,
	const AttributeHandler<T>& attIn,
	AttributeHandler<T>& attOut,
122
	int neigh,
123
124
125
	typename PFP::TVEC3 & position,
	typename PFP::REAL radius,
	const FunctorSelect& select = SelectorTrue())
126
127
{

128
	FunctorAverage<T> fa(attIn) ;
129
130
	Algo::Selection::Collector_WithinSphere<PFP> col(map, position, radius) ;

131
	CellMarker markV(map, VERTEX) ;
132
133
134
135
	for(Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if(select(d) && !markV.isMarked(d))
		{
136
			markV.mark(d) ;
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151

			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() ;
		}
	}
}

template <typename PFP, typename T>
152
153
154
155
void filterAverageVertexAttribute_WithinSphere(
	typename PFP::MAP& map,
	const AttributeHandler<T>& attIn,
	AttributeHandler<T>& attOut,
156
	int neigh,
157
158
159
	typename PFP::TVEC3 & position,
	typename PFP::REAL radius,
	const FunctorSelect& select = SelectorTrue())
160
{
161
162
	FunctorAverage<T> faInside(attIn) ;
	FunctorAverageOnSphereBorder<PFP, T> faBorder(map, attIn, position) ;
163
164
	Algo::Selection::Collector_WithinSphere<PFP> col(map, position, radius) ;

165
	CellMarker markV(map, VERTEX) ;
166
167
168
169
	for(Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if(select(d) && !markV.isMarked(d))
		{
170
			markV.mark(d) ;
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187

			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();
			}
188
			attOut[d] /= faInside.getCount() + faBorder.getCount() ;
189
190
191
192
193
194
195
196
197
		}
	}
}

} // namespace Filtering

} // namespace Algo

} // namespace CGoGN