tuto3.cpp 7.03 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-2012, 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.unistra.fr/                                           *
Pierre Kraemer's avatar
Pierre Kraemer committed
21
22
23
24
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

25
#include "tuto3.h"
Sylvain Thery's avatar
Sylvain Thery committed
26
27
28
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Selection/raySelector.h"
#include "Algo/Modelisation/polyhedron.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
29
30
31
32

using namespace CGoGN ;


Sylvain Thery's avatar
Sylvain Thery committed
33
int main(int argc, char **argv)
Pierre Kraemer's avatar
Pierre Kraemer committed
34
{
Sylvain Thery's avatar
Sylvain Thery committed
35
36
37
38
39
	//	// interface
	QApplication app(argc, argv);
	MyQT sqt;
	// copy output tout Qt console of application (shift enter)
	CGoGNout.toConsole(&sqt);
Pierre Kraemer's avatar
Pierre Kraemer committed
40

Sylvain Thery's avatar
Sylvain Thery committed
41
42
	// example code itself
	sqt.createMap();
Pierre Kraemer's avatar
Pierre Kraemer committed
43

Sylvain Thery's avatar
Sylvain Thery committed
44
	sqt.traverseMap();
Pierre Kraemer's avatar
Pierre Kraemer committed
45

Sylvain Thery's avatar
Sylvain Thery committed
46
47
48
49
	// set help message in menu
	sqt.setHelpMsg("Tuto 3: \nUsage of DartMarker and CellMarker\nPick of dart with mouse");
	// final show for redraw
	sqt.show();
50
51


Sylvain Thery's avatar
Sylvain Thery committed
52
	CGoGNout << "You can pick darts dans see it's id with left mouse button"<< CGoGNendl;
53

Sylvain Thery's avatar
Sylvain Thery committed
54
55
	// and wait for the end
	return app.exec();
56
}
Pierre Kraemer's avatar
Pierre Kraemer committed
57

58
59
Dart xd1;

Sylvain Thery's avatar
Sylvain Thery committed
60
61

void MyQT::traverseMap()
Pierre Kraemer's avatar
Pierre Kraemer committed
62
{
63
64
65
	DartMarker m1(myMap);
	DartMarker m2(myMap);
	myMap.rdfi(myMap.begin(),m1,m2);
Pierre Kraemer's avatar
Pierre Kraemer committed
66

67
	m1.unmarkAll();
Pierre Kraemer's avatar
Pierre Kraemer committed
68

Pierre Kraemer's avatar
Pierre Kraemer committed
69
	m1.markOrbit<VOLUME>(xd1);
Pierre Kraemer's avatar
Pierre Kraemer committed
70

71
72
	// render the topo of the map without boundary darts
	SelectorDartNoBoundary<PFP::MAP> nb(myMap);
Pierre Kraemer's avatar
Pierre Kraemer committed
73
	m_render_topo->updateData<PFP>(myMap, position, 0.9f, 0.9f, nb);
Pierre Kraemer's avatar
Pierre Kraemer committed
74

Sylvain Thery's avatar
Sylvain Thery committed
75
	for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d))
