gmap1.hpp 7.28 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
* 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() ;
}

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

inline unsigned int GMap1::dimension()
{
	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
}

Pierre Kraemer's avatar
Pierre Kraemer committed
55 56 57 58 59 60 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
/*! @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)
{
94
	return beta1(beta0(d)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
95 96 97 98
}

inline Dart GMap1::phi_1(Dart d)
{
99
	return beta0(beta1(d)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
}

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)
{
123
	return beta1(beta0(d)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
124 125 126 127
}

inline Dart GMap1::alpha_1(Dart d)
{
128
	return beta0(beta1(d)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
}

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
147
 *  Topological operations on 1-G-maps
Pierre Kraemer's avatar
Pierre Kraemer committed
148 149 150 151
 *************************************************************************/

inline void GMap1::cutEdge(Dart d)
{
Pierre Kraemer's avatar
Pierre Kraemer committed
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
	Dart dd = beta0(d) ;
	Dart e = newDart();
	Dart f = newDart();
	beta1sew(e, f) ;
	beta0unsew(d) ;
	beta0sew(e, d) ;
	beta0sew(f, dd) ;

	if (isBoundaryMarked(d))
	{
		boundaryMark(e);
		boundaryMark(f);
	}
}

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
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
}

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

inline void GMap1::splitFace(Dart d, Dart e)
{
Thomas's avatar
Thomas committed
192
	assert(d != e && sameFace(d, e)) ;
193

194 195
	if(!sameOrientedFace(d, e))
		e = beta1(e) ;
196

Pierre Kraemer's avatar
Pierre Kraemer committed
197 198 199 200
	Dart d1 = beta1(d) ;
	Dart e1 = beta1(e) ;
	beta1unsew(d) ;
	beta1unsew(e) ;
201 202
	beta1sew(d, e1) ;
	beta1sew(e, d1) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
203 204 205 206 207
}

inline void GMap1::mergeFaces(Dart d, Dart e)
{
	assert(!sameFace(d, e)) ;
208

Pierre Kraemer's avatar
Pierre Kraemer committed
209 210 211 212
	Dart d1 = beta1(d) ;
	Dart e1 = beta1(e) ;
	beta1unsew(d) ;
	beta1unsew(e) ;
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
	beta1sew(d, e1) ;
	beta1sew(e, d1) ;
}

inline void GMap1::linkFaces(Dart d, Dart e)
{
	assert(d != e && !sameFace(d, e)) ;
	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
 *************************************************************************/

inline bool GMap1::sameOrientedFace(Dart d, Dart e)
{
	Dart it = d ;
	do
	{
		if (it == e)
			return true ;
		it = phi1(it) ;
	} while (it != d) ;
	return false ;
}

inline bool GMap1::sameFace(Dart d, Dart e)
{
	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 ;
}

inline unsigned int GMap1::faceDegree(Dart d)
{
	unsigned int count = 0 ;
	Dart it = d ;
	do
	{
		++count ;
		it = phi1(it) ;
	} while (it != d) ;
	return count ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
275
inline bool GMap1::isFaceTriangle(Dart d)
276 277
{
	return (phi1(d) != d) && (phi1(phi1(phi1(d))) == d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
278 279 280 281 282 283
}

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

Sylvain Thery's avatar
Sylvain Thery committed
284
inline bool GMap1::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
285 286 287 288 289 290 291
{
	if (f(d)) return true;
	Dart d1 = beta1(d);
	if (d1 != d) return f(d1);
	return false;
}

Sylvain Thery's avatar
Sylvain Thery committed
292
inline bool GMap1::foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
293 294 295 296 297 298 299
{
	if (f(d)) return true;
	Dart d1 = beta0(d);
	if (d1 != d) return f(d1);
	return false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
300
inline bool GMap1::foreach_dart_of_oriented_face(Dart d, FunctorType& f, unsigned int thread)
301 302 303 304 305 306 307 308 309 310 311
{
	Dart it = d ;
	do
	{
		if (f(it))
			return true ;
		it = phi1(it) ;
	} while (it != d) ;
	return false ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
312
inline bool GMap1::foreach_dart_of_face(Dart d, FunctorType& f, unsigned int thread)
313 314 315 316
{
	return foreach_dart_of_oriented_face(d, f, thread) || foreach_dart_of_oriented_face(beta0(d), f, thread) ;
}

Sylvain Thery's avatar
Sylvain Thery committed
317
inline bool GMap1::foreach_dart_of_volume(Dart d, FunctorType& f, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
318
{
Sylvain Thery's avatar
Sylvain Thery committed
319
	return foreach_dart_of_face(d, f, thread) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
320 321
}

Pierre Kraemer's avatar
Pierre Kraemer committed
322
inline bool GMap1::foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread)
323 324 325 326
{
	return foreach_dart_of_face(d, f, thread) ;
}

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