tuto5.cpp 8.65 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
/*******************************************************************************
* 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                                        *
*                                                                              *
*******************************************************************************/

25
#include "tuto5.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
26

27
#include <iostream>
Pierre Kraemer's avatar
Pierre Kraemer committed
28

29
#include "Topology/generic/parameters.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
30
31
32
#include "Topology/map/map3.h"
#include "Topology/generic/embeddedMap3.h"

33

Pierre Kraemer's avatar
Pierre Kraemer committed
34
35
#include "Geometry/vector_gen.h"
#include "Algo/Geometry/boundingbox.h"
36
37
38
#include "Algo/Render/GL2/mapRender.h"
#include "Utils/shaderSimpleColor.h"

Pierre Kraemer's avatar
Pierre Kraemer committed
39
40
41
42
#include "Algo/Modelisation/primitives3d.h"
#include "Algo/Modelisation/polyhedron.h"
#include "Algo/Modelisation/subdivision.h"

43
#include "Algo/Render/GL2/topo3Render.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
44
45

#include "Topology/generic/cellmarker.h"
46
#include "Utils/text3d.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
47

48
49
#include "Utils/pointSprite.h"
#include "Utils/pointLine.h"
Sylvain Thery's avatar
Sylvain Thery committed
50
51
#include "Utils/cgognStream.h"

Pierre Kraemer's avatar
Pierre Kraemer committed
52
53
54

using namespace CGoGN ;

55
56
struct PFP: public PFP_STANDARD
{
Pierre Kraemer's avatar
Pierre Kraemer committed
57
58
59
60
61
62
63
64
65
66
67
68
69
70
	// definition de la carte
	typedef EmbeddedMap3<Map3> MAP;
	//typedef Map3 MAP;

};

PFP::MAP myMap;
SelectorTrue allDarts;
PFP::TVEC3 position ;
Dart dglobal;

unsigned int idNorm;
unsigned int idCol;

71

72
void MyQT::balls_onoff(bool x)
Pierre Kraemer's avatar
Pierre Kraemer committed
73
{
74
75
76
	render_balls = !render_balls;
	updateGL();
}
Pierre Kraemer's avatar
Pierre Kraemer committed
77

78
79
80
81
82
void MyQT::vectors_onoff(bool x)
{
	render_vectors = !render_vectors;
	updateGL();
}
Pierre Kraemer's avatar
Pierre Kraemer committed
83

84
85
86
87
88
void MyQT::text_onoff(bool x)
{
	render_text = !render_text;
	updateGL();
}
89

90
91
92
93
94
void MyQT::topo_onoff(bool x)
{
	render_topo = !render_topo;
	updateGL();
}
95

96
97
98
99
100
void MyQT::slider_balls(int x)
{
	m_sprite->setSize(0.05f*x);
	updateGL();
}
101

102
103
104
105
106
void MyQT::slider_vectors(int x)
{
	m_lines->setScale(0.02*x);
	updateGL();
}
Pierre Kraemer's avatar
Pierre Kraemer committed
107

108
109
110
111
112
void MyQT::slider_text(int x)
{
	m_strings->setScale(0.02f*x);
	updateGL();
}
Pierre Kraemer's avatar
Pierre Kraemer committed
113
114


115
void MyQT::storeVerticesInfo()
116
117
118
119
120
121
122
123
124
125
{

	CellMarker mv(myMap,VERTEX_CELL);
	for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d))
	{
		if (!mv.isMarked(d))
		{
			mv.mark(d);
			std::stringstream ss;
			ss << d << " : "<< position[d];
126
			m_strings->addString(ss.str(),position[d]);
127
128
129
130
		}
	}
}

