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

25
#include "Topology/generic/dartmarker.h"
26
27
#include "Topology/generic/traversor/traversorCell.h"
#include "Topology/generic/traversor/traversorFactory.h"
28

Pierre Kraemer's avatar
Pierre Kraemer committed
29
30
namespace CGoGN
{
Pierre Kraemer's avatar
Pierre Kraemer committed
31

Pierre Kraemer's avatar
Pierre Kraemer committed
32
33
34
35
36
37
/****************************************
 *           DARTS MANAGEMENT           *
 ****************************************/

inline Dart GenericMap::newDart()
{
38
	unsigned int di = m_attribs[DART].insertLine();		// insert a new dart line
Pierre Kraemer's avatar
Pierre Kraemer committed
39
	for(unsigned int i = 0; i < NB_ORBITS; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
40
	{
41
42
		if (m_embeddings[i])							// set all its embeddings
			(*m_embeddings[i])[di] = EMBNULL ;			// to EMBNULL
Pierre Kraemer's avatar
Pierre Kraemer committed
43
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
44

Pierre Kraemer's avatar
Pierre Kraemer committed
45
	return Dart::create(di) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
46
47
}

Pierre Kraemer's avatar
Pierre Kraemer committed
48
49
50
51
inline void GenericMap::deleteDartLine(unsigned int index)
{
	m_attribs[DART].removeLine(index) ;	// free the dart line

Pierre Kraemer's avatar
Pierre Kraemer committed
52
53
	for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
54
		if (m_embeddings[orbit])									// for each embedded orbit
Pierre Kraemer's avatar
Pierre Kraemer committed
55
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
56
			unsigned int emb = (*m_embeddings[orbit])[index] ;		// get the embedding of the dart
Pierre Kraemer's avatar
Pierre Kraemer committed
57
			if(emb != EMBNULL)
Sylvain Thery's avatar
Sylvain Thery committed
58
				m_attribs[orbit].unrefLine(emb);					// and unref the corresponding line
Pierre Kraemer's avatar
Pierre Kraemer committed
59
60
		}
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
61
}
Pierre Kraemer's avatar
Pierre Kraemer committed
62

Pierre Kraemer's avatar
Pierre Kraemer committed
63
inline unsigned int GenericMap::copyDartLine(unsigned int index)
Pierre Kraemer's avatar
Pierre Kraemer committed
64
{
65
66
	unsigned int newindex = m_attribs[DART].insertLine() ;	// create a new dart line
	m_attribs[DART].copyLine(newindex, index) ;				// copy the given dart line
Pierre Kraemer's avatar
Pierre Kraemer committed
67
68
	for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
69
70
71
72
73
74
		if (m_embeddings[orbit])
		{
			unsigned int emb = (*m_embeddings[orbit])[newindex] ;	// add a ref to the cells pointed
			if(emb != EMBNULL)										// by the new dart line
				m_attribs[orbit].refLine(emb) ;
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
75
76
	}
	return newindex ;
Pierre Kraemer's avatar
Pierre Kraemer committed
77
78
}

79
80
81
82
//inline bool GenericMap::isDartValid(Dart d)
//{
//	return !d.isNil() && m_attribs[DART].used(dartIndex(d)) ;
//}
Pierre Kraemer's avatar
Pierre Kraemer committed
83

Pierre Kraemer's avatar
Pierre Kraemer committed
84
85
86
87
/****************************************
 *         EMBEDDING MANAGEMENT         *
 ****************************************/

88
89
template <unsigned int ORBIT>
inline bool GenericMap::isOrbitEmbedded() const
Pierre Kraemer's avatar
Pierre Kraemer committed
90
{
91
	return (ORBIT == DART) || (m_embeddings[ORBIT] != NULL) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
92
93
}

94
inline bool GenericMap::isOrbitEmbedded(unsigned int orbit) const
Pierre Kraemer's avatar
Pierre Kraemer committed
95
{
96
	return (orbit == DART) || (m_embeddings[orbit] != NULL) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
97
98
}

99
100
template <unsigned int ORBIT>
inline unsigned int GenericMap::newCell()
Pierre Kraemer's avatar
Pierre Kraemer committed
101
{
102
	assert(isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");
103
	return m_attribs[ORBIT].insertLine();
Pierre Kraemer's avatar
Pierre Kraemer committed
104
105
}

106
107
template <unsigned int ORBIT>
inline void GenericMap::copyCell(unsigned int i, unsigned int j)
Pierre Kraemer's avatar
Pierre Kraemer committed
108
{
109
	assert(isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");
110
	m_attribs[ORBIT].copyLine(i, j) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
111
112
}

113
114
template <unsigned int ORBIT>
inline void GenericMap::initCell(unsigned int i)
Pierre Kraemer's avatar
Pierre Kraemer committed
115
{
116
	assert(isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");
117
	m_attribs[ORBIT].initLine(i) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
118
119
}

Pierre Kraemer's avatar
Pierre Kraemer committed
120
/****************************************
Pierre Kraemer's avatar
Pierre Kraemer committed
121
 *   ATTRIBUTES CONTAINERS MANAGEMENT   *
Pierre Kraemer's avatar
Pierre Kraemer committed
122
123
 ****************************************/

124
125
126
127
128
inline unsigned int GenericMap::getNbCells(unsigned int orbit)
{
	return m_attribs[orbit].size() ;
}

129
130
template <unsigned int ORBIT>
inline AttributeContainer& GenericMap::getAttributeContainer()
Pierre Kraemer's avatar
Pierre Kraemer committed
131
{
132
	return m_attribs[ORBIT] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
133
134
}

Sylvain Thery's avatar
Sylvain Thery committed
135
136
137
138
139
140
template <unsigned int ORBIT>
inline const AttributeContainer& GenericMap::getAttributeContainer() const
{
	return m_attribs[ORBIT] ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
141
142
143
144
145
inline AttributeContainer& GenericMap::getAttributeContainer(unsigned int orbit)
{
	return m_attribs[orbit] ;
}

Sylvain Thery's avatar
Sylvain Thery committed
146
147
148
149
150
inline const AttributeContainer& GenericMap::getAttributeContainer(unsigned int orbit) const
{
	return m_attribs[orbit] ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
151
152
153
154
155
inline AttributeMultiVectorGen* GenericMap::getAttributeVectorGen(unsigned int orbit, const std::string& nameAttr)
{
	return m_attribs[orbit].getVirtualDataVector(nameAttr) ;
}

Sylvain Thery's avatar
Sylvain Thery committed
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175

template <unsigned int ORBIT>
AttributeMultiVector<MarkerBool>* GenericMap::askMarkVector()
{
	assert(isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded") ;

//	boost::mutex::scoped_lock lockMV(m_MarkerStorageMutex[ORBIT]);
	if (!m_markVectors_free[ORBIT].empty())
	{
		AttributeMultiVector<MarkerBool>* amv = m_markVectors_free[ORBIT].back();
		m_markVectors_free[ORBIT].pop_back();
		return amv;
	}
	//else add attribute
	AttributeMultiVector<MarkerBool>* amv = m_attribs[ORBIT].addAttribute<MarkerBool>("") ;
	std::cout << "ADD ATTRIBUTE"<< std::endl;
	return amv;
}


176
template <unsigned int ORBIT>
Sylvain Thery's avatar
Sylvain Thery committed
177
inline void GenericMap::releaseMarkVector(AttributeMultiVector<MarkerBool>* amv)
Pierre Kraemer's avatar
Pierre Kraemer committed
178
{
179
	assert(isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded") ;
Sylvain Thery's avatar
Sylvain Thery committed
180
181
182

//	boost::mutex::scoped_lock lockMV(m_MarkerStorageMutex[ORBIT]);
	m_markVectors_free[ORBIT].push_back(amv);
Pierre Kraemer's avatar
Pierre Kraemer committed
183
184
}

Sylvain Thery's avatar
Sylvain Thery committed
185
186


187
188
template <unsigned int ORBIT>
inline AttributeMultiVector<unsigned int>* GenericMap::getEmbeddingAttributeVector()
Pierre Kraemer's avatar
Pierre Kraemer committed
189
{
190
	return m_embeddings[ORBIT] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
191
192
}

193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
template <typename R>
bool GenericMap::registerAttribute(const std::string &nameType)
{
	RegisteredBaseAttribute* ra = new RegisteredAttribute<R>;
	if (ra == NULL)
	{
		CGoGNerr << "Erreur enregistrement attribut" << CGoGNendl;
		return false;
	}

	ra->setTypeName(nameType);

	m_attributes_registry_map->insert(std::pair<std::string, RegisteredBaseAttribute*>(nameType,ra));
	return true;
}

209
210
211
212
213
214
215
/****************************************
 *   EMBEDDING ATTRIBUTES MANAGEMENT    *
 ****************************************/

template <unsigned int ORBIT>
void GenericMap::addEmbedding()
{
216
217
218
219
	if (!isOrbitEmbedded<ORBIT>())
	{
		std::ostringstream oss;
		oss << "EMB_" << ORBIT;
220

221
222
223
		AttributeContainer& dartCont = m_attribs[DART] ;
		AttributeMultiVector<unsigned int>* amv = dartCont.addAttribute<unsigned int>(oss.str()) ;
		m_embeddings[ORBIT] = amv ;
224

225
226
227
228
		// set new embedding to EMBNULL for all the darts of the map
		for(unsigned int i = dartCont.begin(); i < dartCont.end(); dartCont.next(i))
			(*amv)[i] = EMBNULL ;
	}
229
230
}

Pierre Kraemer's avatar
Pierre Kraemer committed
231
/****************************************
Pierre Kraemer's avatar
Pierre Kraemer committed
232
 *          ORBITS TRAVERSALS           *
Pierre Kraemer's avatar
Pierre Kraemer committed
233
234
 ****************************************/

Sylvain Thery's avatar
Sylvain Thery committed
235
236
237
238
239
240
241
242
243
244
245
/****************************************
 *  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))
246
		(*amv)[i] = Dart(i) ;
Sylvain Thery's avatar
Sylvain Thery committed
247
248
249
250

	return amv ;
}

Sylvain Thery's avatar
Sylvain Thery committed
251
252
253
254
255
256
257
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
258
} //namespace CGoGN