genericmap.hpp 7.71 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
35
36
37
38
* 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()
{
39
	Dart d = Dart::create(m_attribs[DART].insertLine());
Pierre Kraemer's avatar
Pierre Kraemer committed
40
41
42
43
44
45
46
47
	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)
{
48
	m_attribs[DART].removeLine(d.index) ;
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
49
	for (unsigned int t = 0; t < m_nbThreads; ++t)
Pierre Kraemer's avatar
Pierre Kraemer committed
50
		m_markTables[DART][t]->operator[](d.index).clear() ;
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
51

Pierre Kraemer's avatar
Pierre Kraemer committed
52
53
54
55
56
57
	for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
	{
		if (m_embeddings[orbit])
		{
			unsigned int emb = (*m_embeddings[orbit])[d.index] ;
			if(emb != EMBNULL)
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
58
59
60
61
			{
				if(m_attribs[orbit].unrefLine(emb))
				{
					for (unsigned int t = 0; t < m_nbThreads; ++t)
Pierre Kraemer's avatar
Pierre Kraemer committed
62
						m_markTables[orbit][t]->operator[](emb).clear() ;
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
63
64
				}
			}
Pierre Kraemer's avatar
Pierre Kraemer committed
65
66
		}
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
67
68
69
70
}

inline bool GenericMap::isDartValid(Dart d)
{
71
	return !d.isNil() && m_attribs[DART].used(d.index) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
72
73
74
75
}

inline unsigned int GenericMap::getNbDarts()
{
76
	return m_attribs[DART].size() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
77
78
79
80
81
82
83
84
}

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

inline bool GenericMap::isOrbitEmbedded(unsigned int orbit) const
{
85
	return (orbit == DART) || (m_embeddings[orbit] != NULL) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
86
87
88
89
90
91
92
93
94
95
96
}

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 ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
97
inline unsigned int GenericMap::getEmbedding(unsigned int orbit, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
98
99
100
{
	assert(isOrbitEmbedded(orbit) || !"Invalid parameter: orbit not embedded");

101
	if (orbit == DART)
Pierre Kraemer's avatar
Pierre Kraemer committed
102
103
104
105
106
107
108
109
		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");
Pierre Kraemer's avatar
Pierre Kraemer committed
110
	setDartEmbedding(orbit, d, getEmbedding(orbit, e));
Pierre Kraemer's avatar
Pierre Kraemer committed
111
112
113
114
115
116
117
118
119
120
121
}

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");
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
122
	FunctorSetEmb<GenericMap> fsetemb(*this, orbit, em);
123
std::cout << "EMBEDORBIT"<< std::endl;
Pierre Kraemer's avatar
Pierre Kraemer committed
124
125
126
127
128
129
130
131
132
133
134
135
136
137
	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);
	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");
Pierre Kraemer's avatar
Pierre Kraemer committed
138
139
	unsigned int dE = getEmbedding(orbit, d) ;
	unsigned int eE = getEmbedding(orbit, e) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
140
141
142
143
144
145
146
147
148
149
150
	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");
Pierre Kraemer's avatar
Pierre Kraemer committed
151
	m_attribs[orbit].copyLine(i, j) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
152
153
154
155
156
157
158
159
160
161
162
163
}

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         *
 ****************************************/

164
inline AttributeContainer& GenericMap::getAttributeContainer(unsigned int orbit)
Pierre Kraemer's avatar
Pierre Kraemer committed
165
{
166
	return m_attribs[orbit] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
167
168
}

Pierre Kraemer's avatar
Pierre Kraemer committed
169
inline AttributeMultiVector<Mark>* GenericMap::getMarkVector(unsigned int orbit, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
170
{
171
	assert(isOrbitEmbedded(orbit) || !"Invalid parameter: orbit not embedded") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
172
	return m_markTables[orbit][thread] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
173
174
}

175
inline AttributeMultiVector<unsigned int>* GenericMap::getEmbeddingAttributeVector(unsigned int orbit)
Pierre Kraemer's avatar
Pierre Kraemer committed
176
{
177
	return m_embeddings[orbit] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
178
179
}

Pierre Kraemer's avatar
Pierre Kraemer committed
180
inline void GenericMap::swapEmbeddingContainers(unsigned int orbit1, unsigned int orbit2)
Pierre Kraemer's avatar
Pierre Kraemer committed
181
{
Pierre Kraemer's avatar
Pierre Kraemer committed
182
	assert(orbit1 != orbit2 || !"Cannot swap a container with itself") ;
183
	assert((orbit1 != DART && orbit2 != DART) || !"Cannot swap the darts container") ;
184

Pierre Kraemer's avatar
Pierre Kraemer committed
185
	m_attribs[orbit1].swap(m_attribs[orbit2]) ;
186
187
188
	m_attribs[orbit1].setOrbit(orbit1) ;	// to update the orbit information
	m_attribs[orbit2].setOrbit(orbit2) ;	// in the contained AttributeMultiVectors

189
	m_embeddings[orbit1]->swap(m_embeddings[orbit2]) ;
190

191
192
	for(unsigned int t = 0; t < m_nbThreads; ++t)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
193
194
195
		AttributeMultiVector<Mark>* m = m_markTables[orbit1][t] ;
		m_markTables[orbit1][t] = m_markTables[orbit2][t] ;
		m_markTables[orbit2][t] = m ;
196

Pierre Kraemer's avatar
Pierre Kraemer committed
197
198
199
		MarkSet ms = m_marksets[orbit1][t] ;
		m_marksets[orbit1][t] = m_marksets[orbit2][t] ;
		m_marksets[orbit2][t] = ms ;
200
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
201
202
203
204
205
206
}

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

Pierre Kraemer's avatar
Pierre Kraemer committed
207
inline Mark GenericMap::getNewMark(unsigned int cell, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
208
{
Pierre Kraemer's avatar
Pierre Kraemer committed
209
210
	assert(isOrbitEmbedded(cell) || !"Try to get a marker on non embedded cell! ") ;
	return m_marksets[cell][thread].getNewMark() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
211
212
}

Pierre Kraemer's avatar
Pierre Kraemer committed
213
inline void GenericMap::releaseMark(Mark m, unsigned int cell, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
214
215
{
	assert(isOrbitEmbedded(cell) || !"Try to release a marker on non embedded cell! ") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
216
	m_marksets[cell][thread].releaseMark(m) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
217
218
219
220
221
222
223
224
}

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

inline Dart GenericMap::begin()
{
225
	return Dart::create(m_attribs[DART].begin());
Pierre Kraemer's avatar
Pierre Kraemer committed
226
227
228
229
}

inline Dart GenericMap::end()
{
230
	return Dart::create(m_attribs[DART].end()) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
231
232
233
234
}

inline void GenericMap::next(Dart& d)
{
235
	m_attribs[DART].next(d.index) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
236
237
238
}

} //namespace CGoGN