tuto4.cpp 5.78 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 "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
// 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
59
60
{

Sylvain Thery's avatar
Sylvain Thery committed
61
	if (button == Qt::LeftButton)
Pierre Kraemer's avatar
Pierre Kraemer committed
62
	{
63
		Dart  d = m_render_topo->picking<PFP>(myMap,x,y);
Sylvain Thery's avatar
Sylvain Thery committed
64
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
		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
96
	}
97
98
}

Sylvain Thery's avatar
Sylvain Thery committed
99
void MyQT::traverseMap()
100
{
Sylvain Thery's avatar
Sylvain Thery committed
101
	//traverse cells with traversor
102

Sylvain Thery's avatar
Sylvain Thery committed
103
104
105
106
	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;
107

Sylvain Thery's avatar
Sylvain Thery committed
108
109
110
111
	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
112

Sylvain Thery's avatar
Sylvain Thery committed
113
114
115
116
	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;
117
118
}

Sylvain Thery's avatar
Sylvain Thery committed
119
120
void MyQT::createMap()
{
121

122
	Dart d1 = Algo::Surface::Modelisation::createHexahedron<PFP>(myMap);
Sylvain Thery's avatar
Sylvain Thery committed
123
124
125

	Dart d2 = d1;

Pierre Kraemer's avatar
Pierre Kraemer committed
126
	position = myMap.addAttribute<PFP::VEC3, VERTEX>("position");
Sylvain Thery's avatar
Sylvain Thery committed
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144

	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
145
    Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
146
147
148
    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
149
150
    // send BB info to interface for centering on GL screen
	setParamObject(lWidthObj, lPosObj.data());
151

Sylvain Thery's avatar
Sylvain Thery committed
152
153
154
155
	// first show for be sure that GL context is binded
	show();
	m_render_topo->updateData<PFP>(myMap, position, 0.9f, 0.9f);
}
156

Sylvain Thery's avatar
Sylvain Thery committed
157
158
159
// initialization GL callback
void MyQT::cb_initGL()
{
160
	m_render_topo = new Algo::Render::GL2::TopoRender() ;
Sylvain Thery's avatar
Sylvain Thery committed
161
162
163
164
165
166
167
168
169
170
171
172
}

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