Commit 07b8b23d authored by untereiner's avatar untereiner

plugin renderTopoSurface ok

parent 46ecc50d
...@@ -6,6 +6,7 @@ ADD_SUBDIRECTORY(differentialProperties) ...@@ -6,6 +6,7 @@ ADD_SUBDIRECTORY(differentialProperties)
ADD_SUBDIRECTORY(render) ADD_SUBDIRECTORY(render)
ADD_SUBDIRECTORY(renderVector) ADD_SUBDIRECTORY(renderVector)
ADD_SUBDIRECTORY(renderExplod) ADD_SUBDIRECTORY(renderExplod)
ADD_SUBDIRECTORY(renderTopoSurface)
ADD_SUBDIRECTORY(subdivideSurface) ADD_SUBDIRECTORY(subdivideSurface)
ADD_SUBDIRECTORY(surfaceDeformation) ADD_SUBDIRECTORY(surfaceDeformation)
ADD_SUBDIRECTORY(renderTopoSurface)
...@@ -36,8 +36,6 @@ public slots: ...@@ -36,8 +36,6 @@ public slots:
void renderFacesChanged(bool b); void renderFacesChanged(bool b);
void facesScaleFactorChanged(int i); void facesScaleFactorChanged(int i);
void volumesScaleFactorChanged(int i); void volumesScaleFactorChanged(int i);
void addAttributeToList(unsigned int orbit, const QString& nameAttr);
}; };
} // namespace SCHNApps } // namespace SCHNApps
......
...@@ -342,7 +342,7 @@ void RenderExplodPlugin::attributeModified(unsigned int orbit, QString nameAttr) ...@@ -342,7 +342,7 @@ void RenderExplodPlugin::attributeModified(unsigned int orbit, QString nameAttr)
// if(params.positionName == nameAttr && params.autoUpdate) // if(params.positionName == nameAttr && params.autoUpdate)
// computeNormal(map->getName(), params.positionName, params.normalName); // computeNormal(map->getName(), params.positionName, params.normalName);
// } // }
} // }
} }
void RenderExplodPlugin::connectivityModified() void RenderExplodPlugin::connectivityModified()
......
...@@ -26,6 +26,7 @@ file( ...@@ -26,6 +26,7 @@ file(
SET( SET(
PLUGIN_QOBJECT_FILES PLUGIN_QOBJECT_FILES
${PLUGIN_ROOT_DIR}/include/renderTopoSurface.h ${PLUGIN_ROOT_DIR}/include/renderTopoSurface.h
${PLUGIN_ROOT_DIR}/include/renderTopoSurfaceDockTab.h
) )
include( ${SCHNApps_ROOT_DIR}/Plugins/plugins_cmake.txt ) include( ${SCHNApps_ROOT_DIR}/Plugins/plugins_cmake.txt )
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>RenderWidget</class> <class>RenderTopoSurfaceDockWidget</class>
<widget class="QWidget" name="RenderWidget"> <widget class="QWidget" name="RenderTopoSurfaceDockWidget">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
<enum>QLayout::SetDefaultConstraint</enum> <enum>QLayout::SetDefaultConstraint</enum>
</property> </property>
<item row="0" column="2"> <item row="0" column="2">
<widget class="QComboBox" name="combo_positionVBO"> <widget class="QComboBox" name="combo_positionAttribute">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
...@@ -99,7 +99,4 @@ ...@@ -99,7 +99,4 @@
</widget> </widget>
<resources/> <resources/>
<connections/> <connections/>
<buttongroups>
<buttongroup name="group_faceShading"/>
</buttongroups>
</ui> </ui>
#ifndef _RENDER_PLUGIN_H_ #ifndef _RENDERTOPO_SURFACE_PLUGIN_H_
#define _RENDER_PLUGIN_H_ #define _RENDERTOPO_SURFACE_PLUGIN_H_
#include "plugin.h" #include "plugin.h"
#include "ui_renderTopoSurface.h" #include "renderTopoSurfaceDockTab.h"
#include "Algo/Render/GL2/topoRender.h" #include "Algo/Render/GL2/topoRender.h"
using namespace CGoGN; namespace CGoGN
using namespace SCHNApps; {
namespace SCHNApps
{
struct PerMapParameterSet struct PerMapParameterSet
{ {
PerMapParameterSet() : PerMapParameterSet(MapHandlerGen* mh);
edgesScaleFactor(1.0f), ~PerMapParameterSet();
facesScaleFactor(1.0f)
{
m_renderTopo = new Algo::Render::GL2::TopoRender();
}
~PerMapParameterSet() void updateRender();
{
delete m_renderTopo; Algo::Render::GL2::TopoRender* m_renderTopo;
} MapHandlerGen* mh;
VertexAttribute<PFP2::VEC3> positionAttribute;
float edgesScaleFactor; float edgesScaleFactor;
float facesScaleFactor; float facesScaleFactor;
Algo::Render::GL2::TopoRender* m_renderTopo;
}; };
struct ParameterSet struct ParameterSet
...@@ -35,35 +32,18 @@ struct ParameterSet ...@@ -35,35 +32,18 @@ struct ParameterSet
ParameterSet() : selectedMap(NULL) ParameterSet() : selectedMap(NULL)
{} {}
QHash<QString, PerMapParameterSet> perMap; QHash<QString, PerMapParameterSet*> perMap;
MapHandlerGen* selectedMap; MapHandlerGen* selectedMap;
}; };
class RenderTopoSurfacePlugin;
class RenderTopoSurfaceDockTab : public QWidget, public Ui::RenderWidget
{
public:
RenderTopoSurfaceDockTab(RenderTopoSurfacePlugin* p) : plugin(p)
{
setupUi(this);
}
void refreshUI(ParameterSet* params);
private:
RenderTopoSurfacePlugin* plugin;
};
class RenderTopoSurfacePlugin : public Plugin class RenderTopoSurfacePlugin : public Plugin
{ {
Q_OBJECT Q_OBJECT
Q_INTERFACES(CGoGN::SCHNApps::Plugin) Q_INTERFACES(CGoGN::SCHNApps::Plugin)
public: public:
RenderTopoSurfacePlugin() : b_refreshingUI(false) RenderTopoSurfacePlugin()
{ {
setProvidesRendering(true); setProvidesRendering(true);
} }
...@@ -83,14 +63,11 @@ public: ...@@ -83,14 +63,11 @@ public:
virtual void mouseMove(View* view, QMouseEvent* event) {} virtual void mouseMove(View* view, QMouseEvent* event) {}
virtual void wheelEvent(View* view, QWheelEvent* event) {} virtual void wheelEvent(View* view, QWheelEvent* event) {}
void setRefreshingUI(bool b) { b_refreshingUI = b; }
protected: protected:
RenderDockTab* m_dockTab; RenderTopoSurfaceDockTab* m_dockTab;
QHash<View*, ParameterSet*> h_viewParams; QHash<View*, ParameterSet*> h_viewParams;
bool b_refreshingUI;
public slots: public slots:
void viewLinked(View* view, Plugin* plugin); void viewLinked(View* view, Plugin* plugin);
void viewUnlinked(View* view, Plugin* plugin); void viewUnlinked(View* view, Plugin* plugin);
...@@ -99,13 +76,19 @@ public slots: ...@@ -99,13 +76,19 @@ public slots:
void mapLinked(MapHandlerGen* m); void mapLinked(MapHandlerGen* m);
void mapUnlinked(MapHandlerGen* m); void mapUnlinked(MapHandlerGen* m);
void changeSelectedMap(View* view, MapHandlerGen* map); void changeSelectedMap(View* view, MapHandlerGen* map, bool fromUI = false);
void changeEdgesScaleFactor(View* view, MapHandlerGen* map, int i);
void changeFacesScaleFactor(View* view, MapHandlerGen* map, int i); void changePositionAttribute(View* view, MapHandlerGen* map, VertexAttribute<PFP2::VEC3> attribute, bool fromUI = false);
void cb_selectedMapChanged(); void changeEdgesScaleFactor(View* view, MapHandlerGen* map, int i, bool fromUI = false);
void cb_edgesScaleFactorChanged(int i); void changeFacesScaleFactor(View* view, MapHandlerGen* map, int i, bool fromUI = false);
void cb_facesScaleFactorChanged(int i);
void attributeModified(unsigned int orbit, QString nameAttr);
void connectivityModified();
}; };
} // namespace SCHNApps
} // namespace CGoGN
#endif #endif
...@@ -2,15 +2,63 @@ ...@@ -2,15 +2,63 @@
#include "mapHandler.h" #include "mapHandler.h"
namespace CGoGN
{
namespace SCHNApps
{
PerMapParameterSet::PerMapParameterSet(MapHandlerGen* m) :
mh(m),
edgesScaleFactor(1.0f),
facesScaleFactor(1.0f)
{
m_renderTopo = new Algo::Render::GL2::TopoRender();
std::cout << "plop" << std::endl;
QString positionName;
QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));
const AttributeHash& attribs = mh->getAttributesList(VERTEX);
for(AttributeHash::const_iterator i = attribs.constBegin(); i != attribs.constEnd(); ++i)
{
if(i.value() == vec3TypeName)
{
if(positionName != "position") // try to select an attribute named "position"
positionName = i.key(); // or anything else if not found
}
}
positionAttribute = mh->getAttribute<PFP2::VEC3, VERTEX>(positionName);
updateRender();
}
PerMapParameterSet::~PerMapParameterSet()
{
delete m_renderTopo;
}
void PerMapParameterSet::updateRender()
{
MapHandler<PFP2>* mh2 = static_cast<MapHandler<PFP2>*>(mh);
if(mh2 == NULL)
return;
PFP2::MAP* m = mh2->getMap();
m_renderTopo->updateData<PFP2>(*m,positionAttribute,edgesScaleFactor,facesScaleFactor);
std::cout << "update render " << std::endl;
}
bool RenderTopoSurfacePlugin::enable() bool RenderTopoSurfacePlugin::enable()
{ {
m_dockTab = new RenderTopoSurfaceDockTab(this); m_dockTab = new RenderTopoSurfaceDockTab(m_window, this);
addTabInDock(m_dockTab, "RenderTopo"); addTabInDock(m_dockTab, "RenderTopoSurface");
connect(m_dockTab->mapList, SIGNAL(itemSelectionChanged()), this, SLOT(cb_selectedMapChanged()));
connect(m_dockTab->slider_edgesScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(cb_edgesScaleFactorChanged(int)));
connect(m_dockTab->slider_facesScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(cb_facesScaleFactorChanged(int)));
connect(m_window, SIGNAL(viewAndPluginLinked(View*, Plugin*)), this, SLOT(viewLinked(View*, Plugin*))); connect(m_window, SIGNAL(viewAndPluginLinked(View*, Plugin*)), this, SLOT(viewLinked(View*, Plugin*)));
connect(m_window, SIGNAL(viewAndPluginUnlinked(View*, Plugin*)), this, SLOT(viewUnlinked(View*, Plugin*))); connect(m_window, SIGNAL(viewAndPluginUnlinked(View*, Plugin*)), this, SLOT(viewUnlinked(View*, Plugin*)));
connect(m_window, SIGNAL(currentViewChanged(View*)), this, SLOT(currentViewChanged(View*))); connect(m_window, SIGNAL(currentViewChanged(View*)), this, SLOT(currentViewChanged(View*)));
...@@ -30,12 +78,14 @@ void RenderTopoSurfacePlugin::redraw(View* view) ...@@ -30,12 +78,14 @@ void RenderTopoSurfacePlugin::redraw(View* view)
const QList<MapHandlerGen*>& maps = view->getLinkedMaps(); const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
foreach(MapHandlerGen* m, maps) foreach(MapHandlerGen* m, maps)
{ {
const PerMapParameterSet& p = params->perMap[m->getName()]; PerMapParameterSet* p = params->perMap[m->getName()];
if(p != NULL)
p->m_renderTopo->drawTopo();
// if (p->m_selectedDart != NIL)
// p->m_renderTopo->overdrawDart(m_selectedDart, 4.0f, 1.0f, 0.0f, 0.0f) ;
if(p.m_renderTopo != NULL)
{
p.m_renderTopo->drawTopo();
}
} }
} }
...@@ -46,10 +96,12 @@ void RenderTopoSurfacePlugin::viewLinked(View* view, Plugin* plugin) ...@@ -46,10 +96,12 @@ void RenderTopoSurfacePlugin::viewLinked(View* view, Plugin* plugin)
ParameterSet* params = new ParameterSet(); ParameterSet* params = new ParameterSet();
h_viewParams.insert(view, params); h_viewParams.insert(view, params);
const QList<MapHandlerGen*>& maps = view->getLinkedMaps(); const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
foreach(MapHandlerGen* map, maps) foreach(MapHandlerGen* mh, maps)
{ {
PerMapParameterSet p(map); PerMapParameterSet* p = new PerMapParameterSet(mh);
params->perMap.insert(map->getName(), p); registerShader(p->m_renderTopo->shader1());
registerShader(p->m_renderTopo->shader2());
params->perMap.insert(mh->getName(), p);
} }
if (!maps.empty()) if (!maps.empty())
changeSelectedMap(view, maps[0]); changeSelectedMap(view, maps[0]);
...@@ -76,7 +128,11 @@ void RenderTopoSurfacePlugin::viewUnlinked(View* view, Plugin* plugin) ...@@ -76,7 +128,11 @@ void RenderTopoSurfacePlugin::viewUnlinked(View* view, Plugin* plugin)
void RenderTopoSurfacePlugin::currentViewChanged(View* view) void RenderTopoSurfacePlugin::currentViewChanged(View* view)
{ {
if(isLinkedToView(view)) if(isLinkedToView(view))
{
// ParameterSet* params = h_viewParams[view];
// changeSelectedMap(view, params->selectedMap);
m_dockTab->refreshUI(h_viewParams[view]); m_dockTab->refreshUI(h_viewParams[view]);
}
} }
void RenderTopoSurfacePlugin::mapLinked(MapHandlerGen* m) void RenderTopoSurfacePlugin::mapLinked(MapHandlerGen* m)
...@@ -84,9 +140,18 @@ void RenderTopoSurfacePlugin::mapLinked(MapHandlerGen* m) ...@@ -84,9 +140,18 @@ void RenderTopoSurfacePlugin::mapLinked(MapHandlerGen* m)
View* view = static_cast<View*>(QObject::sender()); View* view = static_cast<View*>(QObject::sender());
assert(isLinkedToView(view)); assert(isLinkedToView(view));
connect(m, SIGNAL(attributeModified(unsigned int, QString)), this, SLOT(attributeModified(unsigned int, QString)));
connect(m, SIGNAL(connectivityModified()), this, SLOT(connectivityModified()));
ParameterSet* params = h_viewParams[view]; ParameterSet* params = h_viewParams[view];
PerMapParameterSet p(m);
PerMapParameterSet* p = new PerMapParameterSet(m);
registerShader(p->m_renderTopo->shader1());
registerShader(p->m_renderTopo->shader2());
params->perMap.insert(m->getName(), p); params->perMap.insert(m->getName(), p);
if(params->selectedMap == NULL || params->perMap.count() == 1) if(params->selectedMap == NULL || params->perMap.count() == 1)
changeSelectedMap(view, m); changeSelectedMap(view, m);
else else
...@@ -98,6 +163,9 @@ void RenderTopoSurfacePlugin::mapUnlinked(MapHandlerGen* m) ...@@ -98,6 +163,9 @@ void RenderTopoSurfacePlugin::mapUnlinked(MapHandlerGen* m)
View* view = static_cast<View*>(QObject::sender()); View* view = static_cast<View*>(QObject::sender());
assert(isLinkedToView(view)); assert(isLinkedToView(view));
disconnect(m, SIGNAL(attributeModified(unsigned int, QString)), this, SLOT(attributeModified(unsigned int, QString)));
disconnect(m, SIGNAL(connectivityModified()), this, SLOT(connectivityModified()));
ParameterSet* params = h_viewParams[view]; ParameterSet* params = h_viewParams[view];
params->perMap.remove(m->getName()); params->perMap.remove(m->getName());
...@@ -112,7 +180,7 @@ void RenderTopoSurfacePlugin::mapUnlinked(MapHandlerGen* m) ...@@ -112,7 +180,7 @@ void RenderTopoSurfacePlugin::mapUnlinked(MapHandlerGen* m)
m_dockTab->refreshUI(params); m_dockTab->refreshUI(params);
} }
void RenderTopoSurfacePlugin::changeSelectedMap(View* view, MapHandlerGen* map) void RenderTopoSurfacePlugin::changeSelectedMap(View* view, MapHandlerGen* map, bool fromUI)
{ {
ParameterSet* params = h_viewParams[view]; ParameterSet* params = h_viewParams[view];
...@@ -121,104 +189,74 @@ void RenderTopoSurfacePlugin::changeSelectedMap(View* view, MapHandlerGen* map) ...@@ -121,104 +189,74 @@ void RenderTopoSurfacePlugin::changeSelectedMap(View* view, MapHandlerGen* map)
if(view->isCurrentView()) if(view->isCurrentView())
{ {
if(prev) if(!fromUI)
disconnect(map, SIGNAL(vboAdded(Utils::VBO*)), this, SLOT(vboAdded(Utils::VBO*))); m_dockTab->refreshUI(params);
if(map)
connect(map, SIGNAL(vboAdded(Utils::VBO*)), this, SLOT(vboAdded(Utils::VBO*)));
m_dockTab->refreshUI(params);
view->updateGL(); view->updateGL();
} }
} }
void RenderTopoSurfacePlugin::changeEdgesScaleFactor(View* view, MapHandlerGen* map, int i) void RenderTopoSurfacePlugin::changePositionAttribute(View* view, MapHandlerGen* map, VertexAttribute<PFP2::VEC3> attribute, bool fromUI)
{ {
ParameterSet* params = h_viewParams[view]; ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()].edgesScaleFactor = i / 50.0; PerMapParameterSet* perMap = params->perMap[map->getName()];
perMap->positionAttribute = attribute;
perMap->updateRender();
if(view->isCurrentView()) if(view->isCurrentView())
{ {
m_dockTab->refreshUI(params); if(!fromUI)
m_dockTab->refreshUI(params);
view->updateGL(); view->updateGL();
} }
} }
void RenderTopoSurfacePlugin::changeFacesScaleFactor(View* view, MapHandlerGen* map, int i)
void RenderTopoSurfacePlugin::changeEdgesScaleFactor(View* view, MapHandlerGen* map, int i, bool fromUI)
{ {
ParameterSet* params = h_viewParams[view]; ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()].facesScaleFactor = i / 50.0; PerMapParameterSet* perMap = params->perMap[map->getName()];
perMap->edgesScaleFactor = i / 50.0;
perMap->updateRender();
if(view->isCurrentView()) if(view->isCurrentView())
{ {
m_dockTab->refreshUI(params); if(!fromUI)
m_dockTab->refreshUI(params);
view->updateGL(); view->updateGL();
} }
} }
void RenderTopoSurfacePlugin::cb_selectedMapChanged() void RenderTopoSurfacePlugin::changeFacesScaleFactor(View* view, MapHandlerGen* map, int i, bool fromUI)
{ {
if(!b_refreshingUI) ParameterSet* params = h_viewParams[view];
{ PerMapParameterSet* perMap = params->perMap[map->getName()];
QList<QListWidgetItem*> currentItems = m_dockTab->mapList->selectedItems(); perMap->facesScaleFactor = i / 50.0;
if(!currentItems.empty()) perMap->updateRender();
changeSelectedMap(m_window->getCurrentView(), m_window->getMap(currentItems[0]->text()));
}
}
void RenderTopoSurfacePlugin::cb_edgesScaleFactorChanged(int i) if(view->isCurrentView())
{
if(!b_refreshingUI)
{ {
View* view = m_window->getCurrentView(); if(!fromUI)
MapHandlerGen* map = h_viewParams[view]->selectedMap; m_dockTab->refreshUI(params);
changeEdgesScaleFactor(view, map, i); view->updateGL();
} }
} }
void RenderTopoSurfacePlugin::cb_facesScaleFactorChanged(int i) void RenderTopoSurfacePlugin::attributeModified(unsigned int orbit, QString nameAttr)
{ {
if(!b_refreshingUI)
{
View* view = m_window->getCurrentView();
MapHandlerGen* map = h_viewParams[view]->selectedMap;
changeFacesScaleFactor(view, map, i);
}
} }
void RenderDockTab::refreshUI(ParameterSet* params) void RenderTopoSurfacePlugin::connectivityModified()
{ {
plugin->setRefreshingUI(true);
mapList->clear();
combo_positionVBO->clear();
combo_normalVBO->clear();
MapHandlerGen* map = params->selectedMap;
QHash<QString, PerMapParameterSet>::const_iterator i = params->perMap.constBegin();
while (i != params->perMap.constEnd())
{
mapList->addItem(i.key());
if(map != NULL && i.key() == map->getName())
{
QList<QListWidgetItem*> item = mapList->findItems(map->getName(), Qt::MatchExactly);
item[0]->setSelected(true);
PerMapParameterSet& p = params->perMap[map->getName()];
slider_edgesScaleFactor->setSliderPosition(p.edgesScaleFactor * 50.0);
slider_facesScaleFactor->setSliderPosition(p.facesScaleFactor * 50.0);
}
++i;
}
plugin->setRefreshingUI(false);
} }
#ifndef DEBUG #ifndef DEBUG
Q_EXPORT_PLUGIN2(RenderTopoSurfacePlugin, RenderTopoSurfacePlugin) Q_EXPORT_PLUGIN2(RenderTopoSurfacePlugin, RenderTopoSurfacePlugin)
#else #else
Q_EXPORT_PLUGIN2(RenderTopoSurfacePluginD, RenderTopoSurfacePlugin) Q_EXPORT_PLUGIN2(RenderTopoSurfacePluginD, RenderTopoSurfacePlugin)
#endif #endif
} // namespace SCHNApps