taubin.h 4.16 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
38
namespace Filtering
{

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

	FunctorAverage<typename PFP::MAP, typename PFP::VEC3> fa(map, position) ;
	Algo::Selection::Collector_OneRing<PFP> c(map) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
44

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

Pierre Kraemer's avatar
Pierre Kraemer committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
	CellMarkerNoUnmark mv(map, VERTEX) ;
	for(Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if(select(d) && !mv.isMarked(d))
		{
			mv.mark(d);

			c.collectBorder(d) ;
			fa.reset() ;
			c.applyOnBorder(fa) ;
			VEC3 p = position[d] ;
			VEC3 displ = fa.getAverage() - p ;
			displ *= lambda ;
			position2[d] = p + displ ;
		}
	}

	// unshrinking step
	for(Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if(select(d) && mv.isMarked(d))
		{
			mv.unmark(d);

			c.collectBorder(d) ;
			fa.reset() ;
			c.applyOnBorder(fa) ;
			VEC3 p = position2[d] ;
			VEC3 displ = fa.getAverage() - p ;
			displ *= mu ;
			position[d] = p + displ ;
		}
	}
}

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

Pierre Kraemer's avatar
Pierre Kraemer committed
91
92
93
	FunctorAverage<typename PFP::MAP, typename PFP::VEC3> fa(map, position) ;
	Algo::Selection::Collector_OneRing<PFP> c(map) ;

Pierre Kraemer's avatar
Pierre Kraemer committed
94
95
96
	const float lambda = 0.6307 ;
	const float mu = -0.6732 ;

Pierre Kraemer's avatar
Pierre Kraemer committed
97
	CellMarkerNoUnmark mv(map, VERTEX) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
98
99
100
101
102
103
	for(Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if(select(d) && !mv.isMarked(d))
		{
			mv.mark(d);

Pierre Kraemer's avatar
Pierre Kraemer committed
104
105
106
107
108
109
110
			c.collectBorder(d) ;
			fa.reset() ;
			c.applyOnBorder(fa) ;
			VEC3 p = position[d] ;
			VEC3 displ = fa.getAverage() - p ;
			displ *= lambda ;
			position2[d] = p + displ ;
Pierre Kraemer's avatar
Pierre Kraemer committed
111
112
113
114
115
116
117
118
119
120
		}
	}

	// unshrinking step
	for(Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if(select(d) && mv.isMarked(d))
		{
			mv.unmark(d);

Pierre Kraemer's avatar
Pierre Kraemer committed
121
122
123
124
125
126
127
			c.collectBorder(d) ;
			fa.reset() ;
			c.applyOnBorder(fa) ;
			VEC3 p = position2[d] ;
			VEC3 displ = fa.getAverage() - p ;
			displ *= mu ;
			position[d] = p + displ ;
Pierre Kraemer's avatar
Pierre Kraemer committed
128
129
130
131
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
132
} // namespace Filtering
Pierre Kraemer's avatar
Pierre Kraemer committed
133

Pierre Kraemer's avatar
Pierre Kraemer committed
134
} // namespace Algo
Pierre Kraemer's avatar
Pierre Kraemer committed
135

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