Coupure prévue mercredi 4 Août pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

tuto_orbits.cpp 9.47 KB
Newer Older
1
2
3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
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.unistra.fr/                                           *
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/


#include "tuto_orbits.h"
#include <iostream>


#include "Algo/Modelisation/primitives3d.h"
#include "Algo/Modelisation/polyhedron.h"
#include "Algo/Modelisation/subdivision.h"

#include "Algo/Render/GL2/topo3Render.h"
#include "Algo/Render/SVG/mapSVGRender.h"

#include "Algo/Import/import.h"

Pierre Kraemer's avatar
Pierre Kraemer committed
39
MAP myMap;
40
VertexAttribute<VEC3> position ;
Pierre Kraemer's avatar
Pierre Kraemer committed
41
AttributeHandler<VEC3, DART> middleDarts;
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59


void MyQT::text_onoff(bool x)
{
	render_text = !render_text;
	updateGL();
	CGoGNerr << " text_onoff  " << CGoGNflush;
}

void MyQT::slider_text(int x)
{
	m_strings->setScale(0.02f*x);
	updateGL();
}

void MyQT::orbit_list(int x)
{
	current_orbit = x;
60
61
	unsigned int orbs[9] = {VERTEX,EDGE,FACE,VOLUME,PFP::MAP::ORBIT_IN_PARENT(VERTEX),PFP::MAP::ORBIT_IN_PARENT(EDGE),PFP::MAP::ORBIT_IN_PARENT(FACE),PFP::MAP::ORBIT_IN_PARENT2(VERTEX),PFP::MAP::ORBIT_IN_PARENT2(EDGE)};
	storeVerticesInfoGen(orbs[current_orbit], m_att_orbits[x]);
Sylvain Thery's avatar
Sylvain Thery committed
62
63
64

	if (m_clicked != Dart::nil())
	{
65

Sylvain Thery's avatar
Sylvain Thery committed
66
67
68
		m_selected.clear();

		// easy way to traverse darts of orbit
69
70
		Traversor<MAP>* tra = Traversor<MAP>::createDartsOfOrbits(myMap,m_clicked,orbs[current_orbit]);
		for (Dart e = tra->begin(); e != tra->end(); e = tra->next())
Sylvain Thery's avatar
Sylvain Thery committed
71
72
73
74
			m_selected.push_back(e);
	}

	//	m_selected.clear();
75
76
77
	updateGL();
}

78
79
template< unsigned int ORBIT>
void MyQT::storeVerticesInfo(const AttributeHandler<int, ORBIT>* attrib)
80
81
{
	SelectorDartNoBoundary<PFP::MAP> nb(myMap);
Pierre Kraemer's avatar
Pierre Kraemer committed
82
	m_render_topo->computeDartMiddlePositions<PFP>(myMap, middleDarts, nb);
83
84

	m_strings->clear();
Pierre Kraemer's avatar
Pierre Kraemer committed
85
	for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d))
86
87
88
89
	{
		if (nb(d))
		{
			std::stringstream ss;
90
			ss << (*attrib)[d];
Pierre Kraemer's avatar
Pierre Kraemer committed
91
			m_strings->addString(ss.str(), middleDarts[d]);
92
93
94
95
96
		}
	}
    m_strings->sendToVBO();
}

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





