tp_master.cpp 15.8 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                                        *
*                                                                              *
*******************************************************************************/

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
};

60
/// typedef pour simplifier l'ecriture du code
Pierre Kraemer's avatar
Pierre Kraemer committed
61 62
typedef PFP::VEC3 Point3D;

David Cazier's avatar
David Cazier committed
63 64
// Variables pour la gestion des plongements
//		handler d'attribut de position par sommet
65
VertexAttribute<Point3D> position;
David Cazier's avatar
David Cazier committed
66
//		handler d'attribut de normale par sommet
67
VertexAttribute<Point3D> normal;
Pierre Kraemer's avatar
Pierre Kraemer committed
68 69


David Cazier's avatar
David Cazier committed
70
/// Fonctions a connaitre:
Pierre Kraemer's avatar
Pierre Kraemer committed
71
///
David Cazier's avatar
David Cazier committed
72
/// phi1(d), phi2(d) : les parcours topologiques
Pierre Kraemer's avatar
Pierre Kraemer committed
73
///
David Cazier's avatar
David Cazier committed
74
/// Creer un face: newOrientedFace(nb_cotes); renvoit un Dart
Pierre Kraemer's avatar
Pierre Kraemer committed
75
///
David Cazier's avatar
David Cazier committed
76 77
/// Creer un plongement de sommet :
/// 	Point3D P = Point3D(0.0f,0.0f,0.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
78
///
David Cazier's avatar
David Cazier committed
79 80 81 82 83
/// 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
84

David Cazier's avatar
David Cazier committed
85
class Map2TP : public Map2
Pierre Kraemer's avatar
Pierre Kraemer committed
86
{
David Cazier's avatar
David Cazier committed
87 88 89 90 91 92 93 94
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) {
95
		setOrbitEmbeddingOnNewCell<VERTEX>(d);
David Cazier's avatar
David Cazier committed
96
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
97

David Cazier's avatar
David Cazier committed
98 99 100 101 102 103 104 105 106
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
107

David Cazier's avatar
David Cazier committed
108 109
		return NIL;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
110

David Cazier's avatar
David Cazier committed
111 112 113 114 115 116 117
	//  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
118

David Cazier's avatar
David Cazier committed
119 120
		return NIL;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
121

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

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

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

David Cazier's avatar
David Cazier committed
138 139 140 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
	// 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
184

David Cazier's avatar
David Cazier committed
185 186 187 188 189 190
	// 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
191

David Cazier's avatar
David Cazier committed
192 193 194 195
//		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
196

David Cazier's avatar
David Cazier committed
197 198 199 200
	// Touche x
	void coupeFace(Dart d, Dart e)
	{
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
201

David Cazier's avatar
David Cazier committed
202 203 204 205 206 207
	// 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
208

David Cazier's avatar
David Cazier committed
209 210 211 212 213 214 215 216 217 218 219 220 221
	// 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
222

David Cazier's avatar
David Cazier committed
223 224 225
	unsigned face_size(Dart d) {
		return 0;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
226

David Cazier's avatar
David Cazier committed
227 228 229
	// Touche p
	void triangule() {
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
230

David Cazier's avatar
David Cazier committed
231 232 233 234 235 236 237
	// 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
238

David Cazier's avatar
David Cazier committed
239 240 241 242 243 244 245 246
	// 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
247

David Cazier's avatar
David Cazier committed
248 249 250 251
	// Simplification touche k
	void simplifie()
	{
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
252

David Cazier's avatar
David Cazier committed
253
};
Pierre Kraemer's avatar
Pierre Kraemer committed
254

David Cazier's avatar
David Cazier committed
255 256
// definition de la carte comme variable globale
PFP::MAP myMap;
Pierre Kraemer's avatar
Pierre Kraemer committed
257

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

David Cazier's avatar
David Cazier committed
261
// Variables pour le picking (sélection de brins à la souris)
Pierre Kraemer's avatar
Pierre Kraemer committed
262 263 264 265 266 267 268
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;

269
void MyQT::drawSelected()
Pierre Kraemer's avatar
Pierre Kraemer committed
270
{
271

Pierre Kraemer's avatar
Pierre Kraemer committed
272 273 274
	typedef Dart Dart;

// FACES
275 276 277

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

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

		m_ds->end();
Pierre Kraemer's avatar
Pierre Kraemer committed
294 295 296
	}


297 298 299
//edges
	m_ds->begin(GL_LINES);
	m_ds->lineWidth(5.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
300 301 302 303
	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());
304
		m_ds->color3f(1.0f - c , c ,0.);
Pierre Kraemer's avatar
Pierre Kraemer committed
305 306 307

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

Pierre Kraemer's avatar
Pierre Kraemer committed
315 316 317

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

	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());
325
		m_ds->color3f(1.0f - c , 0., c);
Pierre Kraemer's avatar
Pierre Kraemer committed
326 327
		Dart d = d_vertices[i];
		const PFP::VEC3& P = position[d];
328
		m_ds->vertex(P);
Pierre Kraemer's avatar
Pierre Kraemer committed
329
	}
330 331 332
	m_ds->end();

	m_ds->endList();
Pierre Kraemer's avatar
Pierre Kraemer committed
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
	
	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;
		}
	}

}

