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

subdivideSurface.cpp 5.07 KB
Newer Older
1
2
3
4
#include "subdivideSurface.h"

#include "mapHandler.h"

5
6
#include "Algo/Modelisation/subdivision.h"

7
8
9
10
11
12
13
14
bool SubdivideSurfacePlugin::enable()
{
	m_dockTab = new SubdivideSurfaceDockTab();
	addTabInDock(m_dockTab, "SubdivideSurface");

	connect(m_window, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(cb_addMapToList(MapHandlerGen*)));
	connect(m_window, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(cb_removeMapFromList(MapHandlerGen*)));

15
	connect(m_dockTab->mapList, SIGNAL(itemSelectionChanged()), this, SLOT(cb_selectedMapChanged()));
Pierre Kraemer's avatar
Pierre Kraemer committed
16

17
	connect(m_dockTab->button_trianguleFaces, SIGNAL(clicked()), this, SLOT(cb_trianguleFaces()));
Pierre Kraemer's avatar
Pierre Kraemer committed
18
19
	connect(m_dockTab->button_loopSubdivision, SIGNAL(clicked()), this, SLOT(cb_loopSubdivision()));
	connect(m_dockTab->button_CCSubdivision, SIGNAL(clicked()), this, SLOT(cb_CCSubdivision()));
20

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
	QList<MapHandlerGen*> maps = m_window->getMapsList();
	foreach(MapHandlerGen* m, maps)
		m_dockTab->mapList->addItem(m->getName());

	return true;
}

void SubdivideSurfacePlugin::cb_addMapToList(MapHandlerGen* m)
{
	m_dockTab->mapList->addItem(m->getName());
}

void SubdivideSurfacePlugin::cb_removeMapFromList(MapHandlerGen* m)
{
	for(int i = 0; i < m_dockTab->mapList->count(); ++i)
	{
		if(m_dockTab->mapList->item(i)->text() == m->getName())
		{
			delete m_dockTab->mapList->item(i);
			return;
		}
	}
}

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
void SubdivideSurfacePlugin::cb_selectedMapChanged()
{
	QList<QListWidgetItem*> currentItems = m_dockTab->mapList->selectedItems();
	if(!currentItems.empty())
	{
		m_dockTab->combo_positionAttribute->clear();
		const QString& mapname = currentItems[0]->text();
		MapHandlerGen* mh = m_window->getMap(mapname);
		GenericMap* map = mh->getGenericMap();
		AttributeContainer& cont = map->getAttributeContainer<VERTEX>();
		std::vector<std::string> names;
		std::vector<std::string> types;
		cont.getAttributesNames(names);
		cont.getAttributesTypes(types);
		std::string vec3TypeName = VEC3::CGoGNnameOfType();
60
		unsigned int j = 0;
61
62
63
		for(unsigned int i = 0; i < names.size(); ++i)
		{
			if(types[i] == vec3TypeName)
64
			{
65
				m_dockTab->combo_positionAttribute->addItem(QString::fromStdString(names[i]));
66
67
68
69
				if(names[i] == "position") // try to select an attribute named "position"
					m_dockTab->combo_positionAttribute->setCurrentIndex(j);
				++j;
			}
70
71
72
73
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
74
75
76
77
78
79
80
81
82
83
84
void SubdivideSurfacePlugin::cb_loopSubdivision()
{
	QList<QListWidgetItem*> currentItems = m_dockTab->mapList->selectedItems();
	if(!currentItems.empty())
	{
		const QString& mapname = currentItems[0]->text();
		MapHandler<PFP>* mh = reinterpret_cast<MapHandler<PFP>*>(m_window->getMap(mapname));
		MAP* map = mh->getMap();
		std::string positionName = m_dockTab->combo_positionAttribute->currentText().toUtf8().constData();
		VertexAttribute<VEC3> position = map->getAttribute<VEC3, VERTEX>(positionName);

Thery Sylvain's avatar
Thery Sylvain committed
85
		Algo::Surface::Modelisation::LoopSubdivision<PFP>(*map, position);
Pierre Kraemer's avatar
Pierre Kraemer committed
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111

		mh->updatePrimitives(Algo::Render::GL2::POINTS);
		mh->updatePrimitives(Algo::Render::GL2::LINES);
		mh->updatePrimitives(Algo::Render::GL2::TRIANGLES);
		mh->updateVBO(position);

		QList<View*> views = m_window->getViewsList();
		foreach(View* view, views)
		{
			if(view->isLinkedToMap(mh))
				view->updateGL();
		}
	}
}

void SubdivideSurfacePlugin::cb_CCSubdivision()
{
	QList<QListWidgetItem*> currentItems = m_dockTab->mapList->selectedItems();
	if(!currentItems.empty())
	{
		const QString& mapname = currentItems[0]->text();
		MapHandler<PFP>* mh = reinterpret_cast<MapHandler<PFP>*>(m_window->getMap(mapname));
		MAP* map = mh->getMap();
		std::string positionName = m_dockTab->combo_positionAttribute->currentText().toUtf8().constData();
		VertexAttribute<VEC3> position = map->getAttribute<VEC3, VERTEX>(positionName);

Thery Sylvain's avatar
Thery Sylvain committed
112
		Algo::Surface::Modelisation::CatmullClarkSubdivision<PFP>(*map, position);
Pierre Kraemer's avatar
Pierre Kraemer committed
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

		mh->updatePrimitives(Algo::Render::GL2::POINTS);
		mh->updatePrimitives(Algo::Render::GL2::LINES);
		mh->updatePrimitives(Algo::Render::GL2::TRIANGLES);
		mh->updateVBO(position);

		QList<View*> views = m_window->getViewsList();
		foreach(View* view, views)
		{
			if(view->isLinkedToMap(mh))
				view->updateGL();
		}
	}
}

128
129
130
131
132
133
134
135
void SubdivideSurfacePlugin::cb_trianguleFaces()
{
	QList<QListWidgetItem*> currentItems = m_dockTab->mapList->selectedItems();
	if(!currentItems.empty())
	{
		const QString& mapname = currentItems[0]->text();
		MapHandler<PFP>* mh = reinterpret_cast<MapHandler<PFP>*>(m_window->getMap(mapname));
		MAP* map = mh->getMap();
136
137
		std::string positionName = m_dockTab->combo_positionAttribute->currentText().toUtf8().constData();
		VertexAttribute<VEC3> position = map->getAttribute<VEC3, VERTEX>(positionName);
Pierre Kraemer's avatar
Pierre Kraemer committed
138

Thery Sylvain's avatar
Thery Sylvain committed
139
		Algo::Surface::Modelisation::trianguleFaces<PFP>(*map, position);
Pierre Kraemer's avatar
Pierre Kraemer committed
140

141
142
143
		mh->updatePrimitives(Algo::Render::GL2::POINTS);
		mh->updatePrimitives(Algo::Render::GL2::LINES);
		mh->updatePrimitives(Algo::Render::GL2::TRIANGLES);
144
		mh->updateVBO(position);
Pierre Kraemer's avatar
Pierre Kraemer committed
145

146
147
148
149
150
151
		QList<View*> views = m_window->getViewsList();
		foreach(View* view, views)
		{
			if(view->isLinkedToMap(mh))
				view->updateGL();
		}
152
153
154
	}
}

155
156
157
158
159
#ifndef DEBUG
Q_EXPORT_PLUGIN2(SubdivideSurfacePlugin, SubdivideSurfacePlugin)
#else
Q_EXPORT_PLUGIN2(SubdivideSurfacePluginD, SubdivideSurfacePlugin)
#endif