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

extrusionView.cpp 6.39 KB
Newer Older
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
/*******************************************************************************
* 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>

#include "Utils/glutwin.h"

#include "Topology/generic/parameters.h"
#include "Topology/map/map2.h"
#include "Topology/generic/embeddedMap2.h"

#include "Geometry/vector_gen.h"
#include "Geometry/matrix.h"
#include "Geometry/transfo.h"
#include "Algo/Geometry/boundingbox.h"

#include "Algo/Render/vbo_MapRender.h"
#include "Algo/Modelisation/extrusion.h"
#include "Topology/generic/parameters.h"

#include <vector>

using namespace CGoGN;



struct PFP: public PFP_STANDARD
{
	// definition de la carte
	typedef EmbeddedMap2<Map2> MAP;
};


PFP::MAP myMap;


class myGlutWin: public Utils::SimpleGlutWin
{
public:
	/**
	 * position of object
	 */
	Geom::Vec3f gPosObj;

	/**
	 * width of object
	 */
	float gWidthObj;

	/**
	 * redraw CB
	 */
	void myRedraw();

	/**
	 * keyboard CB
	 */
	void myKeyboard(unsigned char keycode, int x, int y);

	/**
	 * Update VBO buffers for map
	 */
	void updateRender();

	/**
	 * GL initialization
	 */
	void init();

	// position handler
	PFP::TVEC3 position ;


	/**
	 * render object
	 */
Sylvain Thery's avatar
Sylvain Thery committed
98
	Algo::Render::GL2::MapRender_VBO* m_render;
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120



	myGlutWin(	int* argc, char **argv, int winX, int winY) :
				SimpleGlutWin(argc,argv,winX,winY),
				m_render(NULL)
				 {	}

	~myGlutWin();
};

myGlutWin::~myGlutWin()
{
	if (m_render)
		delete m_render;
}

void myGlutWin::init()
{

	glClearColor(0.1f,0.1f,0.1f,0.0f);
	glEnable(GL_DEPTH_TEST);
121
//	glEnable(GL_NORMALIZE);
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136

	glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
	glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
	glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
	glEnable(GL_LIGHT0);
}


void myGlutWin::updateRender()
{
	SelectorTrue allDarts;

	// create the renderer (first call only)
	if (m_render == NULL)
Sylvain Thery's avatar
Sylvain Thery committed
137
		m_render = new Algo::Render::GL2::MapRender_VBO() ;
138
139

	// update buffer op vertices positions
Sylvain Thery's avatar
Sylvain Thery committed
140
	m_render->updateData(Algo::Render::GL2::POSITIONS, position);
141
	// update flat faces primtives (warning need position buffer)
Sylvain Thery's avatar
Sylvain Thery committed
142
	m_render->initPrimitives<PFP>(myMap, SelectorTrue(), Algo::Render::GL2::FLAT_TRIANGLES);
143
	// update lines primitives
Sylvain Thery's avatar
Sylvain Thery committed
144
	m_render->initPrimitives<PFP>(myMap, SelectorTrue(), Algo::Render::GL2::LINES);
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161

}


void myGlutWin::myRedraw(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glPushMatrix();

	// center the scene
	float sc = 50./gWidthObj;
	glScalef(sc,sc,sc);
	glTranslatef(-gPosObj[0],-gPosObj[1],-gPosObj[2]);

	// DRAW LINES OF OBJECTS
	glDisable(GL_LIGHTING);
	glColor3f(1.0f,1.0f,0.0f);
Sylvain Thery's avatar
Sylvain Thery committed
162
	m_render->draw(Algo::Render::GL2::LINES) ;
163
164
165
166
167
168
169
170
171
172

	//shit for nice line rendering
	glEnable( GL_POLYGON_OFFSET_FILL );
	glPolygonOffset( 1.0f, 1.0f );

	// DRAW FACES OF OBJECTS
	glEnable(GL_LIGHTING);
	glEnable(GL_COLOR_MATERIAL);
	glColorMaterial(GL_FRONT_AND_BACK,GL_DIFFUSE);
	glColor3f(0.0f,0.0f,0.9f);
Sylvain Thery's avatar
Sylvain Thery committed
173
	m_render->draw(Algo::Render::GL2::FLAT_TRIANGLES) ;
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
232
233
234
235
236
237
238
239
240
241
242

	glDisable( GL_POLYGON_OFFSET_FILL );

	glPopMatrix();
}

void myGlutWin::myKeyboard(unsigned char keycode, int x, int y)
{
	switch(keycode)
	{
	case 27:
		exit(0);
	default:
		break;
	}
}


int main(int argc, char **argv)
{
	/// init glut interface and
	myGlutWin mgw(&argc,argv,800,800);
	mgw.init();

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

	// define the face extruded (here a cross)
	std::vector<PFP::VEC3> objV;
	objV.push_back(PFP::VEC3(-1, 0,-1));
	objV.push_back(PFP::VEC3(-1, 0,-2));
	objV.push_back(PFP::VEC3(+1, 0,-2));
	objV.push_back(PFP::VEC3(+1, 0,-1));
	objV.push_back(PFP::VEC3(+2, 0,-1));
	objV.push_back(PFP::VEC3(+2, 0,+1));
	objV.push_back(PFP::VEC3(+1, 0,+1));
	objV.push_back(PFP::VEC3(+1, 0,+2));
	objV.push_back(PFP::VEC3(-1, 0,+2));
	objV.push_back(PFP::VEC3(-1, 0,+1));
	objV.push_back(PFP::VEC3(-2, 0,+1));
	objV.push_back(PFP::VEC3(-2, 0,-1));

	// define a path (here an helicoid)
	std::vector<PFP::VEC3> pathV;
	// and a varying radius
	std::vector<float> pathRadius;
	for (int i=0; i < 200; ++ i)
	{
		PFP::REAL alpha = 3.141592/20.0 * i;
		PFP::REAL rad = 20.0 - 0.2*i;
		pathV.push_back(PFP::VEC3(rad*cos(alpha),rad*sin(alpha), 0.5*i));
		pathRadius.push_back(1.5f+0.7*cos(alpha));
	}

	// extrusion
	Dart d = Algo::Modelisation::extrusion_scale<PFP>(myMap, mgw.position, objV, PFP::VEC3(0.0,0.0,0.0), PFP::VEC3(0.0,1.0,0.0),true, pathV, false, pathRadius);

	// update renderer
	mgw.updateRender();


	// compute BB and store it for object positionning in screen
	Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap,mgw.position) ;
	mgw.gWidthObj = std::max<PFP::REAL>(std::max<PFP::REAL>(bb.size(0), bb.size(1)), bb.size(2));
	mgw.gPosObj = (bb.min() +  bb.max()) / PFP::REAL(2);

	mgw.mainLoop();

	return 0;
}