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

squelette3carte.cpp 11 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*******************************************************************************
* 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                                        *
*                                                                              *
*******************************************************************************/
/*
 * TODO
 * - pb dans l'ordre des coeff shrinkage du rendu topo
 * - rendu explod object
 * - modifier le update du rendu topo
 * - ajouter l'import de maillage
 * - shader pour l'affichage
 */

#include "squelette3carte.h"

/**********************************************************************************************
 *                                 AntTweakBar CALLBACKS                                      *
 **********************************************************************************************/
void TW_CALL setRenderObjectCB(const void* value, void* clientData)
{
	MyGlutWin* mgw = static_cast<MyGlutWin*>(clientData) ;
	mgw->render_obj = *(GLboolean*)value ;
	if(mgw->render_obj) {
		mgw->initRender() ;
	}
	glutPostRedisplay() ;
}
void TW_CALL getRenderObjectCB(void* value, void* clientData)
{
	MyGlutWin* mgw = static_cast<MyGlutWin*>(clientData) ;
	*(GLboolean*)value = mgw->render_obj ;
}

void TW_CALL setRenderObjStyleCB(const void* value, void* clientData)
{
	MyGlutWin* mgw = static_cast<MyGlutWin*>(clientData) ;
	mgw->renderObjStyle = *(MyGlutWin::renderObjStyleType*)value ;
	glutPostRedisplay() ;
}
void TW_CALL getRenderObjStyleCB(void* value, void* clientData)
{
	MyGlutWin* mgw = static_cast<MyGlutWin*>(clientData) ;
	*(GLenum*)value = mgw->renderObjStyle ;
}

void TW_CALL setRenderTopoCB(const void* value, void* clientData)
{
	MyGlutWin* mgw = static_cast<MyGlutWin*>(clientData) ;
	mgw->render_topo = *(GLboolean*)value ;
	glutPostRedisplay() ;
}
void TW_CALL getRenderTopoCB(void* value, void* clientData)
{
	MyGlutWin* mgw = static_cast<MyGlutWin*>(clientData) ;
	*(GLboolean*)value = mgw->render_topo ;
}

void TW_CALL setRenderTopoStyleCB(const void* value, void* clientData)
{
	MyGlutWin* mgw = static_cast<MyGlutWin*>(clientData) ;
	mgw->renderTopoStyle = *(MyGlutWin::renderTopoStyleType*)value;

	if(mgw->renderTopoStyle == MyGlutWin::T_ALL)
	{
		TwDefine("Viewer/phi1_explod visible=false");
		TwDefine("Viewer/phi2_explod visible=false");
		TwDefine("Viewer/phi3_explod visible=false");
	}
	else if(mgw->renderTopoStyle == MyGlutWin::T_EXPLOD)
	{
		TwDefine("Viewer/phi1_explod visible=true");
		TwDefine("Viewer/phi2_explod visible=true");
		TwDefine("Viewer/phi3_explod visible=true");
	}

	glutPostRedisplay() ;
}
void TW_CALL getRenderTopoStyleCB(void* value, void* clientData)
{
	MyGlutWin* mgw = static_cast<MyGlutWin*>(clientData) ;
	*(GLenum*)value = mgw->renderTopoStyle ;
}


/**********************************************************************************************
 *                                 MyGlutWin IMPLEMENTATION                                   *
 **********************************************************************************************/


MyGlutWin::MyGlutWin(int* argc, char **argv, int winX, int winY) :
	GlutWin_ATB(argc, argv, winX, winY),
	renderObjStyle(O_ALL),
	renderTopoStyle(T_ALL),
	render_obj(true),
	render_topo(false),
	render_help(true)
{
	//AJOUT Shader
}