131
void MyQT::cb_initGL()
Pierre Kraemer's avatar
Pierre Kraemer committed
132
{
133
134
135
136
137
	// choose to use GL version 2
	Utils::GLSLShader::setCurrentOGLVersion(2);

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

139
    m_render_topo = new Algo::Render::GL2::Topo3RenderMapD();
Pierre Kraemer's avatar
Pierre Kraemer committed
140
141


Sylvain Thery's avatar
Sylvain Thery committed
142

143
144
145
 	// create VBO for position
	m_positionVBO = new Utils::VBO();
	m_positionVBO->updateData(position);
Pierre Kraemer's avatar
Pierre Kraemer committed
146

147
148
149
150
	// using simple shader with color
	m_shader = new Utils::ShaderSimpleColor();
	m_shader->setAttributePosition(m_positionVBO);
	m_shader->setColor(Geom::Vec4f(0.,1.,0.,0.));
Sylvain Thery's avatar
Sylvain Thery committed
151

152
153
	m_sprite = new Utils::PointSprite();
	m_sprite->setAttributePosition(m_positionVBO);
Sylvain Thery's avatar
Sylvain Thery committed
154
155


156
157
158
    m_strings = new Utils::Strings3D(true,Geom::Vec3f(0.1,0.,0.3));
    storeVerticesInfo();
    m_strings->sendToVBO();
Sylvain Thery's avatar
Sylvain Thery committed
159

Pierre Kraemer's avatar
Pierre Kraemer committed
160

161
162
163
164
165
166
167
168
169
170
171
172
    // copy de contenu de VBO a la creation
	m_dataVBO = new Utils::VBO(*m_positionVBO);

	m_lines = new Utils::PointLine();
	m_lines->setAttributePosition(m_positionVBO);
	m_lines->setAttributeData(m_dataVBO);
	m_lines->setScale(0.2f);
	m_lines->setColor(Geom::Vec3f(0.0f, 1.0f,0.2f));

	// accede au buffer du VBO pour modification
	PFP::VEC3* data = static_cast<PFP::VEC3*>(m_dataVBO->lockPtr());
	for (unsigned int i=0; i< m_dataVBO->nbElts(); ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
173
	{
174
		data[i].normalize();
Pierre Kraemer's avatar
Pierre Kraemer committed
175
	}
176
	m_dataVBO->releasePtr();
Pierre Kraemer's avatar
Pierre Kraemer committed
177
178


179
180
181
182
	registerRunning(m_shader);
	registerRunning(m_strings);
	registerRunning(m_sprite);
	registerRunning(m_lines);
Pierre Kraemer's avatar
Pierre Kraemer committed
183

184
	SelectorTrue allDarts;
Pierre Kraemer's avatar
Pierre Kraemer committed
185

186
187
188
	m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES);
	m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES);
	m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::POINTS);
Pierre Kraemer's avatar
Pierre Kraemer committed
189

190
191
	m_render_topo->updateData<PFP>(myMap, allDarts, position,  0.9, 0.9, 0.9);
}
Pierre Kraemer's avatar
Pierre Kraemer committed
192

193

