gmap1.hpp 7.43 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 25 26 27
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

namespace CGoGN
{

28
inline void GMap1::init()
Pierre Kraemer's avatar
Pierre Kraemer committed
29 30 31 32
{
	m_beta1 = addRelation("beta1") ;
}

33 34 35 36 37
inline GMap1::GMap1() : GMap0()
{
	init() ;
}

38
inline std::string GMap1::mapTypeName() const
Pierre Kraemer's avatar
Pierre Kraemer committed
39 40 41 42
{
	return "GMap1";
}

43
inline unsigned int GMap1::dimension() const
Pierre Kraemer's avatar
Pierre Kraemer committed
44 45 46 47
{
	return 1;
}

48 49 50
inline void GMap1::clear(bool removeAttrib)
{
	GMap0::clear(removeAttrib) ;
Sylvain Thery's avatar
Sylvain Thery committed
51 52
	if (removeAttrib)
		init() ;
53 54
}

Sylvain Thery's avatar
Sylvain Thery committed
55 56 57 58 59 60
inline void GMap1::update_topo_shortcuts()
{
	GMap0::update_topo_shortcuts();
	m_beta1 = getRelation("beta1");
}

Pierre Kraemer's avatar
Pierre Kraemer committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
/*! @name Basic Topological Operators
 * Access and Modification
 *************************************************************************/

inline Dart GMap1::newDart()
{
	Dart d = GMap0::newDart() ;
	(*m_beta1)[d.index] = d ;
	return d ;
}

inline Dart GMap1::beta1(Dart d)
{
	return (*m_beta1)[d.index] ;
}

template <int N>
inline Dart GMap1::beta(const Dart d)
{
	assert( (N > 0) || !"negative parameters not allowed in template multi-beta");
	if (N<10)
	{
		switch(N)
		{
		case 0 : return beta0(d) ;
		case 1 : return beta1(d) ;
		default : assert(!"Wrong multi-beta relation value") ;
		}
	}
	switch(N%10)
	{
	case 0 : return beta0(beta<N/10>(d)) ;
	case 1 : return beta1(beta<N/10>(d)) ;
	default : assert(!"Wrong multi-beta relation value") ;
	}
}

inline Dart GMap1::phi1(Dart d)
{
100
	return beta1(beta0(d)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
101 102 103 104
}

inline Dart GMap1::phi_1(Dart d)
{
105
	return beta0(beta1(d)) ;
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
}

template <int N>
inline Dart GMap1::phi(Dart d)
{
	assert((N > 0) || !"negative parameters not allowed in template multi-phi");
	if (N < 10)
	{
		switch(N)
		{
		case 1 : return phi1(d) ;
		default : assert(!"Wrong multi-phi relation value") ; return d ;
		}
	}
	switch(N%10)
	{
	case 1 : return phi1(phi<N/10>(d)) ;
	default : assert(!"Wrong multi-phi relation value") ; return d ;
	}
}

inline Dart GMap1::alpha1(Dart d)
{
129
	return beta1(beta0(d)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
130 131 132 133
}

inline Dart GMap1::alpha_1(Dart d)
{
134
	return beta0(beta1(d)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
}

inline void GMap1::beta1sew(Dart d, Dart e)
{
	assert((*m_beta1)[d.index] == d) ;
	assert((*m_beta1)[e.index] == e) ;
	(*m_beta1)[d.index] = e ;
	(*m_beta1)[e.index] = d ;
}

inline void GMap1::beta1unsew(Dart d)
{
	Dart e = (*m_beta1)[d.index] ;
	(*m_beta1)[d.index] = d ;
	(*m_beta1)[e.index] = e ;
}

/*! @name Topological Operators
153
 *  Topological operations on 1-G-maps
Pierre Kraemer's avatar
Pierre Kraemer committed
154 155
 *************************************************************************/

156
inline Dart GMap1::cutEdge(Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
157
{
158 159 160 161 162 163 164 165
	Dart dd = beta0(d) ;
	Dart e = newDart();
	Dart f = newDart();
	beta1sew(e, f) ;
	beta0unsew(d) ;
	beta0sew(e, d) ;
	beta0sew(f, dd) ;

Thery Sylvain's avatar
Thery Sylvain committed
166
	if (isBoundaryMarked2(d))
167
	{
Thery Sylvain's avatar
Thery Sylvain committed
168 169
		boundaryMark2(e);
		boundaryMark2(f);
170
	}
171

172 173 174 175 176 177
	if (isBoundaryMarked3(d))
	{
		boundaryMark3(e);
		boundaryMark3(f);
	}

178
	return f ;
179 180 181 182 183 184 185 186 187 188 189 190
}

inline void GMap1::uncutEdge(Dart d)
{
	Dart d0 = beta0(d) ;
	Dart d1 = phi1(d) ;
	Dart d10 = beta0(d1) ;
	beta0unsew(d) ;
	beta0unsew(d10) ;
	beta0sew(d, d10) ;
	deleteDart(d0) ;
	deleteDart(d1) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
191 192 193 194 195 196 197 198 199 200 201 202 203
}

inline void GMap1::collapseEdge(Dart d)
{
	Dart d1 = beta1(d) ;
	Dart dd = beta0(d) ;
	Dart dd1 = beta1(dd) ;
	beta1unsew(d) ;
	beta1unsew(dd) ;
	beta1sew(d1, dd1) ;
	deleteEdge(d) ;
}

204
inline void GMap1::splitCycle(Dart d, Dart e)
Pierre Kraemer's avatar
Pierre Kraemer committed
205
{
206
	assert(d != e && sameCycle(d, e)) ;
207

208
	if(!sameOrientedCycle(d, e))
209
		e = beta1(e) ;
210

Pierre Kraemer's avatar
Pierre Kraemer committed
211 212 213 214
	Dart d1 = beta1(d) ;
	Dart e1 = beta1(e) ;
	beta1unsew(d) ;
	beta1unsew(e) ;
215 216
	beta1sew(d, e1) ;
	beta1sew(e, d1) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
217 218
}

219
inline void GMap1::mergeCycles(Dart d, Dart e)
Pierre Kraemer's avatar
Pierre Kraemer committed
220
{
221
	assert(!sameCycle(d, e)) ;
222

Pierre Kraemer's avatar
Pierre Kraemer committed
223 224 225 226
	Dart d1 = beta1(d) ;
	Dart e1 = beta1(e) ;
	beta1unsew(d) ;
	beta1unsew(e) ;
227 228 229 230
	beta1sew(d, e1) ;
	beta1sew(e, d1) ;
}

231
inline void GMap1::linkCycles(Dart d, Dart e)
232
{
233
	assert(d != e && !sameCycle(d, e)) ;
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
	Dart d1 = beta1(d) ;
	Dart e1 = beta1(e) ;
	Dart dd = newEdge() ;
	Dart ee = newEdge() ;
	beta1unsew(d) ;
	beta1unsew(e) ;
	beta1sew(d, dd) ;
	beta1sew(e1, beta0(dd)) ;
	beta1sew(e, ee) ;
	beta1sew(d1, beta0(ee)) ;
}

/*! @name Topological Queries
 *  Return or set various topological information
 *************************************************************************/

250
inline bool GMap1::sameOrientedCycle(Dart d, Dart e)
251 252 253 254 255 256 257 258 259 260 261
{
	Dart it = d ;
	do
	{
		if (it == e)
			return true ;
		it = phi1(it) ;
	} while (it != d) ;
	return false ;
}

262
inline bool GMap1::sameCycle(Dart d, Dart e)
263 264 265 266 267 268 269 270 271 272 273 274 275 276
{
	Dart it = d ;
	do
	{
		if (it == e)
			return true ;
		it = beta0(it);
		if (it == e)
			return true ;
		it = beta1(it) ;
	} while (it != d) ;
	return false ;
}

277
inline unsigned int GMap1::cycleDegree(Dart d)
278 279 280 281 282 283 284 285 286 287 288
{
	unsigned int count = 0 ;
	Dart it = d ;
	do
	{
		++count ;
		it = phi1(it) ;
	} while (it != d) ;
	return count ;
}

289
inline bool GMap1::isCycleTriangle(Dart d)
290 291
{
	return (phi1(d) != d) && (phi1(phi1(phi1(d))) == d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
292 293 294 295 296 297
}

/*! @name Cell Functors
 *  Apply functors to all darts of a cell
 *************************************************************************/

298
inline bool GMap1::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int /*thread*/)
Pierre Kraemer's avatar
Pierre Kraemer committed
299 300 301 302 303 304 305
{
	if (f(d)) return true;
	Dart d1 = beta1(d);
	if (d1 != d) return f(d1);
	return false;
}

306
inline bool GMap1::foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int /*thread*/)
Pierre Kraemer's avatar
Pierre Kraemer committed
307 308 309 310 311 312 313
{
	if (f(d)) return true;
	Dart d1 = beta0(d);
	if (d1 != d) return f(d1);
	return false;
}

314
inline bool GMap1::foreach_dart_of_oriented_cc(Dart d, FunctorType& f, unsigned int /*thread*/)
315 316 317 318 319 320 321 322 323 324 325
{
	Dart it = d ;
	do
	{
		if (f(it))
			return true ;
		it = phi1(it) ;
	} while (it != d) ;
	return false ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
326
inline bool GMap1::foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread)
327
{
328 329 330 331 332 333 334 335 336 337 338 339 340
	return GMap1::foreach_dart_of_oriented_cc(d, f, thread) || GMap1::foreach_dart_of_oriented_cc(beta0(d), f, thread) ;

//	Dart it = d ;
//	do
//	{
//		if (f(it))
//			return true ;
//		it = beta0(it);
//		if (f(it))
//			return true ;
//		it = beta1(it) ;
//	} while (it != d) ;
//	return false ;
341 342
}

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