simpleGMap2.cpp 3.77 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, 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 "simpleGMap2.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
26
27
#include "Utils/GLSLShader.h"
#include "Algo/Geometry/boundingbox.h"
28
#include "Algo/Modelisation/polyhedron.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
29

30
SimpleGMap2::SimpleGMap2()
Pierre Kraemer's avatar
Pierre Kraemer committed
31
{
32
	 position = myMap.addAttribute<VEC3, VERTEX>("position");
Pierre Kraemer's avatar
Pierre Kraemer committed
33

34
     Dart d = Algo::Surface::Modelisation::createTetrahedron<PFP>(myMap);
35
     position[d] = VEC3(0,0,0);
thomas's avatar
thomas committed
36
37
38
     position[myMap.phi1(d)] = VEC3(10,0,15);
     position[myMap.phi_1(d)] = VEC3(10,20,15);
     position[myMap.phi_1(myMap.phi2(d))] = VEC3(0,0,30);
Pierre Kraemer's avatar
Pierre Kraemer committed
39

40
     VEC3 mid = (position[d] + position[myMap.phi1(d)]) / 2.0f;
41
42
     myMap.cutEdge(d);
     position[myMap.phi1(d)] = mid;
Pierre Kraemer's avatar
Pierre Kraemer committed
43

44
     Algo::Surface::Modelisation::Polyhedron<PFP> poly(myMap, position);
Pierre Kraemer's avatar
Pierre Kraemer committed
45

46
     d = poly.cylinder_topo(5, 1, false, false);
Pierre Kraemer's avatar
Pierre Kraemer committed
47

48
     poly.embedCylinder(10, 10, 5);
Pierre Kraemer's avatar
Pierre Kraemer committed
49

thomas's avatar
thomas committed
50
51
52
     d = myMap.phi1(d);
     Dart dd = myMap.beta2(d);
     myMap.unsewFaces(d);
53
     myMap.sewFaces(d, dd);
Pierre Kraemer's avatar
Pierre Kraemer committed
54

thomas's avatar
thomas committed
55
     position[d][1] += 3.0f;
Pierre Kraemer's avatar
Pierre Kraemer committed
56
57
}

58
void SimpleGMap2::initGUI()
Pierre Kraemer's avatar
Pierre Kraemer committed
59
60
61
{
}

62
void SimpleGMap2::cb_initGL()
Pierre Kraemer's avatar
Pierre Kraemer committed
63
{
64
	Utils::GLSLShader::setCurrentOGLVersion(1) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
65

66
67
68
69
70
71
72
	Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
	VEC3 gPosObj = bb.center() ;
	float tailleX = bb.size(0) ;
	float tailleY = bb.size(1) ;
	float tailleZ = bb.size(2) ;
	float gWidthObj = std::max<float>(std::max<float>(tailleX, tailleY), tailleZ) ;
	setParamObject(gWidthObj, gPosObj.data());
Pierre Kraemer's avatar
Pierre Kraemer committed
73
74
}

75
void SimpleGMap2::cb_redraw()
Pierre Kraemer's avatar
Pierre Kraemer committed
76
{
77
78
	glDisable(GL_LIGHTING);
	glLineWidth(1.0f);
Thomas's avatar
Thomas committed
79
	Algo::Render::GL1::renderTopoGMD2<PFP>(myMap, position, true, true, true, 0.9f, 0.9f, 0.9f);
Pierre Kraemer's avatar
Pierre Kraemer committed
80
81
}

82
83
84
/**********************************************************************************************
 *                                      MAIN FUNCTION                                         *
 **********************************************************************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
85
86
87

int main(int argc, char **argv)
{
88
	QApplication app(argc, argv) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
89

90
91
92
	SimpleGMap2 sqt ;
	sqt.setGeometry(0, 0, 1000, 800) ;
 	sqt.show() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
93

94
	sqt.initGUI() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
95

96
	return app.exec() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
97
}