genericmap.hpp 7.9 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)
50
		m_markerTables[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 62 63 64
			{
				if(m_attribs[orbit].unrefLine(emb))
				{
					for (unsigned int t = 0; t < m_nbThreads; ++t)
						m_markerTables[orbit][t]->operator[](emb).clear() ;
				}
			}
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
		return d.index;

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

Pierre Kraemer's avatar
Pierre Kraemer committed
107 108 109 110
//inline unsigned int GenericMap::getDartEmbedding(unsigned int orbit, Dart d)
//{
//	assert(isOrbitEmbedded(orbit) || !"Invalid parameter: orbit not embedded");
//
111
//	if (orbit == DART)
Pierre Kraemer's avatar
Pierre Kraemer committed
112 113 114 115 116
//		return d.index;
//
//	return (*m_embeddings[orbit])[d.index] ;
//}

Pierre Kraemer's avatar
Pierre Kraemer committed
117 118 119
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
120
	setDartEmbedding(orbit, d, getEmbedding(orbit, e));
Pierre Kraemer's avatar
Pierre Kraemer committed
121 122 123 124 125 126 127 128 129 130 131
}

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
132
	FunctorSetEmb<GenericMap> fsetemb(*this, orbit, em);
Pierre Kraemer's avatar
Pierre Kraemer committed
133 134 135 136 137 138 139 140 141 142 143 144 145 146
	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
147 148
	unsigned int dE = getEmbedding(orbit, d) ;
	unsigned int eE = getEmbedding(orbit, e) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
149 150 151 152 153 154 155 156 157 158 159
	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
160
	m_attribs[orbit].copyLine(i, j) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
161 162 163 164 165 166 167 168 169 170 171 172
}

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

173
inline AttributeContainer& GenericMap::getAttributeContainer(unsigned int orbit)
Pierre Kraemer's avatar
Pierre Kraemer committed
174
{
175
	return m_attribs[orbit] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
176 177
}

178
inline AttributeMultiVector<Mark>* GenericMap::getMarkerVector(unsigned int orbit, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
179
{
180
	assert(isOrbitEmbedded(orbit) || !"Invalid parameter: orbit not embedded") ;
Sylvain Thery's avatar
Sylvain Thery committed
181
	return m_markerTables[orbit][thread] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
182 183
}

184
inline AttributeMultiVector<unsigned int>* GenericMap::getEmbeddingAttributeVector(unsigned int orbit)
Pierre Kraemer's avatar
Pierre Kraemer committed
185
{
186
	return m_embeddings[orbit] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
187 188
}

Pierre Kraemer's avatar
Pierre Kraemer committed
189
inline void GenericMap::swapEmbeddingContainers(unsigned int orbit1, unsigned int orbit2)
Pierre Kraemer's avatar
Pierre Kraemer committed
190
{
Pierre Kraemer's avatar
Pierre Kraemer committed
191
	assert(orbit1 != orbit2 || !"Cannot swap a container with itself") ;
192
	assert((orbit1 != DART && orbit2 != DART) || !"Cannot swap the darts container") ;
193

Pierre Kraemer's avatar
Pierre Kraemer committed
194
	m_attribs[orbit1].swap(m_attribs[orbit2]) ;
195 196 197
	m_attribs[orbit1].setOrbit(orbit1) ;	// to update the orbit information
	m_attribs[orbit2].setOrbit(orbit2) ;	// in the contained AttributeMultiVectors

198
	m_embeddings[orbit1]->swap(m_embeddings[orbit2]) ;
199

200 201 202 203 204
	for(unsigned int t = 0; t < m_nbThreads; ++t)
	{
		AttributeMultiVector<Mark>* m = m_markerTables[orbit1][t] ;
		m_markerTables[orbit1][t] = m_markerTables[orbit2][t] ;
		m_markerTables[orbit2][t] = m ;
205

206 207 208 209
		MarkerSet ms = m_orbMarker[orbit1][t] ;
		m_orbMarker[orbit1][t] = m_orbMarker[orbit2][t] ;
		m_orbMarker[orbit2][t] = ms ;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
210 211 212 213 214 215
}

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

Sylvain Thery's avatar
Sylvain Thery committed
216
inline Marker GenericMap::getNewMarker(unsigned int cell, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
217
{
Sylvain Thery's avatar
Sylvain Thery committed
218
	return m_orbMarker[cell][thread].getNewMarker(cell) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
219 220
}

Sylvain Thery's avatar
Sylvain Thery committed
221
inline void GenericMap::releaseMarker(Marker m, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
222 223 224
{
	unsigned int cell = m.getCell();
	assert(isOrbitEmbedded(cell) || !"Try to release a marker on non embedded cell! ") ;
Sylvain Thery's avatar
Sylvain Thery committed
225
	m_orbMarker[cell][thread].releaseMarker(m) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
226 227 228 229 230 231 232 233
}

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

inline Dart GenericMap::begin()
{
234
	return Dart::create(m_attribs[DART].begin());
Pierre Kraemer's avatar
Pierre Kraemer committed
235 236 237 238
}

inline Dart GenericMap::end()
{
239
	return Dart::create(m_attribs[DART].end()) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
240 241 242 243
}

inline void GenericMap::next(Dart& d)
{
244
	m_attribs[DART].next(d.index) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
245 246 247
}

} //namespace CGoGN