tuto1.cpp 3.66 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
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
24

25
#include "tuto1.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
26
27
28
29
#include "Algo/Geometry/boundingbox.h"

using namespace CGoGN ;

Sylvain Thery's avatar
Sylvain Thery committed
30
int main(int argc, char **argv)
Sylvain Thery's avatar
Sylvain Thery committed
31
{
Sylvain Thery's avatar
Sylvain Thery committed
32
33
34
	//	// interface
	QApplication app(argc, argv);
	MyQT sqt;
Pierre Kraemer's avatar
Pierre Kraemer committed
35

Sylvain Thery's avatar
Sylvain Thery committed
36
37
	// example code itself
	sqt.createMap();
Sylvain Thery's avatar
Sylvain Thery committed
38

Sylvain Thery's avatar
Sylvain Thery committed
39
40
41
42
43
44
	// set help message in menu
	sqt.setHelpMsg("First Tuto: \nCreate two faces\nsew them\nand affect positions");
	// final show for redraw
	sqt.show();
	// and wait for the end
	return app.exec();
Pierre Kraemer's avatar
Pierre Kraemer committed
45
46
}

Sylvain Thery's avatar
Sylvain Thery committed
47
void MyQT::createMap()
Pierre Kraemer's avatar
Pierre Kraemer committed
48
{
49
50
51
52
	// creation of a new attribute on vertices of type 3D vector for position.
	// a handler to this attribute is returned
	position = myMap.addAttribute<VEC3, VERTEX>("position");

Pierre Kraemer's avatar
Pierre Kraemer committed
53
54
55
56
57
58
59
	// creation of 2 new faces: 1 triangle and 1 square
	Dart d1 = myMap.newFace(3);
	Dart d2 = myMap.newFace(4);

	// sew these faces along one of their edge
	myMap.sewFaces(d1, d2);

Sylvain Thery's avatar
Sylvain Thery committed
60
	// affect position by moving in the map
Pierre Kraemer's avatar
Pierre Kraemer committed
61
62
63
64
65
	position[d1] = VEC3(0, 0, 0);
	position[PHI1(d1)] = VEC3(2, 0, 0);
	position[PHI_1(d1)] = VEC3(1, 2, 0);
	position[PHI<11>(d2)] = VEC3(0, -2, 0);
	position[PHI_1(d2)] = VEC3(2, -2, 0);
Sylvain Thery's avatar
Sylvain Thery committed
66

Sylvain Thery's avatar
Sylvain Thery committed
67
    //  bounding box of scene
Pierre Kraemer's avatar
Pierre Kraemer committed
68
    Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
Sylvain Thery's avatar
Sylvain Thery committed
69
70
71
    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
72
73
    // send BB info to interface for centering on GL screen
	setParamObject(lWidthObj, lPosObj.data());
Pierre Kraemer's avatar
Pierre Kraemer committed
74

Sylvain Thery's avatar
Sylvain Thery committed
75
76
	// first show for be sure that GL context is binded
	show();
Sylvain Thery's avatar
Sylvain Thery committed
77

Sylvain Thery's avatar
Sylvain Thery committed
78
79
	// render the topo of the map without boundary darts
	SelectorDartNoBoundary<PFP::MAP> nb(myMap);
Pierre Kraemer's avatar
Pierre Kraemer committed
80
	m_render_topo->updateData<PFP>(myMap, position, 0.9f, 0.9f, nb);
Sylvain Thery's avatar
Sylvain Thery committed
81
}
82

Sylvain Thery's avatar
Sylvain Thery committed
83
84
85
// initialization GL callback
void MyQT::cb_initGL()
{
86
	m_render_topo = new Algo::Render::GL2::TopoRender() ;
Sylvain Thery's avatar
Sylvain Thery committed
87
}
88

Sylvain Thery's avatar
Sylvain Thery committed
89
90
91
92
93
// redraw GL callback (clear and swap already done)
void MyQT::cb_redraw()
{
	m_render_topo->drawTopo();
}