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

tuto4.cpp 5.79 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 "tuto4.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
26
#include "Algo/Geometry/boundingbox.h"
Sylvain Thery's avatar
Sylvain Thery committed
27
#include "Algo/Modelisation/polyhedron.h"
28

Pierre Kraemer's avatar
Pierre Kraemer committed
29
30
31
using namespace CGoGN ;


Sylvain Thery's avatar
Sylvain Thery committed
32
int main(int argc, char **argv)
Pierre Kraemer's avatar
Pierre Kraemer committed
33
{
Sylvain Thery's avatar
Sylvain Thery committed
34
35
36
37
38
	//	// 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
39

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

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

Sylvain Thery's avatar
Sylvain Thery committed
45
46
47
48
	// 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();
Pierre Kraemer's avatar
Pierre Kraemer committed
49
50


Sylvain Thery's avatar
Sylvain Thery committed
51
	CGoGNout << "You can pick darts dans see incident/dajacent cells (one dart) with click/shift click/ctrl click"<< CGoGNendl;
52

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

Sylvain Thery's avatar
Sylvain Thery committed
57
58
59

// example of usage of traversor for local traverse
void MyQT::cb_mouseClick(int button, int x, int y)
Pierre Kraemer's avatar
Pierre Kraemer committed
60
61
{

Sylvain Thery's avatar
Sylvain Thery committed
62
	if (button == Qt::LeftButton)
Pierre Kraemer's avatar
Pierre Kraemer committed
63
	{
64
		Dart  d = m_render_topo->picking<PFP>(myMap,x,y);
Sylvain Thery's avatar
Sylvain Thery committed
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
		if (d != NIL)
		{
			dart_selected.clear();
			// EDGES INCIDENT TO VERTEX
			if (Shift())
			{
				Traversor2VE<PFP::MAP> tra(myMap,d);
				for (Dart e=tra.begin(); e!=tra.end(); e=tra.next())
					dart_selected.push_back(e);
				CGoGNout << "traverse edges incident to a vertex" << CGoGNendl;
				color = Geom::Vec3f(1,0,0);
			}
			// EDGES INCIDENT TO FACES
			else if (Control())
			{
				Traversor2FE<PFP::MAP> tra(myMap,d);
				for (Dart e=tra.begin(); e!=tra.end(); e=tra.next())
					dart_selected.push_back(e);
				CGoGNout << "traverse edges incident to a face (its boundary)" << CGoGNendl;
				color = Geom::Vec3f(0,1,0);
			}
			// VERTICES ADJACENT TO VERTEX BY A FACE
			else
			{
				Traversor2VVaF<PFP::MAP> tra(myMap,d);
				for (Dart e=tra.begin(); e!=tra.end(); e=tra.next())
					dart_selected.push_back(e);
				CGoGNout << "traverse vertices adjacent to vertex by a face " << CGoGNendl;
				color = Geom::Vec3f(1,1,0);

			}
		}
		updateGL();
Pierre Kraemer's avatar
Pierre Kraemer committed
98
	}
99
100
101
}


Sylvain Thery's avatar
Sylvain Thery committed
102
void MyQT::traverseMap()
103
{
Sylvain Thery's avatar
Sylvain Thery committed
104
	//traverse cells with traversor
105

Sylvain Thery's avatar
Sylvain Thery committed
106
107
108
109
	CGoGNout << "Traverse with Vertex Traversor:  "<< CGoGNendl;
	TraversorV<PFP::MAP> traV(myMap);
	for (Dart d=traV.begin(); d!=traV.end(); d=traV.next())
		CGoGNout << "Vertex of dart "<<d<< CGoGNendl;
110

Sylvain Thery's avatar
Sylvain Thery committed
111
112
113
114
	CGoGNout << "Traverse with Edge Traversor:  "<< CGoGNendl;
	TraversorE<PFP::MAP> traE(myMap);
	for (Dart d=traE.begin(); d!=traE.end(); d=traE.next())
		CGoGNout << "Edge of dart "<<d<< CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
115

Sylvain Thery's avatar
Sylvain Thery committed
116
117
118
119
	CGoGNout << "Traverse with Face Traversor:  "<< CGoGNendl;
	TraversorF<PFP::MAP> traF(myMap);
	for (Dart d=traF.begin(); d!=traF.end(); d=traF.next())
		CGoGNout << "Face of dart "<<d<< CGoGNendl;
120
121
122

}

Pierre Kraemer's avatar
Pierre Kraemer committed
123

124

Pierre Kraemer's avatar
Pierre Kraemer committed
125

Sylvain Thery's avatar
Sylvain Thery committed
126
127
void MyQT::createMap()
{
128

129
	Dart d1 = Algo::Modelisation::createHexahedron<PFP>(myMap);
Sylvain Thery's avatar
Sylvain Thery committed
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151

	Dart d2 = d1;

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

	position[d2] = PFP::VEC3(1, 0, 0);
	d2 = PHI1(d2);
	position[d2] = PFP::VEC3(0, 0, 0);
	d2 = PHI1(d2);
	position[d2] = PFP::VEC3(0, 1, 0);
	d2 = PHI1(d2);
	position[d2] = PFP::VEC3(1, 1, 0);
	d2 = PHI<2112>(d2);
	position[d2] = PFP::VEC3(1, 0, 1);
	d2 = PHI1(d2);
	position[d2] = PFP::VEC3(1, 1, 1);
	d2 = PHI1(d2);
	position[d2] = PFP::VEC3(0, 1, 1);
	d2 = PHI1(d2);
	position[d2] = PFP::VEC3(0, 0, 1);

    //  bounding box of scene
Pierre Kraemer's avatar
Pierre Kraemer committed
152
    Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
153
154
155
    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);

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

Sylvain Thery's avatar
Sylvain Thery committed
159
160
161
162
	// first show for be sure that GL context is binded
	show();
	m_render_topo->updateData<PFP>(myMap, position, 0.9f, 0.9f);
}
163
164


Sylvain Thery's avatar
Sylvain Thery committed
165
166
167
// initialization GL callback
void MyQT::cb_initGL()
{
168
	m_render_topo = new Algo::Render::GL2::TopoRender() ;
Sylvain Thery's avatar
Sylvain Thery committed
169
170
171
172
173
174
175
176
177
178
179
180
181
}

// redraw GL callback (clear and swap already done)
void MyQT::cb_redraw()
{
	if (!dart_selected.empty())
	for (std::vector<Dart>::iterator it = dart_selected.begin(); it != dart_selected.end(); ++it)
	{
		m_render_topo->overdrawDart(*it, 5, color[0],color[1],color[2]);
	}
	m_render_topo->drawTopo();

}
182

Pierre Kraemer's avatar
Pierre Kraemer committed
183
184
185



186