laplacian.hpp 4.67 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
25
26
27
28
29
30
31
32
33
34
35
 * Contact information: cgogn@unistra.fr                                        *
 *                                                                              *
 *******************************************************************************/

#include "Algo/Geometry/basic.h"

namespace CGoGN
{

namespace Algo
{

namespace Geometry
{

36
37
template <typename PFP, typename ATTR_TYPE>
ATTR_TYPE computeLaplacianTopoVertex(
38
39
	typename PFP::MAP& map,
	Dart d,
40
	const AttributeHandler<ATTR_TYPE>& attr)
41
{
42
	ATTR_TYPE l(0) ;
43
	unsigned int val = 0 ;
44
	Dart it = d ;
45
46
	do
	{
47
		l += attr[map.phi1(it)] - attr[it] ;
48
		val++ ;
49
50
		it = map.alpha1(it) ;
	} while(it != d) ;
51
52
53
54
	l /= val ;
	return l ;
}

55
56
template <typename PFP, typename ATTR_TYPE>
ATTR_TYPE computeLaplacianCotanVertex(
57
58
59
	typename PFP::MAP& map,
	Dart d,
	const typename PFP::TREAL& edgeWeight,
60
61
	const typename PFP::TREAL& vertexArea,
	const AttributeHandler<ATTR_TYPE>& attr)
62
63
{
	typedef typename PFP::REAL REAL ;
64
	ATTR_TYPE l(0) ;
65
66
67
68
69
70
	Dart it = d ;
	REAL vArea = vertexArea[d] ;
	REAL val = 0 ;
	do
	{
		REAL w = edgeWeight[it] / vArea ;
71
		l += (attr[map.phi1(it)] - attr[it]) * w ;
72
73
74
75
76
77
78
		val += w ;
		it = map.alpha1(it) ;
	} while(it != d) ;
	l /= val ;
	return l ;
}

79
template <typename PFP, typename ATTR_TYPE>
80
void computeLaplacianTopoVertices(
81
82
83
84
	typename PFP::MAP& map,
	const AttributeHandler<ATTR_TYPE>& attr,
	AttributeHandler<ATTR_TYPE>& laplacian,
	const FunctorSelect& select)
85
86
87
88
89
90
91
{
	CellMarker marker(map, VERTEX);
	for(Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if(select(d) && !marker.isMarked(d))
		{
			marker.mark(d);
92
			laplacian[d] = computeLaplacianTopoVertex<PFP, ATTR_TYPE>(map, d, attr) ;
93
94
95
96
		}
	}
}

97
template <typename PFP, typename ATTR_TYPE>
98
void computeLaplacianCotanVertices(
99
100
101
102
103
104
	typename PFP::MAP& map,
	const typename PFP::TREAL& edgeWeight,
	const typename PFP::TREAL& vertexArea,
	const AttributeHandler<ATTR_TYPE>& attr,
	AttributeHandler<ATTR_TYPE>& laplacian,
	const FunctorSelect& select)
Pierre Kraemer's avatar
Pierre Kraemer committed
105
{
106
	CellMarker marker(map, VERTEX);
Pierre Kraemer's avatar
Pierre Kraemer committed
107
108
109
110
111
	for(Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if(select(d) && !marker.isMarked(d))
		{
			marker.mark(d);
112
			laplacian[d] = computeLaplacianCotanVertex<PFP, ATTR_TYPE>(map, d, edgeWeight, vertexArea, attr) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
113
114
115
116
117
		}
	}
}

template <typename PFP>
118
typename PFP::REAL computeCotanWeightEdge(
Pierre Kraemer's avatar
Pierre Kraemer committed
119
120
	typename PFP::MAP& map,
	Dart d,
121
122
123
124
125
126
127
128
129
130
131
	const typename PFP::TVEC3& position)
{
	typename PFP::REAL alpha = angle<PFP>(map, map.phi_1(d), map.phi2(map.phi1(d)), position) ;
	Dart dd = map.phi2(d) ;
	typename PFP::REAL beta = angle<PFP>(map, map.phi_1(dd), map.phi2(map.phi1(dd)), position) ;
	return 0.5 * ( 1 / tan(alpha) + 1 / tan(beta) ) ;
}

template <typename PFP>
void computeCotanWeightEdges(
	typename PFP::MAP& map,
Pierre Kraemer's avatar
Pierre Kraemer committed
132
	const typename PFP::TVEC3& position,
133
134
	typename PFP::TREAL& edgeWeight,
	const FunctorSelect& select = SelectorTrue())
Pierre Kraemer's avatar
Pierre Kraemer committed
135
{
136
137
	CellMarker marker(map, EDGE);
	for(Dart d = map.begin(); d != map.end(); map.next(d))
Pierre Kraemer's avatar
Pierre Kraemer committed
138
	{
139
140
141
142
143
144
		if(select(d) && !marker.isMarked(d))
		{
			marker.mark(d);
			edgeWeight[d] = computeCotanWeightEdge<PFP>(map, d, position) ;
		}
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
145
146
147
148
149
150
151
}

} // namespace Geometry

} // namespace Algo

} // namespace CGoGN