Commit 8f0aab16 authored by Pierre Kraemer's avatar Pierre Kraemer

SCHNApps: parameterSet management in render plugins

parent cadb8aed
......@@ -11,7 +11,7 @@
bool ImportPlugin::enable()
{
importAction = new QAction("import", this);
addMenuAction("Import;import", importAction);
addMenuAction("Import;Import Surface", importAction);
connect(importAction, SIGNAL(triggered()), this, SLOT(cb_import()));
return true;
}
......@@ -38,8 +38,6 @@ void ImportPlugin::cb_import()
// create VBO for vertex position attribute
h->createVBO(position);
// Utils::VBO* positionVBO = h->getVBO(position.name());
// positionVBO->updateData(position);
// compute vertex normal attribute
VertexAttribute<VEC3> normal = m->getAttribute<VEC3, CGoGN::VERTEX>("normal");
......@@ -49,8 +47,6 @@ void ImportPlugin::cb_import()
// create VBO for vertex normal attribute
h->createVBO(normal);
// CGoGN::Utils::VBO* normalVBO = h->getVBO(normal);
// normalVBO->updateData(normal);
// compute map bounding box
h->updateBB(position);
......
......@@ -50,7 +50,7 @@ void RenderPlugin::disable()
void RenderPlugin::redraw(View* view)
{
TabParams* params = h_viewParams[view];
ParameterSet* params = h_viewParams[view];
const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
foreach(MapHandlerGen* m, maps)
......@@ -96,23 +96,22 @@ void RenderPlugin::redraw(View* view)
void RenderPlugin::viewLinked(View* view)
{
h_viewParams.insert(view, new TabParams(1.0, false, false, true, FLAT));
h_viewParams.insert(view, new ParameterSet());
m_dockTab->refreshUI(h_viewParams[view]);
}
void RenderPlugin::viewUnlinked(View* view)
{
h_viewParams.remove(view);
View* current = m_window->getCurrentView();
if(isLinkedToView(current))
m_dockTab->refreshUI(h_viewParams[current]);
}
void RenderPlugin::currentViewChanged(View* view)
{
TabParams* params = h_viewParams[view];
m_dockTab->check_renderVertices->setChecked(params->renderVertices);
m_dockTab->slider_verticesScaleFactor->setSliderPosition(params->verticesScaleFactor * 50.0);
m_dockTab->check_renderEdges->setChecked(params->renderEdges);
m_dockTab->check_renderFaces->setChecked(params->renderFaces);
m_dockTab->radio_flatShading->setChecked(params->faceStyle == FLAT);
m_dockTab->radio_phongShading->setChecked(params->faceStyle == PHONG);
assert(isLinkedToView(view));
m_dockTab->refreshUI(h_viewParams[view]);
}
void RenderPlugin::cb_renderVerticesChanged(bool b)
......@@ -120,7 +119,7 @@ void RenderPlugin::cb_renderVerticesChanged(bool b)
View* current = m_window->getCurrentView();
assert(isLinkedToView(current));
TabParams* params = h_viewParams[current];
ParameterSet* params = h_viewParams[current];
params->renderVertices = b;
current->updateGL();
}
......@@ -130,7 +129,7 @@ void RenderPlugin::cb_verticesScaleFactorChanged(int i)
View* current = m_window->getCurrentView();
assert(isLinkedToView(current));
TabParams* params = h_viewParams[current];
ParameterSet* params = h_viewParams[current];
params->verticesScaleFactor = i / 50.0;
current->updateGL();
}
......@@ -140,7 +139,7 @@ void RenderPlugin::cb_renderEdgesChanged(bool b)
View* current = m_window->getCurrentView();
assert(isLinkedToView(current));
TabParams* params = h_viewParams[current];
ParameterSet* params = h_viewParams[current];
params->renderEdges = b;
current->updateGL();
}
......@@ -150,7 +149,7 @@ void RenderPlugin::cb_renderFacesChanged(bool b)
View* current = m_window->getCurrentView();
assert(isLinkedToView(current));
TabParams* params = h_viewParams[current];
ParameterSet* params = h_viewParams[current];
params->renderFaces = b;
current->updateGL();
}
......@@ -160,7 +159,7 @@ void RenderPlugin::cb_faceStyleChanged(QAbstractButton* b)
View* current = m_window->getCurrentView();
assert(isLinkedToView(current));
TabParams* params = h_viewParams[current];
ParameterSet* params = h_viewParams[current];
if(m_dockTab->radio_flatShading->isChecked())
params->faceStyle = FLAT;
else if(m_dockTab->radio_phongShading->isChecked())
......@@ -168,6 +167,21 @@ void RenderPlugin::cb_faceStyleChanged(QAbstractButton* b)
current->updateGL();
}
void RenderDockTab::refreshUI(ParameterSet* params)
{
check_renderVertices->setChecked(params->renderVertices);
slider_verticesScaleFactor->setSliderPosition(params->verticesScaleFactor * 50.0);
check_renderEdges->setChecked(params->renderEdges);
check_renderFaces->setChecked(params->renderFaces);
radio_flatShading->setChecked(params->faceStyle == FLAT);
radio_phongShading->setChecked(params->faceStyle == PHONG);
}
/**
* If we want to compile this plugin in debug mode,
* we also define a DEBUG macro at the compilation
......
......@@ -18,27 +18,20 @@ using namespace CGoGN;
using namespace SCHNApps;
class RenderDockTab : public QWidget, public Ui::RenderWidget
{
public:
RenderDockTab() { setupUi(this); }
};
enum FaceShadingStyle
{
FLAT = 0,
PHONG = 1
};
struct TabParams
struct ParameterSet
{
TabParams(float vsf, bool rv, bool re, bool rf, FaceShadingStyle fstyle) :
verticesScaleFactor(vsf),
renderVertices(rv),
renderEdges(re),
renderFaces(rf),
faceStyle(fstyle)
ParameterSet() :
verticesScaleFactor(1.0f),
renderVertices(false),
renderEdges(false),
renderFaces(true),
faceStyle(FLAT)
{}
float verticesScaleFactor;
......@@ -49,6 +42,15 @@ struct TabParams
};
class RenderDockTab : public QWidget, public Ui::RenderWidget
{
public:
RenderDockTab() { setupUi(this); }
void refreshUI(ParameterSet* params);
};
class RenderPlugin : public Plugin
{
Q_OBJECT
......@@ -84,7 +86,7 @@ public:
protected:
RenderDockTab* m_dockTab;
QHash<View*, TabParams*> h_viewParams;
QHash<View*, ParameterSet*> h_viewParams;
CGoGN::Utils::ShaderFlat* m_flatShader;
CGoGN::Utils::ShaderPhong* m_phongShader;
......
......@@ -6,7 +6,7 @@
bool RenderVectorPlugin::enable()
{
m_dockTab = new RenderVectorDockTab();
m_dockTab = new RenderVectorDockTab(this);
addTabInDock(m_dockTab, "RenderVector");
m_vectorShader = new Utils::ShaderVectorPerVertex() ;
......@@ -30,13 +30,12 @@ void RenderVectorPlugin::disable()
void RenderVectorPlugin::redraw(View* view)
{
TabParams* params = h_viewParams[view];
ParameterSet* params = h_viewParams[view];
const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
foreach(MapHandlerGen* m, maps)
{
std::cout << "draw map " << m->getName().toUtf8().constData() << std::endl;
const PerMapTabParams& p = params->perMap[m->getName()];
const PerMapParameterSet& p = params->perMap[m->getName()];
if(p.positionVBO != NULL && p.vectorVBO != NULL)
{
m_vectorShader->setScale(m->getBBdiagSize() / 100.0f * p.vectorsScaleFactor) ;
......@@ -50,251 +49,168 @@ void RenderVectorPlugin::redraw(View* view)
void RenderVectorPlugin::viewLinked(View* view)
{
TabParams* params = new TabParams();
ParameterSet* params = new ParameterSet();
h_viewParams.insert(view, params);
m_dockTab->mapList->clear();
const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
if(maps.empty())
params->selectedMap = NULL;
else
foreach(MapHandlerGen* map, maps)
{
params->selectedMap = maps[0];
for(int i = 0; i < maps.count(); ++i)
{
PerMapTabParams p(NULL, NULL, 1.0f);
params->perMap.insert(maps[i]->getName(), p);
m_dockTab->mapList->addItem(maps[i]->getName());
if(maps[i] == params->selectedMap)
{
m_dockTab->mapList->item(i)->setSelected(true);
m_dockTab->combo_positionVBO->clear();
m_dockTab->combo_vectorVBO->clear();
QList<Utils::VBO*> vbos = maps[i]->getVBOList();
for(int j = 0; j < vbos.count(); ++j)
{
m_dockTab->combo_positionVBO->addItem(QString::fromStdString(vbos[j]->name()));
m_dockTab->combo_vectorVBO->addItem(QString::fromStdString(vbos[j]->name()));
}
if(vbos.count() > 0)
{
p.positionVBO = vbos[0];
m_dockTab->combo_positionVBO->setCurrentIndex(0);
p.vectorVBO = vbos[0];
m_dockTab->combo_vectorVBO->setCurrentIndex(0);
}
}
}
PerMapParameterSet p;
params->perMap.insert(map->getName(), p);
}
m_dockTab->refreshUI(params);
}
void RenderVectorPlugin::viewUnlinked(View* view)
{
h_viewParams.remove(view);
View* current = m_window->getCurrentView();
if(isLinkedToView(current))
m_dockTab->refreshUI(h_viewParams[current]);
}
void RenderVectorPlugin::currentViewChanged(View* view)
{
m_dockTab->refreshUI(h_viewParams[view]);
}
void RenderVectorPlugin::mapLinked(View* view, MapHandlerGen* m)
{
assert(isLinkedToView(view));
TabParams* params = h_viewParams[view];
PerMapTabParams p(NULL, NULL, 1.0f);
ParameterSet* params = h_viewParams[view];
PerMapParameterSet p;
params->perMap.insert(m->getName(), p);
m_dockTab->mapList->addItem(m->getName());
m_dockTab->refreshUI(params);
}
void RenderVectorPlugin::mapUnlinked(View* view, MapHandlerGen* m)
{
assert(isLinkedToView(view));
TabParams* params = h_viewParams[view];
ParameterSet* params = h_viewParams[view];
params->perMap.remove(m->getName());
// 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;
// }
// }
if(params->selectedMap == m)
{
params->selectedMap = NULL;
m_dockTab->refreshUI(params);
}
}
void RenderVectorPlugin::currentViewChanged(View* view)
void RenderVectorPlugin::cb_selectedMapChanged()
{
TabParams* params = h_viewParams[view];
m_dockTab->mapList->clear();
const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
for(int i = 0; i < maps.count(); ++i)
if(!b_refreshingUI)
{
m_dockTab->mapList->addItem(maps[i]->getName());
if(maps[i] == params->selectedMap)
View* view = m_window->getCurrentView();
ParameterSet* params = h_viewParams[view];
QList<QListWidgetItem*> currentItems = m_dockTab->mapList->selectedItems();
if(!currentItems.empty())
{
m_dockTab->mapList->item(i)->setSelected(true);
PerMapTabParams p = params->perMap[maps[i]->getName()];
m_dockTab->slider_vectorsScaleFactor->setSliderPosition(p.vectorsScaleFactor * 50.0);
m_dockTab->combo_positionVBO->clear();
m_dockTab->combo_vectorVBO->clear();
QList<Utils::VBO*> vbos = maps[i]->getVBOList();
for(int j = 0; j < vbos.count(); ++j)
{
m_dockTab->combo_positionVBO->addItem(QString::fromStdString(vbos[j]->name()));
if(vbos[j] == p.positionVBO)
m_dockTab->combo_positionVBO->setCurrentIndex(j);
m_dockTab->combo_vectorVBO->addItem(QString::fromStdString(vbos[j]->name()));
if(vbos[j] == p.vectorVBO)
m_dockTab->combo_vectorVBO->setCurrentIndex(j);
}
if(p.positionVBO == NULL && vbos.count() > 0)
m_dockTab->combo_positionVBO->setCurrentIndex(0);
if(p.vectorVBO == NULL && vbos.count() > 0)
m_dockTab->combo_vectorVBO->setCurrentIndex(0);
const QString& mapname = currentItems[0]->text();
params->selectedMap = m_window->getMap(mapname);
m_dockTab->refreshUI(params);
view->updateGL();
}
}
}
void RenderVectorPlugin::refreshTabInfo()
void RenderVectorPlugin::cb_positionVBOChanged(int index)
{
m_dockTab->mapList->clear();
m_dockTab->combo_positionVBO->clear();
m_dockTab->combo_vectorVBO->clear();
View* view = m_window->getCurrentView();
assert(isLinkedToView(view));
TabParams* params = h_viewParams[view];
MapHandlerGen* map = params->selectedMap;
const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
for(int i = 0; i < maps.count(); ++i)
if(!b_refreshingUI)
{
m_dockTab->mapList->addItem(maps[i]->getName());
if(maps[i] == map)
m_dockTab->mapList->item(i)->setSelected(true);
View* current = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current];
MapHandlerGen* map = params->selectedMap;
params->perMap[map->getName()].positionVBO = map->getVBO(m_dockTab->combo_positionVBO->currentText());
current->updateGL();
}
}
if(map != NULL)
void RenderVectorPlugin::cb_vectorVBOChanged(int index)
{
if(!b_refreshingUI)
{
PerMapTabParams p = params->perMap[map->getName()];
m_dockTab->slider_vectorsScaleFactor->setSliderPosition(p.vectorsScaleFactor * 50.0);
QList<Utils::VBO*> vbos = map->getVBOList();
for(int i = 0; i < vbos.count(); ++i)
{
m_dockTab->combo_positionVBO->addItem(QString::fromStdString(vbos[i]->name()));
if(vbos[i] == p.positionVBO)
m_dockTab->combo_positionVBO->setCurrentIndex(i);
m_dockTab->combo_vectorVBO->addItem(QString::fromStdString(vbos[i]->name()));
if(vbos[i] == p.vectorVBO)
m_dockTab->combo_vectorVBO->setCurrentIndex(i);
}
if(p.positionVBO == NULL && vbos.count() > 0)
{
p.positionVBO = vbos[0];
m_dockTab->combo_positionVBO->setCurrentIndex(0);
}
if(p.vectorVBO == NULL && vbos.count() > 0)
{
p.vectorVBO = vbos[0];
m_dockTab->combo_vectorVBO->setCurrentIndex(0);
}
View* current = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current];
MapHandlerGen* map = params->selectedMap;
params->perMap[map->getName()].vectorVBO = map->getVBO(m_dockTab->combo_vectorVBO->currentText());
current->updateGL();
}
}
void RenderVectorPlugin::cb_selectedMapChanged()
void RenderVectorPlugin::cb_refreshVBOs()
{
View* current = m_window->getCurrentView();
assert(isLinkedToView(current));
TabParams* params = h_viewParams[current];
if(isLinkedToView(current))
m_dockTab->refreshUI(h_viewParams[current]);
}
QList<QListWidgetItem*> currentItems = m_dockTab->mapList->selectedItems();
if(!currentItems.empty())
void RenderVectorPlugin::cb_vectorsScaleFactorChanged(int i)
{
if(!b_refreshingUI)
{
const QString& mapname = currentItems[0]->text();
MapHandlerGen* m = m_window->getMap(mapname);
params->selectedMap = m;
PerMapTabParams p = params->perMap[m->getName()];
m_dockTab->combo_positionVBO->clear();
m_dockTab->combo_vectorVBO->clear();
QList<Utils::VBO*> vbos = m->getVBOList();
for(int j = 0; j < vbos.count(); ++j)
{
m_dockTab->combo_positionVBO->addItem(QString::fromStdString(vbos[j]->name()));
if(vbos[j] == p.positionVBO)
m_dockTab->combo_positionVBO->setCurrentIndex(j);
m_dockTab->combo_vectorVBO->addItem(QString::fromStdString(vbos[j]->name()));
if(vbos[j] == p.vectorVBO)
m_dockTab->combo_vectorVBO->setCurrentIndex(j);
}
if(p.positionVBO == NULL && vbos.count() > 0)
m_dockTab->combo_positionVBO->setCurrentIndex(0);
if(p.vectorVBO == NULL && vbos.count() > 0)
m_dockTab->combo_vectorVBO->setCurrentIndex(0);
View* current = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current];
MapHandlerGen* m = params->selectedMap;
params->perMap[m->getName()].vectorsScaleFactor = i / 50.0;
current->updateGL();
}
}
void RenderVectorPlugin::cb_positionVBOChanged(int index)
{
View* current = m_window->getCurrentView();
assert(isLinkedToView(current));
TabParams* params = h_viewParams[current];
MapHandlerGen* m = params->selectedMap;
params->perMap[m->getName()].positionVBO = m->getVBO(m_dockTab->combo_positionVBO->currentText());
current->updateGL();
}
void RenderVectorPlugin::cb_vectorVBOChanged(int index)
void RenderVectorDockTab::refreshUI(ParameterSet* params)
{
View* current = m_window->getCurrentView();
assert(isLinkedToView(current));
plugin->setRefreshingUI(true);
TabParams* params = h_viewParams[current];
MapHandlerGen* m = params->selectedMap;
params->perMap[m->getName()].vectorVBO = m->getVBO(m_dockTab->combo_vectorVBO->currentText());
current->updateGL();
}
mapList->clear();
combo_positionVBO->clear();
combo_vectorVBO->clear();
void RenderVectorPlugin::cb_refreshVBOs()
{
View* current = m_window->getCurrentView();
assert(isLinkedToView(current));
MapHandlerGen* map = params->selectedMap;
TabParams* params = h_viewParams[current];
MapHandlerGen* m = params->selectedMap;
if(m != NULL)
QHash<QString, PerMapParameterSet>::const_iterator i = params->perMap.constBegin();
while (i != params->perMap.constEnd())
{
PerMapTabParams p = params->perMap[m->getName()];
p.positionVBO = NULL;
p.vectorVBO = NULL;
m_dockTab->combo_positionVBO->clear();
m_dockTab->combo_vectorVBO->clear();
QList<Utils::VBO*> vbos = m->getVBOList();
for(int j = 0; j < vbos.count(); ++j)
mapList->addItem(i.key());
if(map != NULL && i.key() == map->getName())
{
m_dockTab->combo_positionVBO->addItem(QString::fromStdString(vbos[j]->name()));
m_dockTab->combo_vectorVBO->addItem(QString::fromStdString(vbos[j]->name()));
}
if(vbos.count() > 0)
{
p.positionVBO = vbos[0];
m_dockTab->combo_positionVBO->setCurrentIndex(0);
p.vectorVBO = vbos[0];
m_dockTab->combo_vectorVBO->setCurrentIndex(0);
QList<QListWidgetItem*> item = mapList->findItems(map->getName(), Qt::MatchExactly);
item[0]->setSelected(true);
PerMapParameterSet& p = params->perMap[map->getName()];
slider_vectorsScaleFactor->setSliderPosition(p.vectorsScaleFactor * 50.0);
QList<Utils::VBO*> vbos = map->getVBOList();
for(int i = 0; i < vbos.count(); ++i)
{
combo_positionVBO->addItem(QString::fromStdString(vbos[i]->name()));
if(vbos[i] == p.positionVBO)
combo_positionVBO->setCurrentIndex(i);
combo_vectorVBO->addItem(QString::fromStdString(vbos[i]->name()));
if(vbos[i] == p.vectorVBO)
combo_vectorVBO->setCurrentIndex(i);
}
if(p.positionVBO == NULL && vbos.count() > 0)
{
p.positionVBO = vbos[0];
combo_positionVBO->setCurrentIndex(0);
}
if(p.vectorVBO == NULL && vbos.count() > 0)
{
p.vectorVBO = vbos[0];
combo_vectorVBO->setCurrentIndex(0);
}
}
++i;
}
plugin->setRefreshingUI(false);
}
void RenderVectorPlugin::cb_vectorsScaleFactorChanged(int i)
{
View* current = m_window->getCurrentView();
assert(isLinkedToView(current));
TabParams* params = h_viewParams[current];
MapHandlerGen* m = params->selectedMap;
params->perMap[m->getName()].vectorsScaleFactor = i / 50.0;
current->updateGL();
}
/**
* If we want to compile this plugin in debug mode,
......
......@@ -15,17 +15,12 @@ using namespace CGoGN;
using namespace SCHNApps;
class RenderVectorDockTab : public QWidget, public Ui::RenderVectorWidget
{
public:
RenderVectorDockTab() { setupUi(this); }
};
struct PerMapTabParams
struct PerMapParameterSet
{
PerMapTabParams() {}
PerMapParameterSet() : positionVBO(NULL), vectorVBO(NULL), vectorsScaleFactor(1.0f)
{}
PerMapTabParams(Utils::VBO* pos, Utils::VBO* vec, float s) :
PerMapParameterSet(Utils::VBO* pos, Utils::VBO* vec, float s) :
positionVBO(pos),
vectorVBO(vec),
vectorsScaleFactor(s)
......@@ -36,20 +31,40 @@ struct PerMapTabParams
float vectorsScaleFactor;
};
struct TabParams
struct ParameterSet
{
QHash<QString, PerMapTabParams> perMap;
ParameterSet() : selectedMap(NULL)
{}
QHash<QString, PerMapParameterSet> perMap;
MapHandlerGen* selectedMap;
};
class RenderVectorPlugin;
class RenderVectorDockTab : public QWidget, public Ui::RenderVectorWidget
{
public:
RenderVectorDockTab(RenderVectorPlugin* p) : plugin(p)
{
setupUi(this);
}