basic.h 9.75 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 31 32 33 34 35 36 37
#include "Algo/LinearSolving/matrixSetup.h"

namespace CGoGN
{

namespace LinearSolving
{

38 39 40 41
/*******************************************************************************
 * VARIABLES SETUP
 *******************************************************************************/

42
template <typename PFP, typename ATTR_TYPE>
43 44
void setupVariables(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
45 46 47
	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
48
{
49
	FunctorMeshToSolver_Scalar<PFP, ATTR_TYPE> fmts(index, fm, attr) ;
50
	m.template foreach_orbit<VERTEX>(fmts) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
51 52
}

53
template <typename PFP, typename ATTR_TYPE>
54 55
void setupVariables(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
56 57 58
	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,
59
	unsigned int coord)
Pierre Kraemer's avatar
Pierre Kraemer committed
60
{
61
	FunctorMeshToSolver_Vector<PFP, ATTR_TYPE> fmts(index, fm, attr, coord) ;
62
	m.template foreach_orbit<VERTEX>(fmts) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
63 64
}

65 66 67 68
/*******************************************************************************
 * MATRIX SETUP : EQUALITY
 *******************************************************************************/

69
template <typename PFP, typename ATTR_TYPE>
70 71
void addRowsRHS_Equality(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
72 73 74
	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)
75
{
76 77 78 79
	nlEnable(NL_NORMALIZE_ROWS) ;
	FunctorEquality_PerVertexWeight_Scalar<PFP, ATTR_TYPE> feq(index, attr, weight) ;
	m.template foreach_orbit<VERTEX>(feq) ;
	nlDisable(NL_NORMALIZE_ROWS) ;
80 81
}

82
template <typename PFP, typename ATTR_TYPE>
83 84
void addRowsRHS_Equality(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
85 86
	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
87 88
	float weight)
{
89 90 91 92
	nlEnable(NL_NORMALIZE_ROWS) ;
	FunctorEquality_UniformWeight_Scalar<PFP, ATTR_TYPE> feq(index, attr, weight) ;
	m.template foreach_orbit<VERTEX>(feq) ;
	nlDisable(NL_NORMALIZE_ROWS) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
93 94
}

95
template <typename PFP, typename ATTR_TYPE>
Pierre Kraemer's avatar
Pierre Kraemer committed
96 97
void addRowsRHS_Equality(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
98 99 100
	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
101 102
	unsigned int coord)
{
103 104 105 106
	nlEnable(NL_NORMALIZE_ROWS) ;
	FunctorEquality_PerVertexWeight_Vector<PFP, ATTR_TYPE> feq(index, attr, weight, coord) ;
	m.template foreach_orbit<VERTEX>(feq) ;
	nlDisable(NL_NORMALIZE_ROWS) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
107 108
}

109
template <typename PFP, typename ATTR_TYPE>
Pierre Kraemer's avatar
Pierre Kraemer committed
110 111
void addRowsRHS_Equality(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
112 113
	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
114
	float weight,
115 116
	unsigned int coord)
{
117 118 119 120
	nlEnable(NL_NORMALIZE_ROWS) ;
	FunctorEquality_UniformWeight_Vector<PFP, ATTR_TYPE> feq(index, attr, weight, coord) ;
	m.template foreach_orbit<VERTEX>(feq) ;
	nlDisable(NL_NORMALIZE_ROWS) ;
121 122 123 124 125 126
}

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

127
template <typename PFP>
128 129
void addRows_Laplacian_Topo(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
130
	const VertexAttribute<unsigned int, typename PFP::MAP::IMPL> index)
131
{
132 133
	nlEnable(NL_NORMALIZE_ROWS) ;
	FunctorLaplacianTopo<PFP> flt(m, index) ;
134
	m.template foreach_orbit<VERTEX>(flt) ;
135
	nlDisable(NL_NORMALIZE_ROWS) ;
136 137
}

138
template <typename PFP, typename ATTR_TYPE>
139 140
void addRowsRHS_Laplacian_Topo(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
141 142
	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
143
{
144 145
	nlEnable(NL_NORMALIZE_ROWS) ;
	FunctorLaplacianTopoRHS_Scalar<PFP, ATTR_TYPE> flt(m, index, attr) ;
146
	m.template foreach_orbit<VERTEX>(flt) ;
147
	nlDisable(NL_NORMALIZE_ROWS) ;
148 149
}

150
template <typename PFP, typename ATTR_TYPE>
151 152
void addRowsRHS_Laplacian_Topo(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
153 154
	const VertexAttribute<unsigned int, typename PFP::MAP::IMPL> index,
	const VertexAttribute<ATTR_TYPE, typename PFP::MAP::IMPL>& attr,
155 156
	unsigned int coord)
{
157 158
	nlEnable(NL_NORMALIZE_ROWS) ;
	FunctorLaplacianTopoRHS_Vector<PFP, ATTR_TYPE> flt(m, index, attr, coord) ;
159
	m.template foreach_orbit<VERTEX>(flt) ;
160
	nlDisable(NL_NORMALIZE_ROWS) ;
161 162 163 164 165 166
}

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

167
template <typename PFP>
168 169
void addRows_Laplacian_Cotan(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
170 171 172
	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)
173
{
174 175
	nlEnable(NL_NORMALIZE_ROWS) ;
	FunctorLaplacianCotan<PFP> flc(m, index, edgeWeight, vertexArea) ;
176
	m.template foreach_orbit<VERTEX>(flc) ;
177
	nlDisable(NL_NORMALIZE_ROWS) ;
178
}
Pierre Kraemer's avatar
Pierre Kraemer committed
179

180
template <typename PFP, typename ATTR_TYPE>
181 182
void addRowsRHS_Laplacian_Cotan(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
183 184 185 186
	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
187
{
188 189
	nlEnable(NL_NORMALIZE_ROWS) ;
	FunctorLaplacianCotanRHS_Scalar<PFP, ATTR_TYPE> flc(m, index, edgeWeight, vertexArea, attr) ;
190
	m.template foreach_orbit<VERTEX>(flc) ;
191
	nlDisable(NL_NORMALIZE_ROWS) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
192 193
}

194
template <typename PFP, typename ATTR_TYPE>
195 196
void addRowsRHS_Laplacian_Cotan(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
197 198 199 200
	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,
201
	unsigned int coord)
Pierre Kraemer's avatar
Pierre Kraemer committed
202
{
203 204
	nlEnable(NL_NORMALIZE_ROWS) ;
	FunctorLaplacianCotanRHS_Vector<PFP, ATTR_TYPE> flc(m, index, edgeWeight, vertexArea, attr, coord) ;
205
	m.template foreach_orbit<VERTEX>(flc) ;
206
	nlDisable(NL_NORMALIZE_ROWS) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
207 208
}

209 210 211
template <typename PFP, typename ATTR_TYPE>
void addRowsRHS_Laplacian_Cotan_NL(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
212 213 214 215
	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,
216
	unsigned int coord)
Pierre Kraemer's avatar
Pierre Kraemer committed
217
{
218 219 220 221
	nlEnable(NL_NORMALIZE_ROWS) ;
	FunctorLaplacianCotanRHS_Vector<PFP, ATTR_TYPE> flc(m, index, edgeWeight, vertexArea, attr, coord) ;
	m.template foreach_orbit<VERTEX>(flc) ;
	nlDisable(NL_NORMALIZE_ROWS) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
222 223
}

224 225 226 227
/*******************************************************************************
 * GET RESULTS
 *******************************************************************************/

228
template <typename PFP, typename ATTR_TYPE>
229 230
void getResult(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
231 232
	const VertexAttribute<unsigned int, typename PFP::MAP::IMPL> index,
	VertexAttribute<ATTR_TYPE, typename PFP::MAP::IMPL>& attr)
Pierre Kraemer's avatar
Pierre Kraemer committed
233
{
234
	FunctorSolverToMesh_Scalar<PFP, ATTR_TYPE> fstm(index, attr) ;
235
	m.template foreach_orbit<VERTEX>(fstm) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
236 237
}

238
template <typename PFP, typename ATTR_TYPE>
239 240
void getResult(
	typename PFP::MAP& m,
Pierre Kraemer's avatar
Pierre Kraemer committed
241 242
	const VertexAttribute<unsigned int, typename PFP::MAP::IMPL> index,
	VertexAttribute<ATTR_TYPE, typename PFP::MAP::IMPL>& attr,
243
	unsigned int coord)
Pierre Kraemer's avatar
Pierre Kraemer committed
244
{
245
	FunctorSolverToMesh_Vector<PFP, ATTR_TYPE> fstm(index, attr, coord) ;
246
	m.template foreach_orbit<VERTEX>(fstm) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
247 248 249 250 251 252 253
}

} // namespace LinearSolving

} // namespace CGoGN

#endif