void MyQT::storeVerticesInfoGen(unsigned int orb, const AttributeHandlerGen* attrib)
{
	switch(orb)
	{
	case VERTEX:
		storeVerticesInfo<VERTEX>(static_cast< const AttributeHandler<int, VERTEX>* >(attrib));
		break;
	case EDGE:
		storeVerticesInfo<EDGE>(static_cast< const AttributeHandler<int, EDGE>* >(attrib));
		break;
	case FACE:
		storeVerticesInfo<FACE>(static_cast< const AttributeHandler<int, FACE>* >(attrib));
		break;
	case VOLUME:
		storeVerticesInfo<VOLUME>(static_cast< const AttributeHandler<int, VOLUME>* >(attrib));
		break;
	case PFP::MAP::VERTEX_OF_PARENT:
		storeVerticesInfo<PFP::MAP::VERTEX_OF_PARENT>(static_cast< const AttributeHandler<int, PFP::MAP::VERTEX_OF_PARENT>* >(attrib));
		break;
	case PFP::MAP::EDGE_OF_PARENT:
		storeVerticesInfo<PFP::MAP::EDGE_OF_PARENT>(static_cast< const AttributeHandler<int, PFP::MAP::EDGE_OF_PARENT>* >(attrib));
		break;
	case PFP::MAP::FACE_OF_PARENT:
		storeVerticesInfo<PFP::MAP::FACE_OF_PARENT>(static_cast< const AttributeHandler<int, PFP::MAP::FACE_OF_PARENT>* >(attrib));
		break;
	case PFP::MAP::VERTEX_OF_PARENT2:
		storeVerticesInfo<PFP::MAP::VERTEX_OF_PARENT2>(static_cast< const AttributeHandler<int, PFP::MAP::VERTEX_OF_PARENT2>* >(attrib));
		break;
	case PFP::MAP::EDGE_OF_PARENT2:
		storeVerticesInfo<PFP::MAP::EDGE_OF_PARENT2>(static_cast< const AttributeHandler<int, PFP::MAP::EDGE_OF_PARENT2>* >(attrib));
		break;
	}
}



138
139
140
141
142
143
144
145
146
147
148
149
void MyQT::cb_initGL()
{
	// choose to use GL version 2
	Utils::GLSLShader::setCurrentOGLVersion(2);

    m_render_topo = new Algo::Render::GL2::Topo3Render();
	SelectorDartNoBoundary<PFP::MAP> nb(myMap);
	m_render_topo->updateData<PFP>(myMap, position,  0.9f, 0.8f, 0.8f, nb);

    m_strings = new Utils::Strings3D(true, Geom::Vec3f(0.1f,0.0f,0.3f));
	registerShader(m_strings);

150
    storeVerticesInfoGen(VERTEX, m_att_orbits[0]);
151
152
153
154
155
156
157
}

void MyQT::cb_redraw()
{
	m_render_topo->drawTopo();

	for (unsigned int i=0; i< m_selected.size(); ++i)
Sylvain Thery's avatar
Sylvain Thery committed
158
		m_render_topo->overdrawDart(m_selected[i], 7, 1.0f, 0.0f, 1.0f);
159
160
161
162
163
164
165
166
167
168
169

	if (render_text)
		m_strings->drawAll(Geom::Vec3f(0.0f, 1.0f, 1.0f));

}

void MyQT::cb_mousePress(int button, int x, int y)
{
	if (Shift())
	{
		SelectorDartNoBoundary<PFP::MAP> nb(myMap);	
Sylvain Thery's avatar
Sylvain Thery committed
170
171
		m_clicked = m_render_topo->picking<PFP>(myMap, x,y, nb);
		if (m_clicked != Dart::nil())
172
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
173
			unsigned int orbs[9] = {VERTEX,EDGE,FACE,VOLUME,PFP::MAP::ORBIT_IN_PARENT(VERTEX),PFP::MAP::ORBIT_IN_PARENT(EDGE),PFP::MAP::ORBIT_IN_PARENT(FACE),PFP::MAP::ORBIT_IN_PARENT2(VERTEX),PFP::MAP::ORBIT_IN_PARENT2(EDGE)};
174
175
176
			m_selected.clear();

			// easy way to traverse darts of orbit
177
178
			Traversor<MAP>* tra = Traversor<MAP>::createDartsOfOrbits(myMap,m_clicked,orbs[current_orbit]);
			for (Dart e = tra->begin(); e != tra->end(); e = tra->next())
179
180
181
182
183
184
				m_selected.push_back(e);
		}
		updateGL();
	}
}

185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200

template <unsigned int ORB>
void MyQT::init_att_orb(AttributeHandlerGen* attg)
{
	int i=0;
	TraversorCell<MAP,ORB> tra(myMap);

//	AttributeHandler<int,ORB>* attx = reinterpret_cast< AttributeHandler<int,ORB>* >(attg);
	AttributeHandler<int,ORB>* att = static_cast< AttributeHandler<int,ORB>* >(attg);

	for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
	{
		(*att)[d] = i++;
	}
}

