genericmap.hpp 7.54 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
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

namespace CGoGN
{
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//#ifndef CGoGN_FORCE_MR
inline unsigned int GenericMap::dartIndex(Dart d)
{
	if (m_isMultiRes)
	{
		std::cout << "Not implemented"<< std::endl;
		return 0xffffffff;
	}
	return d.index;
}
//#elif CGoGN_FORCE_MR == 1
//inline unsigned int GenericMap::dartIndex(Dart d)
//{
//	std::cout << "Not implemented"<< std::endl;
//	return 0xffffffff;
//}
//#else
//inline unsigned int GenericMap::dartIndex(Dart d)
Sylvain Thery's avatar
Sylvain Thery committed
45
//{
46
//	return d.index;
Sylvain Thery's avatar
Sylvain Thery committed
47
//}
48
49
50
51
52
//#endif




Pierre Kraemer's avatar
Pierre Kraemer committed
53
54
55
56
57
58
59

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

inline Dart GenericMap::newDart()
{
60
	Dart d = Dart::create(m_attribs[DART].insertLine());
61
	unsigned int d_index = dartIndex(d);
Pierre Kraemer's avatar
Pierre Kraemer committed
62
63
	for(unsigned int i = 0; i < NB_ORBITS; ++i)
		if (m_embeddings[i])
64
65
66
67
		{
			(*m_embeddings[i])[d_index] = EMBNULL ;
		}

Pierre Kraemer's avatar
Pierre Kraemer committed
68
69
70
71
72
	return d ;
}

inline void GenericMap::deleteDart(Dart d)
{
73
74
	unsigned int d_index = dartIndex(d);
	m_attribs[DART].removeLine(d_index) ;
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
75
	for (unsigned int t = 0; t < m_nbThreads; ++t)
76
		m_markTables[DART][t]->operator[](d_index).clear() ;
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
77

Pierre Kraemer's avatar
Pierre Kraemer committed
78
79
80
81
	for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
	{
		if (m_embeddings[orbit])
		{
82
			unsigned int emb = (*m_embeddings[orbit])[d_index] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
83
			if(emb != EMBNULL)
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
84
85
86
87
			{
				if(m_attribs[orbit].unrefLine(emb))
				{
					for (unsigned int t = 0; t < m_nbThreads; ++t)
Pierre Kraemer's avatar
Pierre Kraemer committed
88
						m_markTables[orbit][t]->operator[](emb).clear() ;
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
89
90
				}
			}
Pierre Kraemer's avatar
Pierre Kraemer committed
91
92
		}
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
93
94
95
96
}

inline bool GenericMap::isDartValid(Dart d)
{
97
	return !d.isNil() && m_attribs[DART].used( dartIndex(d)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
98
99
100
101
}

inline unsigned int GenericMap::getNbDarts()
{
102
	return m_attribs[DART].size() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
103
104
105
106
107
108
109
110
}

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

inline bool GenericMap::isOrbitEmbedded(unsigned int orbit) const
{
111
	return (orbit == DART) || (m_embeddings[orbit] != NULL) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
112
113
114
115
116
117
118
119
120
121
122
}

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
123
inline unsigned int GenericMap::getEmbedding(unsigned int orbit, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
124
125
126
{
	assert(isOrbitEmbedded(orbit) || !"Invalid parameter: orbit not embedded");

127
128
	unsigned int d_index = dartIndex(d);

129
	if (orbit == DART)
130
		return d_index;
Pierre Kraemer's avatar
Pierre Kraemer committed
131

132
	return (*m_embeddings[orbit])[d_index] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
133
134
135
136
137
}

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
138
	setDartEmbedding(orbit, d, getEmbedding(orbit, e));
Pierre Kraemer's avatar
Pierre Kraemer committed
139
140
141
142
143
144
145
146
147
148
149
}

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
150
	FunctorSetEmb<GenericMap> fsetemb(*this, orbit, em);
Pierre Kraemer's avatar
Pierre Kraemer committed
151
152
153
154
155
156
157
158
159
160
161
162
163
164
	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
165
166
	unsigned int dE = getEmbedding(orbit, d) ;
	unsigned int eE = getEmbedding(orbit, e) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
167
168
169
170
171
172
173
174
175
176
177
	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
178
	m_attribs[orbit].copyLine(i, j) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
179
180
181
182
183
184
185
186
187
188
189
190
}

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

191
inline AttributeContainer& GenericMap::getAttributeContainer(unsigned int orbit)
Pierre Kraemer's avatar
Pierre Kraemer committed
192
{
193
	return m_attribs[orbit] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
194
195
}

Pierre Kraemer's avatar
Pierre Kraemer committed
196
inline AttributeMultiVector<Mark>* GenericMap::getMarkVector(unsigned int orbit, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
197
{
198
	assert(isOrbitEmbedded(orbit) || !"Invalid parameter: orbit not embedded") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
199
	return m_markTables[orbit][thread] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
200
201
}

202
inline AttributeMultiVector<unsigned int>* GenericMap::getEmbeddingAttributeVector(unsigned int orbit)
Pierre Kraemer's avatar
Pierre Kraemer committed
203
{
204
	return m_embeddings[orbit] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
205
206
207
208
209
210
211
212
}

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

inline Dart GenericMap::begin()
{
213
	return Dart::create(m_attribs[DART].begin());
Pierre Kraemer's avatar
Pierre Kraemer committed
214
215
216
217
}

inline Dart GenericMap::end()
{
218
	return Dart::create(m_attribs[DART].end()) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
219
220
221
222
}

inline void GenericMap::next(Dart& d)
{
223
224
225
226
	unsigned int d_index = dartIndex(d);
	m_attribs[DART].next(d_index) ;

	d = Dart::create(d_index);
Pierre Kraemer's avatar
Pierre Kraemer committed
227
228
}

Sylvain Thery's avatar
Sylvain Thery committed
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/****************************************
 *  TOPOLOGICAL ATTRIBUTES MANAGEMENT   *
 ****************************************/

inline AttributeMultiVector<Dart>* GenericMap::addRelation(const std::string& name)
{
	AttributeContainer& cont = m_attribs[DART] ;
	AttributeMultiVector<Dart>* amv = cont.addAttribute<Dart>(name) ;

	// set new relation to fix point for all the darts of the map
	for(unsigned int i = cont.begin(); i < cont.end(); cont.next(i))
		amv->operator[](i) = i ;

	return amv ;
}

Sylvain Thery's avatar
Sylvain Thery committed
245
246
247
248
249
250
251
inline AttributeMultiVector<Dart>* GenericMap::getRelation(const std::string& name)
{
	AttributeContainer& cont = m_attribs[DART] ;
	AttributeMultiVector<Dart>* amv = cont.getDataVector<Dart>(cont.getAttributeIndex(name)) ;
	return amv ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
252
} //namespace CGoGN