gmap1.hpp 6.46 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 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 177 178 179 180 181 182
inline int GMap1::getDartsPerTriangle()
{
	return 6 ;
}

/*! @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)
{
	Dart e = beta0(d) ;
	Dart f = beta1(e) ;
	if(f == e)
		return d ;
	else
		return f ;
}

inline Dart GMap1::phi_1(Dart d)
{
	Dart e = beta1(d) ;
	if(e == d)
		return d ;
	else
		return beta0(e) ;
}

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)
{
	return phi1(d) ;
}

inline Dart GMap1::alpha_1(Dart d)
{
	return phi_1(d) ;
}

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

inline void GMap1::phi1sew(Dart d, Dart e)
{
	Dart f = phi1(d) ;
	Dart g = phi1(e) ;
	beta1unsew(f) ;
	beta1unsew(g) ;
	beta1sew(beta0(d), g) ;
	beta1sew(beta0(e), f) ;
}

inline void GMap1::phi1unsew(Dart d)
{
	Dart e = phi1(d) ;
	Dart f = phi1(e) ;
	beta1unsew(e) ;
	beta1unsew(f) ;
	beta1sew(beta0(d), f) ;
}

/*! @name Topological Operators
 *  Topological operations on 1-maps
 *************************************************************************/

183 184 185 186 187 188 189 190
inline void GMap1::linkVertices(Dart d, Dart e)
{
	assert(d != e && !sameOrientedFace(d, e)) ;
	GMap1::cutEdge(phi_1(d));		// cut the edge before d (insert a new dart before d)
	GMap1::cutEdge(phi_1(e));		// cut the edge before e (insert a new dart before e)
	phi1sew(phi_1(d), phi_1(e)) ;	// phi1sew between the 2 new inserted darts
}

Pierre Kraemer's avatar
Pierre Kraemer committed
191 192
inline void GMap1::cutEdge(Dart d)
{
193 194 195 196 197 198 199
   Dart e = newDart();
   Dart f = newDart();
   beta1sew(e, f) ;
   Dart dd = beta0(d) ;
   beta0unsew(d) ;
   beta0sew(e, d) ;
   beta0sew(f, dd) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
}

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
215
	assert(d != e && sameFace(d, e)) ;
216 217 218 219

	if(!sameOrientedFace(d,e))
		e = beta1(e);

Pierre Kraemer's avatar
Pierre Kraemer committed
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
	Dart d1 = beta1(d) ;
	Dart e1 = beta1(e) ;
	Dart dd = newEdge() ;
	Dart ee = newEdge() ;
	beta1unsew(d) ;
	beta1unsew(e) ;
	beta1sew(d, dd) ;
	beta1sew(beta0(dd), e1) ;
	beta1sew(e, ee) ;
	beta1sew(beta0(ee), d1) ;
}

inline void GMap1::mergeFaces(Dart d, Dart e)
{
	assert(!sameFace(d, e)) ;
	Dart dd = beta0(d) ;
	Dart d1 = beta1(d) ;
	Dart dd1 = beta1(dd) ;
	Dart ee = beta0(e) ;
	Dart e1 = beta1(e) ;
	Dart ee1 = beta1(ee) ;
	beta1unsew(d) ;
	beta1unsew(dd) ;
	beta1unsew(e) ;
	beta1unsew(ee) ;
	beta1sew(d1, ee1) ;
	beta1sew(e1, dd1) ;
	deleteEdge(d) ;
	deleteEdge(e) ;
}

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

Sylvain Thery's avatar
Sylvain Thery committed
255
inline bool GMap1::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
256 257 258 259 260 261 262
{
	if (f(d)) return true;
	Dart d1 = beta1(d);
	if (d1 != d) return f(d1);
	return false;
}

Sylvain Thery's avatar
Sylvain Thery committed
263
inline bool GMap1::foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
264 265 266 267 268 269 270
{
	if (f(d)) return true;
	Dart d1 = beta0(d);
	if (d1 != d) return f(d1);
	return false;
}

Sylvain Thery's avatar
Sylvain Thery committed
271
inline bool GMap1::foreach_dart_of_volume(Dart d, FunctorType& f, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
272
{
Sylvain Thery's avatar
Sylvain Thery committed
273
	return foreach_dart_of_face(d, f, thread) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
274 275 276
}

} // namespace CGoGN