variablesSetup.h 5.01 KB
Newer Older
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           *
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/                                           *
21 22 23 24 25 26 27 28 29 30 31 32 33
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef __LINEAR_SOLVING_VARIABLES_SETUP__
#define __LINEAR_SOLVING_VARIABLES_SETUP__

namespace CGoGN
{

namespace LinearSolving
{

34
template <typename PFP, typename ATTR_TYPE>
35 36
class FunctorMeshToSolver_Scalar : public FunctorType
{
Pierre Kraemer's avatar
Pierre Kraemer committed
37 38 39
	typedef typename PFP::MAP MAP;
	typedef typename PFP::MAP::IMPL MAP_IMPL;

40
protected:
Pierre Kraemer's avatar
Pierre Kraemer committed
41 42 43
	const VertexAttribute<unsigned int, MAP_IMPL>& indexTable ;
	const CellMarker<MAP, VERTEX>& freeMarker ;
	const VertexAttribute<ATTR_TYPE, MAP_IMPL>& attrTable ;
44 45 46 47
	bool lockedVertices ;

public:
	FunctorMeshToSolver_Scalar(
Pierre Kraemer's avatar
Pierre Kraemer committed
48 49 50
		const VertexAttribute<unsigned int, MAP_IMPL>& index,
		const CellMarker<MAP, VERTEX>& fm,
		const VertexAttribute<ATTR_TYPE, MAP_IMPL>& attr
51
	) :	indexTable(index), freeMarker(fm), attrTable(attr), lockedVertices(false)
52 53 54 55
	{}

	bool operator()(Dart d)
	{
56
		nlSetVariable(indexTable[d], attrTable[d]);
57
		if(!freeMarker.isMarked(d))
58
		{
59
			nlLockVariable(indexTable[d]);
60 61 62 63
			lockedVertices = true ;
		}
		return false ;
	}
64

65 66 67
	bool hasLockedVertices() { return lockedVertices ; }
} ;

68
template <typename PFP, typename ATTR_TYPE>
69 70
class FunctorMeshToSolver_Vector : public FunctorType
{
Pierre Kraemer's avatar
Pierre Kraemer committed
71 72 73
	typedef typename PFP::MAP MAP;
	typedef typename PFP::MAP::IMPL MAP_IMPL;

74
protected:
Pierre Kraemer's avatar
Pierre Kraemer committed
75 76 77
	const VertexAttribute<unsigned int, MAP_IMPL>& indexTable ;
	const CellMarker<MAP, VERTEX>& freeMarker ;
	const VertexAttribute<ATTR_TYPE, MAP_IMPL>& attrTable ;
78 79 80 81 82
	unsigned int coord ;
	bool lockedVertices ;

public:
	FunctorMeshToSolver_Vector(
Pierre Kraemer's avatar
Pierre Kraemer committed
83 84 85
		const VertexAttribute<unsigned int, MAP_IMPL>& index,
		const CellMarker<MAP, VERTEX>& fm,
		const VertexAttribute<ATTR_TYPE, MAP_IMPL>& attr,
86
		unsigned int c
87
	) :	indexTable(index), freeMarker(fm), attrTable(attr), coord(c), lockedVertices(false)
88 89 90 91
	{}

	bool operator()(Dart d)
	{
92
		nlSetVariable(indexTable[d], (attrTable[d])[coord]);
93
		if(!freeMarker.isMarked(d))
94
		{
95
			nlLockVariable(indexTable[d]);
96 97 98 99
			lockedVertices = true ;
		}
		return false ;
	}
100

101 102 103
	bool hasLockedVertices() { return lockedVertices ; }
} ;

104
template <typename PFP, typename ATTR_TYPE>
105 106
class FunctorSolverToMesh_Scalar : public FunctorType
{
Pierre Kraemer's avatar
Pierre Kraemer committed
107 108 109
	typedef typename PFP::MAP MAP;
	typedef typename PFP::MAP::IMPL MAP_IMPL;

110
protected:
Pierre Kraemer's avatar
Pierre Kraemer committed
111 112
	const VertexAttribute<unsigned int, MAP_IMPL>& indexTable ;
	VertexAttribute<ATTR_TYPE, MAP_IMPL>& attrTable ;
113 114 115

public:
	FunctorSolverToMesh_Scalar(
Pierre Kraemer's avatar
Pierre Kraemer committed
116 117
		const VertexAttribute<unsigned int, MAP_IMPL>& index,
		VertexAttribute<ATTR_TYPE, MAP_IMPL>& attr
118
	) :	indexTable(index), attrTable(attr)
119 120 121 122
	{}

	bool operator()(Dart d)
	{
123
		attrTable[d] = nlGetVariable(indexTable[d]) ;
124 125 126 127
		return false ;
	}
} ;

128
template <typename PFP, typename ATTR_TYPE>
129 130
class FunctorSolverToMesh_Vector : public FunctorType
{
Pierre Kraemer's avatar
Pierre Kraemer committed
131 132 133
	typedef typename PFP::MAP MAP;
	typedef typename PFP::MAP::IMPL MAP_IMPL;

134
protected:
Pierre Kraemer's avatar
Pierre Kraemer committed
135 136
	const VertexAttribute<unsigned int, MAP_IMPL>& indexTable ;
	VertexAttribute<ATTR_TYPE, MAP_IMPL>& attrTable ;
137 138 139 140
	unsigned int coord ;

public:
	FunctorSolverToMesh_Vector(
Pierre Kraemer's avatar
Pierre Kraemer committed
141 142
		const VertexAttribute<unsigned int, MAP_IMPL>& index,
		VertexAttribute<ATTR_TYPE, MAP_IMPL>& attr,
143
		unsigned int c
144
	) :	indexTable(index), attrTable(attr), coord(c)
145 146 147 148
	{}

	bool operator()(Dart d)
	{
149
		(attrTable[d])[coord] = nlGetVariable(indexTable[d]) ;
150 151 152 153 154 155 156 157 158
		return false ;
	}
} ;

} // namespace LinearSolving

} // namespace CGoGN

#endif