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 7.69 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
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
* 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"

PFP::MAP myMap;
PFP::TVEC3 position ;
PFP::TVEC3 middleDarts;



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)
{
	storeVerticesInfo<int>(m_att_orbits[x]);
	current_orbit = x;
64
	m_selected.clear();
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
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
232
233
234
235
236
237
	updateGL();
}


template<typename T>
void MyQT::storeVerticesInfo(const AttributeHandler<T>& attrib)
{
	SelectorDartNoBoundary<PFP::MAP> nb(myMap);
	m_render_topo->computeDartMiddlePositions<PFP>(myMap,middleDarts,nb);

	m_strings->clear();
	for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d))
	{
		if (nb(d))
		{
			std::stringstream ss;
			ss << attrib[d];
			m_strings->addString(ss.str(),middleDarts[d]);
		}
	}
    m_strings->sendToVBO();
}

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


    storeVerticesInfo<int>(m_att_orbits[0]);


}

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

	for (unsigned int i=0; i< m_selected.size(); ++i)
		m_render_topo->overdrawDart(m_selected[i], 5, 1.0f, 0.0f, 1.0f);

	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);	
		Dart d = m_render_topo->picking<PFP>(myMap, x,y, nb);
		if (d != Dart::nil())
		{
			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)};
			m_selected.clear();

			// easy way to traverse darts of orbit
			TraversorDartsOfOrbit<PFP::MAP> tra(myMap,orbs[current_orbit],d);
			for (Dart e = tra.begin(); e != tra.end(); e = tra.next())
				m_selected.push_back(e);
		}
		updateGL();
	}
}


void MyQT::initMap()
{
	std::cout << "INIT MAP"<< std::endl;

	position = myMap.addAttribute<PFP::VEC3>(VERTEX, "position");
	Algo::Modelisation::Primitive3D<PFP> prim(myMap, position);
	int nb=2;
	prim.hexaGrid_topo(nb,nb,nb);
	prim.embedHexaGrid(1.0f,1.0f,1.0f);

	m_att_orbits[0] = myMap.addAttribute<int>(VERTEX,"vertex");
	m_att_orbits[1] = myMap.addAttribute<int>(EDGE,"edge");
	m_att_orbits[2] = myMap.addAttribute<int>(FACE,"face");
	m_att_orbits[3] = myMap.addAttribute<int>(VOLUME,"volume");
	m_att_orbits[4] = myMap.addAttribute<int>(PFP::MAP::ORBIT_IN_PARENT(VERTEX),"vertex2");
	m_att_orbits[5] = myMap.addAttribute<int>(PFP::MAP::ORBIT_IN_PARENT(EDGE),"edge2");
	m_att_orbits[6] = myMap.addAttribute<int>(PFP::MAP::ORBIT_IN_PARENT(FACE),"face2");
	m_att_orbits[7] = myMap.addAttribute<int>(PFP::MAP::ORBIT_IN_PARENT2(VERTEX),"vertex1");
	m_att_orbits[8] = myMap.addAttribute<int>(PFP::MAP::ORBIT_IN_PARENT2(EDGE),"face1");

	int i=0;
	TraversorCell<PFP::MAP> tra0(myMap, VERTEX);
	for (Dart d = tra0.begin(); d != tra0.end(); d = tra0.next())
	{
		m_att_orbits[0][d] = i++;
	}

	i=0;
	TraversorCell<PFP::MAP> tra1(myMap, EDGE);
	for (Dart d = tra1.begin(); d != tra1.end(); d = tra1.next())
	{
		m_att_orbits[1][d] = i++;
	}

	i=0;
	TraversorCell<PFP::MAP> tra2(myMap, FACE);
	for (Dart d = tra2.begin(); d != tra2.end(); d = tra2.next())
	{
		m_att_orbits[2][d] = i++;
	}

	i=0;
	TraversorCell<PFP::MAP> tra3(myMap, VOLUME);
	for (Dart d = tra3.begin(); d != tra3.end(); d = tra3.next())
	{
		m_att_orbits[3][d] = i++;
	}

	i=0;
	TraversorCell<PFP::MAP> tra02(myMap, PFP::MAP::ORBIT_IN_PARENT(VERTEX));
	for (Dart d = tra02.begin(); d != tra02.end(); d = tra02.next())
	{
		m_att_orbits[4][d] = i++;
	}

	i=0;
	TraversorCell<PFP::MAP> tra12(myMap, PFP::MAP::ORBIT_IN_PARENT(EDGE));
	for (Dart d = tra12.begin(); d != tra12.end(); d = tra12.next())
	{
		m_att_orbits[5][d] = i++;
	}

	i=0;
	TraversorCell<PFP::MAP> tra22(myMap, PFP::MAP::ORBIT_IN_PARENT(FACE));
	for (Dart d = tra22.begin(); d != tra22.end(); d = tra22.next())
	{
		m_att_orbits[6][d] = i++;
	}

	i=0;
	TraversorCell<PFP::MAP> tra01(myMap, PFP::MAP::ORBIT_IN_PARENT2(VERTEX));
	for (Dart d = tra01.begin(); d != tra01.end(); d = tra01.next())
	{
		m_att_orbits[7][d] = i++;
	}

	i=0;
	TraversorCell<PFP::MAP> tra11(myMap, PFP::MAP::ORBIT_IN_PARENT2(EDGE));
	for (Dart d = tra11.begin(); d != tra11.end(); d = tra11.next())
	{
		m_att_orbits[8][d] = i++;
	}

	middleDarts = myMap.addAttribute<PFP::VEC3>(DART, "middle");

}

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
238
	sqt.setHelpMsg("Select an orbit then\nshift click left to select a dart");
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259

	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();
}