taubin.h 4.44 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2011, IGG Team, LSIIT, University of Strasbourg           *
Pierre Kraemer's avatar
Pierre Kraemer committed
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.u-strasbg.fr/                                         *
Pierre Kraemer's avatar
Pierre Kraemer committed
21 22 23 24
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
25 26 27
#include "Algo/Filtering/functors.h"
#include "Algo/Selection/collector.h"

Pierre Kraemer's avatar
Pierre Kraemer committed
28 29 30 31 32 33
namespace CGoGN
{

namespace Algo
{

Pierre Kraemer's avatar
Pierre Kraemer committed
34 35 36 37
namespace Filtering
{

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
38
void filterTaubin(typename PFP::MAP& map, typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const FunctorSelect& select = allDarts)
Pierre Kraemer's avatar
Pierre Kraemer committed
39
{
Pierre Kraemer's avatar
Pierre Kraemer committed
40 41 42
	typedef typename PFP::VEC3 VEC3 ;

	Algo::Selection::Collector_OneRing<PFP> c(map) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
43

Pierre Kraemer's avatar
Pierre Kraemer committed
44 45
	const float lambda = 0.6307 ;
	const float mu = -0.6732 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
46

Pierre Kraemer's avatar
Pierre Kraemer committed
47
	CellMarkerNoUnmark mv(map, VERTEX) ;
48 49

	FunctorAverage<VEC3> fa1(position) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
50 51 52 53 54 55 56
	for(Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if(select(d) && !mv.isMarked(d))
		{
			mv.mark(d);

			c.collectBorder(d) ;
57 58
			fa1.reset() ;
			c.applyOnBorder(fa1) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
59
			VEC3 p = position[d] ;
60
			VEC3 displ = fa1.getAverage() - p ;
Pierre Kraemer's avatar
Pierre Kraemer committed
61 62 63 64 65 66
			displ *= lambda ;
			position2[d] = p + displ ;
		}
	}

	// unshrinking step
Basile Sauvage's avatar
Basile Sauvage committed
67
	FunctorAverage<VEC3> fa2(position2) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
68 69 70 71 72 73 74
	for(Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if(select(d) && mv.isMarked(d))
		{
			mv.unmark(d);

			c.collectBorder(d) ;
75 76
			fa2.reset() ;
			c.applyOnBorder(fa2) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
77
			VEC3 p = position2[d] ;
78
			VEC3 displ = fa2.getAverage() - p ;
Pierre Kraemer's avatar
Pierre Kraemer committed
79 80 81 82 83 84 85 86 87
			displ *= mu ;
			position[d] = p + displ ;
		}
	}
}

/**
 * Taubin filter modified as proposed by [Lav09]
 */
Pierre Kraemer's avatar
Pierre Kraemer committed
88
template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
89
void filterTaubin_modified(typename PFP::MAP& map, typename PFP::TVEC3& position, typename PFP::TVEC3& position2, typename PFP::REAL radius, const FunctorSelect& select = allDarts)
Pierre Kraemer's avatar
Pierre Kraemer committed
90 91 92 93 94 95
{
	typedef typename PFP::VEC3 VEC3 ;

	const float lambda = 0.6307 ;
	const float mu = -0.6732 ;

96
	FunctorAverageOnSphereBorder<PFP, typename PFP::VEC3> fa1(map, position, position) ;
97
	Algo::Selection::Collector_WithinSphere<PFP> c1(map, position, radius) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
98
	CellMarkerNoUnmark mv(map, VERTEX) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
99 100 101 102 103 104
	for(Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if(select(d) && !mv.isMarked(d))
		{
			mv.mark(d);

105 106
			c1.collectBorder(d) ;
			VEC3 center = position[d] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
107
			fa1.reset(center, radius) ;
108 109
			c1.applyOnBorder(fa1) ;
			VEC3 displ = fa1.getAverage() - center ;
Pierre Kraemer's avatar
Pierre Kraemer committed
110
			displ *= lambda ;
111
			position2[d] = center + displ ;
Pierre Kraemer's avatar
Pierre Kraemer committed
112 113 114 115
		}
	}

	// unshrinking step
116
	FunctorAverageOnSphereBorder<PFP, typename PFP::VEC3> fa2(map, position2, position2) ;
117
	Algo::Selection::Collector_WithinSphere<PFP> c2(map, position2, radius) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
118 119 120 121 122 123
	for(Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if(select(d) && mv.isMarked(d))
		{
			mv.unmark(d);

124 125
			c2.collectBorder(d) ;
			VEC3 center = position2[d] ;
126 127 128
			fa2.reset(center, radius) ;
			c2.applyOnBorder(fa2) ;
			VEC3 displ = fa2.getAverage() - center ;
Pierre Kraemer's avatar
Pierre Kraemer committed
129
			displ *= mu ;
130
			position[d] = center + displ ;
Pierre Kraemer's avatar
Pierre Kraemer committed
131 132 133 134
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
135
} // namespace Filtering
Pierre Kraemer's avatar
Pierre Kraemer committed
136

Pierre Kraemer's avatar
Pierre Kraemer committed
137
} // namespace Algo
Pierre Kraemer's avatar
Pierre Kraemer committed
138

Pierre Kraemer's avatar
Pierre Kraemer committed
139
} // namespace CGoGN