Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

tuto4.cpp 7.36 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-2011, 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.u-strasbg.fr/                                         *
Pierre Kraemer's avatar
Pierre Kraemer committed
21
22
23
24
25
26
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#include <iostream>

27
#include "tuto4.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
28

29
#include "Topology/generic/parameters.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
30
31
32
33
34
35
36
37
#include "Topology/map/map2.h"

#include "Geometry/matrix.h"
#include "Geometry/vector_gen.h"
#include "Algo/Import/import.h"
#include "Algo/Geometry/boundingbox.h"
#include "Topology/generic/cellmarker.h"

38
39
#include "Algo/Render/GL2/mapRender.h"
#include "Algo/Render/GL2/topoRender.h"
40
41
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/Shaders/shaderFlat.h"
42

Sylvain Thery's avatar
Sylvain Thery committed
43
#include "Utils/cgognStream.h"
44

Pierre Kraemer's avatar
Pierre Kraemer committed
45
46
using namespace CGoGN ;

47
48
struct PFP: public PFP_STANDARD
{
Pierre Kraemer's avatar
Pierre Kraemer committed
49
50
51
52
53
54
55
56
57
58
	// definition de la carte
	typedef Map2 MAP;
};

PFP::MAP myMap;

PFP::TVEC3 position ;
PFP::TVEC3 normal ;
AttributeHandler<Geom::Vec4f> color ;

59
void MyQT::cb_initGL()
Pierre Kraemer's avatar
Pierre Kraemer committed
60
{
61
	// choose to use GL version 2
62
	Utils::GLSLShader::setCurrentOGLVersion(2);
Pierre Kraemer's avatar
Pierre Kraemer committed
63

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

67
	m_render_topo = new Algo::Render::GL2::TopoRenderMapD();
Pierre Kraemer's avatar
Pierre Kraemer committed
68

69
70
	// create VBO for position
	m_positionVBO = new Utils::VBO();
Pierre Kraemer's avatar
Pierre Kraemer committed
71

72
73
74
75
	// 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
76

77
78
79
	m_shader2 = new Utils::ShaderFlat();
	m_shader2->setAttributePosition(m_positionVBO);

Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
80
81
	registerShader(m_shader);
	registerShader(m_shader2);
Pierre Kraemer's avatar
Pierre Kraemer committed
82
83
}

