matrixSetup.h 3.9 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
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef __LINEAR_SOLVING_LAPLACIAN_SETUP__
#define __LINEAR_SOLVING_LAPLACIAN_SETUP__

namespace CGoGN
{

namespace LinearSolving
{

template<typename PFP, class SOLVER_TRAITS>
35
class FunctorLaplacianTopo : public FunctorMap<typename PFP::MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
36 37 38 39 40 41 42 43
{
protected:
	LinearSolver<SOLVER_TRAITS>* solver ;
	const AttributeHandler<unsigned int>& indexTable ;

public:
	typedef typename PFP::MAP MAP ;

44
	FunctorLaplacianTopo(MAP& m, LinearSolver<SOLVER_TRAITS>* s, const AttributeHandler<unsigned int> index) :
Pierre Kraemer's avatar
Pierre Kraemer committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
		FunctorMap<MAP>(m), solver(s), indexTable(index)
	{}

	bool operator()(Dart d)
	{
		solver->begin_row() ;
		Dart dd = d ;
		float aii = 0.0f ;
		do
		{
			float aij = 1.0f ;
			aii += aij ;
			solver->add_coefficient(indexTable[this->m_map.phi2(dd)], aij) ;
			dd = this->m_map.phi1(this->m_map.phi2(dd)) ;
		} while(dd != d) ;
		solver->add_coefficient(indexTable[d], -aii) ;
		solver->set_right_hand_side(0.0f) ;
		solver->normalize_row() ;
		solver->end_row() ;
		return false ;
	}
} ;

template<typename PFP, class SOLVER_TRAITS>
69
class FunctorLaplacianCotan : public FunctorMap<typename PFP::MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
70 71 72
{
protected:
	LinearSolver<SOLVER_TRAITS>* solver ;
73 74 75
	const AttributeHandler<unsigned int>& indexTable ;
	const typename PFP::TREAL& edgeWeight ;
	const typename PFP::TREAL& vertexArea ;
Pierre Kraemer's avatar
Pierre Kraemer committed
76 77

public:
78 79
	typedef typename PFP::MAP MAP ;
	typedef typename PFP::REAL REAL ;
Pierre Kraemer's avatar
Pierre Kraemer committed
80

81 82 83
	FunctorLaplacianCotan(MAP& m, LinearSolver<SOLVER_TRAITS>* s, const AttributeHandler<unsigned int> index, const typename PFP::TREAL& eWeight, const typename PFP::TREAL& vArea) :
		FunctorMap<MAP>(m), solver(s), indexTable(index), edgeWeight(eWeight), vertexArea(vArea)
	{}
Pierre Kraemer's avatar
Pierre Kraemer committed
84 85 86 87

	bool operator()(Dart d)
	{
		solver->begin_row() ;
88 89 90
		Dart it = d ;
		REAL vArea = vertexArea[d] ;
		REAL aii = 0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
91 92
		do
		{
93
			typename PFP::REAL aij = edgeWeight[it] / vArea ;
Pierre Kraemer's avatar
Pierre Kraemer committed
94
			aii += aij ;
95 96 97 98
			solver->add_coefficient(indexTable[this->m_map.phi2(it)], aij) ;
			it = this->m_map.alpha1(it) ;
		} while(it != d) ;
		solver->add_coefficient(indexTable[d], -aii) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
99 100 101 102 103 104 105 106 107 108 109 110
		solver->set_right_hand_side(0.0f) ;
		solver->normalize_row() ;
		solver->end_row() ;
		return false ;
	}
} ;

}

}

#endif