tuto3.cpp 7.34 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
#include "Topology/map/map2.h"
#include "Topology/generic/cellmarker.h"

#include "Geometry/vector_gen.h"
#include "Algo/Geometry/boundingbox.h"
33
34
35
36
37
#include "Algo/Render/GL2/mapRender.h"
#include "Utils/shaderSimpleColor.h"
#include "Utils/shaderColorPerVertex.h"

#include "tuto3.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
38

39
40
MyQT* sqt1_ptr;
MyQT* sqt2_ptr;
Pierre Kraemer's avatar
Pierre Kraemer committed
41
42
43

using namespace CGoGN ;

44
45
struct PFP: public PFP_STANDARD
{
Pierre Kraemer's avatar
Pierre Kraemer committed
46
47
48
49
50
51
52
53
	// definition de la carte
	typedef Map2 MAP;
};





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

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

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

66
67
68
69
70
71
72
73
74
75
76
77
78
	// using simple shader with color
	m_shader = new Utils::ShaderSimpleColor();
	m_shader->setAttributePosition(m_positionVBO);


	m_shader2 = new Utils::ShaderColorPerVertex();
	m_shader2->setAttributePosition(m_positionVBO);
	m_shader2->setAttributeColor(m_colorVBO);


	registerRunning(m_shader);
	registerRunning(m_shader2);
}
Pierre Kraemer's avatar
Pierre Kraemer committed
79
80


81
void MyQT::cb_redraw()
Pierre Kraemer's avatar
Pierre Kraemer committed
82
{
83
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
Pierre Kraemer's avatar
Pierre Kraemer committed
84

85
86
87
	glLineWidth(2.0f);
	m_shader->setColor(Geom::Vec4f(1.,1.,0.,0.));
	m_render->draw(m_shader, Algo::Render::GL2::LINES);
Pierre Kraemer's avatar
Pierre Kraemer committed
88

89
90
91
92
	glEnable(GL_POLYGON_OFFSET_FILL);
	glPolygonOffset(1.0f, 1.0f);
	m_render->draw(m_shader2, Algo::Render::GL2::TRIANGLES);
	glDisable(GL_POLYGON_OFFSET_FILL);
Pierre Kraemer's avatar
Pierre Kraemer committed
93

94
}
Pierre Kraemer's avatar
Pierre Kraemer committed
95
96


97
98
99
100
101
102
103
104
105
106
107
void MyQT::cb_keyPress(int code)
{
	switch(code)
	{
	case 's':
		if (this == sqt2_ptr)
			sqt1_ptr->synchronize(sqt2_ptr);
		if (this == sqt1_ptr)
			sqt2_ptr->synchronize(sqt1_ptr);
		break;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
108
109
110
111
112
113
114
115


}


int main(int argc, char **argv)
{

116
117
118
119
120
121
	PFP::MAP myMap;
	SelectorTrue allDarts;

	PFP::TVEC3 position ;
	PFP::TVEC3 normal ;
	AttributeHandler<Geom::Vec3f> color ;
Pierre Kraemer's avatar
Pierre Kraemer committed
122
123
124
125
126

	Dart d2 = myMap.newOrientedFace(3);
	Dart d3 = myMap.newOrientedFace(4);
	myMap.sewFaces(d2,d3);

127
128
	position = myMap.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "position");
	color = myMap.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "couleur");
Pierre Kraemer's avatar
Pierre Kraemer committed
129
130

	position[d2] = PFP::VEC3(0.0f, 0.0f, 0.0f);