Pierre Kraemer's avatar
Pierre Kraemer committed
76
	{
77
		if (m2.isMarked(d))
Sylvain Thery's avatar
Sylvain Thery committed
78
		{
79
			m_render_topo->setDartColor(d,1.0f,0.0f,0.0f);
Sylvain Thery's avatar
Sylvain Thery committed
80
		}
81
		if (m1.isMarked(d))
Sylvain Thery's avatar
Sylvain Thery committed
82
		{
83
			m_render_topo->setDartColor(d,0.0f,1.0f,0.0f);
Sylvain Thery's avatar
Sylvain Thery committed
84
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
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
//
//
//	//traverse cells of map using topological markers on darts
//
//	CGoGNout << "Traverse with DartMarkers:"<< CGoGNendl;
//	DartMarker dmV(myMap);
//	DartMarker dmE(myMap);
//	DartMarker dmF(myMap);
//	for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d))
//	{
//		if (!dmV.isMarked(d))
//		{
//			CGoGNout << "Vertex of dart "<<d<<CGoGNendl;
//			dmV.markOrbit(VERTEX,d);
//		}
//		if (!dmE.isMarked(d))
//		{
//			CGoGNout << "Edgee of dart "<<d<<CGoGNendl;
//			dmE.markOrbit(EDGE,d);
//		}
//		if (!dmF.isMarked(d))
//		{
//			CGoGNout << "Face of dart "<<d<<CGoGNendl;
//			dmF.markOrbit(FACE,d);
//		}
//	}
//
//
//	// traverses cells of map with markers on embedded cells.
//	// More efficients but more memory costly if cells are not already embedded.
//	// Avoid using construction of objects not ell embedded
//
//	CGoGNout << "========================="<< CGoGNendl;
//	CGoGNout << "Traverse with CellMarkers:"<< CGoGNendl;
//	CellMarker cmV(myMap,VERTEX);
//	CellMarker cmE(myMap,EDGE);
//	CellMarker cmF(myMap,FACE);
//	for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d))
//	{
//		if (!cmV.isMarked(d))
//		{
//			CGoGNout << "Vertex of dart "<<d<<CGoGNendl;
//			cmV.mark(d);
//		}
//		if (!cmE.isMarked(d))
//		{
//			CGoGNout << "Edgee of dart "<<d<<CGoGNendl;
//			cmE.mark(d);
//		}
//		if (!cmF.isMarked(d))
//		{
//			CGoGNout << "Face of dart "<<d<<CGoGNendl;
//			cmF.mark(d);
//		}
//	}
//
//	// markers are cleaned and released at destruction of DartMarkers & CellMarkers
//	// DartMarkerStore should be used if few darts are traversed
//	// DartMarkerNoUnmark can be use if you want to manage unmarking yourself
Sylvain Thery's avatar
Sylvain Thery committed
146
}
147
148


Sylvain Thery's avatar
Sylvain Thery committed
149
150
void MyQT::createMap()
{
Pierre Kraemer's avatar
Pierre Kraemer committed
151
//	Dart d1 = Algo::Modelisation::createTetrahedron<PFP>(myMap);
152

Pierre Kraemer's avatar
Pierre Kraemer committed
153
//	Dart d2 = d1;
untereiner's avatar
untereiner committed
154

Pierre Kraemer's avatar
Pierre Kraemer committed
155
	position = myMap.addAttribute<PFP::VEC3, VERTEX>("position");
156

157
	Algo::Surface::Modelisation::Polyhedron<PFP> prim1(myMap, position);
Pierre Kraemer's avatar
Pierre Kraemer committed
158
	prim1.cylinder_topo(256, 256, true, true); // topo of sphere is a closed cylinder
159
160
161
162
163
164
165
166
167
168
169
	prim1.embedSphere(2.0f);

//	Dart d2 = d1;
//	position[d2] = PFP::VEC3(1, 0, 0);
//	d2 = PHI1(d2);
//	position[d2] = PFP::VEC3(-1, 0, 0);
//	d2 = PHI1(d2);
//	position[d2] = PFP::VEC3(0, 2, 0);
//	d2 = PHI<211>(d2);
//	position[d2] = PFP::VEC3(0, 1, 2);

170
	Algo::Surface::Modelisation::Polyhedron<PFP> prim2(myMap, position);
Pierre Kraemer's avatar
Pierre Kraemer committed
171
	prim2.cylinder_topo(256, 256, true, true); // topo of sphere is a closed cylinder
172
173
174
175
	prim2.embedSphere(2.0f);

	Geom::Matrix44f trf;
	trf.identity();
Pierre Kraemer's avatar
Pierre Kraemer committed
176
	Geom::translate<float>(5.0f, 0.0, 0.0, trf);
177
178
179
180
181
182
183
184
185
186
187
188
189
190
	prim2.transform(trf);

	xd1 = prim2.getDart();

//	xd1 = Algo::Modelisation::Polyhedron<PFP>::createTetra(myMap);
//	Dart xd2 = xd1;
//
//	position[xd2] = PFP::VEC3(5, 0, 0);
//	xd2 = PHI1(xd2);
//	position[xd2] = PFP::VEC3(3, 0, 0);
//	xd2 = PHI1(xd2);
//	position[xd2] = PFP::VEC3(4, 2, 0);
//	xd2 = PHI<211>(xd2);
//	position[xd2] = PFP::VEC3(4, 1, 2);
191

Sylvain Thery's avatar
Sylvain Thery committed
192
193
194
195
    //  bounding box of scene
    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);
196

Sylvain Thery's avatar
Sylvain Thery committed
197
198
    // send BB info to interface for centering on GL screen
	setParamObject(lWidthObj, lPosObj.data());
199

Sylvain Thery's avatar
Sylvain Thery committed
200
201
	// first show for be sure that GL context is binded
	show();
202

Sylvain Thery's avatar
Sylvain Thery committed
203
204
205
206
	// render the topo of the map without boundary darts
	SelectorDartNoBoundary<PFP::MAP> nb(myMap);
	m_render_topo->updateData<PFP>(myMap, position, 0.9f, 0.9f,nb);
}
207

Sylvain Thery's avatar
Sylvain Thery committed
208
209
210
// initialization GL callback
void MyQT::cb_initGL()
{
211
	m_render_topo = new Algo::Render::GL2::TopoRender();
Sylvain Thery's avatar
Sylvain Thery committed
212
}
213

Sylvain Thery's avatar
Sylvain Thery committed
214
215
216
217
218
219
220
// redraw GL callback (clear and swap already done)
void MyQT::cb_redraw()
{
	if (dart_selected != NIL)
		m_render_topo->overdrawDart(dart_selected, 5, 1.0f,0.0f,0.0f);
	m_render_topo->drawTopo();
}
221

Sylvain Thery's avatar
Sylvain Thery committed
222
223
224
225
226
// mouse picking
void MyQT::cb_mouseClick(int button, int x, int y)
{
	if (button == Qt::LeftButton)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
227
		Dart  d = m_render_topo->picking<PFP>(myMap, x, y);
Sylvain Thery's avatar
Sylvain Thery committed
228
		if (d != NIL)
Pierre Kraemer's avatar
Pierre Kraemer committed
229

Sylvain Thery's avatar
Sylvain Thery committed
230
231
232
233
			CGoGNout << "Dart "<< d <<  CGoGNendl;
		dart_selected=d;
		updateGL();
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
234
}