194
195
196
197
void MyQT::cb_redraw()
{
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glEnable(GL_LIGHTING);
198

199
	m_render->draw(m_shader, Algo::Render::GL2::POINTS);
200

201
202
203
	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
204

205
206
	glEnable(GL_POLYGON_OFFSET_FILL);
	glPolygonOffset(1.0f, 1.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
207

208
209
	if (render_topo)
		m_render_topo->drawTopo();
Pierre Kraemer's avatar
Pierre Kraemer committed
210

211
212
213
214
	Dart d = myMap.phi2( myMap.begin());
	m_render_topo->overdrawDart(d,5,1.0f,0.0f,1.0f);
	 d = myMap.phi1( myMap.begin());
	m_render_topo->overdrawDart(d,5,1.0f,0.0f,1.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
215
216


217
	glDisable(GL_POLYGON_OFFSET_FILL);
218
219


220
221
222
223
224
225
226
227
228
229
230
231
232
	if (render_text)
		m_strings->drawAll(Geom::Vec3f(0.0,1.0,1.0));

	if (render_balls)
	{
		m_sprite->predraw(Geom::Vec3f(1.,0.,0.));
		m_render->draw(m_sprite, Algo::Render::GL2::POINTS);
		m_sprite->postdraw();
	}

	if (render_vectors)
		m_render->draw(m_lines, Algo::Render::GL2::POINTS);

Pierre Kraemer's avatar
Pierre Kraemer committed
233
234
}

Sylvain Thery's avatar
Sylvain Thery committed
235
236
237
238
239
240
241
242
void MyQT::cb_mousePress(int button, int x, int y)
{
	if (Shift())
	{
		Dart d = m_render_topo->picking<PFP>(myMap,allDarts,x,getHeight()-y);
		if (d != Dart::nil())
		{
//			std::stringstream ss;
243
//			ss << "Dart "<< d << " clicked"<< CGoGNendl;
Sylvain Thery's avatar
Sylvain Thery committed
244
245
246
247
248
249
250
251
252
253
254
//			statusMsg(ss.str().c_str());

			CGoGNout << "Dart "<< d << " clicked"<< CGoGNendl;
		}
		else
		{
			statusMsg("");
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
255
256
257

int main(int argc, char **argv)
{
Sylvain Thery's avatar
bug    
Sylvain Thery committed
258
259
260

	position = myMap.addAttribute<PFP::VEC3>(VERTEX_ORBIT,"position");

Sylvain Thery's avatar
Sylvain Thery committed
261
262
263
	CGoGNout << 5.34 << " toto "<< Geom::Vec3f(2.5, 2.2, 4.3) << CGoGNendl;
	CGoGNout << 3 << " tutu "<< 4 <<CGoGNendl;

Sylvain Thery's avatar
bug    
Sylvain Thery committed
264
265
266
267
268
269
270

	Algo::Modelisation::Primitive3D<PFP> prim(myMap,position);
	int nb=3;
	if (argc>1)
		nb = atoi(argv[1]);
	dglobal = prim.hexaGrid_topo(nb,nb,nb);
	prim.embedHexaGrid(1.0f,1.0f,1.0f);
Sylvain Thery's avatar
Sylvain Thery committed
271
272


Pierre Kraemer's avatar
Pierre Kraemer committed
273

274
275
276
    // un peu d'interface
	QApplication app(argc, argv);
	MyQT sqt;
Pierre Kraemer's avatar
Pierre Kraemer committed
277

278
279
280
	// interface de tuto5.ui
    Utils::QT::uiDockInterface dock;
    sqt.setDock(&dock);
Pierre Kraemer's avatar
Pierre Kraemer committed
281

282
283
 	// message d'aide
	sqt.setHelpMsg("");
Pierre Kraemer's avatar
Pierre Kraemer committed
284

285
	CGoGNout.toStatusBar(&sqt);
Sylvain Thery's avatar
Sylvain Thery committed
286
287
	CGoGNout <<"CGoGNOut StatusBar"<< Geom::Vec3f(2.5, 2.2, 4.3) << CGoGNendl;

288
	CGoGNout.toConsole(&sqt);
Sylvain Thery's avatar
Sylvain Thery committed
289
290
291

	CGoGNout <<"CGoGNOut dans la console"<< Geom::Vec3f(2.5, 2.2, 4.3) << CGoGNendl;

292
	CGoGNout.toStatusBar(NULL);
Sylvain Thery's avatar
Sylvain Thery committed
293
294
295
	CGoGNout <<"tirelipinpon .."<< CGoGNendl;
	CGoGNout <<"ah aha ah"<< CGoGNendl;

Pierre Kraemer's avatar
Pierre Kraemer committed
296

297
298
299
300
	//  bounding box
    Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
    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);
Pierre Kraemer's avatar
Pierre Kraemer committed
301

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

305
306
307
308
	sqt.setCallBack( dock.checkBox_balls, SIGNAL(toggled(bool)), SLOT(balls_onoff(bool)) );
	sqt.setCallBack( dock.checkBox_vectors, SIGNAL(toggled(bool)), SLOT(vectors_onoff(bool)) );
	sqt.setCallBack( dock.checkBox_text, SIGNAL(toggled(bool)), SLOT(text_onoff(bool)) );
	sqt.setCallBack( dock.checkBox_topo, SIGNAL(toggled(bool)), SLOT(topo_onoff(bool)) );
Pierre Kraemer's avatar
Pierre Kraemer committed
309

310
311
312
	sqt.setCallBack( dock.slider_balls, SIGNAL(valueChanged(int)), SLOT(slider_balls(int)) );
	sqt.setCallBack( dock.slider_vectors, SIGNAL(valueChanged(int)), SLOT(slider_vectors(int)) );
	sqt.setCallBack( dock.slider_text, SIGNAL(valueChanged(int)), SLOT(slider_text(int)) );
Pierre Kraemer's avatar
Pierre Kraemer committed
313

314
	sqt.show();
Pierre Kraemer's avatar
Pierre Kraemer committed
315

316
317
318
	sqt.slider_balls(50);
	sqt.slider_vectors(50);
	sqt.slider_text(50);
Pierre Kraemer's avatar
Pierre Kraemer committed
319

Sylvain Thery's avatar
Sylvain Thery committed
320
321
	GLint texSize;
	glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize);
322
323
	CGoGNdbg2.toConsole(&sqt);
	CGoGNerr.toConsole(&sqt);
Sylvain Thery's avatar
Sylvain Thery committed
324
325
	CGoGNdbg2 << " TextureSize " <<  texSize << CGoGNendl;
	CGoGNerr << " ERROR  " <<  5*7 << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
326

327
328
	// et on attend la fin.
	return app.exec();
Pierre Kraemer's avatar
Pierre Kraemer committed
329
330

}