Commit 86567a06 authored by untereiner's avatar untereiner

Render Explod plugin + bug corrections

parent 3dbe5b78
......@@ -91,7 +91,7 @@ void SimpleMap3::cb_redraw()
{
glDisable(GL_LIGHTING);
glLineWidth(1.0f);
Algo::Render::GL1::renderTopoMD3<PFP>(myMap, position, true, true, true, 0.9f, 0.9f, 0.9f);
Algo::Render::GL1::renderTopoMD3<PFP>(myMap, position, true, true, true, 0.9f, 0.9f, 0.9f,allDarts);
}
/**********************************************************************************************
......
......@@ -17,7 +17,7 @@
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
......@@ -26,6 +26,7 @@
#include "Utils/Qt/qtSimple.h"
#include "Topology/generic/functor.h"
#include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap3.h"
......
......@@ -31,7 +31,6 @@
#include "Algo/Import/import.h"
#include "Algo/Export/export.h"
#include <typeinfo>
#include "Algo/Modelisation/subdivision.h"
......@@ -66,7 +65,6 @@ int main(int argc, char **argv)
// get a handler to the 3D vector attribute created by the import
VertexAttribute<PFP::VEC3> position = myMap.getAttribute<PFP::VEC3, VERTEX>(attrNames[0]);
FaceAttribute<PFP::VEC3> positionF = myMap.getAttribute<PFP::VEC3, FACE>("position") ;
if(!positionF.isValid())
positionF = myMap.addAttribute<PFP::VEC3, FACE>("position") ;
......
......@@ -5,4 +5,5 @@ ADD_SUBDIRECTORY(importVolume)
ADD_SUBDIRECTORY(differentialProperties)
ADD_SUBDIRECTORY(render)
ADD_SUBDIRECTORY(renderVector)
ADD_SUBDIRECTORY(renderExplod)
ADD_SUBDIRECTORY(subdivideSurface)
cmake_minimum_required(VERSION 2.8)
INCLUDE_DIRECTORIES(
${SCHNApps_ROOT_DIR}/include
${SCHNApps_ROOT_DIR}/Plugins/renderExplod
${CMAKE_CURRENT_BINARY_DIR}
)
SET( PLUGIN_SRC
${SCHNApps_ROOT_DIR}/Plugins/renderExplod/renderExplod.cpp
)
SET( PLUGIN_H
${SCHNApps_ROOT_DIR}/Plugins/renderExplod/renderExplod.h
)
SET( PLUGIN_FORM
${SCHNApps_ROOT_DIR}/Plugins/renderExplod/renderExplod.ui
)
IF( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
ADD_DEFINITIONS(-DDEBUG)
IF(WIN32)
link_directories( ${CGoGN_ROOT_DIR}/lib/Release )
ELSE (WIN32)
link_directories( ${CGoGN_ROOT_DIR}/lib/Debug ${CGoGN_ROOT_DIR}/lib/Release )
ENDIF (WIN32)
QT4_WRAP_UI( PLUGIN_UI ${PLUGIN_FORM} )
QT4_WRAP_CPP( PLUGIN_MOC ${PLUGIN_H} )
ADD_LIBRARY( RenderExplodPluginD SHARED
${PLUGIN_SRC}
${PLUGIN_UI}
${PLUGIN_MOC}
)
TARGET_LINK_LIBRARIES( RenderExplodPluginD
${CGoGN_LIBS_D}
${COMMON_LIBS}
${QGLVIEWER_LIBRARIES}
)
ADD_DEPENDENCIES( RenderExplodPluginD SCHNAppsD )
SET_TARGET_PROPERTIES( RenderExplodPluginD PROPERTIES COMPILE_DEFINITIONS "DEBUG" )
ELSE ( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
IF(WIN32)
link_directories( ${CGoGN_ROOT_DIR}/lib/Release )
ELSE (WIN32)
link_directories( ${CGoGN_ROOT_DIR}/lib/Release )
ENDIF (WIN32)
QT4_WRAP_UI( PLUGIN_UI ${PLUGIN_FORM} )
QT4_WRAP_CPP( PLUGIN_MOC ${PLUGIN_H} )
ADD_LIBRARY( RenderExplodPlugin SHARED
${PLUGIN_SRC}
${PLUGIN_UI}
${PLUGIN_MOC}
)
TARGET_LINK_LIBRARIES( RenderExplodPlugin
${CGoGN_LIBS_R}
${COMMON_LIBS}
${QGLVIEWER_LIBRARIES}
)
ADD_DEPENDENCIES( RenderExplodPlugin SCHNApps )
ENDIF ( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
#include "renderExplod.h"
#include "mapHandler.h"
#include "Algo/Import/import.h"
PerMapParameterSet::PerMapParameterSet(MapHandlerGen* map) :
positionVBO(NULL),
colorVBO(NULL),
facesScaleFactor(1.0f),
volumesScaleFactor(1.0f),
renderEdges(false),
renderFaces(true)
{
QList<Utils::VBO*> vbos = map->getVBOList();
for(int i = 0; i < vbos.count(); ++i)
{
if(vbos[i]->name() == "position") // try to select a VBO named "position"
positionVBO = vbos[i];
if(vbos[i]->name() == "color") // try to select a VBO named "color"
colorVBO = vbos[i];
}
if(positionVBO == NULL && vbos.count() > 0)
positionVBO = vbos[0];
if(colorVBO == NULL && vbos.count() > 0)
colorVBO = vbos[0];
}
bool RenderExplodPlugin::enable()
{
m_dockTab = new RenderExplodDockTab(this);
addTabInDock(m_dockTab, "RenderExplod");
// m_renderExplod = new Algo::Render::GL2::ExplodeVolumeRender(true);
//
// m_renderExplod->setNoClippingPlane();
// m_renderExplod->setExplodeVolumes(0.9f);
// m_renderExplod->setExplodeFaces(1.0f);
//
// //m_renderExplod->setAmbiant(Geom::Vec4f(0.1f,0.1f,0.1f,0.0f));
// //m_renderExplod->setBackColor(Geom::Vec4f(0.1f,1.0f,0.1f,0.0f));
// //m_renderExplod->setColorLine(Geom::Vec4f(0.1f,0.1f,0.1f,0.0f));
// //m_renderExplod->setAmbiant(Geom::Vec4f(0.9f, 0.5f, 0.0f, 0.0f));
// m_renderExplod->setBackColor(Geom::Vec4f(0.9f, 0.5f, 0.0f, 0.0f));
// //m_renderExplod->setColorLine(Geom::Vec4f(0.9f, 0.5f, 0.0f, 0.0f));
// m_renderExplod->setColorLine(Geom::Vec4f(0.0f, 0.0f, 0.0f, 0.0f));
//
// registerShader(m_renderExplod->shaderFaces());
// registerShader(m_renderExplod->shaderLines());
connect(m_dockTab->mapList, SIGNAL(itemSelectionChanged()), this, SLOT(cb_selectedMapChanged()));
connect(m_dockTab->combo_positionVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(cb_positionVBOChanged(int)));
connect(m_dockTab->combo_colorVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(cb_colorVBOChanged(int)));
connect(m_dockTab->button_refreshVBOs, SIGNAL(clicked()), this, SLOT(cb_refreshVBOs()));
connect(m_dockTab->check_renderEdges, SIGNAL(toggled(bool)), this, SLOT(cb_renderEdgesChanged(bool)));
connect(m_dockTab->check_renderFaces, SIGNAL(toggled(bool)), this, SLOT(cb_renderFacesChanged(bool)));
connect(m_dockTab->slider_facesScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(cb_facesScaleFactorChanged(int)));
connect(m_dockTab->slider_volumesScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(cb_volumesScaleFactorChanged(int)));
return true;
}
void RenderExplodPlugin::disable()
{
}
void RenderExplodPlugin::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.positionVBO != NULL)
{
if(p.renderEdges)
{
// m_renderExplod->drawEdges();
}
if(p.renderFaces)
{
// glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
// glEnable(GL_LIGHTING);
// glEnable(GL_POLYGON_OFFSET_FILL);
// glPolygonOffset(1.0f, 1.0f) ;
// m_renderExplod->drawFaces();
// glDisable(GL_POLYGON_OFFSET_FILL);
}
}
}
}
void RenderExplodPlugin::viewLinked(View* view)
{
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())
params->selectedMap = maps[0];
m_dockTab->refreshUI(params);
}
void RenderExplodPlugin::viewUnlinked(View* view)
{
h_viewParams.remove(view);
View* current = m_window->getCurrentView();
if(isLinkedToView(current))
m_dockTab->refreshUI(h_viewParams[current]);
}
void RenderExplodPlugin::currentViewChanged(View* view)
{
assert(isLinkedToView(view));
m_dockTab->refreshUI(h_viewParams[view]);
}
void RenderExplodPlugin::mapLinked(View* view, MapHandlerGen* m)
{
assert(isLinkedToView(view));
ParameterSet* params = h_viewParams[view];
PerMapParameterSet p(m);
params->perMap.insert(m->getName(), p);
if(params->perMap.count() == 1)
params->selectedMap = m;
m_dockTab->refreshUI(params);
}
void RenderExplodPlugin::mapUnlinked(View* view, MapHandlerGen* m)
{
assert(isLinkedToView(view));
ParameterSet* params = h_viewParams[view];
params->perMap.remove(m->getName());
if(params->selectedMap == m)
{
if(!params->perMap.empty())
params->selectedMap = m_window->getMap(params->perMap.begin().key());
else
params->selectedMap = NULL;
m_dockTab->refreshUI(params);
}
}
void RenderExplodPlugin::cb_selectedMapChanged()
{
if(!b_refreshingUI)
{
View* view = m_window->getCurrentView();
ParameterSet* params = h_viewParams[view];
QList<QListWidgetItem*> currentItems = m_dockTab->mapList->selectedItems();
if(!currentItems.empty())
{
const QString& mapname = currentItems[0]->text();
params->selectedMap = m_window->getMap(mapname);
m_dockTab->refreshUI(params);
view->updateGL();
}
}
}
void RenderExplodPlugin::cb_positionVBOChanged(int index)
{
if(!b_refreshingUI)
{
View* current = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current];
MapHandlerGen* map = params->selectedMap;
params->perMap[map->getName()].positionVBO = map->getVBO(m_dockTab->combo_positionVBO->currentText());
current->updateGL();
}
}
void RenderExplodPlugin::cb_colorVBOChanged(int index)
{
if(!b_refreshingUI)
{
}
}
void RenderExplodPlugin::cb_refreshVBOs()
{
View* current = m_window->getCurrentView();
if(isLinkedToView(current))
m_dockTab->refreshUI(h_viewParams[current]);
}
void RenderExplodPlugin::cb_renderEdgesChanged(bool b)
{
if(!b_refreshingUI)
{
View* current = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current];
MapHandlerGen* m = params->selectedMap;
params->perMap[m->getName()].renderEdges = b;
current->updateGL();
}
}
void RenderExplodPlugin::cb_renderFacesChanged(bool b)
{
if(!b_refreshingUI)
{
View* current = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current];
MapHandlerGen* m = params->selectedMap;
params->perMap[m->getName()].renderFaces = b;
current->updateGL();
}
}
void RenderExplodPlugin::cb_facesScaleFactorChanged(int i)
{
if(!b_refreshingUI)
{
View* current = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current];
MapHandlerGen* m = params->selectedMap;
params->perMap[m->getName()].facesScaleFactor = i / 50.0;
current->updateGL();
}
}
void RenderExplodPlugin::cb_volumesScaleFactorChanged(int i)
{
if(!b_refreshingUI)
{
View* current = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current];
MapHandlerGen* m = params->selectedMap;
params->perMap[m->getName()].volumesScaleFactor = i / 50.0;
current->updateGL();
}
}
void RenderExplodDockTab::refreshUI(ParameterSet* params)
{
plugin->setRefreshingUI(true);
mapList->clear();
combo_positionVBO->clear();
combo_colorVBO->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();
// for(int i = 0; i < vbos.count(); ++i)
// {
// combo_positionVBO->addItem(QString::fromStdString(vbos[i]->name()));
// if(p.positionVBO == NULL)
// { // if nothing is specified in the parameter set
// if(vbos[i]->name() == "position") // try to select a VBO named "position"
// {
// p.positionVBO = vbos[i];
// combo_positionVBO->setCurrentIndex(i);
// }
// }
// else if(vbos[i] == p.positionVBO)
// combo_positionVBO->setCurrentIndex(i);
//
// combo_normalVBO->addItem(QString::fromStdString(vbos[i]->name()));
// if(p.normalVBO == NULL)
// { // if nothing is specified in the parameter set
// if(vbos[i]->name() == "normal") // try to select a VBO named "normal"
// {
// p.normalVBO = vbos[i];
// combo_normalVBO->setCurrentIndex(i);
// }
// }
// else if(vbos[i] == p.normalVBO)
// combo_normalVBO->setCurrentIndex(i);
// }
//
// if(p.positionVBO == NULL && vbos.count() > 0)
// {
// p.positionVBO = vbos[0];
// combo_positionVBO->setCurrentIndex(0);
// }
// if(p.normalVBO == NULL && vbos.count() > 0)
// {
// p.normalVBO = vbos[0];
// combo_normalVBO->setCurrentIndex(0);
// }
check_renderEdges->setChecked(p.renderEdges);
check_renderFaces->setChecked(p.renderFaces);
slider_facesScaleFactor->setSliderPosition(p.facesScaleFactor * 50.0);
slider_volumesScaleFactor->setSliderPosition(p.volumesScaleFactor * 50.0);
}
++i;
}
plugin->setRefreshingUI(false);
}
#ifndef DEBUG
Q_EXPORT_PLUGIN2(RenderExplodPlugin, RenderExplodPlugin)
#else
Q_EXPORT_PLUGIN2(RenderExplodPluginD, RenderExplodPlugin)
#endif
#ifndef _RENDER_PLUGIN_H_
#define _RENDER_PLUGIN_H_
#include "plugin.h"
#include "ui_renderExplod.h"
#include "Algo/Render/GL2/explodeVolumeRender.h"
using namespace CGoGN;
using namespace SCHNApps;
struct PerMapParameterSet
{
PerMapParameterSet() :
positionVBO(NULL),
colorVBO(NULL),
facesScaleFactor(1.0f),
volumesScaleFactor(1.0f),
renderEdges(false),
renderFaces(true)
{}
PerMapParameterSet(MapHandlerGen* map);
Utils::VBO* positionVBO;
Utils::VBO* colorVBO;
float facesScaleFactor;
float volumesScaleFactor;
bool renderEdges;
bool renderFaces;
};
struct ParameterSet
{
ParameterSet() : selectedMap(NULL)
{}
QHash<QString, PerMapParameterSet> perMap;
MapHandlerGen* selectedMap;
};
class RenderExplodPlugin;
class RenderExplodDockTab : public QWidget, public Ui::RenderExplodWidget
{
public:
RenderExplodDockTab(RenderExplodPlugin* p) : plugin(p)
{
setupUi(this);
}
void refreshUI(ParameterSet* params);
private:
RenderExplodPlugin* plugin;
};
class RenderExplodPlugin : public Plugin
{
Q_OBJECT
Q_INTERFACES(CGoGN::SCHNApps::Plugin)
public:
RenderExplodPlugin() : b_refreshingUI(false)
{
setProvidesRendering(true);
}
~RenderExplodPlugin()
{}
virtual bool enable();
virtual void disable();
virtual void redraw(View *view);
virtual void keyPress(View* view, int key) {}
virtual void keyRelease(View* view, int key) {}
virtual void mousePress(View* view, int button, int x, int y) {}
virtual void mouseRelease(View* view, int button, int x, int y) {}
virtual void mouseMove(View* view, int buttons, int x, int y) {}
virtual void wheelEvent(View* view, int delta, int x, int y) {}
virtual void viewLinked(View* view);
virtual void viewUnlinked(View* view);
virtual void currentViewChanged(View* view);
virtual void mapLinked(View* view, MapHandlerGen* m);
virtual void mapUnlinked(View* view, MapHandlerGen* m);
void setRefreshingUI(bool b) { b_refreshingUI = b; }
protected:
RenderExplodDockTab* m_dockTab;
QHash<View*, ParameterSet*> h_viewParams;
bool b_refreshingUI;
public slots:
void cb_selectedMapChanged();
void cb_positionVBOChanged(int index);
void cb_colorVBOChanged(int index);
void cb_refreshVBOs();
void cb_renderEdgesChanged(bool b);
void cb_renderFacesChanged(bool b);
void cb_facesScaleFactorChanged(int i);
void cb_volumesScaleFactorChanged(int i);
};
#endif
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RenderExplodWidget</class>
<widget class="QWidget" name="RenderExplodWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>174</width>
<height>553</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="0" colspan="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Position :</string>
</property>
</widget>
</item>
<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="2" column="2" alignment="Qt::AlignRight">
<widget class="QPushButton" name="button_refreshVBOs">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Refresh</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>cColor :</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QComboBox" name="combo_colorVBO">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="check_renderEdges">
<property name="text">
<string>render edges</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="check_renderFaces">
<property name="text">
<string>render faces</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="0">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Explod</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>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>
<item row="2" column="0">