Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

tp_master.cpp 15.4 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2011, IGG Team, LSIIT, University of Strasbourg           *
Pierre Kraemer's avatar
Pierre Kraemer committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
*                                                                              *
* This library is free software; you can redistribute it and/or modify it      *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library is distributed in the hope that it will be useful, but WITHOUT  *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License  *
* for more details.                                                            *
*                                                                              *
* You should have received a copy of the GNU Lesser General Public License     *
* along with this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
20
* Web site: http://cgogn.u-strasbg.fr/                                         *
Pierre Kraemer's avatar
Pierre Kraemer committed
21
22
23
24
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

25
#include "tp_master.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
26

27
#include "Topology/generic/parameters.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
28
#include "Topology/map/embeddedMap2.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
29
30
31
32

#include "Geometry/vector_gen.h"
#include "Geometry/matrix.h"

33
34
#include "Algo/Render/GL2/mapRender.h"
#include "Algo/Render/GL2/topoRender.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
35
36
37
38
39
40
41
#include "Algo/Geometry/normal.h"

#include "Algo/Selection/raySelector.h"

#include "Algo/Import/import.h"
#include "Algo/Geometry/boundingbox.h"

42
43
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/Shaders/shaderPhong.h"
44

45
46
#include "Utils/drawer.h"

David Cazier's avatar
David Cazier committed
47
// pour simplifier l'ecriture du code
Pierre Kraemer's avatar
Pierre Kraemer committed
48
49
using namespace CGoGN;

David Cazier's avatar
David Cazier committed
50
51
// déclaration de la classe utilisée pour le TP
class Map2TP;
Pierre Kraemer's avatar
Pierre Kraemer committed
52

David Cazier's avatar
David Cazier committed
53
// definition de la structure qui decrit le type de carte utilise
54
struct PFP: public PFP_STANDARD
Pierre Kraemer's avatar
Pierre Kraemer committed
55
{
Pierre Kraemer's avatar
Pierre Kraemer committed
56
	// definition of the map
David Cazier's avatar
David Cazier committed
57
	typedef Map2TP MAP;
Pierre Kraemer's avatar
Pierre Kraemer committed
58
59
};

David Cazier's avatar
David Cazier committed
60
61
// fonction qui renvoit vrai (pour sélectioner tous les brins)
SelectorTrue allDarts;
Pierre Kraemer's avatar
Pierre Kraemer committed
62

David Cazier's avatar
David Cazier committed
63
// typedef pour le plongement des sommets
Pierre Kraemer's avatar
Pierre Kraemer committed
64
65
typedef PFP::VEC3 Point3D;

David Cazier's avatar
David Cazier committed
66
67
68
69
70
// Variables pour la gestion des plongements
//		handler d'attribut de position par sommet
AttributeHandler<Point3D> position;
//		handler d'attribut de normale par sommet
AttributeHandler<PFP::VEC3> normal;
Pierre Kraemer's avatar
Pierre Kraemer committed
71
72


David Cazier's avatar
David Cazier committed
73
/// Fonctions a connaitre:
Pierre Kraemer's avatar
Pierre Kraemer committed
74
///
David Cazier's avatar
David Cazier committed
75
/// phi1(d), phi2(d) : les parcours topologiques
Pierre Kraemer's avatar
Pierre Kraemer committed
76
///
David Cazier's avatar
David Cazier committed
77
/// Creer un face: newOrientedFace(nb_cotes); renvoit un Dart
Pierre Kraemer's avatar
Pierre Kraemer committed
78
///
David Cazier's avatar
David Cazier committed
79
80
/// Creer un plongement de sommet :
/// 	Point3D P = Point3D(0.0f,0.0f,0.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
81
///
David Cazier's avatar
David Cazier committed
82
83
84
85
86
/// Lire le plongement d'un sommet (celui du brin d)
///		P = position[d];
///
/// Assigner un plongement à un sommet (celui du brin d)
///		embedVertex(d,P);
Pierre Kraemer's avatar
Pierre Kraemer committed
87

