laplacian.hpp 4.66 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 36
 * Contact information: cgogn@unistra.fr                                        *
 *                                                                              *
 *******************************************************************************/

#include "Algo/Geometry/basic.h"

namespace CGoGN
{

namespace Algo
{

namespace Geometry
{

template <typename PFP>
37 38 39 40 41 42 43 44 45 46 47 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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
typename PFP::VEC3 computeLaplacianTopoVertex(
	typename PFP::MAP& map,
	Dart d,
	const typename PFP::TVEC3& position)
{
	typedef typename PFP::VEC3 VEC3 ;
	VEC3 l(0) ;
	unsigned int val = 0 ;
	Dart dd = d ;
	do
	{
		l += vectorOutOfDart<PFP>(map, dd, position) ;
		val++ ;
		dd = map.alpha1(dd) ;
	} while(dd != d) ;
	l /= val ;
	return l ;
}

template <typename PFP>
typename PFP::VEC3 computeLaplacianCotanVertex(
	typename PFP::MAP& map,
	Dart d,
	const typename PFP::TVEC3& position,
	const typename PFP::TREAL& edgeWeight,
	const typename PFP::TREAL& vertexArea)
{
	typedef typename PFP::VEC3 VEC3 ;
	typedef typename PFP::REAL REAL ;
	VEC3 l(0) ;
	Dart it = d ;
	REAL vArea = vertexArea[d] ;
	REAL val = 0 ;
	do
	{
		REAL w = edgeWeight[it] / vArea ;
		VEC3 v = vectorOutOfDart<PFP>(map, it, position) * w ;
		l += v ;
		val += w ;
		it = map.alpha1(it) ;
	} while(it != d) ;
	l /= val ;
	return l ;
}

template <typename PFP>
void computeLaplacianTopoVertices(
		typename PFP::MAP& map,
		const typename PFP::TVEC3& position,
		typename PFP::TVEC3& laplacian,
		const FunctorSelect& select)
{
	CellMarker marker(map, VERTEX);
	for(Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if(select(d) && !marker.isMarked(d))
		{
			marker.mark(d);
			laplacian[d] = computeLaplacianTopoVertex<PFP>(map, d, position) ;
		}
	}
}

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

template <typename PFP>
121
typename PFP::REAL computeCotanWeightEdge(
Pierre Kraemer's avatar
Pierre Kraemer committed
122 123
	typename PFP::MAP& map,
	Dart d,
124 125 126 127 128 129 130 131 132 133 134
	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
135
	const typename PFP::TVEC3& position,
136 137
	typename PFP::TREAL& edgeWeight,
	const FunctorSelect& select = SelectorTrue())
Pierre Kraemer's avatar
Pierre Kraemer committed
138
{
139 140
	CellMarker marker(map, EDGE);
	for(Dart d = map.begin(); d != map.end(); map.next(d))
Pierre Kraemer's avatar
Pierre Kraemer committed
141
	{
142 143 144 145 146 147
		if(select(d) && !marker.isMarked(d))
		{
			marker.mark(d);
			edgeWeight[d] = computeCotanWeightEdge<PFP>(map, d, position) ;
		}
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
148 149 150 151 152 153 154
}

} // namespace Geometry

} // namespace Algo

} // namespace CGoGN