131
	color[d2] = PFP::VEC3(1.0f, 0.0f, 0.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
132
133
	d2 = myMap.phi1(d2);
	position[d2] = PFP::VEC3(2.0f, 0.0f, 0.0f);
134
	color[d2] = PFP::VEC3(0.0f, 1.0f, 0.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
135
136
	d2 = myMap.phi1(d2);
	position[d2] = PFP::VEC3(1.0f, 3.0f, 0.0f);
137
	color[d2] = PFP::VEC3(0.0f, 0.0f, 1.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
138
139
140
	d2 = myMap.phi1(d2);
	d3 = myMap.phi<11>(d3);
	position[d3] = PFP::VEC3(0.0f, -2.0f, 0.0f);
141
	color[d3] = PFP::VEC3(1.0f, 0.0f, 1.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
142
143
	d3 = myMap.phi1(d3);
	position[d3] = PFP::VEC3(2.0f, -2.0f, 0.0f);
144
	color[d3] = PFP::VEC3(0.0f, 1.0f, 1.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
	d3 = myMap.phi1(d3);


	//MARK !!!

	// on reserve des marqueur de brins
	DartMarkerStore mf(myMap);
	DartMarkerStore me(myMap);

	// avec lesquels on peut marquer des orbits
	mf.markOrbit(FACE_ORBIT, d2);
	me.markOrbit(EDGE_ORBIT, d2);

	// les sommet sont plonges, on peut utiliser un marqueur de cellule sommet
	CellMarker cm(myMap, VERTEX_ORBIT);
	cm.mark(d3);

	for (Dart d = myMap.begin(); d!= myMap.end(); myMap.next(d))
	{
		if (me.isMarked(d))
165
			CGoGNout << "Dart "<< d.label() << " marque par me"<< CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
166
		if (mf.isMarked(d))
167
			CGoGNout << "Dart "<< d.label() << " marque par mf"<< CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
168
		if (cm.isMarked(d))
169
			CGoGNout << "Sommet de dart "<< d.label() << " marque par mcv"<< CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
170
171
	}

172

Pierre Kraemer's avatar
Pierre Kraemer committed
173
174
175
176
	//nettoyage
	cm.unmarkAll();


177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
		// interface:
	QApplication app(argc, argv);

	MyQT sqt;
	sqt1_ptr= &sqt;

	MyQT sqt2;
	sqt2_ptr= &sqt2;

	// message d'aide
	sqt.setHelpMsg("Tuto3:\n"
			"marker tuto\n"
			"using two VBO & two shader");

    //  bounding box
Pierre Kraemer's avatar
Pierre Kraemer committed
192
    Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
    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());

	// show 1 pour GL context
	sqt.show();

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


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

	// show final pour premier redraw
	sqt.show();

	// et pour le fun une deuxieme carte et une deuxieme interface:

	PFP::MAP myMap2;
	PFP::TVEC3 position2 ;
	AttributeHandler<Geom::Vec3f> color2 ;

	Dart dx = myMap2.newOrientedFace(4);

	position2 = myMap2.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "position");
	color2 = myMap2.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "couleur");

	position2[dx] = PFP::VEC3(0.0f, 0.0f, 0.0f);
	color2[dx] = PFP::VEC3(1.0f, 1.0f, 0.0f);
	dx = myMap.phi1(dx);
	position2[dx] = PFP::VEC3(2.0f, 0.0f, 0.0f);
	color2[dx] = PFP::VEC3(0.0f, 1.0f, 0.0f);
	dx = myMap.phi1(dx);
	position2[dx] = PFP::VEC3(2.0f, 2.0f, 0.0f);
	color2[dx] = PFP::VEC3(1.0f, 0.0f, 1.0f);
	dx = myMap.phi1(dx);
	position2[dx] = PFP::VEC3(0.0f, 2.0f, 0.0f);
	color2[dx] = PFP::VEC3(0.0f, 1.0f, 1.0f);



	sqt2.setHelpMsg("Fenetre 2!!");

	sqt2.setParamObject(lWidthObj,lPosObj.data());

	// show 1 pour GL context
	sqt2.show();

	// update du VBO position (context GL necessaire)
	sqt2.m_positionVBO->updateData(position2);
	// update du VBO color
	sqt2.m_colorVBO->updateData(color2);
Pierre Kraemer's avatar
Pierre Kraemer committed
251
252


253
254
255
	// update des primitives du renderer
	sqt2.m_render->initPrimitives<PFP>(myMap2, allDarts, Algo::Render::GL2::TRIANGLES);
	sqt2.m_render->initPrimitives<PFP>(myMap2, allDarts, Algo::Render::GL2::LINES);
Pierre Kraemer's avatar
Pierre Kraemer committed
256
257


258
259
	// et on attend la fin.
	return app.exec();
Pierre Kraemer's avatar
Pierre Kraemer committed
260
261

}