filter.h 5.24 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
/*******************************************************************************
* 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
47 48 49 50 51 52
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
53 54 55 56

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

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

//	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
73 74 75 76 77 78

	return level;
}


template <typename PFP, typename T>
Pierre Kraemer's avatar
Pierre Kraemer committed
79
void filterLowPass(typename PFP::MAP& map, VertexAttribute<T, typename PFP::MAP>& attIn, unsigned int cutoffLevel)
untereiner's avatar
untereiner committed
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
{
	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>
Pierre Kraemer's avatar
Pierre Kraemer committed
97
void filterHighPass(typename PFP::MAP& map, VertexAttribute<T, typename PFP::MAP>& attIn, unsigned int cutoffLevel)
untereiner's avatar
untereiner committed
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
{
	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>
Pierre Kraemer's avatar
Pierre Kraemer committed
115
void filterBandPass(typename PFP::MAP& map, VertexAttribute<T, typename PFP::MAP>& attIn, unsigned int cutoffLevelLow, unsigned int cutoffLevelHigh)
untereiner's avatar
untereiner committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
{
	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);
}

133 134
template <typename PFP>
typename PFP::VEC3 doTwist(typename PFP::VEC3 pos, float t )
untereiner's avatar
untereiner committed
135
{
136
	typedef typename PFP::VEC3 VEC3;
untereiner's avatar
untereiner committed
137

138 139 140 141 142 143 144 145 146 147 148 149 150
	float st = std::sin(t);
	float ct = std::cos(t);
	VEC3 new_pos;

	new_pos[0] = pos[0]*ct - pos[2]*st;
	new_pos[2] = pos[0]*st + pos[2]*ct;

	new_pos[1] = pos[1];

	return new_pos;
}

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
151
void frequencyDeformation(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& attIn, unsigned int cutoffLevel)
152 153 154 155 156 157 158 159
{
	float time = 1.0;
	//float angle_deg_max = 0.4;
	//float height = 0.4;

	float A = 20.0;
	float frequency = 1.0;
	float phase = time * 2.0;
untereiner's avatar
untereiner committed
160 161 162 163

	TraversorV<typename PFP::MAP> tv(map);
	for (Dart d = tv.begin(); d != tv.end(); d = tv.next())
	{
164 165 166 167 168 169 170 171 172 173 174 175 176
		typename PFP::VEC3 p = attIn[d];

		float dist = std::sqrt(p[0]*p[0] + p[2]*p[2]);

		p[1] += A * std::sin(frequency * dist + phase);

//		float angle_deg = angle_deg_max * std::sin(time);
//		float angle_rad = angle_deg * 3.14159 / 180.0;

//		float ang = (height*0.5 + attIn[d][1])/height * angle_rad;

//		attIn[d] = doTwist<PFP>(attIn[d], ang);
	}
untereiner's avatar
untereiner committed
177
}
untereiner's avatar
untereiner committed
178 179 180 181 182 183 184 185

} // namespace MR

} // namespace Algo

} // namespace CGoGN

#endif