void MyGlutWin::myRedraw(void)
{
	glClearColor(backCol[0],backCol[1],backCol[2],backCol[3]);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glPushMatrix();

	// met l'objet au milieu de l'ecran a la bonne taille
	float sc = 50.0f/gWidthObj;
	glScalef(sc,sc,sc);
	glTranslatef(-gPosObj[0],-gPosObj[1],-gPosObj[2]);


	glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
	glDisable(GL_LIGHTING);


	if(render_obj)
	{
		if(renderObjStyle == O_ALL)
		{
			glEnable( GL_POLYGON_OFFSET_FILL );
			glPolygonOffset( 1.0f, 1.0f );

			glColor3f(0.0f,0.5f,0.0f);
Sylvain Thery's avatar
Sylvain Thery committed
145
			m_render->draw(Algo::Render::GL2::TRIANGLES);
Pierre Kraemer's avatar
Pierre Kraemer committed
146
147
148
149
			glDisable( GL_POLYGON_OFFSET_FILL );
			// on trace les ligne devant
			glDisable( GL_POLYGON_OFFSET_FILL );
			glColor3f(1.0f,1.0f,0.0f);
Sylvain Thery's avatar
Sylvain Thery committed
150
			m_render->draw(Algo::Render::GL2::LINES);
Pierre Kraemer's avatar
Pierre Kraemer committed
151
152
153
154
155
156
157
		}
		else if(renderObjStyle == O_FACES)
		{
			glEnable( GL_POLYGON_OFFSET_FILL );
			glPolygonOffset( 1.0f, 1.0f );

			glColor3f(0.0f,0.5f,0.0f);
Sylvain Thery's avatar
Sylvain Thery committed
158
			m_render->draw(Algo::Render::GL2::TRIANGLES);
Pierre Kraemer's avatar
Pierre Kraemer committed
159
160
161
162
163
164
165
			glDisable( GL_POLYGON_OFFSET_FILL );
		}
		else if(renderObjStyle == O_LINE)
		{
			// on trace les ligne devant
			glDisable( GL_POLYGON_OFFSET_FILL );
			glColor3f(1.0f,1.0f,0.0f);
Sylvain Thery's avatar
Sylvain Thery committed
166
			m_render->draw(Algo::Render::GL2::LINES);
Pierre Kraemer's avatar
Pierre Kraemer committed
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
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
		}
		else if(renderObjStyle == O_EXPLOD)
		{

		}
	}

	if(render_topo)
	{
		if(renderTopoStyle == T_ALL)
		{
			glDisable( GL_POLYGON_OFFSET_FILL );
			glColor3f(1.0f,1.0f,0.0f);
			m_render_topo->updateData<PFP>(myMap,allDarts,position,0.9,0.9,0.9);
			m_render_topo->drawTopo();
		}
		else if(renderTopoStyle == T_EXPLOD)
		{
			glDisable( GL_POLYGON_OFFSET_FILL );
			glColor3f(1.0f,1.0f,0.0f);
			m_render_topo->updateData<PFP>(myMap,allDarts,position,coefTopoExplod[0],coefTopoExplod[1],coefTopoExplod[2]);
			m_render_topo->drawTopo();
		}
	}

	if(render_help)
	{
        glColor3f(1.0f,1.0f,1.0f);
        int x = getWinWidth() - 200 ;
        printString2D(x,20,
        		"Keys:\n"
                "h: affiche cette aide\n"
        );
	}

	glPopMatrix();
}

/// Gestion des touches clavier
void MyGlutWin::myKeyboard(unsigned char keycode, int x, int y)
{
        switch(keycode) {
                /** affichage **/
        		case 'h': {
        				render_help = !render_help;
        				break;
        		}
                default : {
                		std::cout << "not implemented" << std::endl;
                		break;
                }

        }
}

void MyGlutWin::init()
{
	coefObjExplod = Geom::Vec3f(1.,1.,1.);
	coefTopoExplod = Geom::Vec3f(0.9,0.9,0.9);
	backCol = Geom::Vec4f(0.533, 0.560, 0.984, 0.984);
}

void MyGlutWin::initRender()
{
    // maj des donnees de position
Sylvain Thery's avatar
Sylvain Thery committed
232
    m_render->updateData(Algo::Render::GL2::POSITIONS, position );
Pierre Kraemer's avatar
Pierre Kraemer committed
233
    // creation des primitives de rendu a partir de la carte
Sylvain Thery's avatar
Sylvain Thery committed
234
235
    m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES);
    m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES);
Pierre Kraemer's avatar
Pierre Kraemer committed
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317

    // creation des primitives de rendu de la topologie a partir de la carte
	m_render_topo->updateData<PFP>(myMap,allDarts,position,coefTopoExplod[0],coefTopoExplod[1],coefTopoExplod[2]);

}

