Coupure prévue mardi 3 Août au matin pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

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

Sylvain Thery's avatar
Sylvain Thery committed
25
26
#include "Algo/MC/windowing.h"
#include "Topology/generic/dartmarker.h"
27
#include <vector>
Pierre Kraemer's avatar
Pierre Kraemer committed
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

namespace CGoGN
{

namespace Algo
{

namespace MC
{
template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
MarchingCube<DataType, Windowing, PFP>::MarchingCube(const char* _cName)
{
	m_Image = new Image<DataType>();

	m_Image->loadInr(_cName); // voxel sizes initialized with (1.0,1.0,1.0)
	m_Buffer = NULL;
	m_map = NULL;

	m_fOrigin = typename PFP::VEC3(0.0,0.0,0.0);
	m_fScal = typename PFP::VEC3(1.0,1.0,1.0);

}


template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
MarchingCube<DataType, Windowing, PFP>::MarchingCube(Image<DataType>* img, Windowing<DataType> wind, bool boundRemoved):
	m_Image(img),
	m_windowFunc(wind),
	m_Buffer(NULL),
	m_map(NULL),
	m_fOrigin(typename PFP::VEC3(0.0,0.0,0.0)),
	m_fScal(typename PFP::VEC3(1.0,1.0,1.0)),
	m_brem(boundRemoved)
{
}

template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
Sylvain Thery's avatar
MAJ MC  
Sylvain Thery committed
65
MarchingCube<DataType, Windowing, PFP>::MarchingCube(Image<DataType>* img, L_MAP* map, const typename PFP::TVEC3& position, Windowing<DataType> wind, bool boundRemoved):
Pierre Kraemer's avatar
Pierre Kraemer committed
66
67
68
69
	m_Image(img),
	m_windowFunc(wind),
	m_Buffer(NULL),
	m_map(map),
Sylvain Thery's avatar
MAJ MC  
Sylvain Thery committed
70
	m_positions(position),
Pierre Kraemer's avatar
Pierre Kraemer committed
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
	m_fOrigin(typename PFP::VEC3(0.0,0.0,0.0)),
	m_fScal(typename PFP::VEC3(1.0,1.0,1.0)),
	m_brem(boundRemoved)
{
}


template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
MarchingCube<DataType, Windowing, PFP>::~MarchingCube()
{
//	if (m_Image != NULL)
//	{
//		delete m_Image;
//	}
//
	if (m_Buffer != NULL)
	{
		delete m_Buffer;
		m_Buffer = NULL;
	}
}

template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
void MarchingCube<DataType, Windowing, PFP>::deleteMesh()
{
	if (m_map != NULL)
	{
		delete m_map;
		m_map = NULL;
	}
}

103
104
105
106
107
108

template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
Dart  MarchingCube<DataType, Windowing, PFP>::createTriEmb(unsigned int e1, unsigned int e2, unsigned int e3)
{
	L_DART d = m_map->newFace(3,false);
		
Sylvain Thery's avatar
Sylvain Thery committed
109
110
111
112
113
114
115
116
117
	FunctorSetEmb<GenericMap> fsetemb(*m_map, VERTEX, e1);
	m_map->foreach_dart_of_orbit(PFP::MAP::ORBIT_IN_PARENT(VERTEX), d, fsetemb);
	d = m_map->phi1(d);
	fsetemb.changeEmb(e2);
	m_map->foreach_dart_of_orbit(PFP::MAP::ORBIT_IN_PARENT(VERTEX), d, fsetemb);
	d = m_map->phi1(d);
	fsetemb.changeEmb(e3);
	m_map->foreach_dart_of_orbit(PFP::MAP::ORBIT_IN_PARENT(VERTEX), d, fsetemb);
	d = m_map->phi1(d);
118
119
120
121

	return d;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
void MarchingCube<DataType, Windowing, PFP>::simpleMeshing()
{

	// create the mesh if needed
	if (m_map==NULL)
	{
		m_map = new L_MAP();
	}

	// create the buffer
	if (m_Buffer != NULL)
	{
		delete m_Buffer;
	}

	m_Buffer = new Buffer<L_DART>(m_Image->getWidthX(),m_Image->getWidthY());

	// compute value to transform points directly to final system coordinate

Sylvain Thery's avatar
Sylvain Thery committed
142
	m_fOrigin   =  typename PFP::VEC3((float)(m_Image->getOrigin()[0]),(float)(m_Image->getOrigin()[1]),(float)(m_Image->getOrigin()[2]));
Pierre Kraemer's avatar
Pierre Kraemer committed
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218

	m_fScal[0] = m_Image->getVoxSizeX();
	m_fScal[1] = m_Image->getVoxSizeY();
	m_fScal[2] = m_Image->getVoxSizeZ();



	// get access to data (pointer + size)

	DataType* ucData = m_Image->getData();

//	DataType* ucDa = ucData;

	int lTx = m_Image->getWidthX();
	int lTy = m_Image->getWidthY();
	int lTz = m_Image->getWidthZ();


/*	gmtl::Vec3i orig = m_Image->getOrigin();*/

	int lTxm = lTx - 1 ;
	int lTym = lTy - 1;
	int lTzm = lTz - 1;

	int lZ,lY,lX;

	lX = 0 ;
	lY = 0 ;
	lZ = 0 ;
	ucData = m_Image->getVoxelPtr(lX,lY,lZ);

	createFaces_1(ucData++,lX++,lY,lZ,1);  // TAG

	while (lX < lTxm)
	{
		createFaces_2(ucData++,lX++,lY,lZ,1);   // TAG
	}
	lY++;

	while (lY < lTym)   // 2nd and others rows  lY = 1..
	{
		lX = 0;
		ucData = m_Image->getVoxelPtr(lX,lY,lZ);

		createFaces_3(ucData++,lX++,lY,lZ,1); // TAG
		while (lX < lTxm)
		{
			createFaces_4(ucData++,lX++,lY,lZ,1);  // TAG
		}
		lY++;
	}
	lZ++;
	m_Buffer->nextSlice();

// middles slices

	while (lZ < lTzm)
	{
		lY = 0;
		lX = 0;

		ucData = m_Image->getVoxelPtr(lX,lY,lZ);

		createFaces_5(ucData++,lX++,lY,lZ,4);  // TAG
		while (lX < lTxm)
		{
			createFaces_6(ucData++,lX++,lY,lZ,4);   // TAG
		}
		lY++;

		while (lY<lTym)   // 2nd and others rows  lY = 1..
		{
			lX = 0;
			ucData = m_Image->getVoxelPtr(lX,lY,lZ);

			createFaces_7(ucData++,lX++,lY,lZ,16); // TAG
Sylvain Thery's avatar
Sylvain Thery committed
219
			while (lX < lTxm-1)
Pierre Kraemer's avatar
Pierre Kraemer committed
220
221
222
			{
				createFaces_8(ucData++,lX++,lY,lZ,0);
			}
Sylvain Thery's avatar
Sylvain Thery committed
223
			createFaces_8(ucData++,lX,lY,lZ,32);   //TAG
Pierre Kraemer's avatar
Pierre Kraemer committed
224
225
226
227
228
229
230
			lY++;
		}

		lZ++;
		m_Buffer->nextSlice();
	}

Sylvain Thery's avatar
MAJ MC  
Sylvain Thery committed
231
	CGoGNout << "Taille 2-carte:"<<m_map->getNbDarts()<<" brins"<<CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
232
233
234
235
236
237
238
239
240
241
242
243

}



template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
unsigned char MarchingCube<DataType, Windowing, PFP>::computeIndex(const DataType* const _ucData) const
{
	unsigned char ucCubeIndex = 0;
	const DataType* ucDataLocal = _ucData;


244
245
	int lTx = m_Image->getWidthX();
	int lTxy = m_Image->getWidthXY();
Pierre Kraemer's avatar
Pierre Kraemer committed
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
275
276
277
278


	if ( m_windowFunc.inside(*ucDataLocal) )
		ucCubeIndex = 1; // point 0
	ucDataLocal ++;
	if ( m_windowFunc.inside(*ucDataLocal) )
		ucCubeIndex += 2; // point 1
	ucDataLocal += lTx;
	if ( m_windowFunc.inside(*ucDataLocal) )
		ucCubeIndex += 4; // point 2
	ucDataLocal --;
	if ( m_windowFunc.inside(*ucDataLocal) )
		ucCubeIndex += 8; // point 3
	ucDataLocal += lTxy;
	if ( m_windowFunc.inside(*ucDataLocal) )
		ucCubeIndex += 128; // point 7
	ucDataLocal -= lTx;
	if ( m_windowFunc.inside(*ucDataLocal) )
		ucCubeIndex += 16; // point 4
	ucDataLocal ++;
	if ( m_windowFunc.inside(*ucDataLocal) )
		ucCubeIndex += 32; // point 5
	ucDataLocal += lTx;
	if ( m_windowFunc.inside(*ucDataLocal) )
		ucCubeIndex += 64; // point 6

	return ucCubeIndex;
}

template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
typename PFP::VEC3 MarchingCube<DataType, Windowing, PFP>::recalPoint(const typename PFP::VEC3& _P, const typename PFP::VEC3& _dec ) const
{
	typename PFP::VEC3 point = _P + _dec ;
279
280
281
282
283
//	point[0] = point[0] * m_fScal[0];
//	point[1] = point[1] * m_fScal[1];
//	point[2] = point[2] * m_fScal[2];
//
//	point += m_fOrigin;
Pierre Kraemer's avatar
Pierre Kraemer committed
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
	return 	point;
}



template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
void MarchingCube<DataType, Windowing, PFP>::createPointEdge0(const unsigned char _ucCubeIndex, const int _lX, const int _lY, const int _lZ,  unsigned int * const lVertTable, const typename PFP::VEC3& vPos)
{

	if  (accelMCTable::m_EdgeTable[_ucCubeIndex] & 1)
	{
		float interp = m_windowFunc.interpole( m_Image->getVoxel(_lX,_lY,_lZ), m_Image->getVoxel(_lX+1,_lY,_lZ) );

//		typename PFP::VEC3 newPoint = recalPoint(vPos,typename PFP::VEC3(interp, 0., 0.));
//		lVertTable[0] = L_EMB::create(newPoint);
299
		lVertTable[0] = m_map->newCell(VERTEX);
Pierre Kraemer's avatar
Pierre Kraemer committed
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
		m_positions[lVertTable[0]] = recalPoint(vPos,typename PFP::VEC3(interp, 0., 0.));
		m_Buffer->setPointEdge0(_lX, _lY,lVertTable[0]);
	}
}



template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
void MarchingCube<DataType, Windowing, PFP>::createPointEdge1(const unsigned char _ucCubeIndex, const int _lX, const int _lY, const int _lZ,  unsigned int * const lVertTable, const typename PFP::VEC3& vPos)
{

	if  (accelMCTable::m_EdgeTable[_ucCubeIndex] & 2)
	{
		float interp = m_windowFunc.interpole( m_Image->getVoxel(_lX,_lY,_lZ), m_Image->getVoxel(_lX,_lY+1,_lZ) );

//		typename PFP::VEC3 newPoint = recalPoint(vPos,typename PFP::VEC3(1.,interp, 0.));
//		lVertTable[1] = L_EMB::create(newPoint);
317
		lVertTable[1] = m_map->newCell(VERTEX);
Pierre Kraemer's avatar
Pierre Kraemer committed
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
		m_positions[lVertTable[1]] = recalPoint(vPos,typename PFP::VEC3(1.,interp, 0.));
		m_Buffer->setPointEdge1(_lX, _lY,lVertTable[1]);
	}
}


template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
void MarchingCube<DataType, Windowing, PFP>::createPointEdge2(const unsigned char _ucCubeIndex, const int _lX, const int _lY, const int _lZ,  unsigned int * const lVertTable, const typename PFP::VEC3& vPos)
{
	if  (accelMCTable::m_EdgeTable[_ucCubeIndex] & 4)
	{
		float interp = m_windowFunc.interpole( m_Image->getVoxel(_lX-1,_lY,_lZ), m_Image->getVoxel(_lX,_lY,_lZ) );

//		typename PFP::VEC3 newPoint = recalPoint(vPos,typename PFP::VEC3(interp, 1., 0.));
//		lVertTable[2] = L_EMB::create(newPoint);
333
		lVertTable[2] = m_map->newCell(VERTEX);
Pierre Kraemer's avatar
Pierre Kraemer committed
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
		m_positions[lVertTable[2]] = recalPoint(vPos,typename PFP::VEC3(interp, 1., 0.));
		m_Buffer->setPointEdge2(_lX, _lY,lVertTable[2]);
	}
}


template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
void MarchingCube<DataType, Windowing, PFP>::createPointEdge3(const unsigned char _ucCubeIndex, const int _lX, const int _lY, const int _lZ, unsigned int * const lVertTable, const typename PFP::VEC3& vPos)
{
	if  (accelMCTable::m_EdgeTable[_ucCubeIndex] & 8)
	{
		float interp = m_windowFunc.interpole( m_Image->getVoxel(_lX,_lY-1,_lZ), m_Image->getVoxel(_lX,_lY,_lZ) );

//		typename PFP::VEC3 newPoint = recalPoint(vPos,typename PFP::VEC3(0., interp, 0.));
//		lVertTable[3] = L_EMB::create(newPoint);
349
		lVertTable[3] = m_map->newCell(VERTEX);
Pierre Kraemer's avatar
Pierre Kraemer committed
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
		m_positions[lVertTable[3]] = recalPoint(vPos,typename PFP::VEC3(0., interp, 0.));
		m_Buffer->setPointEdge3(_lX, _lY,lVertTable[3]);
	}
}


template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
void MarchingCube<DataType, Windowing, PFP>::createPointEdge4(const unsigned char _ucCubeIndex, const int _lX, const int _lY, const int _lZ, unsigned int * const lVertTable, const typename PFP::VEC3& vPos)
{

	if  (accelMCTable::m_EdgeTable[_ucCubeIndex] & 16)
	{
		float interp = m_windowFunc.interpole( m_Image->getVoxel(_lX,_lY,_lZ), m_Image->getVoxel(_lX+1,_lY,_lZ) );

//		typename PFP::VEC3 newPoint = recalPoint(vPos,typename PFP::VEC3(interp, 0., 1.));
//		lVertTable[4] = L_EMB::create(newPoint);
366
		lVertTable[4] = m_map->newCell(VERTEX);
Pierre Kraemer's avatar
Pierre Kraemer committed
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
		m_positions[lVertTable[4]] = recalPoint(vPos,typename PFP::VEC3(interp, 0., 1.));
		m_Buffer->setPointEdge4(_lX, _lY,lVertTable[4]);
	}
}


template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
void MarchingCube<DataType, Windowing, PFP>::createPointEdge5(const unsigned char _ucCubeIndex,  const int _lX, const int _lY, const int _lZ, unsigned int * const lVertTable, const typename PFP::VEC3& vPos)
{

	if  (accelMCTable::m_EdgeTable[_ucCubeIndex] & 32)
 	{
		float interp = m_windowFunc.interpole( m_Image->getVoxel(_lX,_lY,_lZ), m_Image->getVoxel(_lX,_lY+1,_lZ) );

//		typename PFP::VEC3 newPoint = recalPoint(vPos,typename PFP::VEC3(1., interp, 1.));
//		lVertTable[5] = L_EMB::create(newPoint);
383
		lVertTable[5] = m_map->newCell(VERTEX);
Pierre Kraemer's avatar
Pierre Kraemer committed
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
		m_positions[lVertTable[5]] = recalPoint(vPos,typename PFP::VEC3(1., interp, 1.));
		m_Buffer->setPointEdge5(_lX, _lY,lVertTable[5]);
	}
}


template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
void MarchingCube<DataType, Windowing, PFP>::createPointEdge6(const unsigned char _ucCubeIndex, const int _lX, const int _lY, const int _lZ, unsigned int * const lVertTable, const typename PFP::VEC3& vPos)
{

	if  (accelMCTable::m_EdgeTable[_ucCubeIndex] & 64)
	{
		float interp = m_windowFunc.interpole( m_Image->getVoxel(_lX-1,_lY,_lZ), m_Image->getVoxel(_lX,_lY,_lZ) );

//		typename PFP::VEC3 newPoint = recalPoint(vPos,typename PFP::VEC3(interp, 1., 1.));
//		lVertTable[6] = L_EMB::create(newPoint);
400
		lVertTable[6] = m_map->newCell(VERTEX);
Pierre Kraemer's avatar
Pierre Kraemer committed
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
		m_positions[lVertTable[6]] = recalPoint(vPos,typename PFP::VEC3(interp, 1., 1.));
		m_Buffer->setPointEdge6(_lX, _lY,lVertTable[6]);
	}
}


template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
void MarchingCube<DataType, Windowing, PFP>::createPointEdge7(const unsigned char _ucCubeIndex, const int _lX, const int _lY, const int _lZ, unsigned int * const lVertTable, const typename PFP::VEC3& vPos)
{

	if  (accelMCTable::m_EdgeTable[_ucCubeIndex] & 128)
	{
		float interp = m_windowFunc.interpole( m_Image->getVoxel(_lX,_lY-1,_lZ), m_Image->getVoxel(_lX,_lY,_lZ) );

//		typename PFP::VEC3 newPoint = recalPoint(vPos,typename PFP::VEC3(0., interp, 1.));
//		lVertTable[7] = L_EMB::create(newPoint);
417
		lVertTable[7] = m_map->newCell(VERTEX);
Pierre Kraemer's avatar
Pierre Kraemer committed
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
		m_positions[lVertTable[7]] = recalPoint(vPos,typename PFP::VEC3(0., interp, 1.));
		m_Buffer->setPointEdge7(_lX, _lY,lVertTable[7]);
	}
}



template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
void MarchingCube<DataType, Windowing, PFP>::createPointEdge8(const unsigned char _ucCubeIndex, const int _lX, const int _lY, const int _lZ, unsigned int * const lVertTable, const typename PFP::VEC3& vPos)
{

	if  (accelMCTable::m_EdgeTable[_ucCubeIndex] & 256)
	{
		float interp = m_windowFunc.interpole( m_Image->getVoxel(_lX,_lY,_lZ), m_Image->getVoxel(_lX,_lY,_lZ+1) );

//		typename PFP::VEC3 newPoint = recalPoint(vPos,typename PFP::VEC3(0., 0., interp));
//		lVertTable[8] = L_EMB::create(newPoint);
435
		lVertTable[8] = m_map->newCell(VERTEX);
Pierre Kraemer's avatar
Pierre Kraemer committed
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
		m_positions[lVertTable[8]] = recalPoint(vPos,typename PFP::VEC3(0., 0., interp));
		m_Buffer->setPointEdge8(_lX, _lY,lVertTable[8]);
	}
}


template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
void MarchingCube<DataType, Windowing, PFP>::createPointEdge9(const unsigned char _ucCubeIndex,  const int _lX, const int _lY, const int _lZ, unsigned int * const lVertTable, const typename PFP::VEC3& vPos)
{

	if  (accelMCTable::m_EdgeTable[_ucCubeIndex] & 512)
	{
		float interp = m_windowFunc.interpole( m_Image->getVoxel(_lX,_lY,_lZ), m_Image->getVoxel(_lX,_lY,_lZ+1) );

//		typename PFP::VEC3 newPoint = recalPoint(vPos,typename PFP::VEC3(1., 0., interp));
//		lVertTable[9] = L_EMB::create(newPoint);
452
		lVertTable[9] = m_map->newCell(VERTEX);
Pierre Kraemer's avatar
Pierre Kraemer committed
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
		m_positions[lVertTable[9]] = recalPoint(vPos,typename PFP::VEC3(1., 0., interp));
		m_Buffer->setPointEdge9(_lX, _lY,lVertTable[9]);
	}
}


template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
void MarchingCube<DataType, Windowing, PFP>::createPointEdge10(const unsigned char _ucCubeIndex, const int _lX, const int _lY, const int _lZ, unsigned int * const lVertTable, const typename PFP::VEC3& vPos)
{

	if  (accelMCTable::m_EdgeTable[_ucCubeIndex] & 1024)
	{
		float interp = m_windowFunc.interpole( m_Image->getVoxel(_lX,_lY,_lZ), m_Image->getVoxel(_lX,_lY,_lZ+1) );

//		typename PFP::VEC3 newPoint = recalPoint(vPos,typename PFP::VEC3(1., 1., interp));
//		lVertTable[10] = L_EMB::create(newPoint);
469
		lVertTable[10] = m_map->newCell(VERTEX);
Pierre Kraemer's avatar
Pierre Kraemer committed
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
		m_positions[lVertTable[10]] = recalPoint(vPos,typename PFP::VEC3(1., 1., interp));
		m_Buffer->setPointEdge10(_lX, _lY,lVertTable[10]);
	}
}


template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
void MarchingCube<DataType, Windowing, PFP>::createPointEdge11(const unsigned char _ucCubeIndex, const int _lX, const int _lY, const int _lZ, unsigned int * const lVertTable, const typename PFP::VEC3& vPos)
{

	if  (accelMCTable::m_EdgeTable[_ucCubeIndex] & 2048)
	{
		float interp = m_windowFunc.interpole( m_Image->getVoxel(_lX,_lY,_lZ), m_Image->getVoxel(_lX,_lY,_lZ+1) );

//		typename PFP::VEC3 newPoint = recalPoint(vPos,typename PFP::VEC3(0., 1., interp));
//		lVertTable[11] = L_EMB::create(newPoint);
486
		lVertTable[11] = m_map->newCell(VERTEX);
Pierre Kraemer's avatar
Pierre Kraemer committed
487
488
489
490
491
492
493
494
495
496
		m_positions[lVertTable[11]] = recalPoint(vPos,typename PFP::VEC3(0., 1., interp));
		m_Buffer->setPointEdge11(_lX, _lY,lVertTable[11]);
	}
}





template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
497
void MarchingCube<DataType, Windowing, PFP>::createFaces_1(DataType *vox, const int _lX,const int _lY,const int _lZ, unsigned char tag)
Pierre Kraemer's avatar
Pierre Kraemer committed
498
499
500
501
502
503
504
{
	unsigned char ucCubeIndex = computeIndex(vox);
	if ((ucCubeIndex == 0) || (ucCubeIndex == 255))
		return;

	unsigned int  lVertTable[12];

Sylvain Thery's avatar
Sylvain Thery committed
505
506
507
//	typename PFP::VEC3 vPos(float(_lX) , float(_lY) , float(_lZ) );
//	typename PFP::VEC3 vPos(float(_lX) + 0.5f, float(_lY) + 0.5f, (float)_lZ + 0.5f);
	typename PFP::VEC3 vPos(_lX, _lY, _lZ);
Pierre Kraemer's avatar
Pierre Kraemer committed
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561

// create the new  vertices

	int lX = _lX;
	int lY = _lY;
	int lZ = _lZ;

//	float curv = m_Curvature.computeCurvatureSimple(vox);
	float curv = 0.0f;
	createPointEdge0( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	createPointEdge8( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lX++;
	createPointEdge1( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	createPointEdge9( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lY++;
	createPointEdge2( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	createPointEdge10( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lX--;
	createPointEdge3( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	createPointEdge11( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lZ++;
	createPointEdge7( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lY--;
	createPointEdge4( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lX++;
	createPointEdge5( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lY++;
	createPointEdge6( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);


// get the shared vertices corresponding to the shared edges :
	//all edges
	    lVertTable[ 0]  = m_Buffer->getPointEdge0(_lX, _lY);
	    lVertTable[ 1]  = m_Buffer->getPointEdge1(_lX, _lY);
	    lVertTable[ 2]  = m_Buffer->getPointEdge2(_lX, _lY);
	    lVertTable[ 3]  = m_Buffer->getPointEdge3(_lX, _lY);
	    lVertTable[ 4]  = m_Buffer->getPointEdge4(_lX, _lY);
	    lVertTable[ 5]  = m_Buffer->getPointEdge5(_lX, _lY);
	    lVertTable[ 6]  = m_Buffer->getPointEdge6(_lX, _lY);
	    lVertTable[ 7]  = m_Buffer->getPointEdge7(_lX, _lY);
	    lVertTable[ 8]  = m_Buffer->getPointEdge8(_lX, _lY);
	    lVertTable[ 9]  = m_Buffer->getPointEdge9(_lX, _lY);
	    lVertTable[10]  = m_Buffer->getPointEdge10(_lX, _lY);
	    lVertTable[11]  = m_Buffer->getPointEdge11(_lX, _lY);

// create the new faces, the mask (6 bits) of faces to treat is 111111
	createLocalFaces(ucCubeIndex, _lX, _lY, _lZ,  lVertTable, 0x3F, curv, tag);

}




template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
562
void MarchingCube<DataType, Windowing, PFP>::createFaces_2(DataType *vox, const int _lX, const int _lY, const int _lZ, unsigned char tag)
Pierre Kraemer's avatar
Pierre Kraemer committed
563
564
565
566
567
568
{
	unsigned char ucCubeIndex = computeIndex(vox);
	if ((ucCubeIndex == 0) || (ucCubeIndex == 255))
		return;

	unsigned int  lVertTable[12];
Sylvain Thery's avatar
Sylvain Thery committed
569
	typename PFP::VEC3 vPos(_lX, _lY, _lZ);
Pierre Kraemer's avatar
Pierre Kraemer committed
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618

// create the new  vertices
	int lX = _lX;
	int lY = _lY;
	int lZ = _lZ;

//	float curv = m_Curvature.computeCurvatureSimple(vox);
	float curv=0.0f;


	createPointEdge0( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos );
	lX++;
	createPointEdge1( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos );
	createPointEdge9( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos );
	lY++;
	createPointEdge2( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	createPointEdge10( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lX--;
	lZ++;
	lY--;
	createPointEdge4( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lX++;
	createPointEdge5( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos );
	lY++;
	createPointEdge6( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);


// get the shared vertices corresponding to the shared edges :
	//edge 3
	    lVertTable[3]  = m_Buffer->getPointEdge3(_lX, _lY);

	// edge 7
	    lVertTable[7]  = m_Buffer->getPointEdge7(_lX, _lY);

	// edge 8
	    lVertTable[8]  = m_Buffer->getPointEdge8(_lX, _lY);

	//edge 11
	    lVertTable[11] = m_Buffer->getPointEdge11(_lX, _lY);


// create the new faces, the mask (6 bits) of faces to treat is 111110
	createLocalFaces(ucCubeIndex, _lX, _lY, _lZ,  lVertTable, 0x3E, curv, tag);

}



template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
619
void MarchingCube<DataType, Windowing, PFP>::createFaces_3(DataType *vox, const int _lX, const int _lY, const int _lZ, unsigned char tag)
Pierre Kraemer's avatar
Pierre Kraemer committed
620
621
622
623
624
625
{
	unsigned char ucCubeIndex = computeIndex(vox);
	if ((ucCubeIndex == 0) || (ucCubeIndex == 255))
		return;

	unsigned int  lVertTable[12];
Sylvain Thery's avatar
Sylvain Thery committed
626
	typename PFP::VEC3 vPos(_lX, _lY, _lZ);
Pierre Kraemer's avatar
Pierre Kraemer committed
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673

// create the new  vertices
	int lX = _lX;
	int lY = _lY;
	int lZ = _lZ;

//	float curv = m_Curvature.computeCurvatureSimple(vox);
	float curv=0.0f;

	lX++;
	createPointEdge1( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lY++;
	createPointEdge2( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	createPointEdge10( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lX--;
	createPointEdge3( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	createPointEdge11( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lZ++;
	createPointEdge7( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lY--;
	lX++;
	createPointEdge5( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lY++;
	createPointEdge6( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);


// get the shared vertices corresponding to the shared edges :
	//edge 0
	    lVertTable[0] = m_Buffer->getPointEdge0(_lX, _lY);

	// edge 9
	    lVertTable[9] = m_Buffer->getPointEdge9(_lX, _lY);

	// edge 4
	    lVertTable[4] = m_Buffer->getPointEdge4(_lX, _lY);

	//edge 8
	    lVertTable[8] = m_Buffer->getPointEdge8(_lX, _lY);


// create the new faces, the mask (6 bits) of faces to treat is 111011
	createLocalFaces(ucCubeIndex, _lX, _lY, _lZ,  lVertTable, 0x3B, curv, tag);

}


template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
674
void MarchingCube<DataType, Windowing, PFP>::createFaces_4(DataType *vox, const int _lX, const int _lY, const int _lZ, unsigned char tag)
Pierre Kraemer's avatar
Pierre Kraemer committed
675
676
677
678
679
680
{
	unsigned char ucCubeIndex = computeIndex(vox);
	if ((ucCubeIndex == 0) || (ucCubeIndex == 255))
		return;

	unsigned int  lVertTable[12];
Sylvain Thery's avatar
Sylvain Thery committed
681
	typename PFP::VEC3 vPos(_lX, _lY, _lZ);
Pierre Kraemer's avatar
Pierre Kraemer committed
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731

// create the new  vertices
	int lX = _lX;
	int lY = _lY;
	int lZ = _lZ;

//	float curv = m_Curvature.computeCurvatureSimple(vox);
	float curv=0.0f;

	lX++;
	createPointEdge1( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lY++;
	createPointEdge2( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	createPointEdge10( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lZ++;
	lY--;
	createPointEdge5( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lY++;
	createPointEdge6( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);


// get the shared vertices corresponding to the shared edges :
	//edge 3
	    lVertTable[3]  = m_Buffer->getPointEdge3(_lX, _lY);

	// edge 7
	    lVertTable[7]  = m_Buffer->getPointEdge7(_lX, _lY);

	// edge 8
	    lVertTable[8]  = m_Buffer->getPointEdge8(_lX, _lY);

	//edge 11
	    lVertTable[11] = m_Buffer->getPointEdge11(_lX, _lY);

	//edge 0
	    lVertTable[0] = m_Buffer->getPointEdge0(_lX, _lY);

	// edge 9
	    lVertTable[9] = m_Buffer->getPointEdge9(_lX, _lY);

	// edge 4
	    lVertTable[4] = m_Buffer->getPointEdge4(_lX, _lY);

// create the new faces, the mask (6 bits) of faces to treat is 111010
	createLocalFaces(ucCubeIndex, _lX, _lY, _lZ,  lVertTable, 0x3A, curv, tag);

}


template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
732
void MarchingCube<DataType, Windowing, PFP>::createFaces_5(DataType *vox, const int _lX, const int _lY, const int _lZ, unsigned char tag)
Pierre Kraemer's avatar
Pierre Kraemer committed
733
734
735
736
737
738
{
	unsigned char ucCubeIndex = computeIndex(vox);
	if ((ucCubeIndex == 0) || (ucCubeIndex == 255))
		return;

	unsigned int  lVertTable[12];
Sylvain Thery's avatar
Sylvain Thery committed
739
	typename PFP::VEC3 vPos(_lX, _lY, _lZ);
Pierre Kraemer's avatar
Pierre Kraemer committed
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787

// create the new  vertices
	int lX = _lX;
	int lY = _lY;
	int lZ = _lZ;

//	float curv = m_Curvature.computeCurvatureSimple(vox);
	float curv=0.0f;

	createPointEdge8( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lX++;
	createPointEdge9( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lY++;
	createPointEdge10( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lX--;
	createPointEdge3( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	createPointEdge11( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lZ++;
	createPointEdge7( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lY--;
	createPointEdge4( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lX++;
	createPointEdge5( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lY++;
	createPointEdge6( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);


// get the shared vertices corresponding to the shared edges :
	//edge 0
	    lVertTable[0] = m_Buffer->getPointEdge0(_lX, _lY);

	// edge 1
	    lVertTable[1] = m_Buffer->getPointEdge1(_lX, _lY);

	// edge 2
	    lVertTable[2] = m_Buffer->getPointEdge2(_lX, _lY);

	//edge 3
	    lVertTable[3] = m_Buffer->getPointEdge3(_lX, _lY);


// create the new faces, the mask (6 bits) of faces to treat is 101111
	createLocalFaces(ucCubeIndex, _lX, _lY, _lZ,  lVertTable, 0x2F, curv, tag);

}


template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
788
void MarchingCube<DataType, Windowing, PFP>::createFaces_6(DataType *vox, const int _lX, const int _lY, const int _lZ, unsigned char tag)
Pierre Kraemer's avatar
Pierre Kraemer committed
789
790
791
792
793
794
{
	unsigned char ucCubeIndex = computeIndex(vox);
	if ((ucCubeIndex == 0) || (ucCubeIndex == 255))
		return;

	unsigned int  lVertTable[12];
Sylvain Thery's avatar
Sylvain Thery committed
795
	typename PFP::VEC3 vPos(_lX, _lY, _lZ);
Pierre Kraemer's avatar
Pierre Kraemer committed
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848

// create the new  vertices
	int lX = _lX+1;
	int lY = _lY;
	int lZ = _lZ;

	vox++;

//	float curv = m_Curvature.computeCurvatureSimple(vox);
	float curv=0.0f;
	createPointEdge9( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lY++;
	createPointEdge10( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lX--;
	lZ++;
	lY--;
	createPointEdge4( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lX++;
	createPointEdge5( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lY++;
	createPointEdge6( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);


// get the shared vertices corresponding to the shared edges :
	//edge 0
	    lVertTable[0] = m_Buffer->getPointEdge0(_lX, _lY);

	// edge 1
	    lVertTable[1] = m_Buffer->getPointEdge1(_lX, _lY);

	// edge 2
	    lVertTable[2] = m_Buffer->getPointEdge2(_lX, _lY);

	//edge 3
	    lVertTable[3] = m_Buffer->getPointEdge3(_lX, _lY);

	// edge 7
	    lVertTable[7] = m_Buffer->getPointEdge7(_lX, _lY);

	// edge 8
	    lVertTable[8] = m_Buffer->getPointEdge8(_lX, _lY);

	// edge 11
	    lVertTable[11] = m_Buffer->getPointEdge11(_lX, _lY);


// create the new faces, the mask (6 bits) of faces to treat is 101110
	createLocalFaces(ucCubeIndex, _lX, _lY, _lZ,  lVertTable, 0x2E, curv, tag);

}


template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
849
void MarchingCube<DataType, Windowing, PFP>::createFaces_7(DataType *vox, const int _lX, const int _lY, const int _lZ, unsigned char tag)
Pierre Kraemer's avatar
Pierre Kraemer committed
850
851
852
853
854
855
{
	unsigned char ucCubeIndex = computeIndex(vox);
	if ((ucCubeIndex == 0) || (ucCubeIndex == 255))
		return;

	unsigned int  lVertTable[12];
Sylvain Thery's avatar
Sylvain Thery committed
856
	typename PFP::VEC3 vPos(_lX, _lY, _lZ);
Pierre Kraemer's avatar
Pierre Kraemer committed
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909

// create the new  vertices
	int lX = _lX+1;
	int lY = _lY+1;
	int lZ = _lZ;

	vox += m_Image->getWidthX()+1;

//	float curv = m_Curvature.computeCurvatureSimple(vox);
	float curv=0.0f;

	createPointEdge10( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lX--;
	createPointEdge11( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lZ++;
	createPointEdge7( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lY--;
	lX++;
	createPointEdge5( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	lY++;
	createPointEdge6( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);


// get the shared vertices corresponding to the shared edges :
	//edge 0
	    lVertTable[0] = m_Buffer->getPointEdge0(_lX, _lY);

	// edge 1
	    lVertTable[1] = m_Buffer->getPointEdge1(_lX, _lY);

	// edge 2
	    lVertTable[2] = m_Buffer->getPointEdge2(_lX, _lY);

	//edge 3
	    lVertTable[3] = m_Buffer->getPointEdge3(_lX, _lY);

	// edge 4
	    lVertTable[4] = m_Buffer->getPointEdge4(_lX, _lY);

	// edge 8
	    lVertTable[8] = m_Buffer->getPointEdge8(_lX, _lY);

	//edge 9
	    lVertTable[9] = m_Buffer->getPointEdge9(_lX, _lY);


// create the new faces, the mask (6 bits) of faces to treat is 101011
	createLocalFaces(ucCubeIndex, _lX, _lY, _lZ,  lVertTable, 0x2B, curv, tag);
}



template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
910
void MarchingCube<DataType, Windowing, PFP>::createFaces_8(DataType *vox, const int _lX, const int _lY, const int _lZ, unsigned char tag)
Pierre Kraemer's avatar
Pierre Kraemer committed
911
912
913
914
915
916
{
	unsigned char ucCubeIndex = computeIndex(vox);
	if ((ucCubeIndex == 0) || (ucCubeIndex == 255))
		return;

	unsigned int  lVertTable[12];
Sylvain Thery's avatar
Sylvain Thery committed
917
	typename PFP::VEC3 vPos(_lX, _lY, _lZ);
Pierre Kraemer's avatar
Pierre Kraemer committed
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969

// create the new  vertices
	int lX = _lX+1;
	int lY = _lY+1;
	int lZ = _lZ+1;

//	float curv = m_Curvature.computeCurvatureSimple(vox);
	float curv=0.0f;

	createPointEdge6( ucCubeIndex, lX,  lY,  lZ, lVertTable, vPos);
	createPointEdge5( ucCubeIndex, lX,  _lY,  lZ, lVertTable, vPos);
	createPointEdge10( ucCubeIndex, lX,  lY,  _lZ, lVertTable, vPos);


// get the shared vertices corresponding to the shared edges :
	//edge 0
	    lVertTable[0] = m_Buffer->getPointEdge0(_lX, _lY);

	// edge 1
	    lVertTable[1] = m_Buffer->getPointEdge1(_lX, _lY);

	// edge 2
	    lVertTable[2] = m_Buffer->getPointEdge2(_lX, _lY);

	//edge 3
	    lVertTable[3] = m_Buffer->getPointEdge3(_lX, _lY);

	// edge 4
	    lVertTable[4] = m_Buffer->getPointEdge4(_lX, _lY);

	// edge 8
	    lVertTable[8] = m_Buffer->getPointEdge8(_lX, _lY);

	//edge 9
	    lVertTable[9] = m_Buffer->getPointEdge9(_lX, _lY);

	// edge 7
	    lVertTable[7] = m_Buffer->getPointEdge7(_lX, _lY);

	// edge 11
	    lVertTable[11] = m_Buffer->getPointEdge11(_lX, _lY);


// create the new faces, the mask (6 bits) of faces to treat is 101010
	createLocalFaces(ucCubeIndex, _lX, _lY, _lZ,  lVertTable, 0x2A, curv, tag);

}

template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
void MarchingCube<DataType, Windowing, PFP>::setNeighbourSimple(L_DART d1, L_DART d2)
{
	if (m_map->phi2(d1) != d2)
970
		m_map->sewFaces(d1,d2,false);
Pierre Kraemer's avatar
Pierre Kraemer committed
971
972
973
974
975
976
}

template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
void MarchingCube<DataType, Windowing, PFP>::setNeighbour(L_DART d1, L_DART d2)
{
	if (m_map->phi2(d1) != d2)
977
		m_map->sewFaces(d1,d2,false);
Pierre Kraemer's avatar
Pierre Kraemer committed
978
979
980
}

template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
981
void MarchingCube<DataType, Windowing, PFP>::createLocalFaces(const unsigned char _ucCubeIndex, const int _lX, const int _lY, const int _lZ,  unsigned int  const *_lVertTable, const unsigned short _usMask, float curv, unsigned char tag)
Pierre Kraemer's avatar
Pierre Kraemer committed
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
{
// TODO parametre _LZ not used => a supprimer ?
// TODO parametre curv not used => a supprimer ?
// TODO parametre tag not used => a supprimer ?
	
	#define EVENMASK	0x55
	#define ODDMASK	0xAA

// initialize number of created face to 0
	int lNumFaces = 0;

// get the address of buffer table
	L_DART *lFacesTab = m_Buffer->getFacesCubeTableAdr(_lX,_lY);

// To speed access to data "precompute indirection"
997
998
	const char* cTriangle = accelMCTable::m_TriTable[_ucCubeIndex];
	const char* cNeighbour = accelMCTable::m_NeighTable[_ucCubeIndex];
Pierre Kraemer's avatar
Pierre Kraemer committed
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185

//	L_DART dartTriangles[5];

// PASS 1: create faces
 	for (int i=0; cTriangle[i]!=-1;/* incrementation inside */)
	{
	// get index of the 3 points of trianglesfrzr
		int lIndexP1 =  cTriangle[i++];
		int lIndexP2 =  cTriangle[i++];
		int lIndexP3 =  cTriangle[i++];

/*		L_DART edge = m_map->createEmbOriTriangle(_lVertTable[lIndexP1],  //first point/edge
							_lVertTable[lIndexP2], //second point/edge
							_lVertTable[lIndexP3]);// third point/edge
*/
		L_DART edge = createTriEmb(_lVertTable[lIndexP1],  //first point/edge
							_lVertTable[lIndexP2], //second point/edge
							_lVertTable[lIndexP3]);// third point/edge

	// add the face to buffer
		lFacesTab[lNumFaces] = edge;
		lNumFaces++;
	}

// PASS 2: update neighbours
	for (int j=0; j<lNumFaces;++j)
	{
		int i = 3*j;

		int lIndexP1 =  cTriangle[i];
		int lIndexP2 =  cTriangle[i+1];
		int lIndexP3 =  cTriangle[i+2];

		L_DART edge = lFacesTab[j];

		int lLocalNeighbour = cNeighbour[i];
		L_DART dn = lFacesTab[ lLocalNeighbour/3 ];
		if (lLocalNeighbour>0)
			lLocalNeighbour = lLocalNeighbour%3;
		switch(lLocalNeighbour)
		{
			case 0:
				setNeighbourSimple(edge,dn);
				break;
			case 1:
				dn =m_map->phi1(dn);
				setNeighbourSimple(edge,dn);
				break;
			case 2:
				dn = m_map->phi_1(dn); // triangle donc pas besoin de faire le tour par 2xphi1
				setNeighbourSimple(edge,dn);
				break;
			default: // -1
				unsigned char ucCodeEdgeFace = accelMCTable::m_EdgeCode[lIndexP1] & accelMCTable::m_EdgeCode[lIndexP2];
				if (ucCodeEdgeFace & EVENMASK)	// the edge has a neighbour
				{
					L_DART neighbour = m_Buffer->getExternalNeighbour(lIndexP1 , _lX, _lY);	// get neighbour from buffer
					setNeighbour(edge,neighbour);
				}
				break;
		}

		// second edge
		edge =m_map->phi1(edge);
		lLocalNeighbour = cNeighbour[i+1];
		dn = lFacesTab[lLocalNeighbour/3];
		if (lLocalNeighbour>0)
			lLocalNeighbour = lLocalNeighbour%3;
		switch(lLocalNeighbour)
		{
			case 0:
				setNeighbourSimple(edge,dn);
				break;
			case 1:
				dn =m_map->phi1(dn);
				setNeighbourSimple(edge,dn);
				break;
			case 2:
				dn = m_map->phi_1(dn); // triangle donc pas besoin de faire le tour par 2xphi1
				setNeighbourSimple(edge,dn);
				break;
			default: // -1
				unsigned char ucCodeEdgeFace = accelMCTable::m_EdgeCode[lIndexP2] & accelMCTable::m_EdgeCode[lIndexP3];
				if (ucCodeEdgeFace & EVENMASK)	// the edge has a neighbour
				{
					L_DART neighbour = m_Buffer->getExternalNeighbour(lIndexP2 , _lX, _lY);	// get neighbour from buffer
					setNeighbour(edge,neighbour);
				}
				break;
		}

		// third edge
		edge =m_map->phi1(edge);
		lLocalNeighbour = cNeighbour[i+2];
		dn = lFacesTab[lLocalNeighbour/3];
		if (lLocalNeighbour>0)
			lLocalNeighbour = lLocalNeighbour%3;
		switch(lLocalNeighbour)
		{
			case 0:
				setNeighbourSimple(edge,dn);
				break;
			case 1:
				dn =m_map->phi1(dn);
				setNeighbourSimple(edge,dn);
				break;
			case 2:
				dn = m_map->phi_1(dn); // triangle donc pas besoin de faire le tour par 2xphi1
				setNeighbourSimple(edge,dn);
				break;
			default: // -1
				unsigned char ucCodeEdgeFace = accelMCTable::m_EdgeCode[lIndexP3] & accelMCTable::m_EdgeCode[lIndexP1];
				if (ucCodeEdgeFace & EVENMASK)	// the edge has a neighbour
				{
					L_DART neighbour = m_Buffer->getExternalNeighbour(lIndexP3 , _lX, _lY);	// get neighbour from buffer
					setNeighbour(edge,neighbour);
				}
				break;
		}
	}



// PASS 2: set the neighbours in buffer

 	for (int i=0; cTriangle[i]!=-1;/* incrementation inside */)
	{
		L_DART edge = lFacesTab[i/3];

		int lIndexP1 =  cTriangle[i];
		int lIndexP2 =  cTriangle[i+1];
		int lIndexP3 =  cTriangle[i+2];

		if (cNeighbour[i] < 0) // update neighbourhood internal to cube
		{
			// compute the code of the edge (define which face of cube it belongs)
			unsigned char ucCodeEdgeFace = accelMCTable::m_EdgeCode[lIndexP1] & accelMCTable::m_EdgeCode[lIndexP2];
			if (ucCodeEdgeFace & _usMask & ODDMASK)	// the neighbour of the edge not yet created
			{
				m_Buffer->setExternalNeighbour(lIndexP2 , _lX, _lY,  edge);	// set the edge in edge of P2 in the buffer
			}
		}

		edge =m_map->phi1(edge); // next edge
		i++;

		if (cNeighbour[i] < 0)  // update neighbourhood internal to cube
		{
			// compute the code of the edge (define which face of cube it belongs)
			unsigned char ucCodeEdgeFace = accelMCTable::m_EdgeCode[lIndexP2] & accelMCTable::m_EdgeCode[lIndexP3];

			if (ucCodeEdgeFace & _usMask & ODDMASK)	// the neighbour of the edge not yet created
			{
				m_Buffer->setExternalNeighbour(lIndexP3 , _lX, _lY,  edge);	// set the edge in edge of P2 in the buffer
			}
		}

		edge =m_map->phi1(edge); // next edge
		i++;

   		if (cNeighbour[i] < 0)  // update neighbourhood internal to cube
		{
			// compute the code of the edge (define which face of cube it belongs)
			unsigned char ucCodeEdgeFace = accelMCTable::m_EdgeCode[lIndexP3] & accelMCTable::m_EdgeCode[lIndexP1];
			if (ucCodeEdgeFace & _usMask & ODDMASK)	// the neighbour of the edge not yet created
			{
				m_Buffer->setExternalNeighbour(lIndexP1 , _lX, _lY,  edge);	// set the edge in edge of P2 in the buffer
 			}
		}
		i++;

	}


// finish buffer table of faces with -1
// PAS FORCEMENT UTILE A VERIFIER
// 	for(int i=lNumFaces; i <5; i++)
// 	{
// 		lFacesTab[i] = m_map->end();
// 	}

	#undef EVENMASK
	#undef ODDMASK
}



Sylvain Thery's avatar
Sylvain Thery committed
1186
1187
1188
1189
1190
template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
void MarchingCube<DataType, Windowing, PFP>::removeFacesOfBoundary(AttributeHandler<unsigned char>& boundVertices, unsigned int frameWidth)
{

	float xmin = frameWidth;
Sylvain Thery's avatar
Sylvain Thery committed
1191
	float xmax = m_Image->getWidthX() - frameWidth -1;
Sylvain Thery's avatar
Sylvain Thery committed
1192
	float ymin = frameWidth;
Sylvain Thery's avatar
Sylvain Thery committed
1193
	float ymax = m_Image->getWidthY() - frameWidth -1;
Sylvain Thery's avatar
Sylvain Thery committed
1194
	float zmin = frameWidth;
Sylvain Thery's avatar
Sylvain Thery committed
1195
	float zmax = m_Image->getWidthZ() - frameWidth -1;
Sylvain Thery's avatar
Sylvain Thery committed
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212


	// traverse position and create bound attrib
	for(unsigned int it = m_positions.begin(); it != m_positions.end(); m_positions.next(it))
	{
		bool bound = (m_positions[it][0]<=xmin) || (m_positions[it][0]>=xmax) || \
					 (m_positions[it][1]<=ymin) || (m_positions[it][1]>=ymax) || \
					 (m_positions[it][2]<=zmin) || (m_positions[it][2]>=zmax);

		if (bound)
		{
			boundVertices[it] = 1;
		}
		else
			boundVertices[it] = 0;
	}

1213
//	 traverse face and check if all vertices are bound
Sylvain Thery's avatar
Sylvain Thery committed
1214
	DartMarker mf(*m_map);
1215
	for (Dart d = m_map->begin(); d != m_map->end();)	// next done inside loop because of deleteFace
Sylvain Thery's avatar
Sylvain Thery committed
1216
	{
1217
		if (!mf.isMarked(d) && !m_map->isBoundaryMarked(d))
Sylvain Thery's avatar
Sylvain Thery committed
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
		{
			Dart dd = d;
			Dart e = m_map->phi1(d);
			Dart f = m_map->phi1(e);
			m_map->next(d);
			while ((d==e) || (d==f))
			{
				m_map->next(d);
			}
			if ((boundVertices[dd]!=0) && (boundVertices[e]!=0) && (boundVertices[f]!=0))
1228
				m_map->deleteFace(dd,false);
Sylvain Thery's avatar
Sylvain Thery committed
1229
1230
1231
			else
				mf.markOrbit(FACE,dd);
		}
1232
		else m_map->next(d);
Sylvain Thery's avatar
Sylvain Thery committed
1233
	}
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
	m_map->closeMap();

////	 VERSION USING DELETE FACE WITH BOUNDARY
//	DartMarker mf(*m_map);
//	std::vector<Dart> vecF;
//	vecF.reserve(8192);
//	for (Dart d = m_map->begin(); d != m_map->end();m_map->next(d))	// next done inside loop because of deleteFace
//	{
//		if ((!mf.isMarked(d)) && (!m_map->isBoundaryMarked(d)) )
//		{
//			Dart dd = d;
//			Dart e = m_map->phi1(d);
//			Dart f = m_map->phi1(e);
//			if ((boundVertices[dd]!=0) && (boundVertices[e]!=0) && (boundVertices[f]!=0))
//				vecF.push_back(d);
//			mf.markOrbit(FACE,dd);
//		}
//	}
//	for (std::vector<Dart>::iterator it = vecF.begin(); it != vecF.end(); ++it)
//		m_map->deleteFace(*it);
Sylvain Thery's avatar
Sylvain Thery committed
1254
1255
1256

}

1257
template< typename  DataType, template < typename D2 > class Windowing, typename PFP >
Sylvain Thery's avatar
Sylvain Thery committed
1258
void MarchingCube<DataType, Windowing, PFP>::recalPoints(const Geom::Vec3f& origin)
1259
1260
1261
1262
1263
1264
{

	for(unsigned int i=m_positions.begin(); i != m_positions.end(); m_positions.next(i))
	{
		typename PFP::VEC3& P = m_positions[i];
		P -= m_fOrigin;
Sylvain Thery's avatar
Sylvain Thery committed
1265
1266
1267
		P[0] = (P[0]-0.5f) * m_fScal[0];
		P[1] = (P[1]-0.5f) * m_fScal[1];
		P[2] = (P[2]-0.5f) * m_fScal[2];
Sylvain Thery's avatar
Sylvain Thery committed
1268
		P+=origin;
1269
1270
	}
}
Sylvain Thery's avatar
Sylvain Thery committed
1271
1272
1273
1274
1275





Pierre Kraemer's avatar
Pierre Kraemer committed
1276
1277
1278
} // end namespace
} // end namespace
} // end namespace