Commit c990b7f8 authored by Pierre Kraemer's avatar Pierre Kraemer

start new renderScalar plugin

parent c4a807a7
......@@ -5,6 +5,7 @@ ADD_SUBDIRECTORY(importVolume)
ADD_SUBDIRECTORY(differentialProperties)
ADD_SUBDIRECTORY(render)
ADD_SUBDIRECTORY(renderVector)
ADD_SUBDIRECTORY(renderScalar)
ADD_SUBDIRECTORY(renderExplod)
ADD_SUBDIRECTORY(renderTopoSurface)
ADD_SUBDIRECTORY(subdivideSurface)
......
......@@ -29,7 +29,10 @@ ComputeCurvatureDialog::ComputeCurvatureDialog(Window* w) :
const QList<MapHandlerGen*>& maps = m_window->getMapsList();
foreach(MapHandlerGen* map, maps)
mapList->addItem(map->getName());
{
QListWidgetItem* item = new QListWidgetItem(map->getName(), mapList);
item->setCheckState(Qt::Unchecked);
}
}
void ComputeCurvatureDialog::selectedMapChanged()
......@@ -106,7 +109,8 @@ void ComputeCurvatureDialog::selectedMapChanged()
void ComputeCurvatureDialog::addMapToList(MapHandlerGen* m)
{
mapList->addItem(m->getName());
QListWidgetItem* item = new QListWidgetItem(m->getName(), mapList);
item->setCheckState(Qt::Unchecked);
}
void ComputeCurvatureDialog::removeMapFromList(MapHandlerGen* m)
......
......@@ -49,8 +49,19 @@ void DifferentialPropertiesPlugin::attributeModified(unsigned int orbit, QString
if(computeNormalLastParameters.contains(map->getName()))
{
ComputeNormalParameters& params = computeNormalLastParameters[map->getName()];
if(params.positionName == nameAttr && params.autoUpdate)
computeNormal(map->getName(), params.positionName, params.normalName);
if(params.autoUpdate && params.positionName == nameAttr)
computeNormal(map->getName(), params.positionName, params.normalName, true);
}
if(computeCurvatureLastParameters.contains(map->getName()))
{
ComputeCurvatureParameters& params = computeCurvatureLastParameters[map->getName()];
if(params.autoUpdate && (params.positionName == nameAttr || params.normalName == nameAttr))
computeCurvature(
map->getName(),
params.positionName, params.normalName,
params.KmaxName, params.kmaxName, params.KminName, params.kminName, params.KnormalName,
true
);
}
}
}
......
cmake_minimum_required(VERSION 2.8)
SET( PLUGIN_NAME RenderScalar )
SET( PLUGIN_ROOT_DIR ${SCHNApps_ROOT_DIR}/Plugins/renderScalar )
INCLUDE_DIRECTORIES(
${PLUGIN_ROOT_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}
)
file(
GLOB_RECURSE
PLUGIN_FILES
${PLUGIN_ROOT_DIR}/src/*.cpp
${PLUGIN_ROOT_DIR}/include/*.h
${PLUGIN_ROOT_DIR}/include/*.hpp
)
file(
GLOB_RECURSE
PLUGIN_UI_FILES
${PLUGIN_ROOT_DIR}/forms/*.ui
)
SET(
PLUGIN_QOBJECT_FILES
${PLUGIN_ROOT_DIR}/include/renderScalar.h
${PLUGIN_ROOT_DIR}/include/renderScalarDockTab.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">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>174</width>
<height>545</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="mapList"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Position :</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="combo_positionVBO">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Scalars :</string>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="list_scalarVBO">
<property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>156</width>
<height>161</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
#ifndef _RENDERSCALAR_PLUGIN_H_
#define _RENDERSCALAR_PLUGIN_H_
#include "plugin.h"
#include "renderScalarDockTab.h"
#include "Utils/Shaders/shaderScalarField.h"
namespace CGoGN
{
namespace SCHNApps
{
struct PerMapParameterSet
{
PerMapParameterSet() :
positionVBO(NULL)
{}
PerMapParameterSet(MapHandlerGen* map);
Utils::VBO* positionVBO;
std::vector<Utils::VBO*> scalarVBO;
};
struct ParameterSet
{
ParameterSet() : selectedMap(NULL)
{}
QHash<QString, PerMapParameterSet*> perMap;
MapHandlerGen* selectedMap;
};
class RenderScalarPlugin : public Plugin
{
Q_OBJECT
Q_INTERFACES(CGoGN::SCHNApps::Plugin)
public:
RenderScalarPlugin()
{
setProvidesRendering(true);
}
~RenderScalarPlugin()
{}
virtual bool enable();
virtual void disable();
virtual void redraw(View *view);
virtual void keyPress(View* view, QKeyEvent* event) {}
virtual void keyRelease(View* view, QKeyEvent* event) {}
virtual void mousePress(View* view, QMouseEvent* event) {}
virtual void mouseRelease(View* view, QMouseEvent* event) {}
virtual void mouseMove(View* view, QMouseEvent* event) {}
virtual void wheelEvent(View* view, QWheelEvent* event) {}
protected:
RenderScalarDockTab* m_dockTab;
QHash<View*, ParameterSet*> h_viewParams;
CGoGN::Utils::ShaderScalarField* m_scalarShader;
public slots:
void viewLinked(View* view, Plugin* plugin);
void viewUnlinked(View* view, Plugin* plugin);
void currentViewChanged(View* view);
void mapLinked(MapHandlerGen* m);
void mapUnlinked(MapHandlerGen* m);
protected:
void addManagedMap(View *v, MapHandlerGen* m);
void removeManagedMap(View *v, MapHandlerGen* m);
public slots:
void changeSelectedMap(View* view, MapHandlerGen* map);
void changePositionVBO(View* view, MapHandlerGen* map, Utils::VBO* vbo, bool fromUI = false);
void changeSelectedScalarsVBO(View* view, MapHandlerGen* map, const std::vector<Utils::VBO*>& vbos, bool fromUI = false);
};
} // namespace SCHNApps
} // namespace CGoGN
#endif
#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 selectedScalarsVBOChanged();
void addVBOToList(Utils::VBO* vbo);
};
} // namespace SCHNApps
} // namespace CGoGN
#endif
#include "renderScalar.h"
#include "mapHandler.h"
namespace CGoGN
{
namespace SCHNApps
{
PerMapParameterSet::PerMapParameterSet(MapHandlerGen* map) :
positionVBO(NULL)
{
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 != NULL)
{
m_scalarShader->setAttributePosition(p->positionVBO) ;
for(std::vector<Utils::VBO*>::const_iterator it = p->scalarVBO.begin(); it != p->scalarVBO.end(); ++it)
{
m_scalarShader->setAttributeScalar(*it) ;
m->draw(m_scalarShader, Algo::Render::GL2::TRIANGLES) ;
}
}
}
}
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::changeSelectedScalarsVBO(View* view, MapHandlerGen* map, const std::vector<Utils::VBO*>& vbos, bool fromUI)
{
ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()]->scalarVBO = vbos;
if(view->isCurrentView())
{
if(!fromUI)
m_dockTab->refreshUI(params);
view->updateGL();
}
}
#ifndef DEBUG
Q_EXPORT_PLUGIN2(RenderScalarPlugin, RenderScalarPlugin)
#else
Q_EXPORT_PLUGIN2(RenderScalarPluginD, RenderScalarPlugin)
#endif
} // namespace SCHNApps
} // namespace CGoGN
#include "renderScalarDockTab.h"
#include "renderScalar.h"
#include "window.h"
#include "mapHandler.h"
namespace CGoGN
{
namespace SCHNApps
{
RenderScalarDockTab::RenderScalarDockTab(Window* w, RenderScalarPlugin* p) :
m_window(w),
m_plugin(p),
b_refreshingUI(false)
{
setupUi(this);
connect(mapList, SIGNAL(itemSelectionChanged()), this, SLOT(selectedMapChanged()));
connect(combo_positionVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(positionVBOChanged(int)));
connect(list_scalarVBO, SIGNAL(itemSelectionChanged()), this, SLOT(selectedScalarsVBOChanged()));
}
void RenderScalarDockTab::refreshUI(ParameterSet* params)
{
m_currentParams = params;
b_refreshingUI = true;
mapList->clear();
combo_positionVBO->clear();
list_scalarVBO->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()];
QList<Utils::VBO*> vbos = map->getVBOList();
unsigned int j = 0;
for(int i = 0; i < vbos.count(); ++i)
{
unsigned int dataSize = vbos[i]->dataSize();
if(dataSize == 3)
{
combo_positionVBO->addItem(QString::fromStdString(vbos[i]->name()));
if(vbos[i] == p->positionVBO)
combo_positionVBO->setCurrentIndex(j);
++j;
}
else if(dataSize == 1)
{
list_scalarVBO->addItem(QString::fromStdString(vbos[i]->name()));
if(std::find(p->scalarVBO.begin(), p->scalarVBO.end(), vbos[i]) != p->scalarVBO.end())
list_scalarVBO->item(j)->setSelected(true);
}
}
}
++i;
}
b_refreshingUI = false;
}
void RenderScalarDockTab::selectedMapChanged()
{
if(!b_refreshingUI)
{
QList<QListWidgetItem*> currentItems = mapList->selectedItems();
if(!currentItems.empty())
m_plugin->changeSelectedMap(m_window->getCurrentView(), m_window->getMap(currentItems[0]->text()));
}
}
void RenderScalarDockTab::positionVBOChanged(int index)
{
if(!b_refreshingUI)
{
View* view = m_window->getCurrentView();
MapHandlerGen* map = m_currentParams->selectedMap;
m_plugin->changePositionVBO(view, map, map->getVBO(combo_positionVBO->currentText()), true);
}
}
void RenderScalarDockTab::selectedScalarsVBOChanged()
{
if(!b_refreshingUI)
{
View* view = m_window->getCurrentView();
MapHandlerGen* map = m_currentParams->selectedMap;
QList<QListWidgetItem*> currentItems = list_scalarVBO->selectedItems();
std::vector<Utils::VBO*> vbos;
foreach(QListWidgetItem* item, currentItems)
vbos.push_back(map->getVBO(item->text()));
m_plugin->changeSelectedScalarsVBO(view, map, vbos, true);
}
}
void RenderScalarDockTab::addVBOToList(Utils::VBO* vbo)
{
QString name = QString::fromStdString(vbo->name());
unsigned int dataSize = vbo->dataSize();
if(dataSize == 3)
combo_positionVBO->addItem(name);
else if(dataSize == 1)
list_scalarVBO->addItem(name);
}
} // namespace SCHNApps
} // namespace CGoGN
......@@ -2,8 +2,8 @@ importPlugin = schnapps.loadPlugin("ImportSurface");
renderPlugin = schnapps.loadPlugin("Render");
renderVectorPlugin = schnapps.loadPlugin("RenderVector");
renderTopoSurfacePlugin = schnapps.loadPlugin("RenderTopoSurface");
#differentialPropertiesPlugin = schnapps.loadPlugin("DifferentialProperties");
#subdivisionPlugin = schnapps.loadPlugin("SubdivideSurface");
differentialPropertiesPlugin = schnapps.loadPlugin("DifferentialProperties");
subdivisionPlugin = schnapps.loadPlugin("SubdivideSurface");
surfaceDeformationPlugin = schnapps.loadPlugin("SurfaceDeformation");
obj = importPlugin.importFromFile("/home/kraemer/Media/Data/surface/midRes/cow_3k.off");
......
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