void MyGlutWin::initGUI()
{
	//Menu bar
	viewer_bar = TwNewBar("Viewer") ;
	TwDefine("Viewer position='16 16' size='220 450' valueswidth='70'") ;

	//Rendering
	TwAddVarCB(viewer_bar, "Show Object", TW_TYPE_BOOL8, setRenderObjectCB, getRenderObjectCB, this, "");
	TwType tw_render_style = TwDefineEnum("Shading","All,Faces,Lines,Explod") ;
	TwAddVarCB(viewer_bar, "Render Style", tw_render_style, setRenderObjStyleCB, getRenderObjStyleCB, this, "") ;
	TwAddVarCB(viewer_bar, "Show Topology", TW_TYPE_BOOL8, setRenderTopoCB, getRenderTopoCB, this, "") ;
	TwType tw_render_topo = TwDefineEnum("TopoShading","All,Explod");
	TwAddVarCB(viewer_bar, "Render Topology", tw_render_topo, setRenderTopoStyleCB, getRenderTopoStyleCB, this, "") ;
	TwAddVarRW(viewer_bar, "phi1_explod", TW_TYPE_FLOAT, &coefTopoExplod[1], "min=0 max=1 step=0.1 label='Phi1 Explod Coeff'");
	TwAddVarRW(viewer_bar, "phi2_explod", TW_TYPE_FLOAT, &coefTopoExplod[2], "min=0 max=1 step=0.1 label='Phi2 Explod Coeff'");
	TwAddVarRW(viewer_bar, "phi3_explod", TW_TYPE_FLOAT, &coefTopoExplod[0], "min=0 max=1 step=0.1 label='Phi3 Explod Coeff'");
	TwDefine("Viewer/phi1_explod visible=false");
	TwDefine("Viewer/phi2_explod visible=false");
	TwDefine("Viewer/phi3_explod visible=false");

	TwAddSeparator(viewer_bar, "", "") ;

	//Visualisation
	TwAddVarRW(viewer_bar, "background color", TW_TYPE_COLOR4F, &backCol, "");
}

/******** Partie a supprimer ********/
void maillageTest()
{
	/// on creer une carte
	Dart dd = Algo::Modelisation::Polyhedron<PFP>::createOrientedPolyhedron(myMap,4);
	Dart ee = Algo::Modelisation::Polyhedron<PFP>::createOrientedPolyhedron(myMap,4);
    myMap.sewVolumes(dd,ee);

    // plongement
    Dart t1 = dd;
    position[t1] = PFP::VEC3(0.0f, 0.0f, 3.0f);
    t1 = myMap.phi1(t1);
    position[t1] = PFP::VEC3(0.0f, 1.0f, 3.0f);
    t1 = myMap.phi1(t1);
    position[t1] = PFP::VEC3(1.0f, 0.5f, 3.0f);
    t1 = myMap.phi_1(myMap.phi2(dd));
    position[t1] = PFP::VEC3(0.5f, 0.5f, 4.0f);

    Dart t2 = ee;
    position[t2] = PFP::VEC3(0.0f, 1.0f, 3.0f);
    t2 = myMap.phi1(t2);
    position[t2] = PFP::VEC3(0.0f, 0.0f, 3.0f);
    t2 = myMap.phi1(t2);
    position[t2] = PFP::VEC3(1.0f, 0.5f, 3.0f);
    t2 = myMap.phi_1(myMap.phi2(ee));
    position[t2] = PFP::VEC3(0.5f, 0.5f, 2.0f);
}
/***************************/

int main(int argc, char **argv)
{
	//Initilisation du plongement geometrique
	position = myMap.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "position");

	/*
	 * Chargement de maillages
	 */
	maillageTest();

    // un peu d'interface
	MyGlutWin* mgw = new MyGlutWin(&argc,argv,1200,800);

    // calcul de la bounding box
    Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap,position);
    // pour l'affichage
    mgw->gWidthObj = std::max<float>( std::max<float>(bb.size(0),bb.size(1)),bb.size(2));
    mgw->gPosObj =  (bb.min() +  bb.max()) /2.0f;


    // allocation des objets necessaires pour le rendu
Sylvain Thery's avatar
Sylvain Thery committed
318
319
320
    mgw->m_render = new Algo::Render::GL2::MapRender_VBO();
    //mgw->m_render_topo = new Algo::Render::GL2::topo3_VBORenderMap<PFP::MAP>();
    mgw->m_render_topo = new Algo::Render::GL2::topo3_VBORenderMapD();
Pierre Kraemer's avatar
Pierre Kraemer committed
321
322
323
324
325
326
327
328
329
330
331
332

    mgw->init();
    mgw->initRender();
    mgw->initGUI();
    mgw->mainLoop();

    delete mgw->m_render;
    delete mgw->m_render_topo;
    delete mgw;

    return 0;
}