Commit 46ecc50d authored by Lionel Untereiner's avatar Lionel Untereiner

adding new plugin : render topo surface

parent b3f60268
......@@ -8,4 +8,4 @@ ADD_SUBDIRECTORY(renderVector)
ADD_SUBDIRECTORY(renderExplod)
ADD_SUBDIRECTORY(subdivideSurface)
ADD_SUBDIRECTORY(surfaceDeformation)
#ADD_SUBDIRECTORY(renderTopoSurface)
ADD_SUBDIRECTORY(renderTopoSurface)
cmake_minimum_required(VERSION 2.8)
SET( PLUGIN_NAME RenderTopoSurface )
SET( PLUGIN_ROOT_DIR ${SCHNApps_ROOT_DIR}/Plugins/renderTopoSurface )
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/renderTopoSurface.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">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>204</width>
<height>547</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QListWidget" name="mapList"/>
</item>
<item row="1" column="0">
<layout class="QGridLayout" name="gridLayout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item row="0" column="2">
<widget class="QComboBox" name="combo_positionVBO">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Position :</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="Line" name="line"/>
</item>
<item row="3" column="0">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>explod edges</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSlider" name="slider_edgesScaleFactor">
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>explod faces</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSlider" name="slider_facesScaleFactor">
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="0">
<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/>
<buttongroups>
<buttongroup name="group_faceShading"/>
</buttongroups>
</ui>
#ifndef _RENDER_PLUGIN_H_
#define _RENDER_PLUGIN_H_
#include "plugin.h"
#include "ui_renderTopoSurface.h"
#include "Algo/Render/GL2/topoRender.h"
using namespace CGoGN;
using namespace SCHNApps;
struct PerMapParameterSet
{
PerMapParameterSet() :
edgesScaleFactor(1.0f),
facesScaleFactor(1.0f)
{
m_renderTopo = new Algo::Render::GL2::TopoRender();
}
~PerMapParameterSet()
{
delete m_renderTopo;
}
float edgesScaleFactor;
float facesScaleFactor;
Algo::Render::GL2::TopoRender* m_renderTopo;
};
struct ParameterSet
{
ParameterSet() : selectedMap(NULL)
{}
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)
{
setProvidesRendering(true);
}
~RenderTopoSurfacePlugin()
{}
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) {}
void setRefreshingUI(bool b) { b_refreshingUI = b; }
protected:
RenderDockTab* m_dockTab;
QHash<View*, ParameterSet*> h_viewParams;
bool b_refreshingUI;
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);
void changeSelectedMap(View* view, MapHandlerGen* map);
void changeEdgesScaleFactor(View* view, MapHandlerGen* map, int i);
void changeFacesScaleFactor(View* view, MapHandlerGen* map, int i);
void cb_selectedMapChanged();
void cb_edgesScaleFactorChanged(int i);
void cb_facesScaleFactorChanged(int i);
};
#endif
#include "renderTopoSurface.h"
#include "mapHandler.h"
bool RenderTopoSurfacePlugin::enable()
{
m_dockTab = new RenderTopoSurfaceDockTab(this);
addTabInDock(m_dockTab, "RenderTopo");
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*)));
return true;
}
void RenderTopoSurfacePlugin::disable()
{
}
void RenderTopoSurfacePlugin::redraw(View* view)
{
ParameterSet* params = h_viewParams[view];
const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
foreach(MapHandlerGen* m, maps)
{
const PerMapParameterSet& p = params->perMap[m->getName()];
if(p.m_renderTopo != NULL)
{
p.m_renderTopo->drawTopo();
}
}
}
void RenderTopoSurfacePlugin::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* map, maps)
{
PerMapParameterSet p(map);
params->perMap.insert(map->getName(), p);
}
if (!maps.empty())
changeSelectedMap(view, maps[0]);
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 RenderTopoSurfacePlugin::viewUnlinked(View* view, Plugin* plugin)
{
if(plugin == this)
{
h_viewParams.remove(view);
disconnect(view, SIGNAL(mapLinked(MapHandlerGen*)), this, SLOT(mapLinked(MapHandlerGen*)));
disconnect(view, SIGNAL(mapUnlinked(MapHandlerGen*)), this, SLOT(mapUnlinked(MapHandlerGen*)));
}
}
void RenderTopoSurfacePlugin::currentViewChanged(View* view)
{
if(isLinkedToView(view))
m_dockTab->refreshUI(h_viewParams[view]);
}
void RenderTopoSurfacePlugin::mapLinked(MapHandlerGen* m)
{
View* view = static_cast<View*>(QObject::sender());
assert(isLinkedToView(view));
ParameterSet* params = h_viewParams[view];
PerMapParameterSet p(m);
params->perMap.insert(m->getName(), p);
if(params->selectedMap == NULL || params->perMap.count() == 1)
changeSelectedMap(view, m);
else
m_dockTab->refreshUI(params);
}
void RenderTopoSurfacePlugin::mapUnlinked(MapHandlerGen* m)
{
View* view = static_cast<View*>(QObject::sender());
assert(isLinkedToView(view));
ParameterSet* params = h_viewParams[view];
params->perMap.remove(m->getName());
if(params->selectedMap == m)
{
if(!params->perMap.empty())
changeSelectedMap(view, m_window->getMap(params->perMap.begin().key()));
else
changeSelectedMap(view, NULL);
}
else
m_dockTab->refreshUI(params);
}
void RenderTopoSurfacePlugin::changeSelectedMap(View* view, MapHandlerGen* map)
{
ParameterSet* params = h_viewParams[view];
MapHandlerGen* prev = params->selectedMap;
params->selectedMap = 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*)));
m_dockTab->refreshUI(params);
view->updateGL();
}
}
void RenderTopoSurfacePlugin::changeEdgesScaleFactor(View* view, MapHandlerGen* map, int i)
{
ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()].edgesScaleFactor = i / 50.0;
if(view->isCurrentView())
{
m_dockTab->refreshUI(params);
view->updateGL();
}
}
void RenderTopoSurfacePlugin::changeFacesScaleFactor(View* view, MapHandlerGen* map, int i)
{
ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()].facesScaleFactor = i / 50.0;
if(view->isCurrentView())
{
m_dockTab->refreshUI(params);
view->updateGL();
}
}
void RenderTopoSurfacePlugin::cb_selectedMapChanged()
{
if(!b_refreshingUI)
{
QList<QListWidgetItem*> currentItems = m_dockTab->mapList->selectedItems();
if(!currentItems.empty())
changeSelectedMap(m_window->getCurrentView(), m_window->getMap(currentItems[0]->text()));
}
}
void RenderTopoSurfacePlugin::cb_edgesScaleFactorChanged(int i)
{
if(!b_refreshingUI)
{
View* view = m_window->getCurrentView();
MapHandlerGen* map = h_viewParams[view]->selectedMap;
changeEdgesScaleFactor(view, map, i);
}
}
void RenderTopoSurfacePlugin::cb_facesScaleFactorChanged(int i)
{
if(!b_refreshingUI)
{
View* view = m_window->getCurrentView();
MapHandlerGen* map = h_viewParams[view]->selectedMap;
changeFacesScaleFactor(view, map, i);
}
}
void RenderDockTab::refreshUI(ParameterSet* params)
{
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
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