tuto1.cpp 5.66 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
/*******************************************************************************
* 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 <iostream>

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

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

Sylvain Thery's avatar
Sylvain Thery committed
35
36
37
38
#include "Algo/Render/GL2/mapRender.h"
#include "Utils/shaderSimpleColor.h"

#include "tuto1.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
39
40
41
42
43
44
45
46

using namespace CGoGN ;


/**
 * Struct that contains some informations about the types of the manipulated objects
 * Mainly here to be used by the algorithms that are parameterized by it
 */
47
struct PFP: public PFP_STANDARD
Pierre Kraemer's avatar
Pierre Kraemer committed
48
49
50
51
52
53
{
	// definition of the type of the map
	typedef EmbeddedMap2<Map2> MAP;
};


Sylvain Thery's avatar
Sylvain Thery committed
54
55

void MyQT::cb_initGL()
Pierre Kraemer's avatar
Pierre Kraemer committed
56
{
Sylvain Thery's avatar
Sylvain Thery committed
57
58
	// choose to use GL version 2
	Utils::GLSLShader::setCurrentOGLVersion(2);
Pierre Kraemer's avatar
Pierre Kraemer committed
59

Sylvain Thery's avatar
Sylvain Thery committed
60
61
	// create the render
	m_render = new Algo::Render::GL2::MapRender();
Pierre Kraemer's avatar
Pierre Kraemer committed
62

Sylvain Thery's avatar
Sylvain Thery committed
63
64
	// create VBO for position
	m_positionVBO = new Utils::VBO();
Pierre Kraemer's avatar
Pierre Kraemer committed
65

Sylvain Thery's avatar
Sylvain Thery committed
66
67
68
69
	// using simple shader with color
	m_shader = new Utils::ShaderSimpleColor();
	m_shader->setAttributePosition(*m_positionVBO);
	m_shader->setColor(Geom::Vec4f(0.,1.,0.,0.));
Pierre Kraemer's avatar
Pierre Kraemer committed
70

Sylvain Thery's avatar
Sylvain Thery committed
71
72
73
}

void MyQT::cb_updateMatrix()
Pierre Kraemer's avatar
Pierre Kraemer committed
74
{
Sylvain Thery's avatar
Sylvain Thery committed
75
76
77
78
79
	if (m_shader)
	{
		m_shader->updateMatrices(m_projection_matrix, m_modelView_matrix);
	}
}
Pierre Kraemer's avatar
Pierre Kraemer committed
80
81


Sylvain Thery's avatar
Sylvain Thery committed
82
83
void MyQT::cb_redraw()
{
Pierre Kraemer's avatar
Pierre Kraemer committed
84
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
Sylvain Thery's avatar
Sylvain Thery committed
85
86
87
88
89
90
91
92
93
94
95
96
	glEnable(GL_LIGHTING);
	if (m_shader)
	{
		glLineWidth(2.0f);
		m_shader->setColor(Geom::Vec4f(1.,1.,0.,0.));
		m_render->draw(m_shader, Algo::Render::GL2::LINES);

		glEnable(GL_POLYGON_OFFSET_FILL);
		glPolygonOffset(1.0f, 1.0f);

		m_shader->setColor(Geom::Vec4f(0.,1.,0.,0.));
		m_render->draw(m_shader, Algo::Render::GL2::TRIANGLES);
Pierre Kraemer's avatar
Pierre Kraemer committed
97

Sylvain Thery's avatar
Sylvain Thery committed
98
99
100
101
102
103
104
105
		glDisable(GL_POLYGON_OFFSET_FILL);
	}
}

void MyQT::cb_keyPress(int code)
{
	if ((code >65) && (code< 123 ))
		std::cout << " key char " << char(code) << "pressed"<< std::endl;
Pierre Kraemer's avatar
Pierre Kraemer committed
106

Sylvain Thery's avatar
Sylvain Thery committed
107
108
	if ((code >'0') && (code<='9'))
		std::cout << " key num " << code-'0' << "pressed"<< std::endl;
Pierre Kraemer's avatar
Pierre Kraemer committed
109
110
111

}

Sylvain Thery's avatar
Sylvain Thery committed
112

Pierre Kraemer's avatar
Pierre Kraemer committed
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
int main(int argc, char **argv)
{
	// declaration of the map
	PFP::MAP myMap;

	// creation of 2 new faces: 1 triangle and 1 square
	Dart d1 = myMap.newFace(3);
	Dart d2 = myMap.newFace(4);

	// sew these faces along one of their edge
	myMap.sewFaces(d1, d2);

	// creation of a new attribute on vertices of type 3D vector
	// a handler to this attribute is returned
	AttributeHandler<PFP::VEC3> position = myMap.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "position");

	// affect a position to the vertices of the mesh
	position[d1] = PFP::VEC3(0, 0, 0);
	position[myMap.phi1(d1)] = PFP::VEC3(2, 0, 0);
	position[myMap.phi_1(d1)] = PFP::VEC3(1, 2, 0);

	position[myMap.phi<11>(d2)] = PFP::VEC3(0, -2, 0);
	position[myMap.phi_1(d2)] = PFP::VEC3(2, -2, 0);

	// add another triangle
	Dart d3 = myMap.newOrientedFace(3);

	position[d3] = PFP::VEC3(4, 0, 0);
	position[myMap.phi1(d3)] = PFP::VEC3(8, 0, 0);
	position[myMap.phi_1(d3)] = PFP::VEC3(6, 3, 0);


Sylvain Thery's avatar
Sylvain Thery committed
145
146
147
148
149
150
151
152
153
154
155
156
157
158
	// interface:
	QApplication app(argc, argv);
	MyQT sqt;

	// ajout entree dans le menu application
	sqt.add_menu_entry("entree1", SLOT(menu_slot1()));

	// message d'aide
	sqt.setHelpMsg("First Tuto:\n"
			"create 2 faces\n"
			"and sew them \n"
			"simple interface in Qt");

    //  bounding box
Pierre Kraemer's avatar
Pierre Kraemer committed
159
    Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
Sylvain Thery's avatar
Sylvain Thery committed
160
161
162
163
164
    float lWidthObj = std::max<PFP::REAL>(std::max<PFP::REAL>(bb.size(0), bb.size(1)), bb.size(2));
    Geom::Vec3f lPosObj = (bb.min() +  bb.max()) / PFP::REAL(2);

    // envoit info BB a l'interface
	sqt.setParamObject(lWidthObj,lPosObj.data());
Pierre Kraemer's avatar
Pierre Kraemer committed
165

Sylvain Thery's avatar
Sylvain Thery committed
166
167
168
169
170
171
172
173
174
175
	// show 1 pour GL context
	sqt.show();

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

	// update des primitives du renderer
	SelectorTrue allDarts;
	sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES);
	sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES);
Pierre Kraemer's avatar
Pierre Kraemer committed
176

Sylvain Thery's avatar
Sylvain Thery committed
177
178
	// show final pour premier redraw
	sqt.show();
Pierre Kraemer's avatar
Pierre Kraemer committed
179

Sylvain Thery's avatar
Sylvain Thery committed
180
181
	// et on attend la fin.
	return app.exec();
Pierre Kraemer's avatar
Pierre Kraemer committed
182
183

}