365 366 367 368 369 370 371
void MyQT::cb_initGL()
{
	// choose to use GL version 2
	Utils::GLSLShader::setCurrentOGLVersion(2);

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

374
	m_ds = new Utils::Drawer() ;
375

376 377 378 379 380 381 382
	// 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
383 384
	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
385 386 387 388

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

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

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

David Cazier's avatar
David Cazier committed
403 404 405
	// 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
406

David Cazier's avatar
David Cazier committed
407
	m_render_topo->updateData<PFP>(myMap, position, 0.9f, 0.9f);
Pierre Kraemer's avatar
Pierre Kraemer committed
408 409

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

	glEnable( GL_POLYGON_OFFSET_FILL );
418 419 420 421 422
	glPolygonOffset( 1.5f, 1.5f );



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

426

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

433
	m_render->draw(m_shader,Algo::Render::GL2::TRIANGLES) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
434 435 436 437

	glDisable( GL_POLYGON_OFFSET_FILL );
}

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

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

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

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

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

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

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

		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
482
			const Point3D& P = position[darts[0]];
Pierre Kraemer's avatar
Pierre Kraemer committed
483
			ss << " /Emb:" << P;
484
			statusMsg(ss.str().c_str());
Pierre Kraemer's avatar
Pierre Kraemer committed
485 486 487
		}
		break;

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

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

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

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

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

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

David Cazier's avatar
David Cazier committed
530
	// Opérations utilisant 2 brins
Pierre Kraemer's avatar
Pierre Kraemer committed
531
	case 'c':
David Cazier's avatar
David Cazier committed
532 533 534
	case 'm':
	case 'x':
		if (selected_darts.size() >= 2)
Pierre Kraemer's avatar
Pierre Kraemer committed
535
		{
David Cazier's avatar
David Cazier committed
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
			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
551 552 553
		}
		break;

David Cazier's avatar
David Cazier committed
554 555 556 557 558
	// Opérations utilisant un brin
	case 'y':
	case 'z':
	case 'q':
		if (selected_darts.size() >= 1)
Pierre Kraemer's avatar
Pierre Kraemer committed
559
		{
David Cazier's avatar
David Cazier committed
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
			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
575 576 577
		}
		break;

David Cazier's avatar
David Cazier committed
578 579 580 581 582 583 584 585 586 587
	// 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
588 589
		break;
	}
David Cazier's avatar
David Cazier committed
590 591
	// Mise à jour de l'affichage
	updateGL();
Pierre Kraemer's avatar
Pierre Kraemer committed
592 593 594 595
}

int main(int argc, char **argv)
{
596 597 598 599
	// interface:
	QApplication app(argc, argv);
	MyQT sqt;

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

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

David Cazier's avatar
David Cazier committed
619 620 621 622
	// 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;
623 624 625 626 627 628 629 630 631 632 633 634 635 636
	sqt.setParamObject(lWidthObj,lPosObj.data());

	// show 1 pour optenir le contexte GL
	sqt.show();

	// update du VBO position (contexte GL necessaire)
	sqt.m_positionVBO->updateData(position);
	sqt.m_normalVBO->updateData(normal);

	// update des primitives du renderer
	sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES);
	sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES);

	sqt.m_render_topo->updateData<PFP>(myMap, position, 0.9f, 0.9f);
Pierre Kraemer's avatar
Pierre Kraemer committed
637

638 639
	// show final pour premier redraw
	sqt.show();
Pierre Kraemer's avatar
Pierre Kraemer committed
640

641 642
	// et on attend la fin.
	return app.exec();
Pierre Kraemer's avatar
Pierre Kraemer committed
643
}