David Cazier's avatar
David Cazier committed
88
class Map2TP : public Map2
Pierre Kraemer's avatar
Pierre Kraemer committed
89
{
David Cazier's avatar
David Cazier committed
90
91
92
93
94
95
96
97
98
99
private:
	// 3 brins de la carte
	Dart d_carre;
	Dart d_tri;
	Dart d_multiFaces;

	// Assigne un nouveau plongement au sommet. Les anciens plongements sont libérés.
	void newVertex(Dart d) {
		embedNewCell(VERTEX,d);
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
100

David Cazier's avatar
David Cazier committed
101
102
103
104
105
106
107
108
109
public:
	//  Fonction Carre: construit un carre et renvoit un brin
	Dart Carre()
	{
		Point3D P[4];
		P[0] = Point3D(0.0f,0.0f,0.0f);
		P[1] = Point3D(1.0f,0.0f,0.0f);
		P[2] = Point3D(1.0f,1.0f,0.0f);
		P[3] = Point3D(0.0f,1.0f,0.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
110

David Cazier's avatar
David Cazier committed
111
112
		return NIL;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
113

David Cazier's avatar
David Cazier committed
114
115
116
117
118
119
120
	//  Fonction Triangle: construit un triangle et renvoit un brin
	Dart Triangle()
	{
		Point3D P[3];
		P[0] = Point3D(0.0f,1.1f,0.0f);
		P[1] = Point3D(1.0f,1.1f,0.0f);
		P[2] = Point3D(0.5f,2.0f,0.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
121

David Cazier's avatar
David Cazier committed
122
123
		return NIL;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
124

David Cazier's avatar
David Cazier committed
125
126
127
128
129
	// Construit un polygone de taille "size"
	Dart Polygone(Point3D* P, unsigned size)
	{
		return NIL;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
130

David Cazier's avatar
David Cazier committed
131
132
133
134
	// appel clavier touche 'c'
	void Colle(Dart d, Dart e)
	{
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
135

David Cazier's avatar
David Cazier committed
136
137
138
139
	// appel clavier touche 'm'
	void ColleMilieu(Dart d, Dart e)
	{
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
140

David Cazier's avatar
David Cazier committed
141
142
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
	// Construit une figure
	Dart MultiFaces()
	{
		Point3D P[6];
		P[0] = Point3D(2.0f,0.0f,0.0f);
		P[1] = Point3D(3.0f,0.0f,0.0f);
		P[2] = Point3D(3.5f,1.0f,0.0f);
		P[3] = Point3D(3.0f,1.8f,0.0f);
		P[4] = Point3D(2.0f,1.8f,0.0f);
		P[5] = Point3D(1.5f,1.0f,0.0f);
		Dart hexa = Polygone(P,6);

		Point3D Q[3];
		Q[0] = Point3D(2.0f,2.0f,0.0f);
		Q[1] = Point3D(3.0f,2.0f,0.0f);
		Q[2] = Point3D(2.5f,3.0f,0.0f);
		Dart triangle = Polygone(Q,3);

		Point3D R[4];
		R[0] = Point3D(4.0f,0.0f,0.0f);
		R[1] = Point3D(5.0f,0.0f,0.0f);
		R[2] = Point3D(5.0f,1.0f,0.0f);
		R[3] = Point3D(4.0f,1.0f,0.0f);
		Dart carre = Polygone(R,4);

		Point3D S[3];
		S[0] = Point3D(4.0f,1.2f,0.0f);
		S[1] = Point3D(5.0f,1.2f,0.0f);
		S[2] = Point3D(4.5f,2.2f,0.0f);
		Dart triangle2 = Polygone(S,3);

		Dart haut_carre = phi1(phi1(carre));
		Dart hexa2 = phi1(phi1(phi1(hexa)));

	//	Test du phi1Sew
	//	myMap.phi1sew(hexa,hexa2);
	//	myMap.phi1sew(myMap.phi1(hexa),myMap.phi_1(carre));

		// Génére un maillage à la fin
//		Colle(haut_carre,triangle2);
//		Colle(hexa2,triangle);
//		Colle(phi_1(triangle2),phi_1(hexa2));
//		Colle(phi1(hexa),phi_1(carre));

		return hexa;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
187

David Cazier's avatar
David Cazier committed
188
189
190
191
192
193
	// Fonction de creation de la carte (appelee par le main)
	void createMap()
	{
		d_carre = Carre();
		d_tri = Triangle();
//		d_multiFaces = MultiFaces();
Pierre Kraemer's avatar
Pierre Kraemer committed
194

David Cazier's avatar
David Cazier committed
195
196
197
198
//		Colle(phi1(phi1(d_carre)),d_tri);
//		Colle(phi_1(d_multiFaces),phi1(d_carre));
//		Colle(phi_1(phi_1(d_multiFaces)),phi1(d_tri));
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
199

David Cazier's avatar
David Cazier committed
200
201
202
203
	// Touche x
	void coupeFace(Dart d, Dart e)
	{
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
204

David Cazier's avatar
David Cazier committed
205
206
207
208
209
210
	// Touche y
	void coupeArete(Dart d) {
		Point3D p = position[d];
		Point3D q = position[phi1(d)];
		Point3D milieu = (p + q + Point3D(0.2f,0.2f,0.0f) /* decalage pour voir le point */ )/2;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
211

David Cazier's avatar
David Cazier committed
212
213
214
215
216
217
218
219
220
221
222
223
224
	// Touche z
	void arrondi(Dart d) {
		Dart e = phi_1(d);
		coupeArete(d);
		coupeArete(e);
		e = phi1(e);
		Point3D P = position[d];
		Point3D Q = position[e];
		Point3D R = position[phi1(d)];
		Point3D M = (P + P + Q + R)/4;

		position[d] = M;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
225

David Cazier's avatar
David Cazier committed
226
227
228
	unsigned face_size(Dart d) {
		return 0;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
229

David Cazier's avatar
David Cazier committed
230
231
232
	// Touche p
	void triangule() {
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
233

David Cazier's avatar
David Cazier committed
234
235
236
237
238
239
240
	// Touche q
	void fusionSommet(Dart d)
	{
		Point3D P = position[d];
		Point3D Q = position[phi1(d)];
		Point3D M = (P + Q)/2;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
241

David Cazier's avatar
David Cazier committed
242
243
244
245
246
247
248
249
	// Longueur d'une arête
	double longueur(Dart d)
	{
		Point3D P = position[d];
		Point3D Q = position[phi1(d)];
		Point3D V = P-Q;
		return V.norm();
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
250

David Cazier's avatar
David Cazier committed
251
252
253
254
	// Simplification touche k
	void simplifie()
	{
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
255

David Cazier's avatar
David Cazier committed
256
};
Pierre Kraemer's avatar
Pierre Kraemer committed
257

David Cazier's avatar
David Cazier committed
258
259
// definition de la carte comme variable globale
PFP::MAP myMap;
Pierre Kraemer's avatar
Pierre Kraemer committed
260

David Cazier's avatar
David Cazier committed
261
262
// pile des brins selectionnes (6 max)
std::vector<Dart> selected_darts;
Pierre Kraemer's avatar
Pierre Kraemer committed
263

David Cazier's avatar
David Cazier committed
264
// Variables pour le picking (sélection de brins à la souris)
Pierre Kraemer's avatar
Pierre Kraemer committed
265
266
267
268
269
270
271
PFP::VEC3 rayA;
PFP::VEC3 rayB;
std::vector<PFP::VEC3> inters;
std::vector<Dart> d_faces;
std::vector<Dart> d_edges;
std::vector<Dart> d_vertices;

272
void MyQT::drawSelected()
Pierre Kraemer's avatar
Pierre Kraemer committed
273
{
274

Pierre Kraemer's avatar
Pierre Kraemer committed
275
276
277
	typedef Dart Dart;

// FACES
278
279
280

	m_ds->newList(GL_COMPILE_AND_EXECUTE);
	m_ds->lineWidth(5.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
281
282
	for(unsigned int i=0; i < d_faces.size(); ++i)
	{
283
		m_ds->begin(GL_POLYGON);
Pierre Kraemer's avatar
Pierre Kraemer committed
284
285
		// fait varier la couleur du plus pres au plus loin
		float c = float (i) / float (d_faces.size());
286
		m_ds->color3f(1.0f - c , 0.0f, c);
Pierre Kraemer's avatar
Pierre Kraemer committed
287
288
289
290
291

		Dart d = d_faces[i];
		do
		{
			const PFP::VEC3& P = position[d];
292
			m_ds->vertex(P);
Pierre Kraemer's avatar
Pierre Kraemer committed
293
294
			d = myMap.phi1(d);
		} while (d!=d_faces[i]);
295
296

		m_ds->end();
Pierre Kraemer's avatar
Pierre Kraemer committed
297
298
299
	}


300
301
302
//edges
	m_ds->begin(GL_LINES);
	m_ds->lineWidth(5.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
303
304
305
306
	for(unsigned int i=0; i < d_edges.size(); ++i)
	{
		// fait varier la couleur du plus pres au plus loin
		float c = float (i) / float (d_edges.size());
307
		m_ds->color3f(1.0f - c , c ,0.);
Pierre Kraemer's avatar
Pierre Kraemer committed
308
309
310

		Dart d = d_edges[i];
		const PFP::VEC3& P = position[d];
311
		m_ds->vertex(P);
Pierre Kraemer's avatar
Pierre Kraemer committed
312
313
		d = myMap.phi1(d);
		const PFP::VEC3& Q =  position[d];
314
		m_ds->vertex(Q);
Pierre Kraemer's avatar
Pierre Kraemer committed
315
	}
316
317
	m_ds->end();

Pierre Kraemer's avatar
Pierre Kraemer committed
318
319
320

//VERTICES
//edges
321
322
	m_ds->pointSize(9.0f);
	m_ds->begin(GL_POINTS);
Pierre Kraemer's avatar
Pierre Kraemer committed
323
324
325
326
327

	for(unsigned int i=0; i < d_vertices.size(); ++i)
	{
		// fait varier la couleur du plus pres au plus loin
		float c = float (i) / float (d_vertices.size());
328
		m_ds->color3f(1.0f - c , 0., c);
Pierre Kraemer's avatar
Pierre Kraemer committed
329
330
		Dart d = d_vertices[i];
		const PFP::VEC3& P = position[d];
331
		m_ds->vertex(P);
Pierre Kraemer's avatar
Pierre Kraemer committed
332
	}
333
334
335
	m_ds->end();

	m_ds->endList();
Pierre Kraemer's avatar
Pierre Kraemer committed
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
	
	for(unsigned int i=0; i < selected_darts.size(); ++i)
	{
		// fait varier la couleur du plus pres au plus loin
		Dart d = selected_darts[i];
		switch(i)
		{
			case 0:
				m_render_topo->overdrawDart(d, 5, 1.0f,0.0f,0.0f);
				break;
			case 1:
				m_render_topo->overdrawDart(d, 5, 0.0f,1.0f,0.0f);
				break;
			case 2:
				m_render_topo->overdrawDart(d, 5, 0.0f,0.0f,1.0f);
				break;
			case 3:
				m_render_topo->overdrawDart(d, 5, 1.0f,1.0f,0.0f);
				break;
			case 4:
				m_render_topo->overdrawDart(d, 5, 1.0f,0.0f,1.0f);
				break;
			case 5:
				m_render_topo->overdrawDart(d, 5, 0.0f,1.0f,1.0f);
				break;
			default:
				break;
		}
	}

}

368
369
370
371
372
373
374
375
376
void MyQT::cb_initGL()
{
	// choose to use GL version 2
	Utils::GLSLShader::setCurrentOGLVersion(2);

	// create the render
	m_render = new Algo::Render::GL2::MapRender();
	m_render_topo = new Algo::Render::GL2::TopoRenderMapD() ;

377
378
	m_ds = new Utils::Drawer();

379
380
381
382
383
384
385
	// create VBO for position
	m_positionVBO = new Utils::VBO();
	m_normalVBO = new Utils::VBO();

	m_shader = new Utils::ShaderPhong();
	m_shader->setAttributePosition(m_positionVBO);
	m_shader->setAttributeNormal(m_normalVBO);
thery's avatar
thery committed
386
387
	m_shader->setDiffuse(Geom::Vec4f(0.0f,0.6f,0.0f,0.0f));
	m_shader->setSpecular(Geom::Vec4f(0.0f,0.0f,0.0f,0.0f)); // no specular
388
389
390
391

	// using simple shader with color
	m_shader2 = new Utils::ShaderSimpleColor();
	m_shader2->setAttributePosition(m_positionVBO);
thery's avatar
thery committed
392
	m_shader2->setColor(Geom::Vec4f(0.0f,0.1f,0.0f,0.0f));
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
393
394
	registerShader(m_shader);
	registerShader(m_shader2);
395
}
Pierre Kraemer's avatar
Pierre Kraemer committed
396

David Cazier's avatar
David Cazier committed
397
398
399
400
void MyQT::cb_redraw()
{
	// update des normales aux sommets
	Algo::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
401

David Cazier's avatar
David Cazier committed
402
403
404
	// update du VBO position (contexte GL necessaire)
	m_positionVBO->updateData(position);
	m_normalVBO->updateData(normal);
Pierre Kraemer's avatar
Pierre Kraemer committed
405

David Cazier's avatar
David Cazier committed
406
407
408
	// update des primitives du renderer
	m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES);
	m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES);
Pierre Kraemer's avatar
Pierre Kraemer committed
409

David Cazier's avatar
David Cazier committed
410
	m_render_topo->updateData<PFP>(myMap, position, 0.9f, 0.9f);
Pierre Kraemer's avatar
Pierre Kraemer committed
411
412

	drawSelected();
413
414
415
	if (renderTopo)
	{
		glEnable( GL_POLYGON_OFFSET_FILL );
416
		glPolygonOffset( 1.0f, 1.0f );
417
418
		m_render_topo->drawTopo();
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
419
420

	glEnable( GL_POLYGON_OFFSET_FILL );
421
422
423
424
425
	glPolygonOffset( 1.5f, 1.5f );



	glPolygonOffset( 2.0f, 2.0f );
426
427
	glLineWidth(1.0f);
	m_render->draw(m_shader2,Algo::Render::GL2::LINES) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
428

429

Pierre Kraemer's avatar
Pierre Kraemer committed
430
	/// Rendu faces pleines
431
432
	glEnable(GL_CULL_FACE);
	glFrontFace(GL_CCW);
Pierre Kraemer's avatar
Pierre Kraemer committed
433
434
435
	glPolygonMode(GL_FRONT,GL_FILL);
	glPolygonMode(GL_BACK,GL_NONE);

436
	m_render->draw(m_shader,Algo::Render::GL2::TRIANGLES) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
437
438
439
440

	glDisable( GL_POLYGON_OFFSET_FILL );
}

441
void MyQT::cb_keyPress(int keycode)
Pierre Kraemer's avatar
Pierre Kraemer committed
442
{
David Cazier's avatar
David Cazier committed
443
	// coordonnées du clic et calcul du rayon dans l'espace 3D
444
445
	int x,y;
	glMousePosition(x,y);
David Cazier's avatar
David Cazier committed
446
447
448
449
450
	float dist = getOrthoScreenRay(x,y,rayA,rayB);
	PFP::VEC3 AB = rayB-rayA;

	// tableau de brins pour la sélection
	std::vector<Dart> darts;
451

Pierre Kraemer's avatar
Pierre Kraemer committed
452
453
	switch(keycode)
	{
David Cazier's avatar
David Cazier committed
454
	// Bascule affichage topologie - normal
Pierre Kraemer's avatar
Pierre Kraemer committed
455
456
457
458
	case 't':
		renderTopo = !renderTopo;
		break;

David Cazier's avatar
David Cazier committed
459
	// Oublie les brins sélectionnés
Pierre Kraemer's avatar
Pierre Kraemer committed
460
461
462
463
	case '0':
		selected_darts.clear();
		break;

David Cazier's avatar
David Cazier committed
464
	// Sélectionne un brin
Pierre Kraemer's avatar
Pierre Kraemer committed
465
	case 'd':
466
		Algo::Selection::dartsRaySelection<PFP>(myMap, position, rayA, AB, darts, SelectorTrue());
Pierre Kraemer's avatar
Pierre Kraemer committed
467

David Cazier's avatar
David Cazier committed
468
469
470
471
		if (!darts.empty() && selected_darts.size() < 6)
		{
			selected_darts.push_back(darts[0]);
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
472
473
		break;

David Cazier's avatar
David Cazier committed
474
	// Affiche les informations sur un brin
Pierre Kraemer's avatar
Pierre Kraemer committed
475
	case 'D':
476
		Algo::Selection::dartsRaySelection<PFP>(myMap, position, rayA, AB, darts, SelectorTrue());
Pierre Kraemer's avatar
Pierre Kraemer committed
477
478
479
480
481
482
483
484

		if (!darts.empty()) 
		{
			std::stringstream ss;
			Dart d1 = myMap.phi1(darts[0]);
			Dart d2 = myMap.phi2(darts[0]);
			ss << "dart:" << darts[0].index<<" /phi1:"<< d1.index<<" /phi2:"<< d2.index;

David Cazier's avatar
David Cazier committed
485
			const Point3D& P = position[darts[0]];
Pierre Kraemer's avatar
Pierre Kraemer committed
486
			ss << " /Emb:" << P;
487
			statusMsg(ss.str().c_str());
Pierre Kraemer's avatar
Pierre Kraemer committed
488
489
490
		}
		break;

David Cazier's avatar
David Cazier committed
491
	// Sélectionne des faces
Pierre Kraemer's avatar
Pierre Kraemer committed
492
493
	case 'f':
		d_faces.clear();
494
		Algo::Selection:: facesRaySelection<PFP>(myMap, position, SelectorTrue(), rayA, AB, d_faces);
Pierre Kraemer's avatar
Pierre Kraemer committed
495

496
497
		if (!d_faces.empty())
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
498
			std::stringstream ss;
499
500
			ss << "Face " << d_faces[0].index/3;
			statusMsg(ss.str().c_str());
Pierre Kraemer's avatar
Pierre Kraemer committed
501
502
503
		}
		break;

David Cazier's avatar
David Cazier committed
504
	// Sélectionne des arêtes
Pierre Kraemer's avatar
Pierre Kraemer committed
505
506
	case 'a':
		d_edges.clear();
507
		Algo::Selection::edgesRaySelection<PFP>(myMap, position, SelectorTrue(), rayA, AB, d_edges,dist);
Pierre Kraemer's avatar
Pierre Kraemer committed
508
509
510
511
512

		if (!d_edges.empty())
		{
			std::stringstream ss;
			Dart dd = myMap.phi2(d_edges[0]);
513
			ss << "Arete:  dart: " << d_edges[0].index<<" phi1: "<< myMap.phi1(d_edges[0]).index;
Pierre Kraemer's avatar
Pierre Kraemer committed
514
			if (dd != d_edges[0])
Sylvain Thery's avatar
Sylvain Thery committed
515
				ss << " phi2: " << dd.index<<" phi1: "<< myMap.phi1(dd).index;
516
			statusMsg(ss.str().c_str());
Pierre Kraemer's avatar
Pierre Kraemer committed
517
518
519
		}
		break;

David Cazier's avatar
David Cazier committed
520
	// Sélectionne des sommets
Pierre Kraemer's avatar
Pierre Kraemer committed
521
522
	case 's':
		d_vertices.clear();
523
		Algo::Selection::verticesRaySelection<PFP>(myMap, position,rayA, AB, d_vertices,dist,SelectorTrue());
Pierre Kraemer's avatar
Pierre Kraemer committed
524
525
526
527

		if (!d_vertices.empty())
		{
			std::stringstream ss;
528
			ss << "Sommet:  dart: " << d_vertices[0].index << ": " << position[d_vertices[0]]<< "( id emb:"<< myMap.getEmbedding(VERTEX,d_vertices[0])<<")"<< std::endl; ;
529
			statusMsg(ss.str().c_str());
Pierre Kraemer's avatar
Pierre Kraemer committed
530
531
532
		}
		break;

David Cazier's avatar
David Cazier committed
533
	// Opérations utilisant 2 brins
Pierre Kraemer's avatar
Pierre Kraemer committed
534
	case 'c':
David Cazier's avatar
David Cazier committed
535
536
537
	case 'm':
	case 'x':
		if (selected_darts.size() >= 2)
Pierre Kraemer's avatar
Pierre Kraemer committed
538
		{
David Cazier's avatar
David Cazier committed
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
			switch (keycode) {
			// Colle 2 arêtes
			case 'c':
				myMap.Colle(selected_darts[0], selected_darts[1]);
				break;
			// Colle 2 arêtes en leur milieu
			case 'm':
				myMap.ColleMilieu(selected_darts[0], selected_darts[1]);
				break;
			// Coupe une face en 2 avec une nouvelle arête
			case 'x':
				myMap.coupeFace(selected_darts[0], selected_darts[1]);
				break;
			}
			selected_darts.clear();
Pierre Kraemer's avatar
Pierre Kraemer committed
554
555
556
		}
		break;

David Cazier's avatar
David Cazier committed
557
558
559
560
561
	// Opérations utilisant un brin
	case 'y':
	case 'z':
	case 'q':
		if (selected_darts.size() >= 1)
Pierre Kraemer's avatar
Pierre Kraemer committed
562
		{
David Cazier's avatar
David Cazier committed
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
			switch (keycode) {
			// Coupe une arête en 2 avec un nouveau sommet
			case 'y':
				myMap.coupeArete(selected_darts[0]);
				break;
			// Arrondi
			case 'z':
				myMap.arrondi(selected_darts[0]);
				break;
			// Fusion de sommet
			case 'q':
				myMap.fusionSommet(selected_darts[0]);
				break;
			}
			selected_darts.clear();
Pierre Kraemer's avatar
Pierre Kraemer committed
578
579
580
		}
		break;

David Cazier's avatar
David Cazier committed
581
582
583
584
585
586
587
588
589
590
	// Opérations globales
	// Triangulation
	case 'p':
		myMap.triangule();
		selected_darts.clear();
		break;
	// Simplification
	case 'k':
		myMap.simplifie();
		selected_darts.clear();
Pierre Kraemer's avatar
Pierre Kraemer committed
591
592
		break;
	}
David Cazier's avatar
David Cazier committed
593
594
	// Mise à jour de l'affichage
	updateGL();
Pierre Kraemer's avatar
Pierre Kraemer committed
595
596
597
598
}

int main(int argc, char **argv)
{
599
600
601
602
	// interface:
	QApplication app(argc, argv);
	MyQT sqt;

David Cazier's avatar
David Cazier committed
603
	if (argc == 2) {
Pierre Kraemer's avatar
Pierre Kraemer committed
604
605
		std::vector<std::string> attrNames ;
		Algo::Import::importMesh<PFP>(myMap, argv[1], attrNames) ;
David Cazier's avatar
David Cazier committed
606
		position = myMap.getAttribute<Point3D>(VERTEX, attrNames[0]) ;
607
		normal = myMap.addAttribute<PFP::VEC3>(VERTEX, "normal");
608
		Algo::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
609
	}
David Cazier's avatar
David Cazier committed
610
611
	else {
		position = myMap.addAttribute<Point3D>(VERTEX, "position");
612
		normal = myMap.addAttribute<PFP::VEC3>(VERTEX, "normal");
David Cazier's avatar
David Cazier committed
613
614
		myMap.createMap();
		Algo::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
615
616
	}

David Cazier's avatar
David Cazier committed
617
618
	if (myMap.getNbDarts()==0) {
		CGoGNout << "Aucun brin dans la carte. Sortie ..." << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
619
		exit(0);
David Cazier's avatar
David Cazier committed
620
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
621

David Cazier's avatar
David Cazier committed
622
623
624
625
	// Parametre de la fenetre en fonction de la taille du maillage à afficher
	Geom::BoundingBox<Point3D> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
	float lWidthObj = std::max(std::max(bb.size(0), bb.size(1)), bb.size(2));
	Point3D lPosObj = (bb.min() +  bb.max()) / 2;
626
627
	sqt.setParamObject(lWidthObj,lPosObj.data());

David Cazier's avatar
David Cazier committed
628
	// show pour optenir le contexte GL
629
	sqt.show();
Pierre Kraemer's avatar
Pierre Kraemer committed
630

631
632
	// et on attend la fin.
	return app.exec();
Pierre Kraemer's avatar
Pierre Kraemer committed
633
}