tuto1.cpp 5.45 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
/*******************************************************************************
* 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                                        *
*                                                                              *
*******************************************************************************/
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
24

25
//#define GL3_PROTOTYPES
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
26

27
#include "tuto1.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
28
29
30

#include <iostream>

31
#include "Topology/generic/parameters.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
32
33
34
35
36
37
38
#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
39
40
41
#include "Algo/Render/GL2/mapRender.h"
#include "Utils/shaderSimpleColor.h"

42
43
#include <glm/gtc/type_ptr.hpp>

Pierre Kraemer's avatar
Pierre Kraemer committed
44
45
46
47
48
49
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
 */
50
struct PFP: public PFP_STANDARD
Pierre Kraemer's avatar
Pierre Kraemer committed
51
52
53
54
55
{
	// definition of the type of the map
	typedef EmbeddedMap2<Map2> MAP;
};

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

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

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

Sylvain Thery's avatar
Sylvain Thery committed
67
68
	// using simple shader with color
	m_shader = new Utils::ShaderSimpleColor();
69
	m_shader->setAttributePosition(m_positionVBO);
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
70
71
	m_shader->setColor(Geom::Vec4f(0.0f, 1.0f, 0.0f, 0.0f));
	registerShader(m_shader);
Sylvain Thery's avatar
Sylvain Thery committed
72
73
74
75
}

void MyQT::cb_redraw()
{
Pierre Kraemer's avatar
Pierre Kraemer committed
76
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
77
	glEnable(GL_CULL_FACE);
Sylvain Thery's avatar
Sylvain Thery committed
78
79
80
81
82
83
84
85
86
87
88
89
	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
90

Sylvain Thery's avatar
Sylvain Thery committed
91
92
93
94
95
96
97
		glDisable(GL_POLYGON_OFFSET_FILL);
	}
}

void MyQT::cb_keyPress(int code)
{
	if ((code >65) && (code< 123 ))
98
		CGoGNout << " key char " << char(code) << "pressed"<< CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
99

Sylvain Thery's avatar
Sylvain Thery committed
100
	if ((code >'0') && (code<='9'))
101
		CGoGNout << " key num " << code-'0' << "pressed"<< CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
}

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

Sylvain Thery's avatar
Sylvain Thery committed
128
129
130
131
132
133
134
135
136
137
138
139
140
141
	// 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
142
    Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
Sylvain Thery's avatar
Sylvain Thery committed
143
144
145
146
    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
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
147
	sqt.setParamObject(lWidthObj, lPosObj.data());
Pierre Kraemer's avatar
Pierre Kraemer committed
148

Sylvain Thery's avatar
Sylvain Thery committed
149
150
151
152
153
154
155
156
157
158
	// 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
159

Sylvain Thery's avatar
Sylvain Thery committed
160
161
	// show final pour premier redraw
	sqt.show();
Pierre Kraemer's avatar
Pierre Kraemer committed
162

Sylvain Thery's avatar
Sylvain Thery committed
163
164
	// et on attend la fin.
	return app.exec();
Pierre Kraemer's avatar
Pierre Kraemer committed
165
}