Commit 07b8b23d authored by untereiner's avatar untereiner

plugin renderTopoSurface ok

parent 46ecc50d
......@@ -6,6 +6,7 @@ ADD_SUBDIRECTORY(differentialProperties)
ADD_SUBDIRECTORY(render)
ADD_SUBDIRECTORY(renderVector)
ADD_SUBDIRECTORY(renderExplod)
ADD_SUBDIRECTORY(renderTopoSurface)
ADD_SUBDIRECTORY(subdivideSurface)
ADD_SUBDIRECTORY(surfaceDeformation)
ADD_SUBDIRECTORY(renderTopoSurface)
......@@ -36,8 +36,6 @@ public slots:
void renderFacesChanged(bool b);
void facesScaleFactorChanged(int i);
void volumesScaleFactorChanged(int i);
void addAttributeToList(unsigned int orbit, const QString& nameAttr);
};
} // namespace SCHNApps
......
......@@ -342,7 +342,7 @@ void RenderExplodPlugin::attributeModified(unsigned int orbit, QString nameAttr)
// if(params.positionName == nameAttr && params.autoUpdate)
// computeNormal(map->getName(), params.positionName, params.normalName);
// }
}
// }
}
void RenderExplodPlugin::connectivityModified()
......
......@@ -26,6 +26,7 @@ file(
SET(
PLUGIN_QOBJECT_FILES
${PLUGIN_ROOT_DIR}/include/renderTopoSurface.h
${PLUGIN_ROOT_DIR}/include/renderTopoSurfaceDockTab.h
)
include( ${SCHNApps_ROOT_DIR}/Plugins/plugins_cmake.txt )
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RenderWidget</class>
<widget class="QWidget" name="RenderWidget">
<class>RenderTopoSurfaceDockWidget</class>
<widget class="QWidget" name="RenderTopoSurfaceDockWidget">
<property name="geometry">
<rect>
<x>0</x>
......@@ -23,7 +23,7 @@
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item row="0" column="2">
<widget class="QComboBox" name="combo_positionVBO">
<widget class="QComboBox" name="combo_positionAttribute">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
......@@ -99,7 +99,4 @@
</widget>
<resources/>
<connections/>
<buttongroups>
<buttongroup name="group_faceShading"/>
</buttongroups>
</ui>
#ifndef _RENDER_PLUGIN_H_
#define _RENDER_PLUGIN_H_
#ifndef _RENDERTOPO_SURFACE_PLUGIN_H_
#define _RENDERTOPO_SURFACE_PLUGIN_H_
#include "plugin.h"
#include "ui_renderTopoSurface.h"
#include "renderTopoSurfaceDockTab.h"
#include "Algo/Render/GL2/topoRender.h"
using namespace CGoGN;
using namespace SCHNApps;
namespace CGoGN
{
namespace SCHNApps
{
struct PerMapParameterSet
{
PerMapParameterSet() :
edgesScaleFactor(1.0f),
facesScaleFactor(1.0f)
{
m_renderTopo = new Algo::Render::GL2::TopoRender();
}
PerMapParameterSet(MapHandlerGen* mh);
~PerMapParameterSet();
~PerMapParameterSet()
{
delete m_renderTopo;
}
void updateRender();
Algo::Render::GL2::TopoRender* m_renderTopo;
MapHandlerGen* mh;
VertexAttribute<PFP2::VEC3> positionAttribute;
float edgesScaleFactor;
float facesScaleFactor;
Algo::Render::GL2::TopoRender* m_renderTopo;
};
struct ParameterSet
......@@ -35,35 +32,18 @@ struct ParameterSet
ParameterSet() : selectedMap(NULL)
{}
QHash<QString, PerMapParameterSet> perMap;
QHash<QString, PerMapParameterSet*> perMap;
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
{
Q_OBJECT
Q_INTERFACES(CGoGN::SCHNApps::Plugin)
public:
RenderTopoSurfacePlugin() : b_refreshingUI(false)
RenderTopoSurfacePlugin()
{
setProvidesRendering(true);
}
......@@ -83,14 +63,11 @@ public:
virtual void mouseMove(View* view, QMouseEvent* event) {}
virtual void wheelEvent(View* view, QWheelEvent* event) {}
void setRefreshingUI(bool b) { b_refreshingUI = b; }
protected:
RenderDockTab* m_dockTab;
RenderTopoSurfaceDockTab* m_dockTab;
QHash<View*, ParameterSet*> h_viewParams;
bool b_refreshingUI;
public slots:
void viewLinked(View* view, Plugin* plugin);
void viewUnlinked(View* view, Plugin* plugin);
......@@ -99,13 +76,19 @@ public slots:
void mapLinked(MapHandlerGen* m);
void mapUnlinked(MapHandlerGen* m);
void changeSelectedMap(View* view, MapHandlerGen* map);
void changeEdgesScaleFactor(View* view, MapHandlerGen* map, int i);
void changeFacesScaleFactor(View* view, MapHandlerGen* map, int i);
void changeSelectedMap(View* view, MapHandlerGen* map, bool fromUI = false);
void changePositionAttribute(View* view, MapHandlerGen* map, VertexAttribute<PFP2::VEC3> attribute, bool fromUI = false);
void cb_selectedMapChanged();
void cb_edgesScaleFactorChanged(int i);
void cb_facesScaleFactorChanged(int i);
void changeEdgesScaleFactor(View* view, MapHandlerGen* map, int i, bool fromUI = false);
void changeFacesScaleFactor(View* view, MapHandlerGen* map, int i, bool fromUI = false);
void attributeModified(unsigned int orbit, QString nameAttr);
void connectivityModified();
};
} // namespace SCHNApps
} // namespace CGoGN
#endif
......@@ -2,15 +2,63 @@
#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()
{
m_dockTab = new RenderTopoSurfaceDockTab(this);
addTabInDock(m_dockTab, "RenderTopo");
m_dockTab = new RenderTopoSurfaceDockTab(m_window, this);
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(viewAndPluginUnlinked(View*, Plugin*)), this, SLOT(viewUnlinked(View*, Plugin*)));
connect(m_window, SIGNAL(currentViewChanged(View*)), this, SLOT(currentViewChanged(View*)));
......@@ -30,12 +78,14 @@ void RenderTopoSurfacePlugin::redraw(View* view)
const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
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)
ParameterSet* params = new ParameterSet();
h_viewParams.insert(view, params);
const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
foreach(MapHandlerGen* map, maps)
foreach(MapHandlerGen* mh, maps)
{
PerMapParameterSet p(map);
params->perMap.insert(map->getName(), p);
PerMapParameterSet* p = new PerMapParameterSet(mh);
registerShader(p->m_renderTopo->shader1());
registerShader(p->m_renderTopo->shader2());
params->perMap.insert(mh->getName(), p);
}
if (!maps.empty())
changeSelectedMap(view, maps[0]);
......@@ -76,7 +128,11 @@ void RenderTopoSurfacePlugin::viewUnlinked(View* view, Plugin* plugin)
void RenderTopoSurfacePlugin::currentViewChanged(View* view)
{
if(isLinkedToView(view))
{
// ParameterSet* params = h_viewParams[view];
// changeSelectedMap(view, params->selectedMap);
m_dockTab->refreshUI(h_viewParams[view]);
}
}
void RenderTopoSurfacePlugin::mapLinked(MapHandlerGen* m)
......@@ -84,9 +140,18 @@ void RenderTopoSurfacePlugin::mapLinked(MapHandlerGen* m)
View* view = static_cast<View*>(QObject::sender());
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];
PerMapParameterSet p(m);
PerMapParameterSet* p = new PerMapParameterSet(m);
registerShader(p->m_renderTopo->shader1());
registerShader(p->m_renderTopo->shader2());
params->perMap.insert(m->getName(), p);
if(params->selectedMap == NULL || params->perMap.count() == 1)
changeSelectedMap(view, m);
else
......@@ -98,6 +163,9 @@ void RenderTopoSurfacePlugin::mapUnlinked(MapHandlerGen* m)
View* view = static_cast<View*>(QObject::sender());
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];
params->perMap.remove(m->getName());
......@@ -112,7 +180,7 @@ void RenderTopoSurfacePlugin::mapUnlinked(MapHandlerGen* m)
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];
......@@ -121,104 +189,74 @@ void RenderTopoSurfacePlugin::changeSelectedMap(View* view, MapHandlerGen* map)
if(view->isCurrentView())
{
if(prev)
disconnect(map, SIGNAL(vboAdded(Utils::VBO*)), this, SLOT(vboAdded(Utils::VBO*)));
if(map)
connect(map, SIGNAL(vboAdded(Utils::VBO*)), this, SLOT(vboAdded(Utils::VBO*)));
if(!fromUI)
m_dockTab->refreshUI(params);
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];
params->perMap[map->getName()].edgesScaleFactor = i / 50.0;
PerMapParameterSet* perMap = params->perMap[map->getName()];
perMap->positionAttribute = attribute;
perMap->updateRender();
if(view->isCurrentView())
{
if(!fromUI)
m_dockTab->refreshUI(params);
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];
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(!fromUI)
m_dockTab->refreshUI(params);
view->updateGL();
}
}
void RenderTopoSurfacePlugin::cb_selectedMapChanged()
void RenderTopoSurfacePlugin::changeFacesScaleFactor(View* view, MapHandlerGen* map, int i, bool fromUI)
{
if(!b_refreshingUI)
{
QList<QListWidgetItem*> currentItems = m_dockTab->mapList->selectedItems();
if(!currentItems.empty())
changeSelectedMap(m_window->getCurrentView(), m_window->getMap(currentItems[0]->text()));
}
}
ParameterSet* params = h_viewParams[view];
PerMapParameterSet* perMap = params->perMap[map->getName()];
perMap->facesScaleFactor = i / 50.0;
perMap->updateRender();
void RenderTopoSurfacePlugin::cb_edgesScaleFactorChanged(int i)
{
if(!b_refreshingUI)
if(view->isCurrentView())
{
View* view = m_window->getCurrentView();
MapHandlerGen* map = h_viewParams[view]->selectedMap;
changeEdgesScaleFactor(view, map, i);
if(!fromUI)
m_dockTab->refreshUI(params);
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
Q_EXPORT_PLUGIN2(RenderTopoSurfacePlugin, RenderTopoSurfacePlugin)
#else
Q_EXPORT_PLUGIN2(RenderTopoSurfacePluginD, RenderTopoSurfacePlugin)
#endif
} // namespace SCHNApps
} // namespace CGoGN
......@@ -36,9 +36,9 @@
#include "Utils/vbo_base.h"
#include "Utils/svg.h"
// forward
namespace CGoGN { namespace Utils { class ShaderSimpleColor; } }
namespace CGoGN { namespace Utils { class ShaderColorPerVertex; } }
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/Shaders/shaderColorPerVertex.h"
namespace CGoGN
{
......@@ -285,6 +285,9 @@ public:
* @param ns distance shift
*/
void setBoundaryShift(float bs);
Utils::GLSLShader* shader1() { return static_cast<Utils::GLSLShader*>(m_shader1); }
Utils::GLSLShader* shader2() { return static_cast<Utils::GLSLShader*>(m_shader2); }
};
// just for compatibility with old code
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment