firstPlugin.cpp 1.87 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
#include "firstPlugin.h"
#include "Algo/Geometry/boundingbox.h"
3
#include "Algo/Import/import.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
4

5
bool FirstPlugin::enable()
6
{
7
8
9
10
11
12
13
14
	m_render = new Algo::Render::GL2::MapRender() ;
	m_positionVBO = new Utils::VBO() ;
	m_flatShader = new Utils::ShaderFlat() ;
	m_flatShader->setAttributePosition(m_positionVBO) ;
	m_flatShader->setAmbiant(Geom::Vec4f(0.2f, 0.2f, 0.2f, 0.1f)) ;
	m_flatShader->setDiffuse(Geom::Vec4f(0.8f, 0.9f, 0.7f, 1.0f)) ;
	m_flatShader->setExplode(1.0f) ;
	CGoGN::Utils::GLSLShader::registerShader(NULL, m_flatShader) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
15

16
17
18
	std::vector<std::string> attrNames ;
	CGoGN::Algo::Import::importMesh<PFP>(myMap, "/home/kraemer/Media/Data/surface/lowRes/duck_163.ply", attrNames);
	position = myMap.getAttribute<PFP::VEC3, VERTEX>(attrNames[0]) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
19

20
21
22
	m_render->initPrimitives<PFP>(myMap, allDarts, CGoGN::Algo::Render::GL2::POINTS) ;
	m_render->initPrimitives<PFP>(myMap, allDarts, CGoGN::Algo::Render::GL2::LINES) ;
	m_render->initPrimitives<PFP>(myMap, allDarts, CGoGN::Algo::Render::GL2::TRIANGLES) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
23

24
	m_positionVBO->updateData(position) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
25

26
27
	return true;
}
Pierre Kraemer's avatar
Pierre Kraemer committed
28

29
30
void FirstPlugin::disable()
{
Pierre Kraemer's avatar
Pierre Kraemer committed
31
32
}

33
34
void FirstPlugin::redraw(View* view)
{
35
36
37
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) ;
	glEnable(GL_LIGHTING) ;
	m_render->draw(m_flatShader, Algo::Render::GL2::TRIANGLES) ;
38
39
40
41
}

void FirstPlugin::viewAdded(View* view)
{
42
43
44
45
	CGoGN::Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
	qglviewer::Vec min(bb.min()[0], bb.min()[1], bb.min()[2]);
	qglviewer::Vec max(bb.max()[0], bb.max()[1], bb.max()[2]);
	view->setSceneBoundingBox(min, max);
46
47
}

Pierre Kraemer's avatar
Pierre Kraemer committed
48
49
50
51
52
/**
 * If we want to compile this plugin in debug mode,
 * we also define a DEBUG macro at the compilation
 */
#ifndef DEBUG
Pierre Kraemer's avatar
Pierre Kraemer committed
53
54
55
// essential Qt function:
// arguments are
//  - the complied name of the plugin
Pierre Kraemer's avatar
Pierre Kraemer committed
56
//  - the main class of our plugin
Pierre Kraemer's avatar
Pierre Kraemer committed
57
Q_EXPORT_PLUGIN2(FirstPlugin, FirstPlugin)
Pierre Kraemer's avatar
Pierre Kraemer committed
58
#else
Pierre Kraemer's avatar
Pierre Kraemer committed
59
Q_EXPORT_PLUGIN2(FirstPluginD, FirstPlugin)
Pierre Kraemer's avatar
Pierre Kraemer committed
60
#endif