84
void MyQT::cb_redraw()
Pierre Kraemer's avatar
Pierre Kraemer committed
85
{
86
87
88
89
	if(render_topo)
	{
		m_render_topo->drawTopo();
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
90
91
92

	if(render_obj)
	{
93
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
Pierre Kraemer's avatar
Pierre Kraemer committed
94
95
96

		glEnable( GL_POLYGON_OFFSET_FILL );
		glPolygonOffset( 1.0f, 1.0f );
97
98
		m_render->draw(m_shader2, Algo::Render::GL2::TRIANGLES);
		glDisable(GL_POLYGON_OFFSET_FILL);
Pierre Kraemer's avatar
Pierre Kraemer committed
99
	}
100
101
102
103
104
105
}


void MyQT::cb_keyPress(int code)
{
	switch(code)
Pierre Kraemer's avatar
Pierre Kraemer committed
106
	{
107
108
109
110
111
112
113
114
115
	case 'o':
		render_obj = !render_obj;
		updateGL();
		break;

	case 't':
		render_topo = !render_topo;
		updateGL();
		break;
Pierre Kraemer's avatar
Pierre Kraemer committed
116
	}
117
118
119
120
121
122
123
}

void MyQT::button_compile()
{
	QString st1 = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->vertexEdit->toPlainText();
	QString st2 = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->fragmentEdit->toPlainText();
	QString st3 = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->geometryEdit->toPlainText();
Pierre Kraemer's avatar
Pierre Kraemer committed
124

125
126
127
128
129
130
131
132
133
134
135
136
	m_shader2->reloadVertexShaderFromMemory(st1.toStdString().c_str());
	m_shader2->reloadFragmentShaderFromMemory(st2.toStdString().c_str());
	m_shader2->reloadGeometryShaderFromMemory(st3.toStdString().c_str());

	m_shader2->recompile();
	updateGLMatrices();
}

void MyQT::slider_explode(int x)
{
	m_shader2->setExplode(0.01*x);
	updateGL();
Pierre Kraemer's avatar
Pierre Kraemer committed
137
138
139
140
141
}

int main(int argc, char **argv)
{
	/// Utilisation des Marker
142
	position = myMap.addAttribute<Geom::Vec3f>(VERTEX, "position");
Pierre Kraemer's avatar
Pierre Kraemer committed
143

144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
	Algo::Modelisation::Polyhedron<PFP> prim3(myMap, position);
	Dart d2 = prim3.tore_topo(16, 24);
	prim3.embedTore(1.0f,0.3f);

//	position[d2] = PFP::VEC3(0.0f, 0.0f, 0.0f);
//	d2 = myMap.phi1(d2);
//	position[d2] = PFP::VEC3(2.0f, 0.0f, 0.0f);
//	d2 = myMap.phi1(d2);
//	position[d2] = PFP::VEC3(1.0f, 3.0f, 0.0f);
//	d2 = myMap.phi1(d2);
//	d3 = myMap.phi<11>(d3);
//	position[d3] = PFP::VEC3(0.0f, -2.0f, 0.0f);
//	d3 = myMap.phi1(d3);
//	position[d3] = PFP::VEC3(2.0f, -2.0f, 0.0f);
//	d3 = myMap.phi1(d3);
Pierre Kraemer's avatar
Pierre Kraemer committed
159

160
161
//	unsigned int idAttV2 = myMap.addAttribute<float>(VERTEX,"reel");
//	PFP::AttributeHandler<float> tableReels(idAttV2,VERTEX,myMap);
Pierre Kraemer's avatar
Pierre Kraemer committed
162
163
164
165
166
167
//
//	tableReels[d2] = 3.5f;
//	tableReels[myMap.phi1(d2)] = 3.7f;
//
//	// Attention ici on cree un attribut de FACE donc les face sont maintenant plangees
//	// l'attribut cree se detruira a la fin de la portee de l'objet
168
//	PFP::MAP::AutoAttributeHandler<Geom::Vec3f> tableRGB(myMap, FACE, "RGB"); // "RGB" optionnel
Pierre Kraemer's avatar
Pierre Kraemer committed
169
170
171
172
173
174
//
//	tableRGB[d3] = Geom::Vec3f(1.0f,2.0f,3.0f);
//
//	// acces par les brins
//	for (Dart d = myMap.begin(); d!= myMap.end(); myMap.next(d))
//	{
175
//		CGoGNout << "Brin "<<d.label()<< " reel="<<tableReels[d]<< "  RGB="<<tableRGB[d]<<CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
176
177
178
179
180
//	}
//
//	//acces direct par balayge du tableau
//	for (unsigned int id = tableRGB.begin(); id != tableRGB.end(); tableRGB.next(id))
//	{
181
//		CGoGNout << "RGB["<<id<<"] = "<<tableRGB.at(id)<<CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
182
183
//	}

184
	CellMarkerStore cm(myMap, VERTEX);
Pierre Kraemer's avatar
Pierre Kraemer committed
185

186
	Dart d3 = myMap.phi1(d2);
Pierre Kraemer's avatar
Pierre Kraemer committed
187
188
189
190
	cm.mark(d2);
	cm.mark(d3);
	cm.unmarkAll();

191
192
193
194
195
196
197
	// interface:
	QApplication app(argc, argv);
	MyQT sqt;

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

199
200
201
202
	// message d'aide
	sqt.setHelpMsg("Tuto4");

    //  bounding box
Pierre Kraemer's avatar
Pierre Kraemer committed
203
    Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
    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());

	sqt.setCallBack( dock.compileButton, SIGNAL(clicked()), SLOT(button_compile()) );
	sqt.setCallBack( dock.explodeSlider, SIGNAL(valueChanged(int)), SLOT(slider_explode(int)) );

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

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

	// 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);
Pierre Kraemer's avatar
Pierre Kraemer committed
222

223
	sqt.m_render_topo->updateData<PFP>(myMap, position, 0.9f, 0.9f);
Pierre Kraemer's avatar
Pierre Kraemer committed
224

225
226
227
228
229
	dock.vertexEdit->setPlainText(QString(sqt.m_shader2->getVertexShaderSrc()));
	dock.fragmentEdit->setPlainText(QString(sqt.m_shader2->getFragmentShaderSrc()));
	dock.geometryEdit->setPlainText(QString(sqt.m_shader2->getGeometryShaderSrc()));
	// show final pour premier redraw
	sqt.show();
Pierre Kraemer's avatar
Pierre Kraemer committed
230

231
232
	CGoGNout.toConsole(&sqt);
	CGoGNerr.toConsole(&sqt);
233

234
235
	// et on attend la fin.
	return app.exec();
Pierre Kraemer's avatar
Pierre Kraemer committed
236
}