bufferGen.hpp 12.2 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 28 29 30
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

namespace CGoGN
{

namespace Algo
{

31 32 33
namespace Surface
{

Pierre Kraemer's avatar
Pierre Kraemer committed
34 35 36 37 38 39 40
namespace MC
{

/*
* constructor
*/
template<typename DART, typename DATATYPE>
41
BufferGen<DART,DATATYPE>::BufferGen(int _lWidth, int _lHeight)
Pierre Kraemer's avatar
Pierre Kraemer committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
{
	m_lWidth = _lWidth+1;
	m_lHeight = _lHeight+1;
	m_hcSlice0 = new HalfCubeGen<DART>[m_lWidth*m_lHeight];
	m_hcSlice1 = new HalfCubeGen<DART>[m_lWidth*m_lHeight];
	m_lZpos = 0;

	m_dataSl0 = new DATATYPE[m_lWidth*m_lHeight];
	m_dataSl1 = new DATATYPE[m_lWidth*m_lHeight];	

}


/*
* destructor
*/
template<typename DART, typename DATATYPE>
BufferGen<DART,DATATYPE>::~BufferGen()
{                         	
	delete[] m_hcSlice0;
	delete[] m_hcSlice1;

	delete[] m_dataSl0;
	delete[] m_dataSl1;

}



/*
* get the face inside a cube of the buffer
*/	
// template <typename DART, typename DATATYPE>
75
// const DART* BufferGen<DART,DATATYPE>::getFacesCube(int _lX, int _lY, int _lZ) const
Pierre Kraemer's avatar
Pierre Kraemer committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
// {
// 
// 	if (_lZ == m_lZpos)				// if current slice ..
// 	{
// 		return m_hcSlice0[_lX + _lY*m_lWidth].m_lFaceEdges;
// 	}
// 	if (_lZ == m_lZpos-1)		// if previous slice ...
// 	{
// 		return m_hcSlice1[_lX + _lY*m_lWidth].m_lFaceEdges;
// 	}
// 	
// 	abort();
// 	return NULL; // never reached but remove warning
// }


/*
* set the face inside a cube of the buffer
*/
template <typename DART, typename DATATYPE>
96
void BufferGen<DART,DATATYPE>::setFacesCube(int _lX,int _lY, const DART* const _lFace)
Pierre Kraemer's avatar
Pierre Kraemer committed
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
{
	// get the address of cube's table
	DART* lLocFaces  = m_hcSlice1[_lX + _lY*m_lWidth].m_lFaceEdges;
	
//	for (int i=0; i<4; ++i)
	for (int i=0; i<5; ++i)  // 5!!!
	{
		lLocFaces[i] = _lFace[i];     // copy faces indices
	}
}	


/*
* next slice !!
*/
template <typename DART, typename DATATYPE>
void BufferGen<DART,DATATYPE>::nextSlice()
{
	 m_lZpos ++;					// increase position
	
	 HalfCubeGen<DART> *lTemp = m_hcSlice0;
	 m_hcSlice0 = m_hcSlice1;     // current slice -> old slice
	 m_hcSlice1 = lTemp;          // old slice -> new slice

	DATATYPE *lTemp2 = m_dataSl0;
	m_dataSl0 = m_dataSl1;
	m_dataSl1 = lTemp2;
}


/*
*  get address of face table for direct access
*/
template <typename DART, typename DATATYPE>
131
DART* BufferGen<DART,DATATYPE>::getFacesCubeTableAdr(int _lX,int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
132 133 134 135 136 137 138 139 140 141
{
	return  m_hcSlice0[_lX + _lY*m_lWidth].m_lFaceEdges;
}


/*
* set point on edges functions
*/

template <typename DART, typename DATATYPE>
142
void BufferGen<DART,DATATYPE>::setPointEdge0(int _lX,int _lY, unsigned int _lPoint)
Pierre Kraemer's avatar
Pierre Kraemer committed
143 144 145 146 147 148
{
	m_hcSlice0[_lX + _lY*m_lWidth].m_lX = _lPoint;
}


template <typename DART, typename DATATYPE>
149
void BufferGen<DART,DATATYPE>::setPointEdge3(int _lX,int _lY, unsigned int _lPoint)
Pierre Kraemer's avatar
Pierre Kraemer committed
150 151 152 153 154 155
{
	m_hcSlice0[_lX +(_lY-1)*m_lWidth].m_lY = _lPoint;
}


template <typename DART, typename DATATYPE>
156
void BufferGen<DART,DATATYPE>::setPointEdge8(int _lX,int _lY, unsigned int _lPoint)
Pierre Kraemer's avatar
Pierre Kraemer committed
157 158 159 160 161 162
{
	m_hcSlice0[_lX + _lY*m_lWidth].m_lZ = _lPoint;
}


template <typename DART, typename DATATYPE>
163
void BufferGen<DART,DATATYPE>::setPointEdge2(int _lX,int _lY, unsigned int _lPoint)
Pierre Kraemer's avatar
Pierre Kraemer committed
164 165 166 167 168 169
{
	m_hcSlice0[(_lX-1) +_lY*m_lWidth].m_lX =_lPoint;
}


template <typename DART, typename DATATYPE>
170
void BufferGen<DART,DATATYPE>::setPointEdge11(int _lX,int _lY, unsigned int _lPoint)
Pierre Kraemer's avatar
Pierre Kraemer committed
171 172 173 174 175 176
{
	m_hcSlice0[_lX + _lY*m_lWidth].m_lZ = _lPoint;
}


template <typename DART, typename DATATYPE>
177
void BufferGen<DART,DATATYPE>::setPointEdge1(int _lX,int _lY, unsigned int _lPoint)
Pierre Kraemer's avatar
Pierre Kraemer committed
178 179 180 181 182 183
{
	m_hcSlice0[_lX +_lY*m_lWidth].m_lY =_lPoint;
}


template <typename DART, typename DATATYPE>
184
void BufferGen<DART,DATATYPE>::setPointEdge9(int _lX,int _lY, unsigned int _lPoint)
Pierre Kraemer's avatar
Pierre Kraemer committed
185 186 187 188 189 190
{
	m_hcSlice0[_lX +_lY*m_lWidth].m_lZ =_lPoint;
}


template <typename DART, typename DATATYPE>
191
void BufferGen<DART,DATATYPE>::setPointEdge10(int _lX,int _lY, unsigned int _lPoint)
Pierre Kraemer's avatar
Pierre Kraemer committed
192 193 194 195 196 197
{
	m_hcSlice0[_lX +_lY*m_lWidth].m_lZ =_lPoint;
}


template <typename DART, typename DATATYPE>
198
void BufferGen<DART,DATATYPE>::setPointEdge7(int _lX,int _lY, unsigned int _lPoint)
Pierre Kraemer's avatar
Pierre Kraemer committed
199 200 201 202 203 204
{
	m_hcSlice1[_lX +(_lY-1)*m_lWidth].m_lY =_lPoint;
}


template <typename DART, typename DATATYPE>
205
void BufferGen<DART,DATATYPE>::setPointEdge4(int _lX,int _lY, unsigned int _lPoint)
Pierre Kraemer's avatar
Pierre Kraemer committed
206 207 208 209 210 211
{
	m_hcSlice1[_lX +_lY*m_lWidth].m_lX =_lPoint;
}


template <typename DART, typename DATATYPE>
212
void BufferGen<DART,DATATYPE>::setPointEdge6(int _lX,int _lY, unsigned int _lPoint)
Pierre Kraemer's avatar
Pierre Kraemer committed
213 214 215 216 217 218
{
	m_hcSlice1[(_lX-1) + _lY*m_lWidth].m_lX =_lPoint;
}


template <typename DART, typename DATATYPE>
219
void BufferGen<DART,DATATYPE>::setPointEdge5(int _lX,int _lY, unsigned int _lPoint)
Pierre Kraemer's avatar
Pierre Kraemer committed
220 221 222 223 224 225 226 227 228 229
{
	m_hcSlice1[_lX +_lY*m_lWidth].m_lY =_lPoint;
}


/*
* get point on edges functions
*/

template <typename DART, typename DATATYPE>
230
unsigned int BufferGen<DART,DATATYPE>::getPointEdge0(int _lX,int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
231 232 233 234 235 236
{
	return m_hcSlice0[_lX + _lY*m_lWidth].m_lX;
}


template <typename DART, typename DATATYPE>
237
unsigned int BufferGen<DART,DATATYPE>::getPointEdge3(int _lX,int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
238 239 240 241 242 243
{
	return m_hcSlice0[_lX +_lY*m_lWidth].m_lY;
}


template <typename DART, typename DATATYPE>
244
unsigned int BufferGen<DART,DATATYPE>::getPointEdge8(int _lX,int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
245 246 247 248 249 250
{
	return m_hcSlice0[_lX + _lY*m_lWidth].m_lZ;
}


template <typename DART, typename DATATYPE>
251
unsigned int BufferGen<DART,DATATYPE>::getPointEdge2(int _lX,int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
252 253 254 255 256 257
{
	return m_hcSlice0[_lX +(_lY+1)*m_lWidth].m_lX;
}


template <typename DART, typename DATATYPE>
258
unsigned int BufferGen<DART,DATATYPE>::getPointEdge11(int _lX,int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
259 260 261 262 263 264
{
	return m_hcSlice0[_lX + (_lY+1)*m_lWidth].m_lZ;
}


template <typename DART, typename DATATYPE>
265
unsigned int BufferGen<DART,DATATYPE>::getPointEdge1(int _lX,int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
266 267 268 269 270 271
{
	return m_hcSlice0[(_lX+1) +_lY*m_lWidth].m_lY;
}


template <typename DART, typename DATATYPE>
272
unsigned int BufferGen<DART,DATATYPE>::getPointEdge9(int _lX,int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
273 274 275 276 277 278
{
	return m_hcSlice0[(_lX+1) +_lY*m_lWidth].m_lZ;
}


template <typename DART, typename DATATYPE>
279
unsigned int BufferGen<DART,DATATYPE>::getPointEdge10(int _lX,int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
280 281 282 283 284 285
{
	return m_hcSlice0[(_lX+1) +(_lY+1)*m_lWidth].m_lZ;
}


template <typename DART, typename DATATYPE>
286
unsigned int BufferGen<DART,DATATYPE>::getPointEdge7(int _lX,int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
287 288 289 290 291 292
{
	return m_hcSlice1[_lX +_lY*m_lWidth].m_lY;
}


template <typename DART, typename DATATYPE>
293
unsigned int BufferGen<DART,DATATYPE>::getPointEdge4(int _lX,int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
294 295 296 297 298 299
{
	return m_hcSlice1[_lX +_lY*m_lWidth].m_lX;
}


template <typename DART, typename DATATYPE>
300
unsigned int BufferGen<DART,DATATYPE>::getPointEdge6(int _lX,int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
301 302 303 304 305 306
{
	return m_hcSlice1[_lX +(_lY+1)*m_lWidth].m_lX;
}


template <typename DART, typename DATATYPE>
307
unsigned int BufferGen<DART,DATATYPE>::getPointEdge5(int _lX,int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
308 309 310 311 312 313
{
	return m_hcSlice1[(_lX+1) +_lY*m_lWidth].m_lY;
}


template <typename DART, typename DATATYPE>
314
DART BufferGen<DART,DATATYPE>::getExternalNeighbour(char _cEdge, int _lX, int _lY) const
Pierre Kraemer's avatar
Pierre Kraemer committed
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
{

	switch(_cEdge)
	{
		case 0:
			return m_hcSlice0[_lX + _lY*m_lWidth].m_lNX;
			break;
			
		case 1:
			return m_hcSlice0[(_lX+1) +_lY*m_lWidth].m_lNY;
 			break;

		case 2:
			return m_hcSlice0[_lX +(_lY+1)*m_lWidth].m_lNX;
			break;

		case 3:
			return m_hcSlice0[_lX +_lY*m_lWidth].m_lNY;
			break;

		case 4:
			return m_hcSlice1[_lX +_lY*m_lWidth].m_lNX;
			break;

		case 5:
			return m_hcSlice1[(_lX+1) +_lY*m_lWidth].m_lNY;
			break;

		case 6:
			return m_hcSlice1[_lX +(_lY+1)*m_lWidth].m_lNX;
			break;

		case 7:
			return m_hcSlice1[_lX +_lY*m_lWidth].m_lNY;
			break;

		case 8:
			return m_hcSlice0[_lX + _lY*m_lWidth].m_lNZ;
			break;

		case 9:
			return m_hcSlice0[(_lX+1) +_lY*m_lWidth].m_lNZ;
			break;

		case 10:
			return m_hcSlice0[(_lX+1) +(_lY+1)*m_lWidth].m_lNZ;
			break;

		case 11:
			return m_hcSlice0[_lX + (_lY+1)*m_lWidth].m_lNZ;
			break;
	
		default:
368
			CGoGNerr << "ERROR"<<CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
369 370 371 372
			return m_hcSlice0[0].m_lNX; // pipo value
	}

	// just for removing the warning never reached because of the default of switch
373
CGoGNerr << "ERROR"<<CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
374 375 376 377 378
	return m_hcSlice0[0].m_lNX;
}


template <typename DART, typename DATATYPE>
379
void BufferGen<DART,DATATYPE>::setExternalNeighbour(char _cEdge, int _lX, int _lY, DART _lNeighbour)
Pierre Kraemer's avatar
Pierre Kraemer committed
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
{
	switch(_cEdge)
	{
		case 0:
			m_hcSlice0[_lX + _lY*m_lWidth].m_lNX = _lNeighbour;
			break;

		case 1:
			m_hcSlice0[(_lX+1) +_lY*m_lWidth].m_lNY = _lNeighbour;
 			break;

		case 2:
			m_hcSlice0[_lX +(_lY+1)*m_lWidth].m_lNX = _lNeighbour;
			break;

		case 3:
			m_hcSlice0[_lX +_lY*m_lWidth].m_lNY = _lNeighbour;
			break;

		case 4:
			m_hcSlice1[_lX +_lY*m_lWidth].m_lNX = _lNeighbour;
			break;

		case 5:
			m_hcSlice1[(_lX+1) +_lY*m_lWidth].m_lNY = _lNeighbour;
			break;

		case 6:
			m_hcSlice1[_lX +(_lY+1)*m_lWidth].m_lNX = _lNeighbour;
			break;

		case 7:
			m_hcSlice1[_lX +_lY*m_lWidth].m_lNY = _lNeighbour;
			break;

		case 8:
			m_hcSlice0[_lX + _lY*m_lWidth].m_lNZ = _lNeighbour;
			break;

		case 9:
			m_hcSlice0[(_lX+1) +_lY*m_lWidth].m_lNZ = _lNeighbour;
			break;

		case 10:
			m_hcSlice0[(_lX+1) +(_lY+1)*m_lWidth].m_lNZ = _lNeighbour;
			break;

		case 11:
			m_hcSlice0[_lX + (_lY+1)*m_lWidth].m_lNZ = _lNeighbour;
			break;
	
		default:
432
			CGoGNerr << "ERROR"<<CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
433 434 435 436
	}
}

/*template <typename DART, typename DATATYPE>
437
void BufferGen<DART,DATATYPE>::setData(int _lX, int _lY, DATATYPE data)
Pierre Kraemer's avatar
Pierre Kraemer committed
438 439 440 441 442 443
{
	m_dataSl0[_lX +_lY*m_lWidth] = data;
}


template <typename DART, typename DATATYPE>
444
DATATYPE BufferGen<DART,DATATYPE>::getData(int _lX, int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
445 446 447 448 449
{
	return m_dataSl0[_lX +_lY*m_lWidth];
}

template <typename DART, typename DATATYPE>
450
void BufferGen<DART,DATATYPE>::setData2(int _lX, int _lY, DATATYPE data)
Pierre Kraemer's avatar
Pierre Kraemer committed
451 452 453 454 455 456
{
		m_dataSl1[_lX +_lY*m_lWidth] = data;
}


template <typename DART, typename DATATYPE>
457
DATATYPE BufferGen<DART,DATATYPE>::getData2(int _lX, int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
458 459 460 461 462 463
{
	return m_dataSl1[_lX +_lY*m_lWidth];
}*/


template <typename DART, typename DATATYPE>
464
void BufferGen<DART,DATATYPE>::setData(int _lX, int _lY, DATATYPE data)
Pierre Kraemer's avatar
Pierre Kraemer committed
465 466 467 468 469 470 471
{
//	m_hcSlice0[_lX +_lY*m_lWidth].m_data = data;
	m_dataSl0[_lX +_lY*m_lWidth] = data;
}


template <typename DART, typename DATATYPE>
472
DATATYPE BufferGen<DART,DATATYPE>::getData(int _lX, int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
473 474
{
// 	if (m_dataSl0[_lX +_lY*m_lWidth] != m_hcSlice0[_lX +_lY*m_lWidth].m_data)
475
// 		CGoGNout << "ERRORRRRR !! "<<CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
476 477 478 479 480 481

	return m_dataSl0[_lX +_lY*m_lWidth];
//	return m_hcSlice0[_lX +_lY*m_lWidth].m_data;
}

template <typename DART, typename DATATYPE>
482
void BufferGen<DART,DATATYPE>::setData2(int _lX, int _lY, DATATYPE data)
Pierre Kraemer's avatar
Pierre Kraemer committed
483 484 485 486 487 488 489
{
		//m_hcSlice1[_lX +_lY*m_lWidth].m_data = data;
		m_dataSl1[_lX +_lY*m_lWidth] = data;
}


template <typename DART, typename DATATYPE>
490
DATATYPE BufferGen<DART,DATATYPE>::getData2(int _lX, int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
491 492
{
// 	if (m_dataSl1[_lX +_lY*m_lWidth] != m_hcSlice1[_lX +_lY*m_lWidth].m_data)
493
// 		CGoGNout << "ERRORRRRR !! "<<CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
494 495 496 497 498 499 500 501
	return m_dataSl1[_lX +_lY*m_lWidth];
//	return m_hcSlice1[_lX +_lY*m_lWidth].m_data;
}


} // end namespace
} // end namespace
} // end namespace
502
}
Pierre Kraemer's avatar
Pierre Kraemer committed
503