Coupure prévue mardi 3 Août au matin pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

extrusionView.cpp 5.26 KB
Newer Older
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           *
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/                                           *
21
22
23
24
25
26
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#include <iostream>

27
#include "extrusionView.h"
28
29

#include "Topology/generic/parameters.h"
30
#include "Topology/map/embeddedMap2.h"
31
32
33
34
35

#include "Geometry/vector_gen.h"
#include "Geometry/matrix.h"
#include "Geometry/transfo.h"

36
#include "Algo/Geometry/boundingbox.h"
37
38
39
#include "Algo/Modelisation/extrusion.h"
#include "Topology/generic/parameters.h"

40
#include "Algo/Render/GL2/mapRender.h"
41
42
#include "Utils/Shaders/shaderFlat.h"
#include "Utils/Shaders/shaderSimpleColor.h"
Thery Sylvain's avatar
Thery Sylvain committed
43
#include "Utils/vbo.h"
44

45
46
47
48
49
50
51
#include <vector>

using namespace CGoGN;

struct PFP: public PFP_STANDARD
{
	// definition de la carte
52
	typedef EmbeddedMap2 MAP;
53
54
};

55
56
57
58
typedef PFP::MAP MAP ;
typedef PFP::VEC3 VEC3 ;

MAP myMap;
59

60
void MyQT::cb_initGL()
61
{
62
63
	// choose to use GL version 2
	Utils::GLSLShader::setCurrentOGLVersion(2);
64

65
66
	// create the render
	m_render = new Algo::Render::GL2::MapRender();
67

68
69
	// create VBO for position
	m_positionVBO = new Utils::VBO();
70

71
72
73
	m_shader = new Utils::ShaderFlat();
	m_shader->setAttributePosition(m_positionVBO);
	m_shader->setDiffuse(Geom::Vec4f(0.,1.,0.,0.));
74

75
76
77
78
	// using simple shader with color
	m_shader2 = new Utils::ShaderSimpleColor();
	m_shader2->setAttributePosition(m_positionVBO);
	m_shader2->setColor(Geom::Vec4f(1.,1.,0.,0.));
79
80


Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
81
82
	registerShader(m_shader);
	registerShader(m_shader2);
83
84
}

85
void MyQT::cb_redraw()
86
{
87
88
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glEnable(GL_LIGHTING);
89

90
	m_render->draw(m_shader2, Algo::Render::GL2::LINES);
91
92
93
94

	glEnable( GL_POLYGON_OFFSET_FILL );
	glPolygonOffset( 1.0f, 1.0f );

95
	m_render->draw(m_shader, Algo::Render::GL2::TRIANGLES);
96

97
	glDisable(GL_POLYGON_OFFSET_FILL);
98
99
100
101
}

int main(int argc, char **argv)
{
102
103
104
	// interface:
	QApplication app(argc, argv);
	MyQT sqt;
105

106
	VertexAttribute<VEC3> position = myMap.addAttribute<VEC3, VERTEX>("position") ;
107
108
109
110

	// define the face extruded (here a cross)
	std::vector<PFP::VEC3> objV;
	objV.push_back(PFP::VEC3(-2, 0,-1));
Sylvain Thery's avatar
Sylvain Thery committed
111
112
113
114
115
116
117
118
119
120
121
	objV.push_back(PFP::VEC3(-2, 0,+1));
	objV.push_back(PFP::VEC3(-1, 0,+1));
	objV.push_back(PFP::VEC3(-1, 0,+2));
	objV.push_back(PFP::VEC3(+1, 0,+2));
	objV.push_back(PFP::VEC3(+1, 0,+1));
	objV.push_back(PFP::VEC3(+2, 0,+1));
	objV.push_back(PFP::VEC3(+2, 0,-1));
	objV.push_back(PFP::VEC3(+1, 0,-1));
	objV.push_back(PFP::VEC3(+1, 0,-2));
	objV.push_back(PFP::VEC3(-1, 0,-2));
	objV.push_back(PFP::VEC3(-1, 0,-1));
122
123
124
125
126
127
128
129
130
131

	// define a path (here an helicoid)
	std::vector<PFP::VEC3> pathV;
	// and a varying radius
	std::vector<float> pathRadius;
	for (int i=0; i < 200; ++ i)
	{
		PFP::REAL alpha = 3.141592/20.0 * i;
		PFP::REAL rad = 20.0 - 0.2*i;
		pathV.push_back(PFP::VEC3(rad*cos(alpha),rad*sin(alpha), 0.5*i));
Sylvain Thery's avatar
Sylvain Thery committed
132
		pathRadius.push_back(2.0f+0.3*cos(alpha));
133
134
135
	}

	// extrusion
136
	Algo::Surface::Modelisation::extrusion_scale<PFP>(myMap, position, objV, PFP::VEC3(0.0,0.0,0.0), PFP::VEC3(0.0,1.0,0.0),true, pathV, false, pathRadius);
137

138
139
140
141
    //  bounding box
    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);
142

143
    // send the BB to the interface
144
145
	sqt.setParamObject(lWidthObj,lPosObj.data());

146
	// first show creates GL context
147
148
	sqt.show();

149
	// update position VBO
150
151
	sqt.m_positionVBO->updateData(position);

152
	// update render primitives
153
154
	sqt.m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::TRIANGLES);
	sqt.m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::LINES);
155

156
157
	sqt.show();
	return app.exec();
158
}