basic.h 9.93 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-2012, 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.unistra.fr/                                           *
Pierre Kraemer's avatar
Pierre Kraemer committed
21 22 23 24 25 26 27
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef __LINEAR_SOLVING_BASIC__
#define __LINEAR_SOLVING_BASIC__

28
#include "NL/nl.h"
29
#include "Algo/LinearSolving/variablesSetup.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
30
#include "Algo/LinearSolving/matrixSetup.h"
31
#include "Algo/Topo/basic.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
32 33 34 35 36 37 38

namespace CGoGN
{

namespace LinearSolving
{

39 40 41 42
/*******************************************************************************
 * VARIABLES SETUP
 *******************************************************************************/

43
template <typename PFP, typename ATTR_TYPE>
44 45
void setupVariables(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
46 47 48
	const VertexAttribute<unsigned int, typename PFP::MAP::IMPL>& index,
	const CellMarker<typename PFP::MAP, VERTEX>& fm,
	const VertexAttribute<ATTR_TYPE, typename PFP::MAP::IMPL>& attr)
Pierre Kraemer's avatar
Pierre Kraemer committed
49
{
50 51 52 53 54 55
//	TraversorV<MAP> t(m);
//	for (Dart d = t.begin(); d != t.end(); d = t.next())
//	{

//	}

56
	FunctorMeshToSolver_Scalar<PFP, ATTR_TYPE> fmts(index, fm, attr) ;
57
	Algo::Topo::foreach_orbit<VERTEX>(m, fmts) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
58 59
}

60
template <typename PFP, typename ATTR_TYPE>
61 62
void setupVariables(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
63 64 65
	const VertexAttribute<unsigned int, typename PFP::MAP::IMPL>& index,
	const CellMarker<typename PFP::MAP, VERTEX>& fm,
	const VertexAttribute<ATTR_TYPE, typename PFP::MAP::IMPL>& attr,
66
	unsigned int coord)
Pierre Kraemer's avatar
Pierre Kraemer committed
67
{
68
	FunctorMeshToSolver_Vector<PFP, ATTR_TYPE> fmts(index, fm, attr, coord) ;
69
	Algo::Topo::foreach_orbit<VERTEX>(m, fmts) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
70 71
}

72 73 74 75
/*******************************************************************************
 * MATRIX SETUP : EQUALITY
 *******************************************************************************/

76
template <typename PFP, typename ATTR_TYPE>
77 78
void addRowsRHS_Equality(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
79 80 81
	const VertexAttribute<unsigned int, typename PFP::MAP::IMPL>& index,
	const VertexAttribute<ATTR_TYPE, typename PFP::MAP::IMPL>& attr,
	const VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& weight)
82
{
83 84
	nlEnable(NL_NORMALIZE_ROWS) ;
	FunctorEquality_PerVertexWeight_Scalar<PFP, ATTR_TYPE> feq(index, attr, weight) ;
85
	Algo::Topo::foreach_orbit<VERTEX>(m, feq) ;
86
	nlDisable(NL_NORMALIZE_ROWS) ;
87 88
}

89
template <typename PFP, typename ATTR_TYPE>
90 91
void addRowsRHS_Equality(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
92 93
	const VertexAttribute<unsigned int, typename PFP::MAP::IMPL>& index,
	const VertexAttribute<ATTR_TYPE, typename PFP::MAP::IMPL>& attr,
Pierre Kraemer's avatar
Pierre Kraemer committed
94 95
	float weight)
{
96 97
	nlEnable(NL_NORMALIZE_ROWS) ;
	FunctorEquality_UniformWeight_Scalar<PFP, ATTR_TYPE> feq(index, attr, weight) ;
98
	Algo::Topo::foreach_orbit<VERTEX>(m, feq) ;
99
	nlDisable(NL_NORMALIZE_ROWS) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
100 101
}

102
template <typename PFP, typename ATTR_TYPE>
Pierre Kraemer's avatar
Pierre Kraemer committed
103 104
void addRowsRHS_Equality(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
105 106 107
	const VertexAttribute<unsigned int, typename PFP::MAP::IMPL>& index,
	const VertexAttribute<ATTR_TYPE, typename PFP::MAP::IMPL>& attr,
	const VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& weight,
Pierre Kraemer's avatar
Pierre Kraemer committed
108 109
	unsigned int coord)
{
110 111
	nlEnable(NL_NORMALIZE_ROWS) ;
	FunctorEquality_PerVertexWeight_Vector<PFP, ATTR_TYPE> feq(index, attr, weight, coord) ;
112
	Algo::Topo::foreach_orbit<VERTEX>(m, feq) ;
113
	nlDisable(NL_NORMALIZE_ROWS) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
114 115
}

116
template <typename PFP, typename ATTR_TYPE>
Pierre Kraemer's avatar
Pierre Kraemer committed
117 118
void addRowsRHS_Equality(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
119 120
	const VertexAttribute<unsigned int, typename PFP::MAP::IMPL>& index,
	const VertexAttribute<ATTR_TYPE, typename PFP::MAP::IMPL>& attr,
Pierre Kraemer's avatar
Pierre Kraemer committed
121
	float weight,
122 123
	unsigned int coord)
{
124 125
	nlEnable(NL_NORMALIZE_ROWS) ;
	FunctorEquality_UniformWeight_Vector<PFP, ATTR_TYPE> feq(index, attr, weight, coord) ;
126
	Algo::Topo::foreach_orbit<VERTEX>(m, feq) ;
127
	nlDisable(NL_NORMALIZE_ROWS) ;
128 129 130 131 132 133
}

/*******************************************************************************
 * MATRIX SETUP : LAPLACIAN TOPO
 *******************************************************************************/

134
template <typename PFP>
135 136
void addRows_Laplacian_Topo(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
137
	const VertexAttribute<unsigned int, typename PFP::MAP::IMPL> index)
138
{
139 140
	nlEnable(NL_NORMALIZE_ROWS) ;
	FunctorLaplacianTopo<PFP> flt(m, index) ;
141
	Algo::Topo::foreach_orbit<VERTEX>(m, flt) ;
142
	nlDisable(NL_NORMALIZE_ROWS) ;
143 144
}

145
template <typename PFP, typename ATTR_TYPE>
146 147
void addRowsRHS_Laplacian_Topo(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
148 149
	const VertexAttribute<unsigned int, typename PFP::MAP::IMPL> index,
	const VertexAttribute<ATTR_TYPE, typename PFP::MAP::IMPL>& attr)
Pierre Kraemer's avatar
Pierre Kraemer committed
150
{
151 152
	nlEnable(NL_NORMALIZE_ROWS) ;
	FunctorLaplacianTopoRHS_Scalar<PFP, ATTR_TYPE> flt(m, index, attr) ;
153
	Algo::Topo::foreach_orbit<VERTEX>(m, flt) ;
154
	nlDisable(NL_NORMALIZE_ROWS) ;
155 156
}

157
template <typename PFP, typename ATTR_TYPE>
158 159
void addRowsRHS_Laplacian_Topo(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
160 161
	const VertexAttribute<unsigned int, typename PFP::MAP::IMPL> index,
	const VertexAttribute<ATTR_TYPE, typename PFP::MAP::IMPL>& attr,
162 163
	unsigned int coord)
{
164 165
	nlEnable(NL_NORMALIZE_ROWS) ;
	FunctorLaplacianTopoRHS_Vector<PFP, ATTR_TYPE> flt(m, index, attr, coord) ;
166
	Algo::Topo::foreach_orbit<VERTEX>(m, flt) ;
167
	nlDisable(NL_NORMALIZE_ROWS) ;
168 169 170 171 172 173
}

/*******************************************************************************
 * MATRIX SETUP : LAPLACIAN COTAN
 *******************************************************************************/

174
template <typename PFP>
175 176
void addRows_Laplacian_Cotan(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
177 178 179
	const VertexAttribute<unsigned int, typename PFP::MAP::IMPL> index,
	const EdgeAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& edgeWeight,
	const VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& vertexArea)
180
{
181 182
	nlEnable(NL_NORMALIZE_ROWS) ;
	FunctorLaplacianCotan<PFP> flc(m, index, edgeWeight, vertexArea) ;
183
	Algo::Topo::foreach_orbit<VERTEX>(m, flc) ;
184
	nlDisable(NL_NORMALIZE_ROWS) ;
185
}
Pierre Kraemer's avatar
Pierre Kraemer committed
186

187
template <typename PFP, typename ATTR_TYPE>
188 189
void addRowsRHS_Laplacian_Cotan(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
190 191 192 193
	const VertexAttribute<unsigned int, typename PFP::MAP::IMPL> index,
	const EdgeAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& edgeWeight,
	const VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& vertexArea,
	const VertexAttribute<ATTR_TYPE, typename PFP::MAP::IMPL>& attr)
Pierre Kraemer's avatar
Pierre Kraemer committed
194
{
195 196
	nlEnable(NL_NORMALIZE_ROWS) ;
	FunctorLaplacianCotanRHS_Scalar<PFP, ATTR_TYPE> flc(m, index, edgeWeight, vertexArea, attr) ;
197
	Algo::Topo::foreach_orbit<VERTEX>(m, flc) ;
198
	nlDisable(NL_NORMALIZE_ROWS) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
199 200
}

201
template <typename PFP, typename ATTR_TYPE>
202 203
void addRowsRHS_Laplacian_Cotan(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
204 205 206 207
	const VertexAttribute<unsigned int, typename PFP::MAP::IMPL> index,
	const EdgeAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& edgeWeight,
	const VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& vertexArea,
	const VertexAttribute<ATTR_TYPE, typename PFP::MAP::IMPL>& attr,
208
	unsigned int coord)
Pierre Kraemer's avatar
Pierre Kraemer committed
209
{
210 211
	nlEnable(NL_NORMALIZE_ROWS) ;
	FunctorLaplacianCotanRHS_Vector<PFP, ATTR_TYPE> flc(m, index, edgeWeight, vertexArea, attr, coord) ;
212
	Algo::Topo::foreach_orbit<VERTEX>(m, flc) ;
213
	nlDisable(NL_NORMALIZE_ROWS) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
214 215
}

216 217 218
template <typename PFP, typename ATTR_TYPE>
void addRowsRHS_Laplacian_Cotan_NL(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
219 220 221 222
	const VertexAttribute<unsigned int, typename PFP::MAP::IMPL> index,
	const EdgeAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& edgeWeight,
	const VertexAttribute<typename PFP::REA, typename PFP::MAP::IMPLL>& vertexArea,
	const VertexAttribute<ATTR_TYPE, typename PFP::MAP::IMPL>& attr,
223
	unsigned int coord)
Pierre Kraemer's avatar
Pierre Kraemer committed
224
{
225 226
	nlEnable(NL_NORMALIZE_ROWS) ;
	FunctorLaplacianCotanRHS_Vector<PFP, ATTR_TYPE> flc(m, index, edgeWeight, vertexArea, attr, coord) ;
227
	Algo::Topo::foreach_orbit<VERTEX>(m, flc) ;
228
	nlDisable(NL_NORMALIZE_ROWS) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
229 230
}

231 232 233 234
/*******************************************************************************
 * GET RESULTS
 *******************************************************************************/

235
template <typename PFP, typename ATTR_TYPE>
236 237
void getResult(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
238 239
	const VertexAttribute<unsigned int, typename PFP::MAP::IMPL> index,
	VertexAttribute<ATTR_TYPE, typename PFP::MAP::IMPL>& attr)
Pierre Kraemer's avatar
Pierre Kraemer committed
240
{
241
	FunctorSolverToMesh_Scalar<PFP, ATTR_TYPE> fstm(index, attr) ;
242
	Algo::Topo::foreach_orbit<VERTEX>(m, fstm) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
243 244
}

245
template <typename PFP, typename ATTR_TYPE>
246 247
void getResult(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
248 249
	const VertexAttribute<unsigned int, typename PFP::MAP::IMPL> index,
	VertexAttribute<ATTR_TYPE, typename PFP::MAP::IMPL>& attr,
250
	unsigned int coord)
Pierre Kraemer's avatar
Pierre Kraemer committed
251
{
252
	FunctorSolverToMesh_Vector<PFP, ATTR_TYPE> fstm(index, attr, coord) ;
253
	Algo::Topo::foreach_orbit<VERTEX>(m, fstm) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
254 255 256 257 258 259 260
}

} // namespace LinearSolving

} // namespace CGoGN

#endif