genericmap.hpp 8.63 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg                *
*                                                                              *
* 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.           *
*                                                                              *
* Web site: https://iggservis.u-strasbg.fr/CGoGN/                              *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

namespace CGoGN
{

inline bool GenericMap::chechXmlNode(xmlNodePtr node, const std::string& name)
{
	return (strcmp((char*)(node->name),(char*)(name.c_str())) == 0);
}

/****************************************
 *           DARTS MANAGEMENT           *
 ****************************************/

inline Dart GenericMap::newDart()
{
	Dart d = Dart::create(m_attribs[DART_ORBIT].insertLine());
	for(unsigned int i = 0; i < NB_ORBITS; ++i)
		if (m_embeddings[i])
			(*m_embeddings[i])[d.index] = EMBNULL ;
	return d ;
}

inline void GenericMap::deleteDart(Dart d)
{
	m_attribs[DART_ORBIT].removeLine(d.index) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
49
50
51
52
53
54
55
56
	for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
	{
		if (m_embeddings[orbit])
		{
			unsigned int emb = (*m_embeddings[orbit])[d.index] ;
			if(emb != EMBNULL)
				m_attribs[orbit].unrefLine(emb) ;
		}
sylvain thery's avatar
sylvain thery committed
57
58
		for (unsigned int t=0; t<m_nbThreads; ++t)
			m_markerTables[DART_ORBIT][t]->operator[](d.index).clear() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
59
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
}

inline bool GenericMap::isDartValid(Dart d)
{
	return !d.isNil() && m_attribs[DART_ORBIT].used(d.index) ;
}

inline unsigned int GenericMap::getNbDarts()
{
	return m_attribs[DART_ORBIT].size() ;
}

/****************************************
 *         EMBEDDING MANAGEMENT         *
 ****************************************/

inline bool GenericMap::isOrbitEmbedded(unsigned int orbit) const
{
	return (orbit == DART_ORBIT) || (m_embeddings[orbit] != NULL) ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
81
82
83
84
85
inline AttribMultiVect<unsigned int>* GenericMap::getEmbeddingAttributeVector(unsigned int orbit) const
{
	return m_embeddings[orbit] ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
inline unsigned int GenericMap::nbEmbeddings() const
{
	unsigned int nb = 0;
	for(unsigned int i = 0; i < NB_ORBITS; ++i)
		if (isOrbitEmbedded(i))
			++nb;
	return nb ;
}

inline unsigned int GenericMap::getEmbedding(Dart d, unsigned int orbit)
{
	assert(isOrbitEmbedded(orbit) || !"Invalid parameter: orbit not embedded");

	if (orbit == DART_ORBIT)
		return d.index;

	unsigned int emb = (*m_embeddings[orbit])[d.index] ;
	if(emb != EMBNULL)
		return emb ;

Pierre Kraemer's avatar
Pierre Kraemer committed
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
	class FunctorGetLazyEmb: public FunctorType
	{
	protected:
		GenericMap& m_map;
		unsigned int m_orbit;
		AttribMultiVect<unsigned int>* m_emb;
		unsigned int m_val;
		std::vector<Dart> m_darts;

	public:
		FunctorGetLazyEmb(GenericMap& map, unsigned int orbit):
			m_map(map), m_orbit(orbit), m_val(EMBNULL)
		{
			m_emb = m_map.getEmbeddingAttributeVector(orbit) ;
			m_darts.reserve(8) ;
		}

		bool operator()(Dart d)
		{
			if ((*m_emb)[d.index] != EMBNULL)
			{
				m_val = (*m_emb)[d.index];
				return true;
			}
			m_darts.push_back(d);
			return false;
		}

		unsigned int getVal()
		{
			if(m_val != EMBNULL)
			{
				AttribContainer& cont = m_map.getAttributeContainer(m_orbit) ;
				for(std::vector<Dart>::iterator it = m_darts.begin(); it != m_darts.end(); ++it)
				{
					(*m_emb)[it->index] = m_val;
					cont.refLine(m_val) ;
				}
			}

			return m_val;
		}
	};

	FunctorGetLazyEmb fle(*this, orbit);
Pierre Kraemer's avatar
Pierre Kraemer committed
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
	foreach_dart_of_orbit(orbit, d, fle);

	return fle.getVal();
}

inline unsigned int GenericMap::getDartEmbedding(unsigned int orbit, Dart d)
{
	assert(isOrbitEmbedded(orbit) || !"Invalid parameter: orbit not embedded");

	if (orbit == DART_ORBIT)
		return d.index;

	return (*m_embeddings[orbit])[d.index] ;
}

inline void GenericMap::copyDartEmbedding(unsigned int orbit, Dart d, Dart e)
{
	assert(isOrbitEmbedded(orbit) || !"Invalid parameter: orbit not embedded");
	setDartEmbedding(orbit, d, getDartEmbedding(orbit, e));
}

inline unsigned int GenericMap::newCell(unsigned int orbit)
{
	assert(isOrbitEmbedded(orbit) || !"Invalid parameter: orbit not embedded");
	return m_attribs[orbit].insertLine();
}

inline void GenericMap::embedOrbit(unsigned int orbit, Dart d, unsigned int em)
{
	assert(isOrbitEmbedded(orbit) || !"Invalid parameter: orbit not embedded");
	FunctorSetEmb<GenericMap> fsetemb(*this,orbit,em);
	foreach_dart_of_orbit(orbit, d, fsetemb);
}

inline unsigned int GenericMap::embedNewCell(unsigned int orbit, Dart d)
{
	assert(isOrbitEmbedded(orbit) || !"Invalid parameter: orbit not embedded");
	unsigned int em = newCell(orbit);
//	setDartEmbedding(orbit, d, em) ; // possible ?? utile ??
	embedOrbit(orbit, d, em);
	return em;
}

inline void GenericMap::copyCell(unsigned int orbit, Dart d, Dart e)
{
	assert(isOrbitEmbedded(orbit) || !"Invalid parameter: orbit not embedded");
	unsigned int dE = getEmbedding(d, orbit) ;
	unsigned int eE = getEmbedding(e, orbit) ;
	if(eE != EMBNULL)	// if the source is NULL, nothing to copy
	{
		if(dE == EMBNULL)	// if the dest is NULL, create a new cell
		{
			dE = embedNewCell(orbit, d) ;
		}
		m_attribs[orbit].copyLine(dE, eE) ;	// copy the data
	}
}

inline void GenericMap::copyCell(unsigned int orbit, unsigned int i, unsigned int j)
{
	assert(isOrbitEmbedded(orbit) || !"Invalid parameter: orbit not embedded");
	m_attribs[orbit].copyLine(i,j) ;
}

inline void GenericMap::initCell(unsigned int orbit, unsigned int i)
{
	assert(isOrbitEmbedded(orbit) || !"Invalid parameter: orbit not embedded");
	m_attribs[orbit].initLine(i) ;
}

/****************************************
 *        ATTRIBUTES MANAGEMENT         *
 ****************************************/

template <typename T>
inline AttribMultiVect<T>& GenericMap::getAttributeVector(unsigned int idAttr)
{
Pierre Kraemer's avatar
Pierre Kraemer committed
228
	assert(idAttr != AttribContainer::UNKNOWN) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
229
230
231
	return m_attribs[AttribContainer::orbitAttr(idAttr)].getDataVector<T>(AttribContainer::indexAttr(idAttr)) ;
}

Sylvain Thery's avatar
Sylvain Thery committed
232
inline AttribMultiVect<Mark>* GenericMap::getMarkerVector(unsigned int orbit, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
233
234
{
	assert(isOrbitEmbedded(orbit) || !"Invalid parameter: orbit not embedded");
Sylvain Thery's avatar
Sylvain Thery committed
235
	return m_markerTables[orbit][thread] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
236
237
238
239
}

inline AttribMultiVectGen& GenericMap::getMultiVec(unsigned int idAttr)
{
Pierre Kraemer's avatar
Pierre Kraemer committed
240
	assert(idAttr != AttribContainer::UNKNOWN) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
241
242
243
244
245
246
247
248
249
250
251
252
	return m_attribs[AttribContainer::orbitAttr(idAttr)].getVirtualDataVector(AttribContainer::indexAttr(idAttr)) ;
}

inline AttribContainer& GenericMap::getAttributeContainer(unsigned int orbit)
{
	return m_attribs[orbit] ;
}

/****************************************
 *          MARKERS MANAGEMENT          *
 ****************************************/

Sylvain Thery's avatar
Sylvain Thery committed
253
inline Marker GenericMap::getNewMarker(unsigned int cell, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
254
{
255

256
//	assert(isOrbitEmbedded(cell) || !"Try to get a marker on non embedded cell! ") ;
Sylvain Thery's avatar
Sylvain Thery committed
257
	return m_orbMarker[cell][thread].getNewMarker(cell) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
258
259
}

Sylvain Thery's avatar
Sylvain Thery committed
260
inline void GenericMap::releaseMarker(Marker m, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
261
262
263
{
	unsigned int cell = m.getCell();
	assert(isOrbitEmbedded(cell) || !"Try to release a marker on non embedded cell! ") ;
Sylvain Thery's avatar
Sylvain Thery committed
264
	m_orbMarker[cell][thread].releaseMarker(m) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
}

/****************************************
 *           DARTS TRAVERSALS           *
 ****************************************/

inline Dart GenericMap::begin()
{
	return Dart::create(m_attribs[DART_ORBIT].begin());
}

inline Dart GenericMap::end()
{
	return Dart::create(m_attribs[DART_ORBIT].end()) ;
}

inline void GenericMap::next(Dart& d)
{
	m_attribs[DART_ORBIT].next(d.index) ;
}

} //namespace CGoGN