topo_render.hpp 16.2 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg                *
*                                                                              *
* 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.           *
*                                                                              *
* Web site: https://iggservis.u-strasbg.fr/CGoGN/                              *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#include <limits>
#include "Topology/generic/autoAttributeHandler.h"

untereiner's avatar
untereiner committed
28 29
#include "Geometry/vector_gen.h"

Pierre Kraemer's avatar
Pierre Kraemer committed
30 31 32 33 34 35 36 37 38
namespace CGoGN
{

namespace Algo
{

namespace Render
{

Sylvain Thery's avatar
Sylvain Thery committed
39
namespace GL1
Pierre Kraemer's avatar
Pierre Kraemer committed
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
{
	
//template<typename PFP>
//class FunctorGM2Face: public FunctorMap<typename PFP::MAP>
//{
//	typedef typename PFP::MAP MAP;
//	typedef typename PFP::EMB EMB;
//
//
//protected:
//	std::vector<gmtl::Vec3f>& m_vf1;
//	std::vector<gmtl::Vec3f>& m_vf2;
//	int m_lab;
//	Marker m_mark;
//
//public:
//	FunctorGM2Face(MAP& map, std::vector<gmtl::Vec3f>& vf1, std::vector<gmtl::Vec3f>& vf2, Marker m):
//		FunctorMap<MAP>(map), m_vf1(vf1), m_vf2(vf2), m_lab(0), m_mark(m)
//	{}
//
//	bool operator()(Dart d)
//	{
//		std::vector<gmtl::Vec3f> vecPos;
//		vecPos.reserve(16);
//
//		Dart dd = d;
//		int nb=0;
//		gmtl::Vec3f center = Geometry::faceCentroid<PFP>(this->m_map, d);
//		do
//		{
//			const gmtl::Vec3f& P = this->m_map.getVertexEmb(d)->getPosition();
//			vecPos.push_back(P);
//			nb++;
//			d->setLabel(m_lab++);
//			d = this->m_map.alpha(0,d);
//			d->setLabel(m_lab++);
//			d = this->m_map.alpha1(d);
//		} while (d!=dd);
//
//		for (int i=0; i<nb; ++i)
//		{
//			vecPos[i] = center*0.05f + vecPos[i]*0.95f;
//		}
//		vecPos.push_back(vecPos.front());
//
//		for (int i=0; i<nb; ++i)
//		{
//			if (this->m_map.isMarkedDart(d,m_mark))
//				glColor3f(1.,1.,0.);
//			else
//				glColor3f(1.,1.,1.);
//			// pour d
//			gmtl::Vec3f P = vecPos[i]*0.9f + vecPos[i+1]*0.1f;
//			gmtl::Vec3f M = vecPos[i]*0.55f + vecPos[i+1]*0.45f;
//			glVertex3fv(P.getData());
//			glVertex3fv(M.getData());
//			gmtl::Vec3f f = vecPos[i]*0.8f + vecPos[i+1]*0.2f;
//			m_vf1.push_back(f);
//			f = vecPos[i]*0.6f + vecPos[i+1]*0.4f;
//			m_vf2.push_back(f);
//
//			d = this->m_map.alpha(0,d);
//
//			if (this->m_map.isMarkedDart(d,m_mark))
//				glColor3f(1.,1.,0.);
//			else
//				glColor3f(1.,1.,1.);
//			// pour alpha(0,d)
//			P = vecPos[i+1]*0.9f + vecPos[i]*0.1f;
//			M = vecPos[i+1]*0.55f + vecPos[i]*0.45f;
//			glVertex3fv(P.getData());
//			glVertex3fv(M.getData());
//			f = vecPos[i+1]*0.8f + vecPos[i]*0.2f;
//			m_vf1.push_back(f);
//			f = vecPos[i+1]*0.6f + vecPos[i]*0.4f;
//			m_vf2.push_back(f);
//
//			d = this->m_map.alpha1(d);
//		}
//		return false;
//	}
//};
//
//template <typename PFP>
untereiner's avatar
untereiner committed
124
//void renderTopoGM2(typename PFP::MAP& map, Marker m)
Pierre Kraemer's avatar
Pierre Kraemer committed
125 126 127 128 129
//{
//
//
//	std::vector<gmtl::Vec3f> fv1;
//	std::vector<gmtl::Vec3f> fv2;
untereiner's avatar
untereiner committed
130 131
//	fv1.reserve(map.getNbDarts());
//	fv2.reserve(map.getNbDarts());
Pierre Kraemer's avatar
Pierre Kraemer committed
132 133
//
//	// first pass render the triangles
untereiner's avatar
untereiner committed
134
//	FunctorGM2Face<PFP> fgl_gc(map,fv1,fv2,m);
Pierre Kraemer's avatar
Pierre Kraemer committed
135 136 137 138 139
//
//	glLineWidth(1.0f);
//	glBegin(GL_LINES);
//	glColor3f(1.0,1.0,1.0);
//
untereiner's avatar
untereiner committed
140
//	map.foreach_orbit(2,fgl_gc);
Pierre Kraemer's avatar
Pierre Kraemer committed
141 142 143
//	glEnd();
//	glLineWidth(2.0f);
//	glBegin(GL_LINES);
untereiner's avatar
untereiner committed
144
//	for(Dart d = map.begin(); d!= map.end(); map.next(d))
Pierre Kraemer's avatar
Pierre Kraemer committed
145 146 147
//	{
//		glColor3f(0.0,1.0,1.0);
//		int i=d->getLabel();
untereiner's avatar
untereiner committed
148
//		int j=(map.alpha1(d))->getLabel();
Pierre Kraemer's avatar
Pierre Kraemer committed
149 150 151
//		glVertex3fv(fv1[i].getData());
//		glVertex3fv(fv1[j].getData());
//		glColor3f(1.0,0.0,0.0);
untereiner's avatar
untereiner committed
152
//		j=(map.alpha(2,d))->getLabel();
Pierre Kraemer's avatar
Pierre Kraemer committed
153 154 155 156 157 158 159 160 161
//		glVertex3fv(fv2[i].getData());
//		glVertex3fv(fv2[j].getData());
//	}
//	glEnd();
//}



template <typename PFP>
untereiner's avatar
untereiner committed
162
void renderTopoMD2(typename PFP::MAP& map, const typename PFP::TVEC3& positions, bool drawPhi1, bool drawPhi2, float ke, float kf)
Pierre Kraemer's avatar
Pierre Kraemer committed
163 164 165 166
{
	typedef typename PFP::VEC3 VEC3;
	typedef typename PFP::REAL REAL;
	
untereiner's avatar
untereiner committed
167 168 169 170
	AutoAttributeHandler<Geom::Vec3f> fv1(map, DART);
	AutoAttributeHandler<Geom::Vec3f> fv11(map, DART);
	AutoAttributeHandler<Geom::Vec3f> fv2(map, DART);
	AutoAttributeHandler<Geom::Vec3f> vert(map, DART);
Pierre Kraemer's avatar
Pierre Kraemer committed
171 172

	glLineWidth(2.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
173
	glColor3f(0.9f,0.9f,0.9f);
Pierre Kraemer's avatar
Pierre Kraemer committed
174 175
	glBegin(GL_LINES);

untereiner's avatar
untereiner committed
176 177
	DartMarker mf(map);
	for(Dart d = map.begin(); d!= map.end(); map.next(d))
Pierre Kraemer's avatar
Pierre Kraemer committed
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
	{
		if (!mf.isMarked(d))
		{
			std::vector<VEC3> vecPos;
			vecPos.reserve(16);

			std::vector<VEC3> vecF1;
			vecF1.reserve(16);

			// store the face & center
			VEC3 center(0.0f,0.0f,0.0f);
			Dart dd = d;
			do
			{
				const VEC3& P = positions[d];
				vecPos.push_back(positions[d]);
				center += P;
untereiner's avatar
untereiner committed
195
				d = map.phi1(d);
Pierre Kraemer's avatar
Pierre Kraemer committed
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
			}while (d!=dd);
			center /= REAL(vecPos.size());

			//shrink the face
			unsigned int nb = vecPos.size();
			float k = 1.0f - kf;
			for (unsigned int i=0; i<nb; ++i)
			{
				vecPos[i] = center*k + vecPos[i]*kf;
			}
			vecPos.push_back(vecPos.front()); // copy the first for easy computation on next loop

			k = 1.0f - ke;
			for (unsigned int i=0; i<nb; ++i)
			{
				VEC3 P = vecPos[i]*ke + vecPos[i+1]*k;
				VEC3 Q = vecPos[i+1]*ke + vecPos[i]*k;
				glVertex3fv(P.data());
				glVertex3fv(Q.data());
				vert[d] = P;
				VEC3 f = P*0.5f + Q*0.5f;
				fv2[d] = f;
				f = P*0.1f + Q*0.9f;
				fv1[d] = f;
				f = P*0.9f + Q*0.1f;
				fv11[d] = f;
untereiner's avatar
untereiner committed
222
				d = map.phi1(d);
Pierre Kraemer's avatar
Pierre Kraemer committed
223
			}
224
			mf.markOrbit(FACE, d);
Pierre Kraemer's avatar
Pierre Kraemer committed
225 226 227
		}
	}

untereiner's avatar
untereiner committed
228
	for(Dart d = map.begin(); d != map.end(); map.next(d))
Pierre Kraemer's avatar
Pierre Kraemer committed
229
	{
untereiner's avatar
untereiner committed
230
		Dart e = map.phi2(d);
Pierre Kraemer's avatar
Pierre Kraemer committed
231 232 233 234 235 236 237 238
		if ((d<e) && drawPhi2)
		{
			glColor3f(1.0,0.0,0.0);
			glVertex3fv(fv2[d].data());
			glVertex3fv(fv2[e].data());
		}
		if (drawPhi1)
		{
untereiner's avatar
untereiner committed
239
			e = map.phi1(d);
Pierre Kraemer's avatar
Pierre Kraemer committed
240 241 242 243 244 245 246 247 248 249 250
			glColor3f(0.0f,1.0f,1.0f);
			glVertex3fv(fv1[d].data());
			glVertex3fv(fv11[e].data());
		}
	}
	
	glEnd(); // LINES

	glPointSize(5.0f);
	glColor3f(0.0f,0.0f,0.0f);
	glBegin(GL_POINTS);
untereiner's avatar
untereiner committed
251
	for(Dart d = map.begin(); d!= map.end(); map.next(d))
Pierre Kraemer's avatar
Pierre Kraemer committed
252 253 254 255 256 257 258
	{
		glVertex3fv(vert[d].data());
	}
	glEnd();

}

untereiner's avatar
untereiner committed
259 260


Pierre Kraemer's avatar
Pierre Kraemer committed
261 262 263 264
//template<typename PFP>
//class FunctorMD3Face : public FunctorMap<typename PFP::MAP>
//{
//	typedef typename PFP::MAP MAP;
untereiner's avatar
untereiner committed
265
//	typedef typename PFP::VEC3 VEC3;
Pierre Kraemer's avatar
Pierre Kraemer committed
266 267 268
//
//
//	protected:
untereiner's avatar
untereiner committed
269
//		std::vector<VEC3>& m_vf1;
Pierre Kraemer's avatar
Pierre Kraemer committed
270
//
untereiner's avatar
untereiner committed
271
//		VEC3 m_volCenter;
Pierre Kraemer's avatar
Pierre Kraemer committed
272 273 274 275
//		int m_lab;
//		float m_ke;
//		float m_kf;
//		float m_kv;
untereiner's avatar
untereiner committed
276
//		DartMarkerStore m_mark;
Pierre Kraemer's avatar
Pierre Kraemer committed
277 278
//		bool m_drawPhi1;
//
untereiner's avatar
untereiner committed
279
//		typename PFP::TVEC3 m_positions;
Pierre Kraemer's avatar
Pierre Kraemer committed
280 281
//
//	public:
untereiner's avatar
untereiner committed
282 283
//	FunctorMD3Face(MAP& map, typename PFP::TVEC3& positions, std::vector<VEC3>& vf1, float ke, float kf, float kv, Marker m, bool df1):
//		FunctorMap<MAP>(map), m_positions(positions), m_vf1(vf1), m_lab(0), m_ke(ke), m_kf(kf), m_kv(kv), m_mark(m),m_drawPhi1(df1)
Pierre Kraemer's avatar
Pierre Kraemer committed
284 285
//	{}
//
untereiner's avatar
untereiner committed
286
//	void setVolCenter(const VEC3& vc) { m_volCenter = vc;}
Pierre Kraemer's avatar
Pierre Kraemer committed
287 288 289
//
//	bool operator()(Dart d)
//	{
untereiner's avatar
untereiner committed
290
//		this->m_mark.markDart(d);
Pierre Kraemer's avatar
Pierre Kraemer committed
291
//
untereiner's avatar
untereiner committed
292
//		VEC3 vPosPhi1[256];	// max 256 sides per face
Pierre Kraemer's avatar
Pierre Kraemer committed
293
//
untereiner's avatar
untereiner committed
294
//		std::vector<VEC3> vecPos;
Pierre Kraemer's avatar
Pierre Kraemer committed
295
//		vecPos.reserve(16);
untereiner's avatar
untereiner committed
296
//		VEC3 centerFace(0.0f,0.0f,0.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
297 298 299 300 301 302
//
//		float k = 1.0f - m_kv;
//
//		Dart dd = d;
//		do
//		{
untereiner's avatar
untereiner committed
303 304
//			VEC3 P = m_positions[dd];//this->m_map.getEmbedding(VERTEX,dd)->getPosition();
//			VEC3 Q = m_volCenter*k + m_kv*P;
Pierre Kraemer's avatar
Pierre Kraemer committed
305 306
//			centerFace += Q;
//			vecPos.push_back(Q);
untereiner's avatar
untereiner committed
307
//			dd = m_lab++;
Pierre Kraemer's avatar
Pierre Kraemer committed
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
//			dd = this->m_map.phi1(dd);
//		}while (dd!=d);
//
//		int nb=vecPos.size();
//
//		centerFace /= float(nb);
//
//		k = 1.0f - m_kf;
//		for (int i=0; i<nb; ++i)
//		{
//			vecPos[i] = centerFace*k + vecPos[i]*m_kf;
//		}
//		vecPos.push_back(vecPos.front());
//
//		glTexCoord3f(m_volCenter[0],m_volCenter[1],m_volCenter[2]);
//
//		k = (1.0f - m_ke)/2.0f;
//		float ke = 1.0f - k;
//
//		for (int i=0; i<nb; ++i)
//		{
untereiner's avatar
untereiner committed
329 330
//			VEC3 P = vecPos[i];
//			VEC3 Q = vecPos[i+1]*ke + vecPos[i]*k;
Pierre Kraemer's avatar
Pierre Kraemer committed
331
//			glColor3f(1.0f,1.0f,0.0f);
untereiner's avatar
untereiner committed
332
//			glVertex3fv(P);
Pierre Kraemer's avatar
Pierre Kraemer committed
333
//			glColor3f(1.0f,1.0f,1.0f);
untereiner's avatar
untereiner committed
334 335
//			glVertex3fv(Q);
//			VEC3 f = P*0.5f + Q*0.5f;
Pierre Kraemer's avatar
Pierre Kraemer committed
336 337 338 339 340 341 342 343 344 345 346
//			m_vf1.push_back(f);
//			f = P*0.9f + Q*0.1f;
//			vPosPhi1[i] = f;
//			d = this->m_map.phi1(d);
//		}
//
//		if (m_drawPhi1)
//		{
//			for (int i=0; i<nb; ++i)
//			{
//				glColor3f(0.0f,1.0f,1.0f);
untereiner's avatar
untereiner committed
347
//				int k=d;
Pierre Kraemer's avatar
Pierre Kraemer committed
348
//				int j=(i+1)%nb;
untereiner's avatar
untereiner committed
349 350 351
//				VEC3 fv3 = 2.0f*m_vf1[k] - vPosPhi1[i];
//				glVertex3fv(fv3);
//				glVertex3fv(vPosPhi1[j]);
Pierre Kraemer's avatar
Pierre Kraemer committed
352 353 354 355 356 357
//				d = this->m_map.phi1(d);
//			}
//		}
//		return false;
//	}
//};
untereiner's avatar
untereiner committed
358 359 360



Pierre Kraemer's avatar
Pierre Kraemer committed
361
//template <typename PFP>
untereiner's avatar
untereiner committed
362
//void renderTopoMD3(typename PFP::MAP& map, typename PFP::TVEC3& positions, bool drawPhi1, bool drawPhi2, bool drawPhi3, float ke, float kf, float kv, FunctorType& good)
Pierre Kraemer's avatar
Pierre Kraemer committed
363
//{
untereiner's avatar
untereiner committed
364 365
//	typedef typename PFP::VEC3 VEC3;
//	typedef typename PFP::REAL REAL;
Pierre Kraemer's avatar
Pierre Kraemer committed
366
//
untereiner's avatar
untereiner committed
367
//	std::vector<VEC3> vPosPhi23;
Pierre Kraemer's avatar
Pierre Kraemer committed
368
//
untereiner's avatar
untereiner committed
369
//	vPosPhi23.reserve(map.getNbDarts());
Pierre Kraemer's avatar
Pierre Kraemer committed
370 371 372 373 374 375 376 377 378
//
// 	glLineWidth(1.0f);
//	glBegin(GL_LINES);
//	glColor3f(1.0f,1.0f,1.0f);
//
//	std::vector<Dart> vecDarts;
//	vecDarts.reserve(50);
//	FunctorStore fvol(vecDarts);
//
untereiner's avatar
untereiner committed
379 380 381
//	DartMarkerStore markerFace(map);
//
//	FunctorMD3Face<PFP> fgl_cd(map,positions,vPosPhi23,ke,kf,kv,markerFace,drawPhi1);
Pierre Kraemer's avatar
Pierre Kraemer committed
382 383
//
//	// Scan all darts of the map
untereiner's avatar
untereiner committed
384
//	for(Dart d = map.begin(); d != map.end(); map.next(d))
Pierre Kraemer's avatar
Pierre Kraemer committed
385
//	{
untereiner's avatar
untereiner committed
386
//		if ( good(d) && (!markerFace.isMarked(d))) // foreach volume (not already marked)
Pierre Kraemer's avatar
Pierre Kraemer committed
387
//		{
untereiner's avatar
untereiner committed
388
//			VEC3 centerVol= Algo::Geometry::volumeCentroid<PFP>(map,d, positions) ; // compute center
Pierre Kraemer's avatar
Pierre Kraemer committed
389 390 391
//			fgl_cd.setVolCenter(centerVol);		//set center of volume in face drawing fonctor
//
//			vecDarts.clear();
untereiner's avatar
untereiner committed
392
//			map.foreach_dart_of_oriented_volume(d,fvol);	// get all darts of voluùe
Pierre Kraemer's avatar
Pierre Kraemer committed
393 394 395
//
//			for (typename std::vector<Dart>::iterator it = vecDarts.begin(); it != vecDarts.end(); ++it)
//			{
untereiner's avatar
untereiner committed
396
//				if (!markerFace.isMarked(*it))	// for all face of the volume
Pierre Kraemer's avatar
Pierre Kraemer committed
397 398 399 400 401 402 403
//				{
//					fgl_cd(*it);
//				}
//			}
//		}
//	 }
//
untereiner's avatar
untereiner committed
404
//	markerFace.unmarkAll();
Pierre Kraemer's avatar
Pierre Kraemer committed
405 406 407 408 409 410 411 412
//
// 	glEnd();
// 	glLineWidth(2.0f);
// 	glBegin(GL_LINES);
//
//	// si on doit tracer phi2 & phi3 : unes seule passe
//	if ( drawPhi2 && drawPhi3)
//	{
untereiner's avatar
untereiner committed
413
//		for(Dart d = map.begin(); d!= map.end(); map.next(d))
Pierre Kraemer's avatar
Pierre Kraemer committed
414 415 416
//		{
//			if (good(d))
//			{
untereiner's avatar
untereiner committed
417
//				int i=d;
Pierre Kraemer's avatar
Pierre Kraemer committed
418 419
//				glTexCoord3f(vPosPhi23[i][0],vPosPhi23[i][1],vPosPhi23[i][2]);
//
untereiner's avatar
untereiner committed
420
//				if (good(map.phi2(d)))
Pierre Kraemer's avatar
Pierre Kraemer committed
421 422
//				{
//					glColor3f(1.0,0.0,0.0);
untereiner's avatar
untereiner committed
423
//					int j=(map.phi2(d));
Pierre Kraemer's avatar
Pierre Kraemer committed
424 425 426
//					glVertex3fv(vPosPhi23[i].getData());
//					glVertex3fv(vPosPhi23[j].getData());
//				}
untereiner's avatar
untereiner committed
427
//				if (good(map.phi3(d)))
Pierre Kraemer's avatar
Pierre Kraemer committed
428 429
//				{
//					glColor3f(1.0,0.0,1.0);
untereiner's avatar
untereiner committed
430
//					int j=(map.phi3(d));
Pierre Kraemer's avatar
Pierre Kraemer committed
431 432 433 434 435 436 437 438 439 440 441
//					glVertex3fv(vPosPhi23[i].getData());
//					glVertex3fv(vPosPhi23[j].getData());
//				}
//			}
//		}
//		glEnd();
//		return;	// on sort pour ne pas repasser dans les 2 if (pas très grave)
//	}
//
//	if (drawPhi2)
//	{
untereiner's avatar
untereiner committed
442
//		for(Dart d = map.begin(); d!= map.end(); map.next(d))
Pierre Kraemer's avatar
Pierre Kraemer committed
443
//		{
untereiner's avatar
untereiner committed
444
//			if (good(d) && good(map.phi2(d)))
Pierre Kraemer's avatar
Pierre Kraemer committed
445 446
//			{
//				glColor3f(1.0,0.0,0.0);
untereiner's avatar
untereiner committed
447
//				int i=d;
Pierre Kraemer's avatar
Pierre Kraemer committed
448
//				glTexCoord3f(vPosPhi23[i][0],vPosPhi23[i][1],vPosPhi23[i][2]);
untereiner's avatar
untereiner committed
449
//				int	j=(map.phi2(d));
Pierre Kraemer's avatar
Pierre Kraemer committed
450 451 452 453 454 455 456 457
//				glVertex3fv(vPosPhi23[i].getData());
//				glVertex3fv(vPosPhi23[j].getData());
//			}
//		}
//	}
//
//	if (drawPhi3)
//	{
untereiner's avatar
untereiner committed
458
//		for(Dart d = map.begin(); d!= map.end(); map.next(d))
Pierre Kraemer's avatar
Pierre Kraemer committed
459
//		{
untereiner's avatar
untereiner committed
460
//			if (good(d) && good(map.phi3(d)))
Pierre Kraemer's avatar
Pierre Kraemer committed
461 462
//			{
//				glColor3f(1.0,0.0,1.0);
untereiner's avatar
untereiner committed
463
//				int i=d;
Pierre Kraemer's avatar
Pierre Kraemer committed
464
//				glTexCoord3f(vPosPhi23[i][0],vPosPhi23[i][1],vPosPhi23[i][2]);
untereiner's avatar
untereiner committed
465
//				int	j=(map.phi3(d));
Pierre Kraemer's avatar
Pierre Kraemer committed
466 467 468 469 470 471 472 473 474 475
//				glVertex3fv(vPosPhi23[i].getData());
//				glVertex3fv(vPosPhi23[j].getData());
//			}
//		}
//	}
//
//	glEnd();	// end Lines for phi
//
//}

untereiner's avatar
untereiner committed
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 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 562 563 564 565 566 567 568 569 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 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644
template <typename PFP>
void renderTopoMD3(typename PFP::MAP& map, typename PFP::TVEC3& positions, bool drawPhi1, bool drawPhi2, bool drawPhi3, float ke, float kf, float kv)
{
	typedef typename PFP::VEC3 VEC3;
	typedef typename PFP::REAL REAL;


	AutoAttributeHandler<Geom::Vec3f> fv1(map, DART);
	AutoAttributeHandler<Geom::Vec3f> fv11(map, DART);
	AutoAttributeHandler<Geom::Vec3f> fv2(map, DART);
	AutoAttributeHandler<Geom::Vec3f> fv2x(map, DART);
	AutoAttributeHandler<Geom::Vec3f> vert(map, DART);


	int m_nbDarts = 0;

	// table of center of volume
	std::vector<VEC3> vecCenters;
	vecCenters.reserve(1000);
	// table of nbfaces per volume
	std::vector<unsigned int> vecNbFaces;
	vecNbFaces.reserve(1000);
	// table of face (one dart of each)
	std::vector<Dart> vecDartFaces;
	vecDartFaces.reserve(map.getNbDarts()/4);

	DartMarker mark(map);					// marker for darts
	for (Dart d = map.begin(); d != map.end(); map.next(d))
	{
			CellMarkerStore markVert(map, VERTEX);		//marker for vertices
			VEC3 center(0, 0, 0);
			unsigned int nbv = 0;
			unsigned int nbf = 0;
			std::list<Dart> visitedFaces;	// Faces that are traversed
			visitedFaces.push_back(d);		// Start with the face of d

			// For every face added to the list
			for (std::list<Dart>::iterator face = visitedFaces.begin(); face != visitedFaces.end(); ++face)
			{
				if (!mark.isMarked(*face))		// Face has not been visited yet
				{
					// store a dart of face
					vecDartFaces.push_back(*face);
					nbf++;
					Dart dNext = *face ;
					do
					{
						if (!markVert.isMarked(dNext))
						{
							markVert.mark(dNext);
							center += positions[dNext];
							nbv++;
						}
						mark.mark(dNext);					// Mark
						m_nbDarts++;
						Dart adj = map.phi2(dNext);				// Get adjacent face
						if (adj != dNext && !mark.isMarked(adj))
							visitedFaces.push_back(adj);	// Add it
						dNext = map.phi1(dNext);
					} while(dNext != *face);
				}
			}
			center /= typename PFP::REAL(nbv);
			vecCenters.push_back(center);
			vecNbFaces.push_back(nbf);
	}

 	glLineWidth(1.0f);
	glBegin(GL_LINES);
	glColor3f(1.0f,1.0f,1.0f);

	std::vector<Dart>::iterator face = vecDartFaces.begin();
	for (unsigned int iVol=0; iVol<vecNbFaces.size(); ++iVol)
	{
		for (unsigned int iFace = 0; iFace < vecNbFaces[iVol]; ++iFace)
		{
			Dart d = *face++;

			std::vector<VEC3> vecPos;
			vecPos.reserve(16);

			// store the face & center
			VEC3 center(0, 0, 0);
			Dart dd = d;
			do
			{
				const VEC3& P = positions[d];
				vecPos.push_back(P);
				//m_attIndex[d] = posDBI;
				center += P;
				d = map.phi1(d);
			} while (d != dd);
			center /= REAL(vecPos.size());

			//shrink the face
			unsigned int nb = vecPos.size();
			float okf = 1.0f - kf;
			float okv = 1.0f - kv;
			for (unsigned int i = 0; i < nb; ++i)
			{
				vecPos[i] = vecCenters[iVol]*okv + vecPos[i]*kv;
				vecPos[i] = center*okf + vecPos[i]*kf;
			}
			vecPos.push_back(vecPos.front()); // copy the first for easy computation on next loop

			// compute position of points to use for drawing topo
			float oke = 1.0f - ke;
			for (unsigned int i = 0; i < nb; ++i)
			{
				VEC3 P = vecPos[i]*ke + vecPos[i+1]*oke;
				VEC3 Q = vecPos[i+1]*ke + vecPos[i]*oke;

				vert[d] = P;

				glVertex3fv(P.data());
				glVertex3fv(Q.data());

				fv1[d] = P*0.1f + Q*0.9f;
				fv11[d] = P*0.9f + Q*0.1f;

				fv2[d] = P*0.52f + Q*0.48f;
				fv2x[d] = P*0.48f + Q*0.52f;

				d = map.phi1(d);
			}

		}
	}


	for(Dart d = map.begin(); d != map.end(); map.next(d))
	{
		Dart e = map.phi2(d);
		if ((d<e) && drawPhi2)
		{
			glColor3f(1.0,0.0,0.0);
			glVertex3fv(fv2[d].data());
			glVertex3fv(fv2[e].data());
		}

		e = map.phi3(d);
		if ((d<e) && drawPhi3)
		{
			glColor3f(1.0,1.0,0.0);
			glVertex3fv(fv2[d].data());
			glVertex3fv(fv2[e].data());
		}
		if (drawPhi1)
		{
			e = map.phi1(d);
			glColor3f(0.0f,1.0f,1.0f);
			glVertex3fv(fv1[d].data());
			glVertex3fv(fv11[e].data());
		}
	}

	glEnd(); // LINES

	glPointSize(5.0f);
	glColor3f(0.0f,0.0f,0.0f);
	glBegin(GL_POINTS);
	for(Dart d = map.begin(); d!= map.end(); map.next(d))
	{
		glVertex3fv(vert[d].data());
	}
	glEnd();

}

Pierre Kraemer's avatar
Pierre Kraemer committed
645 646 647 648 649 650

} // endnamespace
} // endnamespace
} // endnamespace
} // endnamespace