tuto3.cpp 5.6 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-2011, 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.u-strasbg.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

Sylvain Thery's avatar
Sylvain Thery committed
58
59

void MyQT::traverseMap()
Pierre Kraemer's avatar
Pierre Kraemer committed
60
61
{

Sylvain Thery's avatar
Sylvain Thery committed
62
	//traverse cells of map using topological markers on darts
Pierre Kraemer's avatar
Pierre Kraemer committed
63

Sylvain Thery's avatar
Sylvain Thery committed
64
65
66
67
68
	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))
69
	{
Sylvain Thery's avatar
Sylvain Thery committed
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
		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);
		}
85
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
86
87


Sylvain Thery's avatar
Sylvain Thery committed
88
89
90
	// 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
Pierre Kraemer's avatar
Pierre Kraemer committed
91

Sylvain Thery's avatar
Sylvain Thery committed
92
93
94
95
96
97
	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))
Pierre Kraemer's avatar
Pierre Kraemer committed
98
	{
Sylvain Thery's avatar
Sylvain Thery committed
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
		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);
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
114
115
	}

Sylvain Thery's avatar
Sylvain Thery committed
116
117
118
	// 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
119

Sylvain Thery's avatar
Sylvain Thery committed
120
}
121
122


Sylvain Thery's avatar
Sylvain Thery committed
123
124
void MyQT::createMap()
{
125

Sylvain Thery's avatar
Sylvain Thery committed
126
	Dart d1 = Algo::Modelisation::Polyhedron<PFP>::createTetra(myMap);
127

Sylvain Thery's avatar
Sylvain Thery committed
128
	Dart d2 = d1;
129

Sylvain Thery's avatar
Sylvain Thery committed
130
	position = myMap.addAttribute<PFP::VEC3>(VERTEX, "position");
131

Sylvain Thery's avatar
Sylvain Thery committed
132
133
134
135
136
137
138
	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);
139

Sylvain Thery's avatar
Sylvain Thery committed
140
141
142
143
    //  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);
144

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

Sylvain Thery's avatar
Sylvain Thery committed
148
149
	// first show for be sure that GL context is binded
	show();
150

Sylvain Thery's avatar
Sylvain Thery committed
151
152
153
154
	// 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);
}
155
156


Sylvain Thery's avatar
Sylvain Thery committed
157
158
159
160
161
// initialization GL callback
void MyQT::cb_initGL()
{
	m_render_topo = new Algo::Render::GL2::TopoRenderMapD() ;
}
162

Sylvain Thery's avatar
Sylvain Thery committed
163
164
165
166
167
168
// 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();
169

Sylvain Thery's avatar
Sylvain Thery committed
170
}
171

Sylvain Thery's avatar
Sylvain Thery committed
172
173
174
175
176
177
178
// mouse picking
void MyQT::cb_mouseClick(int button, int x, int y)
{
	if (button == Qt::LeftButton)
	{
		Dart  d = m_render_topo->picking<PFP>(myMap,allDarts,x,y);
		if (d != NIL)
Pierre Kraemer's avatar
Pierre Kraemer committed
179

Sylvain Thery's avatar
Sylvain Thery committed
180
181
182
183
			CGoGNout << "Dart "<< d <<  CGoGNendl;
		dart_selected=d;
		updateGL();
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
184
185

}