Commit aadb3d36 authored by Pierre Kraemer's avatar Pierre Kraemer

SCHNApps: new plugin for differential properties + user selection of VBOs for render plugin

parent 84bb3a4d
cmake_minimum_required(VERSION 2.8)
ADD_SUBDIRECTORY(importSurface)
ADD_SUBDIRECTORY(differentialProperties)
ADD_SUBDIRECTORY(render)
ADD_SUBDIRECTORY(renderVector)
ADD_SUBDIRECTORY(subdivideSurface)
cmake_minimum_required(VERSION 2.8)
INCLUDE_DIRECTORIES(
${SCHNApps_ROOT_DIR}/include
${SCHNApps_ROOT_DIR}/Plugins/differentialProperties
${CMAKE_CURRENT_BINARY_DIR}
)
SET( PLUGIN_SRC
${SCHNApps_ROOT_DIR}/Plugins/differentialProperties/differentialProperties.cpp
)
SET( PLUGIN_H
${SCHNApps_ROOT_DIR}/Plugins/differentialProperties/differentialProperties.h
)
SET( PLUGIN_FORM
${SCHNApps_ROOT_DIR}/Plugins/differentialProperties/computeNormalsDialog.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( DifferentialPropertiesPluginD SHARED
${PLUGIN_SRC}
${PLUGIN_UI}
${PLUGIN_MOC}
)
TARGET_LINK_LIBRARIES( DifferentialPropertiesPluginD
${CGoGN_LIBS_D}
${COMMON_LIBS}
${QGLVIEWER_LIBRARIES}
)
ADD_DEPENDENCIES( DifferentialPropertiesPluginD SCHNAppsD )
SET_TARGET_PROPERTIES( DifferentialPropertiesPluginD 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( DifferentialPropertiesPlugin SHARED
${PLUGIN_SRC}
${PLUGIN_UI}
${PLUGIN_MOC}
)
TARGET_LINK_LIBRARIES( DifferentialPropertiesPlugin
${CGoGN_LIBS_R}
${COMMON_LIBS}
${QGLVIEWER_LIBRARIES}
)
ADD_DEPENDENCIES( DifferentialPropertiesPlugin SCHNApps )
ENDIF ( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ComputeNormalsDialog</class>
<widget class="QDialog" name="ComputeNormalsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>223</height>
</rect>
</property>
<property name="windowTitle">
<string>Compute Normals</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">
<property name="text">
<string>Attribute name :</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="attributeName"/>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ComputeNormalsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ComputeNormalsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
#include "differentialProperties.h"
#include "mapHandler.h"
#include "Algo/Geometry/normal.h"
bool DifferentialPropertiesPlugin::enable()
{
m_computeNormalsDialog = new ComputeNormalsDialog();
computeNormalsAction = new QAction("import", this);
addMenuAction("Surface;DifferentialProperties;Compute Normals", computeNormalsAction);
connect(computeNormalsAction, SIGNAL(triggered()), this, SLOT(cb_computeNormals()));
return true;
}
void DifferentialPropertiesPlugin::cb_computeNormals()
{
m_computeNormalsDialog->mapList->clear();
m_computeNormalsDialog->attributeName->setText("normal");
const QList<MapHandlerGen*>& maps = m_window->getMapsList();
foreach(MapHandlerGen* map, maps)
m_computeNormalsDialog->mapList->addItem(map->getName());
m_computeNormalsDialog->show();
}
#ifndef DEBUG
Q_EXPORT_PLUGIN2(DifferentialPropertiesPlugin, DifferentialPropertiesPlugin)
#else
Q_EXPORT_PLUGIN2(DifferentialPropertiesPluginD, DifferentialPropertiesPlugin)
#endif
#ifndef _DIFFERENTIALPROPERTIES_PLUGIN_H_
#define _DIFFERENTIALPROPERTIES_PLUGIN_H_
#include "plugin.h"
#include "ui_computeNormalsDialog.h"
#include "Topology/generic/functor.h"
#include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h"
#include "Topology/generic/attributeHandler.h"
using namespace CGoGN;
using namespace SCHNApps;
struct PFP: public PFP_STANDARD
{
typedef EmbeddedMap2 MAP;
};
typedef PFP::MAP MAP;
typedef PFP::VEC3 VEC3;
class ComputeNormalsDialog : public QDialog, public Ui::ComputeNormalsDialog
{
public:
ComputeNormalsDialog() { setupUi(this); }
};
class DifferentialPropertiesPlugin : public Plugin
{
Q_OBJECT
Q_INTERFACES(CGoGN::SCHNApps::Plugin)
public:
DifferentialPropertiesPlugin()
{
setProvidesRendering(false);
}
~DifferentialPropertiesPlugin()
{}
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) {}
public slots:
void cb_computeNormals();
private:
ComputeNormalsDialog* m_computeNormalsDialog;
QAction* computeNormalsAction;
};
#endif
......@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8)
INCLUDE_DIRECTORIES(
${SCHNApps_ROOT_DIR}/include
${SCHNApps_ROOT_DIR}/Plugins/import
${SCHNApps_ROOT_DIR}/Plugins/importSurface
${CMAKE_CURRENT_BINARY_DIR}
)
......
......@@ -10,7 +10,7 @@
bool ImportSurfacePlugin::enable()
{
importAction = new QAction("import", this);
addMenuAction("Import;Import Surface", importAction);
addMenuAction("Surface;Import", importAction);
connect(importAction, SIGNAL(triggered()), this, SLOT(cb_import()));
return true;
}
......@@ -34,22 +34,13 @@ void ImportSurfacePlugin::cb_import()
// create VBO for vertex position attribute
h->createVBO(position);
// compute vertex normal attribute
VertexAttribute<VEC3> normal = m->getAttribute<VEC3, CGoGN::VERTEX>("normal");
if(!normal.isValid())
normal = m->addAttribute<VEC3, CGoGN::VERTEX>("normal");
Algo::Geometry::computeNormalVertices<PFP>(*m, position, normal);
// create VBO for vertex normal attribute
h->createVBO(normal);
// compute map bounding box
h->updateBB(position);
// compute primitive connectivity VBOs
h->updatePrimitives(CGoGN::Algo::Render::GL2::POINTS, CGoGN::allDarts);
h->updatePrimitives(CGoGN::Algo::Render::GL2::LINES, CGoGN::allDarts);
h->updatePrimitives(CGoGN::Algo::Render::GL2::TRIANGLES, CGoGN::allDarts);
h->updatePrimitives(Algo::Render::GL2::POINTS);
h->updatePrimitives(Algo::Render::GL2::LINES);
h->updatePrimitives(Algo::Render::GL2::TRIANGLES);
m_window->addMap(h);
}
......
......@@ -6,7 +6,7 @@
bool RenderPlugin::enable()
{
m_dockTab = new RenderDockTab();
m_dockTab = new RenderDockTab(this);
addTabInDock(m_dockTab, "Render");
m_flatShader = new CGoGN::Utils::ShaderFlat();
......@@ -31,6 +31,10 @@ bool RenderPlugin::enable()
registerShader(m_simpleColorShader);
registerShader(m_pointSprite);
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_normalVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(cb_normalVBOChanged(int)));
connect(m_dockTab->button_refreshVBOs, SIGNAL(clicked()), this, SLOT(cb_refreshVBOs()));
connect(m_dockTab->check_renderVertices, SIGNAL(toggled(bool)), this, SLOT(cb_renderVerticesChanged(bool)));
connect(m_dockTab->slider_verticesScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(cb_verticesScaleFactorChanged(int)));
connect(m_dockTab->check_renderEdges, SIGNAL(toggled(bool)), this, SLOT(cb_renderEdgesChanged(bool)));
......@@ -55,54 +59,68 @@ void RenderPlugin::redraw(View* view)
const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
foreach(MapHandlerGen* m, maps)
{
CGoGN::Utils::VBO* positionVBO = m->getVBO("position");
CGoGN::Utils::VBO* normalVBO = m->getVBO("normal");
if(params->renderVertices)
const PerMapParameterSet& p = params->perMap[m->getName()];
if(p.positionVBO != NULL)
{
m_pointSprite->setSize(m->getBBdiagSize() / 200.0f * params->verticesScaleFactor);
m_pointSprite->setAttributePosition(positionVBO);
m_pointSprite->predraw(CGoGN::Geom::Vec3f(0.0f, 0.0f, 1.0f));
m->draw(m_pointSprite, CGoGN::Algo::Render::GL2::POINTS);
m_pointSprite->postdraw();
}
if(params->renderEdges)
{
glLineWidth(1.0f);
m_simpleColorShader->setAttributePosition(positionVBO);
m->draw(m_simpleColorShader, CGoGN::Algo::Render::GL2::LINES);
}
if(params->renderFaces)
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_LIGHTING);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f, 1.0f);
switch(params->faceStyle)
if(p.renderVertices)
{
m_pointSprite->setSize(m->getBBdiagSize() / 200.0f * p.verticesScaleFactor);
m_pointSprite->setAttributePosition(p.positionVBO);
m_pointSprite->predraw(CGoGN::Geom::Vec3f(0.0f, 0.0f, 1.0f));
m->draw(m_pointSprite, CGoGN::Algo::Render::GL2::POINTS);
m_pointSprite->postdraw();
}
if(p.renderEdges)
{
case FLAT :
m_flatShader->setAttributePosition(positionVBO);
m->draw(m_flatShader, CGoGN::Algo::Render::GL2::TRIANGLES);
break ;
case PHONG :
m_phongShader->setAttributePosition(positionVBO) ;
m_phongShader->setAttributeNormal(normalVBO) ;
m->draw(m_phongShader, CGoGN::Algo::Render::GL2::TRIANGLES);
break ;
glLineWidth(1.0f);
m_simpleColorShader->setAttributePosition(p.positionVBO);
m->draw(m_simpleColorShader, CGoGN::Algo::Render::GL2::LINES);
}
if(p.renderFaces)
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_LIGHTING);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f, 1.0f);
switch(p.faceStyle)
{
case FLAT :
m_flatShader->setAttributePosition(p.positionVBO);
m->draw(m_flatShader, CGoGN::Algo::Render::GL2::TRIANGLES);
break ;
case PHONG :
if(p.normalVBO != NULL)
{
m_phongShader->setAttributePosition(p.positionVBO) ;
m_phongShader->setAttributeNormal(p.normalVBO) ;
m->draw(m_phongShader, CGoGN::Algo::Render::GL2::TRIANGLES);
}
break ;
}
glDisable(GL_POLYGON_OFFSET_FILL);
}
glDisable(GL_POLYGON_OFFSET_FILL);
}
}
}
void RenderPlugin::viewLinked(View* view)
{
h_viewParams.insert(view, new ParameterSet());
m_dockTab->refreshUI(h_viewParams[view]);
ParameterSet* params = new ParameterSet();
h_viewParams.insert(view, params);
const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
foreach(MapHandlerGen* map, maps)
{
PerMapParameterSet p;
params->perMap.insert(map->getName(), p);
}
m_dockTab->refreshUI(params);
}
void RenderPlugin::viewUnlinked(View* view)
{
h_viewParams.remove(view);
View* current = m_window->getCurrentView();
if(isLinkedToView(current))
m_dockTab->refreshUI(h_viewParams[current]);
......@@ -114,69 +132,195 @@ void RenderPlugin::currentViewChanged(View* view)
m_dockTab->refreshUI(h_viewParams[view]);
}
void RenderPlugin::cb_renderVerticesChanged(bool b)
void RenderPlugin::mapLinked(View* view, MapHandlerGen* m)
{
View* current = m_window->getCurrentView();
assert(isLinkedToView(current));
assert(isLinkedToView(view));
ParameterSet* params = h_viewParams[view];
PerMapParameterSet p;
params->perMap.insert(m->getName(), p);
ParameterSet* params = h_viewParams[current];
params->renderVertices = b;
current->updateGL();
m_dockTab->refreshUI(params);
}
void RenderPlugin::cb_verticesScaleFactorChanged(int i)
void RenderPlugin::mapUnlinked(View* view, MapHandlerGen* m)
{
View* current = m_window->getCurrentView();
assert(isLinkedToView(current));
assert(isLinkedToView(view));
ParameterSet* params = h_viewParams[view];
params->perMap.remove(m->getName());
ParameterSet* params = h_viewParams[current];
params->verticesScaleFactor = i / 50.0;
current->updateGL();
if(params->selectedMap == m)
{
params->selectedMap = NULL;
m_dockTab->refreshUI(params);
}
}
void RenderPlugin::cb_renderEdgesChanged(bool b)
void RenderPlugin::cb_selectedMapChanged()
{
View* current = m_window->getCurrentView();
assert(isLinkedToView(current));
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();
}
}
}
ParameterSet* params = h_viewParams[current];
params->renderEdges = b;
current->updateGL();
void RenderPlugin::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 RenderPlugin::cb_renderFacesChanged(bool b)
void RenderPlugin::cb_normalVBOChanged(int index)
{
if(!b_refreshingUI)
{
View* current = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current];
MapHandlerGen* map = params->selectedMap;
params->perMap[map->getName()].normalVBO = map->getVBO(m_dockTab->combo_normalVBO->currentText());
current->updateGL();
}
}
void RenderPlugin::cb_refreshVBOs()
{
View* current = m_window->getCurrentView();
assert(isLinkedToView(current));
if(isLinkedToView(current))
m_dockTab->refreshUI(h_viewParams[current]);
}
ParameterSet* params = h_viewParams[current];
params->renderFaces = b;
current->updateGL();
void RenderPlugin::cb_renderVerticesChanged(bool b)
{
if(!b_refreshingUI)
{
View* current = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current];
MapHandlerGen* m = params->selectedMap;
params->perMap[m->getName()].renderVertices = b;
current->updateGL();
}
}
void RenderPlugin::cb_faceStyleChanged(QAbstractButton* b)
void RenderPlugin::cb_verticesScaleFactorChanged(int i)
{
View* current = m_window->getCurrentView();
assert(isLinkedToView(current));
if(!b_refreshingUI)
{
View* current = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current];
MapHandlerGen* m = params->selectedMap;
params->perMap[m->getName()].verticesScaleFactor = i / 50.0;
current->updateGL();
}
}
ParameterSet* params = h_viewParams[current];
if(m_dockTab->radio_flatShading->isChecked())
params->faceStyle = FLAT;
else if(m_dockTab->radio_phongShading->isChecked())
params->faceStyle = PHONG;
current->updateGL();
void RenderPlugin::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 RenderPlugin::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 RenderPlugin::cb_faceStyleChanged(QAbstractButton* b)
{
if(!b_refreshingUI)
{
View* current = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current];
MapHandlerGen* m = params->selectedMap;
if(m_dockTab->radio_flatShading->isChecked())
params->perMap[m->getName()].faceStyle = FLAT;
else if(m_dockTab->radio_phongShading->isChecked())
params->perMap[m->getName()].faceStyle = PHONG;
current->updateGL();
}
}
void RenderDockTab::refreshUI(ParameterSet* params)