filter.h 4.6 KB
Newer Older
untereiner's avatar
untereiner committed
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
36
37
38
39
40
41
42
43
44
45
46
47
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009-2012, 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.unistra.fr/                                           *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef __MR_FILTERS__
#define __MR_FILTERS__

#include <cmath>


namespace CGoGN
{

namespace Algo
{

namespace MR
{

class Filter
{
public:
	Filter() {}
	virtual ~Filter() {}
	virtual void operator() () = 0 ;
} ;

untereiner's avatar
untereiner committed
48
49
50
51
52
53
template <typename PFP>
unsigned int vertexLevel(typename PFP::MAP& map, Dart d)
{
	assert(map.getDartLevel(d) <= map.getCurrentLevel() || !"edgeLevel : called with a dart inserted after current level") ;

	unsigned int level = map.getMaxLevel();
untereiner's avatar
untereiner committed
54
55
56
57

	TraversorDartsOfOrbit<typename PFP::MAP,VERTEX> tv(map,d);

	for(Dart dit = tv.begin() ; dit != tv.end() ; dit = tv.next())
untereiner's avatar
untereiner committed
58
59
60
61
62
	{
		unsigned int ldit = map.getDartLevel(dit) ;
		if(ldit < level)
			level = ldit;
	}
untereiner's avatar
untereiner committed
63
64
65
66
67
68
69
70
71
72
73

//	Dart dit = d;
//	do
//	{
//		unsigned int ldit = map.getDartLevel(dit) ;
//		if(ldit < level)
//			level = ldit;
//
//		dit = map.phi2(map.phi_1(dit));
//	}
//	while(dit != d);
untereiner's avatar
untereiner committed
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145

	return level;
}


template <typename PFP, typename T>
void filterLowPass(typename PFP::MAP& map, VertexAttribute<T>& attIn, unsigned int cutoffLevel)
{
	unsigned int cur = map.getCurrentLevel();
	unsigned int max = map.getMaxLevel();

	map.setCurrentLevel(max);

	TraversorV<typename PFP::MAP> tv(map);
	for (Dart d = tv.begin(); d != tv.end(); d = tv.next())
	{
		if(vertexLevel<PFP>(map,d) > cutoffLevel)
			attIn[d] = T(0.0);
	}

	map.setCurrentLevel(cur);
}

template <typename PFP, typename T>
void filterHighPass(typename PFP::MAP& map, VertexAttribute<T>& attIn, unsigned int cutoffLevel)
{
	unsigned int cur = map.getCurrentLevel();
	unsigned int max = map.getMaxLevel();

	map.setCurrentLevel(max);

	TraversorV<typename PFP::MAP> tv(map);
	for (Dart d = tv.begin(); d != tv.end(); d = tv.next())
	{
		if(vertexLevel<PFP>(map,d) < cutoffLevel)
			attIn[d] = T(0.0);
	}

	map.setCurrentLevel(cur);
}

template <typename PFP, typename T>
void filterBandPass(typename PFP::MAP& map, VertexAttribute<T>& attIn, unsigned int cutoffLevelLow, unsigned int cutoffLevelHigh)
{
	unsigned int cur = map.getCurrentLevel();
	unsigned int max = map.getMaxLevel();

	map.setCurrentLevel(max);

	TraversorV<typename PFP::MAP> tv(map);
	for (Dart d = tv.begin(); d != tv.end(); d = tv.next())
	{
		unsigned int vLevel = vertexLevel<PFP>(map,d);
		if(cutoffLevelLow > vLevel && vLevel < cutoffLevelHigh)
			attIn[d] = T(0.0);
	}

	map.setCurrentLevel(cur);
}

template <typename PFP, typename T>
void frequencyDeformation(typename PFP::MAP& map, VertexAttribute<T>& attIn, unsigned int cutoffLevel)
{
	unsigned int cur = map.getCurrentLevel();
	unsigned int max = map.getMaxLevel();

	map.setCurrentLevel(max);

	TraversorV<typename PFP::MAP> tv(map);
	for (Dart d = tv.begin(); d != tv.end(); d = tv.next())
	{
		if(vertexLevel<PFP>(map,d) == cutoffLevel)
untereiner's avatar
untereiner committed
146
			attIn[d] += T(0.0,0.0,0.2);
untereiner's avatar
untereiner committed
147
148
149
150
	}

	map.setCurrentLevel(cur);
}
untereiner's avatar
untereiner committed
151

untereiner's avatar
untereiner committed
152

untereiner's avatar
untereiner committed
153
154
155
156
157
158
159
160
} // namespace MR

} // namespace Algo

} // namespace CGoGN

#endif