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

#include <vector>
#include <algorithm>

namespace CGoGN
{

template <typename MAP3>
void EmbeddedMap3<MAP3>::sewVolumes(Dart d, Dart e)
{
	//topological sewing
	MAP3::sewVolumes(d,e);

untereiner's avatar
untereiner committed
37 38
	//embed the vertex orbits from the oriented face with dart e
	//with vertex orbits value from oriented face with dart d
39
	if (MAP3::isOrbitEmbedded(VERTEX))
Pierre Kraemer's avatar
Pierre Kraemer committed
40
	{
untereiner's avatar
untereiner committed
41
		unsigned int vEmb1 = EMBNULL ;
Pierre Kraemer's avatar
Pierre Kraemer committed
42 43
		Dart dd = d ;
		do {
untereiner's avatar
untereiner committed
44 45
			vEmb1 = MAP3::getEmbedding(VERTEX, dd);
			MAP3::embedOrbit(VERTEX, dd, vEmb1) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
46 47 48 49 50
			dd = MAP3::phi1(dd) ;
		} while(dd != d) ;
	}

	//embed the new edge orbit with the old edge orbit value
untereiner's avatar
untereiner committed
51
	//for all the face
52
	if (MAP3::isOrbitEmbedded(EDGE))
Pierre Kraemer's avatar
Pierre Kraemer committed
53
	{
untereiner's avatar
untereiner committed
54
		unsigned int vEmb1 = EMBNULL ;
Pierre Kraemer's avatar
Pierre Kraemer committed
55 56
		Dart dd = d ;
		do {
57 58
			vEmb1 = MAP3::getEmbedding(EDGE, d);
			MAP3::embedOrbit(EDGE, d, vEmb1) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
59 60 61
			dd = MAP3::phi1(dd) ;
		} while(dd != d) ;
	}
untereiner's avatar
untereiner committed
62

untereiner's avatar
untereiner committed
63
	//embed the face orbit from the volume sewn
64 65
	if (MAP3::isOrbitEmbedded(FACE))
		MAP3::copyDartEmbedding(FACE, e, d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
66 67 68 69 70
}

template <typename MAP3>
void EmbeddedMap3<MAP3>::unsewVolumes(Dart d)
{
Thomas's avatar
Thomas committed
71 72 73 74 75 76 77 78 79 80 81 82 83
//	Dart d3 = MAP3::phi3(d);
//
//	bool boundaryD = false;
//	bool boundaryE = false;
//
//	if(MAP3::isOrbitEmbedded(VERTEX))
//	{
//		if(MAP3::isBoundaryVertex(d))
//			boundaryD = true;
//		if(MAP3::isBoundaryVertex(MAP3::phi1(d)))
//			boundaryE = true;
//	}
//
untereiner's avatar
untereiner committed
84
	MAP3::unsewVolumes(d);
Thomas's avatar
Thomas committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
//
//	Dart dd = d;
//	Dart dd3 = d3;
//
//	do
//	{
//		if(MAP3::isOrbitEmbedded(VERTEX))
//			MAP3::copyCell(VERTEX, dd3, MAP3::phi1(dd));
//
//		if(MAP3::isOrbitEmbedded(EDGE))
//
//
//		if(MAP3::isOrbitEmbedded(FACE))
//
//
//		dd = MAP3::phi1(dd) ;
//	}while( dd != d );
untereiner's avatar
untereiner committed
102

Pierre Kraemer's avatar
Pierre Kraemer committed
103 104 105 106 107 108 109

}

template <typename MAP3>
bool EmbeddedMap3<MAP3>::mergeVolumes(Dart d)
{
	Dart d2 = MAP3::phi2(d);
untereiner's avatar
untereiner committed
110
	Dart a_2 = MAP3::phi3(MAP3::phi2(d));
Pierre Kraemer's avatar
Pierre Kraemer committed
111 112 113

	if(MAP3::mergeVolumes(d))
	{
114
		if (MAP3::isOrbitEmbedded(VOLUME))
Pierre Kraemer's avatar
Pierre Kraemer committed
115
		{
116 117
				unsigned int vEmb = MAP3::getEmbedding(VOLUME, d2);
				MAP3::embedOrbit(VOLUME, a_2, vEmb) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
118 119 120 121 122 123 124 125 126 127
		}
		return true;
	}
	return false;
}

template <typename MAP3>
void EmbeddedMap3<MAP3>::splitFace(Dart d, Dart e)
{
	MAP3::splitFace(d,e);
untereiner's avatar
untereiner committed
128

129
	if(MAP3::isOrbitEmbedded(VERTEX))
Pierre Kraemer's avatar
Pierre Kraemer committed
130
	{
untereiner's avatar
ihm3  
untereiner committed
131 132
		MAP3::copyDartEmbedding(VERTEX, MAP3::phi2(MAP3::phi_1(d)), d);
		MAP3::copyDartEmbedding(VERTEX, MAP3::phi2(MAP3::phi_1(e)), e);
untereiner's avatar
untereiner committed
133 134 135 136 137 138

		if(MAP3::phi3(d) != d)
		{
			Dart d3 = MAP3::phi3(d);
			Dart e3 = MAP3::phi3(e);

139 140
			MAP3::copyDartEmbedding(VERTEX, MAP3::phi1(d3), MAP3::phi1(MAP3::phi2(MAP3::phi1(d3))));
			MAP3::copyDartEmbedding(VERTEX, MAP3::phi1(e3), MAP3::phi1(MAP3::phi2(MAP3::phi1(e3))));
untereiner's avatar
untereiner committed
141 142
		}

Pierre Kraemer's avatar
Pierre Kraemer committed
143 144
	}

145
	if(MAP3::isOrbitEmbedded(FACE))
untereiner's avatar
untereiner committed
146
	{
147 148
		MAP3::embedNewCell(FACE, MAP3::phi2(MAP3::phi_1(d)));
		MAP3::copyCell(FACE, MAP3::phi2(MAP3::phi_1(d)), d);
untereiner's avatar
untereiner committed
149
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
150

151
	if(MAP3::isOrbitEmbedded(VOLUME))
Pierre Kraemer's avatar
Pierre Kraemer committed
152
	{
153 154
		MAP3::copyDartEmbedding(VOLUME, MAP3::phi_1(d),  d);
		MAP3::copyDartEmbedding(VOLUME, MAP3::phi2(MAP3::phi_1(d)),  d);
Pierre Kraemer's avatar
Pierre Kraemer committed
155

untereiner's avatar
untereiner committed
156
		if(MAP3::phi3(d) != d)
Pierre Kraemer's avatar
Pierre Kraemer committed
157
		{
untereiner's avatar
untereiner committed
158 159
			Dart d3 = MAP3::phi3(d);

160 161
			MAP3::copyDartEmbedding(VOLUME, MAP3::phi1(d3), d3);
			MAP3::copyDartEmbedding(VOLUME, MAP3::phi2(MAP3::phi1(d3)), d3);
Pierre Kraemer's avatar
Pierre Kraemer committed
162 163 164 165 166 167 168 169 170 171
		}

	}

}

template <typename MAP3>
void EmbeddedMap3<MAP3>::cutEdge(Dart d)
{
	MAP3::cutEdge(d);
untereiner's avatar
untereiner committed
172

173
	if(MAP3::isOrbitEmbedded(EDGE))
untereiner's avatar
untereiner committed
174
	{
Thomas's avatar
Thomas committed
175 176 177 178
		Dart nd = MAP3::phi1(d) ;

		MAP3::embedNewCell(EDGE, nd) ;
		MAP3::copyCell(EDGE, nd, d) ;
untereiner's avatar
untereiner committed
179

Thomas's avatar
Thomas committed
180 181
		unsigned int vEmb = MAP3::getEmbedding(EDGE, d);
		MAP3::embedOrbit(EDGE, d, vEmb) ;
untereiner's avatar
untereiner committed
182 183
	}

184
	if(MAP3::isOrbitEmbedded(FACE))
untereiner's avatar
untereiner committed
185
	{
Thomas's avatar
Thomas committed
186 187 188 189 190 191 192 193 194 195 196 197
		Dart f = d;
		do
		{
			Dart nd = MAP3::phi1(f) ;
			MAP3::copyDartEmbedding(FACE, nd, f);

			Dart f2 = MAP3::phi2(nd);
			if(f2!=nd)
			{
				Dart nd2 = MAP3::phi2(f);
				MAP3::copyDartEmbedding(FACE, nd2, f2);
			}
untereiner's avatar
untereiner committed
198

Thomas's avatar
Thomas committed
199 200
			f = MAP3::alpha2(f);
		} while(f != d);
untereiner's avatar
untereiner committed
201 202
	}

203
	if(MAP3::isOrbitEmbedded(VOLUME))
untereiner's avatar
untereiner committed
204
	{
Thomas's avatar
Thomas committed
205
		Dart f = d;
untereiner's avatar
untereiner committed
206 207
		do
		{
Thomas's avatar
Thomas committed
208 209 210 211 212 213
			Dart nd = MAP3::phi1(f) ;
			MAP3::copyDartEmbedding(VOLUME, nd, f);

			Dart nd2 = MAP3::phi2(f);
			if(f!=nd2)
				MAP3::copyDartEmbedding(VOLUME, nd2, f);
untereiner's avatar
untereiner committed
214 215

			f = MAP3::alpha2(f);
Thomas's avatar
Thomas committed
216
		} while(f != d);
untereiner's avatar
untereiner committed
217
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
218 219 220 221 222 223 224 225 226
}


template <typename MAP3>
int EmbeddedMap3<MAP3>::collapseEdge(Dart d, bool delDegenerateFaces,
		bool delDegenerateVolumes)
{

	unsigned int vEmb = EMBNULL ;
227
	if(MAP3::isOrbitEmbedded(VERTEX))
Pierre Kraemer's avatar
Pierre Kraemer committed
228
	{
229 230 231
		vEmb = MAP3::getEmbedding(VERTEX, d) ;
		MAP3::embedOrbit(VERTEX,d,vEmb);
		MAP3::embedOrbit(VERTEX,MAP3::phi2(d),vEmb);
Pierre Kraemer's avatar
Pierre Kraemer committed
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
	}

	int nbCol = MAP3::collapseEdge(d,delDegenerateFaces,delDegenerateVolumes);

	return nbCol;
}

template <typename MAP3>
void EmbeddedMap3<MAP3>::collapseFace(Dart d, bool delDegenerateFaces,
		bool delDegenerateVolumes)
{
	//unsigned int degree = MAP3::faceDegree(d);
	//Dart dsave;

//	//si degree face = 3
//	if(degree == 3)
//	{
//		dsave = MAP3::phi3(MAP3::phi2(MAP3::phi1(d)));
//		dsave = MAP3::phi3(MAP3::phi2(MAP3::phi1(dsave)));
//		//ATTENTION : il faut trouver un brin de l'orbite sommet de d non modifie par l'operation !!
//	}
//	else if(degree > 3)
//	{
//		dsave = MAP3::phi1(MAP3::phi2(MAP3::phi1(d)));
//		dsave = MAP3::phi1(MAP3::phi2(MAP3::phi1(dsave)));
//	}
//	else
//		return;


//	unsigned int vEmb = EMBNULL ;
263
//	if(MAP3::isOrbitEmbedded(VERTEX))
Pierre Kraemer's avatar
Pierre Kraemer committed
264
//	{
265
//		vEmb = MAP3::getEmbedding(d, VERTEX) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
266 267 268 269
//	}

	MAP3::collapseFace(d,delDegenerateFaces,delDegenerateVolumes);

270
//	if(MAP3::isOrbitEmbedded(VERTEX))
Pierre Kraemer's avatar
Pierre Kraemer committed
271
//	{
272
//		MAP3::embedOrbit(VERTEX,dsave,vEmb);
Pierre Kraemer's avatar
Pierre Kraemer committed
273 274 275 276
//	}

}

untereiner's avatar
untereiner committed
277 278
//TODO collapseVolume

Pierre Kraemer's avatar
Pierre Kraemer committed
279 280 281 282 283 284 285 286 287 288
template <typename MAP3>
Dart EmbeddedMap3<MAP3>::cutSpike(Dart d)
{

	Dart e = MAP3::cutSpike(d);

	return e;
}


untereiner's avatar
untereiner committed
289 290 291 292 293 294 295 296 297
template <typename MAP3>
unsigned int EmbeddedMap3<MAP3>::closeHole(Dart d)
{
	unsigned int nbE = MAP3::closeHole(d);
	Dart dd = MAP3::phi2(d);
	Dart f = dd;

	do
	{
298 299 300 301 302 303
		if(MAP3::isOrbitEmbedded(VERTEX))
			MAP3::copyDartEmbedding(VERTEX,f, MAP3::phi1(MAP3::phi2(f)));
		if(MAP3::isOrbitEmbedded(EDGE))
			MAP3::copyDartEmbedding(EDGE, f, MAP3::phi2(f));
		if(MAP3::isOrbitEmbedded(VOLUME))
			MAP3::copyDartEmbedding(VOLUME, f, MAP3::phi2(f));
untereiner's avatar
untereiner committed
304 305 306 307 308 309 310

		f = MAP3::phi1(f);
	}
	while(dd != f);

	return nbE;
}
Pierre Kraemer's avatar
Pierre Kraemer committed
311 312


untereiner's avatar
untereiner committed
313 314 315 316 317 318 319 320 321
template <typename MAP3>
void EmbeddedMap3<MAP3>::closeMap(DartMarker &marker)
{
	MAP3::closeMap(marker);

	for(Dart d = MAP3::begin() ; d != MAP3::end() ; MAP3::next(d))
	{
		if(marker.isMarked(d))
		{
322
			if(MAP3::isOrbitEmbedded(VERTEX))
untereiner's avatar
untereiner committed
323
			{
324
				MAP3::copyDartEmbedding(VERTEX, d, MAP3::phi1(MAP3::phi3(d)));
untereiner's avatar
untereiner committed
325 326 327
			}
		}
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
328

untereiner's avatar
untereiner committed
329
}
Pierre Kraemer's avatar
Pierre Kraemer committed
330

untereiner's avatar
ihm3  
untereiner committed
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
template <typename MAP3>
bool EmbeddedMap3<MAP3>::check()
{
	bool topo = MAP3::check() ;
	if (!topo)
		return false ;

	CGoGNout << "Check: embedding begin" << CGoGNendl ;
	for(Dart d = MAP3::begin(); d != MAP3::end(); MAP3::next(d))
	{
		if (MAP3::isOrbitEmbedded(VERTEX))
		{
			if (MAP3::phi2(MAP3::phi_1(d)) != MAP3::phi_1(d) && MAP3::getEmbedding(VERTEX, d) != MAP3::getEmbedding(VERTEX, MAP3::phi2(MAP3::phi_1(d))))
			{
				CGoGNout << "Check: different embeddings on vertex" << CGoGNendl ;
				return false ;
			}

untereiner's avatar
untereiner committed
349
			 if(MAP3::phi3(d) != d && MAP3::getEmbedding(VERTEX, d) != MAP3::getEmbedding(VERTEX, MAP3::phi1(MAP3::phi3(d))))
untereiner's avatar
ihm3  
untereiner committed
350 351
			 {
					CGoGNout << "Check: different embeddings on vertex in the 2 oriented faces" << CGoGNendl ;
untereiner's avatar
untereiner committed
352 353 354
					std::cout << "Dart #" << d << std::endl;
					std::cout << "Emb(d) = " << MAP3::getEmbedding(VERTEX, d) << std::endl;
					std::cout << "Emb(phi32(d)) = " << MAP3::getEmbedding(VERTEX, MAP3::phi3(MAP3::phi2(d))) << std::endl;
untereiner's avatar
ihm3  
untereiner committed
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
					return false ;
			 }

		}

//		if (MAP2::isOrbitEmbedded(EDGE))
//		{
//			if (MAP2::getEmbedding(EDGE, d) != MAP2::getEmbedding(EDGE, MAP2::phi2(d)))
//			{
//				CGoGNout << "Check: different embeddings on edge" << CGoGNendl ;
//				return false ;
//			}
//		}
//
//		if (MAP2::isOrbitEmbedded(FACE))
//		{
//			if (MAP2::getEmbedding(FACE, d) != MAP2::getEmbedding(FACE, MAP2::phi1(d)))
//		{
//				CGoGNout << "Check: different embeddings on face" << CGoGNendl ;
//				return false ;
//			}
//		}
	}
	CGoGNout << "Check: embedding ok" << CGoGNendl ;
	return true ;
}

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