201
202
203
204
void MyQT::initMap()
{
	std::cout << "INIT MAP"<< std::endl;

Pierre Kraemer's avatar
Pierre Kraemer committed
205
	position = myMap.addAttribute<VEC3, VERTEX>("position");
206
207
208
209
210
	Algo::Modelisation::Primitive3D<PFP> prim(myMap, position);
	int nb=2;
	prim.hexaGrid_topo(nb,nb,nb);
	prim.embedHexaGrid(1.0f,1.0f,1.0f);

211
212
213
	AttributeHandler<int, VERTEX> att0  = myMap.addAttribute<int, VERTEX>("vertex");
	m_att_orbits[0] = new AttributeHandler<int, VERTEX>(att0);
	init_att_orb<VERTEX>(m_att_orbits[0]);
214

215
216
217
218
219
220
221
222
	m_att_orbits[1] = new AttributeHandler<int, EDGE>(myMap.addAttribute<int, EDGE>("edge"));
	m_att_orbits[2] = new AttributeHandler<int, FACE>(myMap.addAttribute<int, FACE>("face"));
	m_att_orbits[3] = new AttributeHandler<int, VOLUME>(myMap.addAttribute<int, VOLUME>("volume"));
	m_att_orbits[4] = new AttributeHandler<int, VERTEX + PFP::MAP::IN_PARENT>(myMap.addAttribute<int, VERTEX + PFP::MAP::IN_PARENT>("vertex2"));
	m_att_orbits[5] = new AttributeHandler<int, EDGE + PFP::MAP::IN_PARENT>(myMap.addAttribute<int, EDGE + PFP::MAP::IN_PARENT>("edge2"));
	m_att_orbits[6] = new AttributeHandler<int, FACE + PFP::MAP::IN_PARENT>(myMap.addAttribute<int, FACE + PFP::MAP::IN_PARENT>("face2"));
	m_att_orbits[7] = new AttributeHandler<int, VERTEX + PFP::MAP::IN_PARENT2>(myMap.addAttribute<int, VERTEX + PFP::MAP::IN_PARENT2>("vertex1"));
	m_att_orbits[8] = new AttributeHandler<int, EDGE + PFP::MAP::IN_PARENT2>(myMap.addAttribute<int, EDGE + PFP::MAP::IN_PARENT2>("face1"));
223
224
225



226
	init_att_orb<EDGE>(m_att_orbits[1]);
227

228
	init_att_orb<FACE>(m_att_orbits[2]);
229

230
	init_att_orb<VOLUME>(m_att_orbits[3]);
231

232
	init_att_orb<PFP::MAP::VERTEX_OF_PARENT>(m_att_orbits[4]);
233

234
	init_att_orb<PFP::MAP::EDGE_OF_PARENT>(m_att_orbits[5]);
235

236
237
238
239
240
	init_att_orb<PFP::MAP::FACE_OF_PARENT>(m_att_orbits[6]);

	init_att_orb<PFP::MAP::VERTEX_OF_PARENT2>(m_att_orbits[7]);

	init_att_orb<PFP::MAP::EDGE_OF_PARENT2>(m_att_orbits[8]);
241

Pierre Kraemer's avatar
Pierre Kraemer committed
242
	middleDarts = myMap.addAttribute<VEC3, DART>("middle");
243
244
245
246
247
248
249
250
251
252
253
254
255
}

int main(int argc, char **argv)
{
    // un peu d'interface
	QApplication app(argc, argv);
	MyQT sqt;

	// interface de tuto5.ui
    Utils::QT::uiDockInterface dock;
    sqt.setDock(&dock);

 	// message d'aide
256
	sqt.setHelpMsg("Select an orbit then\nshift click left to select a dart");
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277

	sqt.initMap();

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

    // envoit info BB a l'interface
	sqt.setParamObject(lWidthObj, lPosObj.data());

	sqt.setCallBack( dock.checkBox_text, SIGNAL(toggled(bool)), SLOT(text_onoff(bool)) );
	sqt.setCallBack( dock.slider_text, SIGNAL(valueChanged(int)), SLOT(slider_text(int)) );
	sqt.setCallBack( dock.Orbits, SIGNAL(	currentIndexChanged(int)), SLOT(orbit_list(int)) );

	sqt.show();
	sqt.slider_text(50);

	// et on attend la fin.
	return app.exec();
}