Commit 1346483a authored by Pierre Kraemer's avatar Pierre Kraemer

new plugin : surface render scalar

parent 5b63bed6
......@@ -3,5 +3,6 @@ cmake_minimum_required(VERSION 2.8)
ADD_SUBDIRECTORY(surface_import)
ADD_SUBDIRECTORY(surface_render)
ADD_SUBDIRECTORY(surface_renderVector)
ADD_SUBDIRECTORY(surface_renderScalar)
ADD_SUBDIRECTORY(surface_differentialProperties)
ADD_SUBDIRECTORY(surface_subdivision)
cmake_minimum_required(VERSION 2.8)
SET( PLUGIN_NAME RenderScalar )
SET( PLUGIN_NAME Surface_RenderScalar )
SET( PLUGIN_ROOT_DIR ${SCHNApps_ROOT_DIR}/Plugins/renderScalar )
SET( PLUGIN_ROOT_DIR ${SCHNApps_ROOT_DIR}/Plugins/surface_renderScalar )
INCLUDE_DIRECTORIES(
${PLUGIN_ROOT_DIR}/include
......@@ -25,8 +25,8 @@ file(
SET(
PLUGIN_QOBJECT_FILES
${PLUGIN_ROOT_DIR}/include/renderScalar.h
${PLUGIN_ROOT_DIR}/include/renderScalarDockTab.h
${PLUGIN_ROOT_DIR}/include/surface_renderScalar.h
${PLUGIN_ROOT_DIR}/include/surface_renderScalar_dockTab.h
)
include( ${SCHNApps_ROOT_DIR}/Plugins/plugins_cmake.txt )
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RenderScalarDockWidget</class>
<widget class="QWidget" name="RenderScalarDockWidget">
<class>Surface_RenderScalar_TabWidget</class>
<widget class="QWidget" name="Surface_RenderScalar_TabWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>181</width>
<height>545</height>
<width>200</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="4">
<widget class="QListWidget" name="mapList"/>
</item>
<item row="1" column="0">
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Position :</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="3">
<item row="0" column="2" colspan="2">
<widget class="QComboBox" name="combo_positionVBO">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
......@@ -32,30 +29,72 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>- select VBO -</string>
</property>
</item>
</widget>
</item>
<item row="2" column="0">
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Scalar :</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="4">
<item row="2" column="0" colspan="4">
<widget class="QListWidget" name="list_scalarVBO">
<property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum>
<enum>QAbstractItemView::SingleSelection</enum>
</property>
</widget>
</item>
<item row="3" column="0" colspan="3">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Colormap :</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<item row="3" column="3">
<widget class="QComboBox" name="combo_colorMap">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>BWR</string>
</property>
</item>
<item>
<property name="text">
<string>CWR</string>
</property>
</item>
<item>
<property name="text">
<string>BCGYR</string>
</property>
</item>
<item>
<property name="text">
<string>BGR</string>
</property>
</item>
</widget>
</item>
<item row="4" column="0" colspan="3">
<widget class="QLabel" name="label">
<property name="text">
<string>Expansion :</string>
</property>
</widget>
</item>
<item row="5" column="2" colspan="2">
<item row="4" column="3">
<widget class="QSlider" name="slider_expansion">
<property name="maximum">
<number>10</number>
......@@ -68,7 +107,7 @@
</property>
</widget>
</item>
<item row="6" column="0" colspan="4">
<item row="5" column="1" colspan="3">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -81,37 +120,6 @@
</property>
</spacer>
</item>
<item row="4" column="0" colspan="2">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Colormap :</string>
</property>
</widget>
</item>
<item row="4" column="2" colspan="2">
<widget class="QComboBox" name="combo_colorMap">
<item>
<property name="text">
<string>BlueWhiteRed</string>
</property>
</item>
<item>
<property name="text">
<string>CyanWhiteRed</string>
</property>
</item>
<item>
<property name="text">
<string>BlueCyanGreenYellowRed</string>
</property>
</item>
<item>
<property name="text">
<string>BlueGreenRed</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
<resources/>
......
#ifndef _RENDERSCALAR_DOCK_TAB_H_
#define _RENDERSCALAR_DOCK_TAB_H_
#include "ui_renderScalar.h"
#include "Utils/vbo.h"
namespace CGoGN
{
namespace SCHNApps
{
class Window;
class RenderScalarPlugin;
struct ParameterSet;
class RenderScalarDockTab : public QWidget, public Ui::RenderScalarDockWidget
{
Q_OBJECT
public:
RenderScalarDockTab(Window* w, RenderScalarPlugin* p);
private:
Window* m_window;
RenderScalarPlugin* m_plugin;
ParameterSet* m_currentParams;
bool b_refreshingUI;
public slots:
void refreshUI(ParameterSet* params);
void selectedMapChanged();
void positionVBOChanged(int index);
void selectedScalarVBOChanged();
void colorMapChanged(int index);
void expansionChanged(int i);
void addVBOToList(Utils::VBO* vbo);
};
} // namespace SCHNApps
} // namespace CGoGN
#endif
#ifndef _RENDERSCALAR_PLUGIN_H_
#define _RENDERSCALAR_PLUGIN_H_
#ifndef _SURFACE_RENDERSCALAR_PLUGIN_H_
#define _SURFACE_RENDERSCALAR_PLUGIN_H_
#include "plugin.h"
#include "renderScalarDockTab.h"
#include "plugin_interaction.h"
#include "surface_renderScalar_dockTab.h"
#include "Utils/Shaders/shaderScalarField.h"
......@@ -19,14 +19,17 @@ enum ColorMap {
BlueGreenRed = 3
};
struct PerMapParameterSet
struct MapParameters
{
PerMapParameterSet() :
positionVBO(NULL)
MapParameters() :
positionVBO(NULL),
scalarVBO(NULL),
scalarMin(0.0f),
scalarMax(0.0f),
colorMap(0),
expansion(0)
{}
PerMapParameterSet(MapHandlerGen* map);
Utils::VBO* positionVBO;
Utils::VBO* scalarVBO;
float scalarMin, scalarMax;
......@@ -34,34 +37,25 @@ struct PerMapParameterSet
int expansion;
};
struct ParameterSet
{
ParameterSet() : selectedMap(NULL)
{}
QHash<QString, PerMapParameterSet*> perMap;
MapHandlerGen* selectedMap;
};
class RenderScalarPlugin : public Plugin
class Surface_RenderScalar_Plugin : public PluginInteraction
{
Q_OBJECT
Q_INTERFACES(CGoGN::SCHNApps::Plugin)
friend class Surface_RenderScalar_DockTab;
public:
RenderScalarPlugin()
{
setProvidesRendering(true);
}
Surface_RenderScalar_Plugin()
{}
~RenderScalarPlugin()
~Surface_RenderScalar_Plugin()
{}
virtual bool enable();
virtual void disable();
virtual void redraw(View *view);
virtual void draw(View *view) {}
virtual void drawMap(View* view, MapHandlerGen* map);
virtual void keyPress(View* view, QKeyEvent* event) {}
virtual void keyRelease(View* view, QKeyEvent* event) {}
......@@ -70,33 +64,34 @@ public:
virtual void mouseMove(View* view, QMouseEvent* event) {}
virtual void wheelEvent(View* view, QWheelEvent* event) {}
protected:
RenderScalarDockTab* m_dockTab;
QHash<View*, ParameterSet*> h_viewParams;
virtual void viewLinked(View *view) {}
virtual void viewUnlinked(View *view) {}
CGoGN::Utils::ShaderScalarField* m_scalarShader;
private slots:
// slots called from SCHNApps signals
void selectedViewChanged(View* prev, View* cur);
void selectedMapChanged(MapHandlerGen* prev, MapHandlerGen* cur);
void mapAdded(MapHandlerGen* map);
void mapRemoved(MapHandlerGen* map);
// slots called from MapHandler signals
void vboAdded(Utils::VBO* vbo);
void vboRemoved(Utils::VBO* vbo);
void attributeModified(unsigned int orbit, QString nameAttr);
public slots:
void viewLinked(View* view, Plugin* plugin);
void viewUnlinked(View* view, Plugin* plugin);
void currentViewChanged(View* view);
// slots for Python calls
void changePositionVBO(const QString& view, const QString& map, const QString& vbo);
void changeScalarVBO(const QString& view, const QString& map, const QString& vbo);
void changeColorMap(const QString& view, const QString& map, int c);
void changeExpansion(const QString& view, const QString& map, int i);
void mapLinked(MapHandlerGen* m);
void mapUnlinked(MapHandlerGen* m);
protected:
void addManagedMap(View *v, MapHandlerGen* m);
void removeManagedMap(View *v, MapHandlerGen* m);
Surface_RenderScalar_DockTab* m_dockTab;
QHash<View*, QHash<MapHandlerGen*, MapParameters> > h_viewParameterSet;
public slots:
void changeSelectedMap(View* view, MapHandlerGen* map);
void changePositionVBO(View* view, MapHandlerGen* map, Utils::VBO* vbo, bool fromUI = false);
void changeScalarVBO(View* view, MapHandlerGen* map, Utils::VBO* vbo, bool fromUI = false);
void changeColorMap(View* view, MapHandlerGen* map, int c, bool fromUI = false);
void changeExpansion(View* view, MapHandlerGen* map, int i, bool fromUI = false);
void attributeModified(unsigned int orbit, QString nameAttr);
CGoGN::Utils::ShaderScalarField* m_scalarShader;
};
} // namespace SCHNApps
......
#ifndef _SURFACE_RENDERSCALAR_DOCK_TAB_H_
#define _SURFACE_RENDERSCALAR_DOCK_TAB_H_
#include "ui_surface_renderScalar.h"
#include "Utils/vbo.h"
namespace CGoGN
{
namespace SCHNApps
{
class SCHNApps;
class Surface_RenderScalar_Plugin;
struct MapParameters;
class Surface_RenderScalar_DockTab : public QWidget, public Ui::Surface_RenderScalar_TabWidget
{
Q_OBJECT
friend class Surface_RenderScalar_Plugin;
public:
Surface_RenderScalar_DockTab(SCHNApps* s, Surface_RenderScalar_Plugin* p);
private:
SCHNApps* m_schnapps;
Surface_RenderScalar_Plugin* m_plugin;
MapParameters* m_currentParams;
bool b_updatingUI;
private slots:
void positionVBOChanged(int index);
void selectedScalarVBOChanged();
void colorMapChanged(int index);
void expansionChanged(int i);
private:
void addPositionVBO(QString name);
void removePositionVBO(QString name);
void addScalarVBO(QString name);
void removeScalarVBO(QString name);
void updateMapParameters();
};
} // namespace SCHNApps
} // namespace CGoGN
#endif
#include "renderScalar.h"
#include "mapHandler.h"
namespace CGoGN
{
namespace SCHNApps
{
PerMapParameterSet::PerMapParameterSet(MapHandlerGen* map) :
positionVBO(NULL),
scalarVBO(NULL),
colorMap(BlueWhiteRed),
expansion(0)
{
bool positionFound = false;
QList<Utils::VBO*> vbos = map->getVBOList();
for(int i = 0; i < vbos.count(); ++i)
{
if(vbos[i]->dataSize() == 3)
{
if(!positionFound) positionVBO = vbos[i];
if(vbos[i]->name() == "position") // try to select a VBO named "position"
{
positionVBO = vbos[i];
positionFound = true;
}
}
}
}
bool RenderScalarPlugin::enable()
{
m_dockTab = new RenderScalarDockTab(m_window, this);
addTabInDock(m_dockTab, "RenderScalar");
m_scalarShader = new Utils::ShaderScalarField();
registerShader(m_scalarShader);
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*)));
return true;
}
void RenderScalarPlugin::disable()
{
delete m_scalarShader;
}
void RenderScalarPlugin::redraw(View* view)
{
ParameterSet* params = h_viewParams[view];
const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
foreach(MapHandlerGen* m, maps)
{
PerMapParameterSet* p = params->perMap[m->getName()];
if(p->positionVBO && p->scalarVBO)
{
m_scalarShader->setAttributePosition(p->positionVBO);
m_scalarShader->setAttributeScalar(p->scalarVBO);
m_scalarShader->setMinValue(p->scalarMin);
m_scalarShader->setMaxValue(p->scalarMax);
m_scalarShader->setColorMap(p->colorMap);
m_scalarShader->setExpansion(p->expansion);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f, 1.0f);
m->draw(m_scalarShader, Algo::Render::GL2::TRIANGLES);
glDisable(GL_POLYGON_OFFSET_FILL);
}
}
}
void RenderScalarPlugin::viewLinked(View* view, Plugin* plugin)
{
if(plugin == this)
{
ParameterSet* params = new ParameterSet();
h_viewParams.insert(view, params);
const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
foreach(MapHandlerGen* mh, maps)
addManagedMap(view, mh);
connect(view, SIGNAL(mapLinked(MapHandlerGen*)), this, SLOT(mapLinked(MapHandlerGen*)));
connect(view, SIGNAL(mapUnlinked(MapHandlerGen*)), this, SLOT(mapUnlinked(MapHandlerGen*)));
if(view->isCurrentView())
m_dockTab->refreshUI(params);
}
}
void RenderScalarPlugin::viewUnlinked(View* view, Plugin* plugin)
{
if(plugin == this)
{
const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
foreach(MapHandlerGen* mh, maps)
removeManagedMap(view, mh);
ParameterSet* params = h_viewParams[view];
delete params;
h_viewParams.remove(view);
disconnect(view, SIGNAL(mapLinked(MapHandlerGen*)), this, SLOT(mapLinked(MapHandlerGen*)));
disconnect(view, SIGNAL(mapUnlinked(MapHandlerGen*)), this, SLOT(mapUnlinked(MapHandlerGen*)));
}
}
void RenderScalarPlugin::currentViewChanged(View* view)
{
if(isLinkedToView(view))
m_dockTab->refreshUI(h_viewParams[view]);
}
void RenderScalarPlugin::mapLinked(MapHandlerGen* m)
{
View* view = static_cast<View*>(QObject::sender());
assert(isLinkedToView(view));
addManagedMap(view, m);
}
void RenderScalarPlugin::mapUnlinked(MapHandlerGen* m)
{
View* view = static_cast<View*>(QObject::sender());
assert(isLinkedToView(view));
removeManagedMap(view, m);
}
void RenderScalarPlugin::addManagedMap(View* v, MapHandlerGen *m)
{
connect(m, SIGNAL(attributeModified(unsigned int, QString)), this, SLOT(attributeModified(unsigned int, QString)));
// connect(m, SIGNAL(connectivityModified()), this, SLOT(connectivityModified()));
ParameterSet* params = h_viewParams[v];
PerMapParameterSet* perMap = new PerMapParameterSet(m);
params->perMap.insert(m->getName(), perMap);
if(params->selectedMap == NULL || params->perMap.count() == 1)
changeSelectedMap(v, m);
else
m_dockTab->refreshUI(params);
}
void RenderScalarPlugin::removeManagedMap(View *v, MapHandlerGen *m)
{
disconnect(m, SIGNAL(attributeModified(unsigned int, QString)), this, SLOT(attributeModified(unsigned int, QString)));
// disconnect(m, SIGNAL(connectivityModified()), this, SLOT(connectivityModified()));
ParameterSet* params = h_viewParams[v];
PerMapParameterSet* perMap = params->perMap[m->getName()];
delete perMap;
params->perMap.remove(m->getName());
if(params->selectedMap == m)
{
if(!params->perMap.empty())
changeSelectedMap(v, m_window->getMap(params->perMap.begin().key()));
else
changeSelectedMap(v, NULL);
}
else
m_dockTab->refreshUI(params);
}
void RenderScalarPlugin::changeSelectedMap(View* view, MapHandlerGen* map)
{
ParameterSet* params = h_viewParams[view];
MapHandlerGen* prev = params->selectedMap;
params->selectedMap = map;
if(view->isCurrentView())
{
if(prev)
disconnect(prev, SIGNAL(vboAdded(Utils::VBO*)), m_dockTab, SLOT(addVBOToList(Utils::VBO*)));
if(map)
connect(map, SIGNAL(vboAdded(Utils::VBO*)), m_dockTab, SLOT(addVBOToList(Utils::VBO*)));
m_dockTab->refreshUI(params);
}
}
void RenderScalarPlugin::changePositionVBO(View* view, MapHandlerGen* map, Utils::VBO* vbo, bool fromUI)
{
ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()]->positionVBO = vbo;
if(view->isCurrentView())
{
if(!fromUI)
m_dockTab->refreshUI(params);
view->updateGL();
}
}
void RenderScalarPlugin::changeScalarVBO(View* view, MapHandlerGen* map, Utils::VBO* vbo, bool fromUI)
{
ParameterSet* params = h_viewParams[view];
PerMapParameterSet* perMap = params->perMap[map->getName()];
perMap->scalarVBO = vbo;
if(vbo != NULL)
{
const VertexAttribute<PFP2::REAL>& attr = map->getAttribute<PFP2::REAL, VERTEX>(QString::fromStdString(vbo->name()));
perMap->scalarMin = 1e20;
perMap->scalarMax = -1e20;
for(unsigned int i = attr.begin(); i != attr.end(); attr.next(i))
{
perMap->scalarMin = attr[i] < perMap->scalarMin ? attr[i] : perMap->scalarMin;
perMap->scalarMax = attr[i] > perMap->scalarMax ? attr[i] : perMap->scalarMax;
}
}
if(view->isCurrentView())
{
if(!fromUI)
m_dockTab->refreshUI(params);
view->updateGL();