buffer.hpp 9.39 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>
41
Buffer<DART>::Buffer(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
{
	m_lWidth = _lWidth+1;
	m_lHeight = _lHeight+1;
	m_hcSlice0 = new HalfCube<DART>[m_lWidth*m_lHeight];
	m_hcSlice1 = new HalfCube<DART>[m_lWidth*m_lHeight];
	m_lZpos = 0;

}


/*
* destructor
*/
template<typename DART>
Buffer<DART>::~Buffer()
{                         	
	delete[] m_hcSlice0;
	delete[] m_hcSlice1;
}



/*
* get the face inside a cube of the buffer
*/	
// template <typename DART>
68
// const DART* Buffer<DART>::getFacesCube(int _lX, int _lY, int _lZ) const
Pierre Kraemer's avatar
Pierre Kraemer committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
// {
// 
// 	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>
89
void Buffer<DART>::setFacesCube(int _lX,int _lY, const DART* const _lFace)
Pierre Kraemer's avatar
Pierre Kraemer committed
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
{
	// 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>
void Buffer<DART>::nextSlice()
{
	 m_lZpos ++;					// increase position
	
	 HalfCube<DART> *lTemp = m_hcSlice0;
	 m_hcSlice0 = m_hcSlice1;     // current slice -> old slice
	 m_hcSlice1 = lTemp;          // old slice -> new slice
}


/*
*  get address of face table for direct access
*/
template <typename DART>
120
DART* Buffer<DART>::getFacesCubeTableAdr(int _lX,int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
121 122 123 124 125 126 127 128 129 130
{
	return  m_hcSlice0[_lX + _lY*m_lWidth].m_lFaceEdges;
}


/*
* set point on edges functions
*/

template <typename DART>
131
void Buffer<DART>::setPointEdge0(int _lX,int _lY, unsigned int _lPoint)
Pierre Kraemer's avatar
Pierre Kraemer committed
132 133 134 135 136 137
{
	m_hcSlice0[_lX + _lY*m_lWidth].m_lX = _lPoint;
}


template <typename DART>
138
void Buffer<DART>::setPointEdge3(int _lX,int _lY, unsigned int _lPoint)
Pierre Kraemer's avatar
Pierre Kraemer committed
139 140 141 142 143 144
{
	m_hcSlice0[_lX +(_lY-1)*m_lWidth].m_lY = _lPoint;
}


template <typename DART>
145
void Buffer<DART>::setPointEdge8(int _lX,int _lY, unsigned int _lPoint)
Pierre Kraemer's avatar
Pierre Kraemer committed
146 147 148 149 150 151
{
	m_hcSlice0[_lX + _lY*m_lWidth].m_lZ = _lPoint;
}


template <typename DART>
152
void Buffer<DART>::setPointEdge2(int _lX,int _lY, unsigned int _lPoint)
Pierre Kraemer's avatar
Pierre Kraemer committed
153 154 155 156 157 158
{
	m_hcSlice0[(_lX-1) +_lY*m_lWidth].m_lX =_lPoint;
}


template <typename DART>
159
void Buffer<DART>::setPointEdge11(int _lX,int _lY, unsigned int _lPoint)
Pierre Kraemer's avatar
Pierre Kraemer committed
160 161 162 163 164 165
{
	m_hcSlice0[_lX + _lY*m_lWidth].m_lZ = _lPoint;
}


template <typename DART>
166
void Buffer<DART>::setPointEdge1(int _lX,int _lY, unsigned int _lPoint)
Pierre Kraemer's avatar
Pierre Kraemer committed
167 168 169 170 171 172
{
	m_hcSlice0[_lX +_lY*m_lWidth].m_lY =_lPoint;
}


template <typename DART>
173
void Buffer<DART>::setPointEdge9(int _lX,int _lY, unsigned int _lPoint)
Pierre Kraemer's avatar
Pierre Kraemer committed
174 175 176 177 178 179
{
	m_hcSlice0[_lX +_lY*m_lWidth].m_lZ =_lPoint;
}


template <typename DART>
180
void Buffer<DART>::setPointEdge10(int _lX,int _lY, unsigned int _lPoint)
Pierre Kraemer's avatar
Pierre Kraemer committed
181 182 183 184 185 186
{
	m_hcSlice0[_lX +_lY*m_lWidth].m_lZ =_lPoint;
}


template <typename DART>
187
void Buffer<DART>::setPointEdge7(int _lX,int _lY, unsigned int _lPoint)
Pierre Kraemer's avatar
Pierre Kraemer committed
188 189 190 191 192 193
{
	m_hcSlice1[_lX +(_lY-1)*m_lWidth].m_lY =_lPoint;
}


template <typename DART>
194
void Buffer<DART>::setPointEdge4(int _lX,int _lY, unsigned int _lPoint)
Pierre Kraemer's avatar
Pierre Kraemer committed
195 196 197 198 199 200
{
	m_hcSlice1[_lX +_lY*m_lWidth].m_lX =_lPoint;
}


template <typename DART>
201
void Buffer<DART>::setPointEdge6(int _lX,int _lY, unsigned int _lPoint)
Pierre Kraemer's avatar
Pierre Kraemer committed
202 203 204 205 206 207
{
	m_hcSlice1[(_lX-1) + _lY*m_lWidth].m_lX =_lPoint;
}


template <typename DART>
208
void Buffer<DART>::setPointEdge5(int _lX,int _lY, unsigned int _lPoint)
Pierre Kraemer's avatar
Pierre Kraemer committed
209 210 211 212 213 214 215 216 217 218
{
	m_hcSlice1[_lX +_lY*m_lWidth].m_lY =_lPoint;
}


/*
* get point on edges functions
*/

template <typename DART>
219
unsigned int Buffer<DART>::getPointEdge0(int _lX,int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
220 221 222 223 224 225
{
	return m_hcSlice0[_lX + _lY*m_lWidth].m_lX;
}


template <typename DART>
226
unsigned int Buffer<DART>::getPointEdge3(int _lX,int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
227 228 229 230 231 232
{
	return m_hcSlice0[_lX +_lY*m_lWidth].m_lY;
}


template <typename DART>
233
unsigned int Buffer<DART>::getPointEdge8(int _lX,int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
234 235 236 237 238 239
{
	return m_hcSlice0[_lX + _lY*m_lWidth].m_lZ;
}


template <typename DART>
240
unsigned int Buffer<DART>::getPointEdge2(int _lX,int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
241 242 243 244 245 246
{
	return m_hcSlice0[_lX +(_lY+1)*m_lWidth].m_lX;
}


template <typename DART>
247
unsigned int Buffer<DART>::getPointEdge11(int _lX,int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
248 249 250 251 252 253
{
	return m_hcSlice0[_lX + (_lY+1)*m_lWidth].m_lZ;
}


template <typename DART>
254
unsigned int Buffer<DART>::getPointEdge1(int _lX,int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
255 256 257 258 259 260
{
	return m_hcSlice0[(_lX+1) +_lY*m_lWidth].m_lY;
}


template <typename DART>
261
unsigned int Buffer<DART>::getPointEdge9(int _lX,int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
262 263 264 265 266 267
{
	return m_hcSlice0[(_lX+1) +_lY*m_lWidth].m_lZ;
}


template <typename DART>
268
unsigned int Buffer<DART>::getPointEdge10(int _lX,int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
269 270 271 272 273 274
{
	return m_hcSlice0[(_lX+1) +(_lY+1)*m_lWidth].m_lZ;
}


template <typename DART>
275
unsigned int Buffer<DART>::getPointEdge7(int _lX,int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
276 277 278 279 280 281
{
	return m_hcSlice1[_lX +_lY*m_lWidth].m_lY;
}


template <typename DART>
282
unsigned int Buffer<DART>::getPointEdge4(int _lX,int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
283 284 285 286 287 288
{
	return m_hcSlice1[_lX +_lY*m_lWidth].m_lX;
}


template <typename DART>
289
unsigned int Buffer<DART>::getPointEdge6(int _lX,int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
290 291 292 293 294 295
{
	return m_hcSlice1[_lX +(_lY+1)*m_lWidth].m_lX;
}


template <typename DART>
296
unsigned int Buffer<DART>::getPointEdge5(int _lX,int _lY)
Pierre Kraemer's avatar
Pierre Kraemer committed
297 298 299 300 301 302
{
	return m_hcSlice1[(_lX+1) +_lY*m_lWidth].m_lY;
}


template <typename DART>
303
DART Buffer<DART>::getExternalNeighbour(char _cEdge, int _lX, int _lY) const
Pierre Kraemer's avatar
Pierre Kraemer committed
304 305 306 307 308 309 310 311 312 313 314 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
{

	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:
357
			CGoGNerr << "ERROR"<<CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
358 359 360 361
			return m_hcSlice0[0].m_lNX; // pipo value
	}

	// just for removing the warning never reached because of the default of switch
362
CGoGNerr << "ERROR"<<CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
363 364 365 366 367
	return m_hcSlice0[0].m_lNX;
}


template <typename DART>
368
void Buffer<DART>::setExternalNeighbour(char _cEdge, int _lX, int _lY, DART _lNeighbour)
Pierre Kraemer's avatar
Pierre Kraemer committed
369 370 371 372 373 374 375 376 377 378 379 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
{
	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:
421
			CGoGNerr << "ERROR"<<CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
422 423 424
	}
}

425
}
Pierre Kraemer's avatar
Pierre Kraemer committed
426 427 428 429
} // end namespace
} // end namespace
} // end namespace