Commit 2dd3f2a4 authored by Pierre Kraemer's avatar Pierre Kraemer

add surface modelisation plugin

parent ea92bf90
......@@ -9,3 +9,4 @@ ADD_SUBDIRECTORY(surface_differentialProperties)
ADD_SUBDIRECTORY(surface_subdivision)
ADD_SUBDIRECTORY(surface_selection)
ADD_SUBDIRECTORY(surface_deformation)
ADD_SUBDIRECTORY(surface_modelisation)
cmake_minimum_required(VERSION 2.8)
SET( PLUGIN_NAME Surface_Modelisation )
SET( PLUGIN_ROOT_DIR ${SCHNApps_ROOT_DIR}/Plugins/surface_modelisation )
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/surface_modelisation.h
${PLUGIN_ROOT_DIR}/include/surface_modelisation_dockTab.h
)
include( ${SCHNApps_ROOT_DIR}/Plugins/plugins_cmake.txt )
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Surface_Modelisation_TabWidget</class>
<widget class="QWidget" name="Surface_Modelisation_TabWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>259</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0" colspan="3">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Vertex selector :</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>Edge selector :</string>
</property>
</widget>
</item>
<item row="2" column="2" colspan="3">
<widget class="QComboBox" name="combo_edgeSelector">
<item>
<property name="text">
<string>- select selector -</string>
</property>
</item>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Face selector :</string>
</property>
</widget>
</item>
<item row="3" column="2" colspan="3">
<widget class="QComboBox" name="combo_faceSelector">
<item>
<property name="text">
<string>- select selector -</string>
</property>
</item>
</widget>
</item>
<item row="4" column="0" colspan="5">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="3" colspan="2">
<widget class="QComboBox" name="combo_vertexSelector">
<item>
<property name="text">
<string>- select selector -</string>
</property>
</item>
</widget>
</item>
<item row="5" column="0" colspan="5">
<widget class="QPushButton" name="button_createCube">
<property name="text">
<string>Create cube</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="5">
<widget class="QPushButton" name="button_flipEdge">
<property name="text">
<string>Flip edge</string>
</property>
</widget>
</item>
<item row="7" column="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="2" colspan="3">
<widget class="QComboBox" name="combo_positionAttribute">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>- select attribute -</string>
</property>
</item>
</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>
</widget>
<resources/>
<connections/>
</ui>
#ifndef _SURFACE_MODELISATION_PLUGIN_H_
#define _SURFACE_MODELISATION_PLUGIN_H_
#include "plugin_interaction.h"
#include "surface_modelisation_dockTab.h"
#include "mapHandler.h"
namespace CGoGN
{
namespace SCHNApps
{
struct MapParameters
{
MapParameters() :
vertexSelector(NULL),
edgeSelector(NULL),
faceSelector(NULL)
{}
VertexAttribute<PFP2::VEC3> positionAttribute;
CellSelector<VERTEX>* vertexSelector;
CellSelector<EDGE>* edgeSelector;
CellSelector<FACE>* faceSelector;
};
class Surface_Modelisation_Plugin : public PluginInteraction
{
Q_OBJECT
Q_INTERFACES(CGoGN::SCHNApps::Plugin)
friend class Surface_Modelisation_DockTab;
public:
Surface_Modelisation_Plugin();
~Surface_Modelisation_Plugin()
{}
virtual bool enable();
virtual void disable();
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) {}
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) {}
virtual void viewLinked(View *view) {}
virtual void viewUnlinked(View *view) {}
private slots:
// slots called from SCHNApps signals
void selectedMapChanged(MapHandlerGen* prev, MapHandlerGen* cur);
void mapAdded(MapHandlerGen* map);
void mapRemoved(MapHandlerGen* map);
// slots called from MapHandler signals
void attributeAdded(unsigned int orbit, const QString& name);
void cellSelectorAdded(unsigned int orbit, const QString& name);
void cellSelectorRemoved(unsigned int orbit, const QString& name);
public slots:
// slots for Python calls
void changePositionAttribute(const QString& view, const QString& map, const QString& name);
void changeVertexSelector(const QString& map, const QString& name);
void changeEdgeSelector(const QString& map, const QString& name);
void changeFaceSelector(const QString& map, const QString& name);
protected:
void createCube(MapHandlerGen* mhg);
void flipEdge(MapHandlerGen* mhg);
protected:
Surface_Modelisation_DockTab* m_dockTab;
QHash<MapHandlerGen*, MapParameters> h_parameterSet;
};
} // namespace SCHNApps
} // namespace CGoGN
#endif
#ifndef _SURFACE_MODELISATION_DOCK_TAB_H_
#define _SURFACE_MODELISATION_DOCK_TAB_H_
#include "ui_surface_modelisation.h"
namespace CGoGN
{
namespace SCHNApps
{
class SCHNApps;
class Surface_Modelisation_Plugin;
struct MapParameters;
class Surface_Modelisation_DockTab : public QWidget, public Ui::Surface_Modelisation_TabWidget
{
Q_OBJECT
friend class Surface_Modelisation_Plugin;
public:
Surface_Modelisation_DockTab(SCHNApps* s, Surface_Modelisation_Plugin* p);
private:
SCHNApps* m_schnapps;
Surface_Modelisation_Plugin* m_plugin;
bool b_updatingUI;
private slots:
void positionAttributeChanged(int index);
void vertexSelectorChanged(int index);
void edgeSelectorChanged(int index);
void faceSelectorChanged(int index);
void createCubeButtonClicked();
void flipEdgeButtonClicked();
private:
void addVertexAttribute(const QString& name);
void updateMapParameters();
};
} // namespace SCHNApps
} // namespace CGoGN
#endif
#include "surface_modelisation.h"
#include "schnapps.h"
#include "view.h"
#include "mapHandler.h"
#include "Algo/Modelisation/polyhedron.h"
namespace CGoGN
{
namespace SCHNApps
{
Surface_Modelisation_Plugin::Surface_Modelisation_Plugin()
{}
bool Surface_Modelisation_Plugin::enable()
{
m_dockTab = new Surface_Modelisation_DockTab(m_schnapps, this);
m_schnapps->addPluginDockTab(this, m_dockTab, "Surface_Modelisation");
connect(m_schnapps, SIGNAL(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)), this, SLOT(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)));
connect(m_schnapps, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(mapAdded(MapHandlerGen*)));
connect(m_schnapps, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(mapRemoved(MapHandlerGen*)));
foreach(MapHandlerGen* map, m_schnapps->getMapSet().values())
mapAdded(map);
m_dockTab->updateMapParameters();
return true;
}
void Surface_Modelisation_Plugin::disable()
{
disconnect(m_schnapps, SIGNAL(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)), this, SLOT(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)));
}
void Surface_Modelisation_Plugin::selectedMapChanged(MapHandlerGen *prev, MapHandlerGen *cur)
{
m_dockTab->updateMapParameters();
}
void Surface_Modelisation_Plugin::mapAdded(MapHandlerGen* map)
{
connect(map, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(attributeAdded(unsigned int, const QString&)));
}
void Surface_Modelisation_Plugin::mapRemoved(MapHandlerGen* map)
{
disconnect(map, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(attributeAdded(unsigned int, const QString&)));
}
void Surface_Modelisation_Plugin::attributeAdded(unsigned int orbit, const QString& name)
{
MapHandlerGen* map = static_cast<MapHandlerGen*>(QObject::sender());
if(orbit == VERTEX && map->isSelectedMap())
m_dockTab->addVertexAttribute(name);
}
void Surface_Modelisation_Plugin::changePositionAttribute(const QString& view, const QString& map, const QString& name)
{
MapHandlerGen* m = m_schnapps->getMap(map);
if(m)
{
h_parameterSet[m].positionAttribute = m->getAttribute<PFP2::VEC3, VERTEX>(name);
if(m->isSelectedMap())
m_dockTab->updateMapParameters();
}
}
void Surface_Modelisation_Plugin::changeVertexSelector(const QString& map, const QString& name)
{
MapHandlerGen* m = m_schnapps->getMap(map);
if(m)
{
MapParameters& p = h_parameterSet[m];
p.vertexSelector = m->getCellSelector<VERTEX>(name);
if(m->isSelectedMap())
m_dockTab->updateMapParameters();
}
}
void Surface_Modelisation_Plugin::changeEdgeSelector(const QString& map, const QString& name)
{
MapHandlerGen* m = m_schnapps->getMap(map);
if(m)
{
MapParameters& p = h_parameterSet[m];
p.edgeSelector = m->getCellSelector<EDGE>(name);
if(m->isSelectedMap())
m_dockTab->updateMapParameters();
}
}
void Surface_Modelisation_Plugin::changeFaceSelector(const QString& map, const QString& name)
{
MapHandlerGen* m = m_schnapps->getMap(map);
if(m)
{
MapParameters& p = h_parameterSet[m];
p.faceSelector = m->getCellSelector<FACE>(name);
if(m->isSelectedMap())
m_dockTab->updateMapParameters();
}
}
void Surface_Modelisation_Plugin::createCube(MapHandlerGen *mhg)
{
MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(mhg);
PFP2::MAP* map = mh->getMap();
VertexAttribute<PFP2::VEC3>& position = h_parameterSet[mhg].positionAttribute;
Algo::Surface::Modelisation::embedPrism<PFP2>(*map, position, 4, false, 1.0f, 1.0f, 1.0f);
mh->notifyAttributeModification(position);
mh->notifyConnectivityModification();
}
void Surface_Modelisation_Plugin::flipEdge(MapHandlerGen *mhg)
{
MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(mhg);
PFP2::MAP* map = mh->getMap();
const MapParameters& p = h_parameterSet[mhg];
if(p.edgeSelector && !p.edgeSelector->getSelectedCells().empty())
{
const std::vector<Dart>& edge = p.edgeSelector->getSelectedCells();
map->flipEdge(edge[0]);
}
mh->notifyConnectivityModification();
}
#ifndef DEBUG
Q_EXPORT_PLUGIN2(Surface_Modelisation_Plugin, Surface_Modelisation_Plugin)
#else
Q_EXPORT_PLUGIN2(Surface_Modelisation_PluginD, Surface_Modelisation_Plugin)
#endif
} // namespace SCHNApps
} // namespace CGoGN
#include "surface_modelisation_dockTab.h"
#include "surface_modelisation.h"
#include "mapHandler.h"
namespace CGoGN
{
namespace SCHNApps
{
Surface_Modelisation_DockTab::Surface_Modelisation_DockTab(SCHNApps* s, Surface_Modelisation_Plugin* p) :
m_schnapps(s),
m_plugin(p),
b_updatingUI(false)
{
setupUi(this);
connect(combo_positionAttribute, SIGNAL(currentIndexChanged(int)), this, SLOT(positionAttributeChanged(int)));
connect(button_createCube, SIGNAL(clicked()), this, SLOT(createCubeButtonClicked()));
connect(button_flipEdge, SIGNAL(clicked()), this, SLOT(flipEdgeButtonClicked()));
}
void Surface_Modelisation_DockTab::positionAttributeChanged(int index)
{
if(!b_updatingUI)
{
MapHandlerGen* map = m_schnapps->getSelectedMap();
if(map)
m_plugin->h_parameterSet[map].positionAttribute = map->getAttribute<PFP2::VEC3, VERTEX>(combo_positionAttribute->currentText());
}
}
void Surface_Modelisation_DockTab::vertexSelectorChanged(int index)
{
if(!b_updatingUI)
{
MapHandlerGen* map = m_schnapps->getSelectedMap();
if(map)
m_plugin->h_parameterSet[map].vertexSelector = map->getCellSelector<VERTEX>(combo_vertexSelector->currentText());
}
}
void Surface_Modelisation_DockTab::edgeSelectorChanged(int index)
{
if(!b_updatingUI)
{
MapHandlerGen* map = m_schnapps->getSelectedMap();
if(map)
m_plugin->h_parameterSet[map].edgeSelector = map->getCellSelector<EDGE>(combo_edgeSelector->currentText());
}
}
void Surface_Modelisation_DockTab::faceSelectorChanged(int index)
{
if(!b_updatingUI)
{
MapHandlerGen* map = m_schnapps->getSelectedMap();
if(map)
m_plugin->h_parameterSet[map].faceSelector = map->getCellSelector<FACE>(combo_faceSelector->currentText());
}
}
void Surface_Modelisation_DockTab::createCubeButtonClicked()
{
if(!b_updatingUI)
{
MapHandlerGen* map = m_schnapps->getSelectedMap();
if(map)
m_plugin->createCube(map);
}
}
void Surface_Modelisation_DockTab::flipEdgeButtonClicked()
{
if(!b_updatingUI)
{
MapHandlerGen* map = m_schnapps->getSelectedMap();
if(map)
m_plugin->flipEdge(map);
}
}
void Surface_Modelisation_DockTab::addVertexAttribute(const QString& nameAttr)
{
b_updatingUI = true;
QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));
const QString& typeAttr = m_schnapps->getSelectedMap()->getAttributeTypeName(VERTEX, nameAttr);
if(typeAttr == vec3TypeName)
combo_positionAttribute->addItem(nameAttr);
b_updatingUI = false;
}
void Surface_Modelisation_DockTab::updateMapParameters()
{
b_updatingUI = true;
combo_positionAttribute->clear();
combo_positionAttribute->addItem("- select attribute -");
MapHandlerGen* map = m_schnapps->getSelectedMap();
if(map)
{
const MapParameters& p = m_plugin->h_parameterSet[map];
QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));
unsigned int i = 1;
const AttributeSet& attribs = map->getAttributeSet(VERTEX);
for(AttributeSet::const_iterator it = attribs.constBegin(); it != attribs.constEnd(); ++it)
{
if(it.value() == vec3TypeName)
{
combo_positionAttribute->addItem(it.key());
if(p.positionAttribute.isValid() && it.key() == QString::fromStdString(p.positionAttribute.name()))
combo_positionAttribute->setCurrentIndex(i);
++i;
}
}
}
b_updatingUI = false;
}
} // namespace SCHNApps
} // namespace CGoGN
......@@ -13,11 +13,12 @@
#include "Topology/generic/functor.h"
#include "Topology/generic/attributeHandler.h"
//#include "Utils/drawer.h"
#include "Algo/Render/GL2/mapRender.h"
#include "Algo/Geometry/boundingbox.h"
#include "Utils/vbo.h"
#include "Utils/drawer.h"
namespace CGoGN
{
......@@ -54,9 +55,9 @@ public slots:
Utils::GLSLShader* getBBDrawerShader() const
{
if(m_bbDrawer)
return m_bbDrawer->getShader();
else
// if(m_bbDrawer)
// return m_bbDrawer->getShader();
// else
return NULL;
}
......@@ -188,7 +189,7 @@ protected:
qglviewer::Vec m_bbMin;
qglviewer::Vec m_bbMax;
float m_bbDiagSize;
Utils::Drawer* m_bbDrawer;
// Utils::Drawer* m_bbDrawer;
Algo::Render::GL2::MapRender* m_render;
......
......@@ -75,17 +75,17 @@ void MapHandler<PFP>::draw(Utils::GLSLShader* shader, int primitive)
template <typename PFP>
void MapHandler<PFP>::drawBB()
{
if(!m_bbDrawer)
{
m_bbDrawer = new Utils::Drawer();
updateBBDrawer();
}
glPushMatrix();
glMultMatrixd(m_frame->matrix());
// QGLViewer::drawAxis();
m_bbDrawer->callList();
glPopMatrix();
// if(!m_bbDrawer)
// {
// m_bbDrawer = new Utils::Drawer();
// updateBBDrawer();
// }
// glPushMatrix();
// glMultMatrixd(m_frame->matrix());
//// QGLViewer::drawAxis();
// m_bbDrawer->callList();
// glPopMatrix();
}
template <typename PFP>
......@@ -96,46 +96,46 @@ void MapHandler<PFP>::updateBB(const VertexAttribute<typename PFP::VEC3>& positi
m_bbMax = qglviewer::Vec(m_bb.max()[0], m_bb.max()[1], m_bb.max()[2]);
m_bbDiagSize = (m_bbMax - m_bbMin).norm();
updateBBDrawer();
// updateBBDrawer();
}
template <typename PFP>
void MapHandler<PFP>::updateBBDrawer()
{
if(!m_bbDrawer)
m_bbDrawer = new Utils::Drawer();
const Geom::Vec3f& bbmin = m_bb.min();
const Geom::Vec3f& bbmax = m_bb.max();
m_bbDrawer->newList(GL_COMPILE);
m_bbDrawer->color3f(0.0f,1.0f,0.0f);
m_bbDrawer->lineWidth(1.0f);
m_bbDrawer->begin(GL_LINE_LOOP);
m_bbDrawer->vertex(bbmin);
m_bbDrawer->vertex3f(bbmin[0], bbmax[1], bbmin[2]);
m_bbDrawer->vertex3f(bbmax[0], bbmax[1], bbmin[2]);
m_bbDrawer->vertex3f(bbmax[0], bbmin[1], bbmin[2]);
m_bbDrawer->vertex(bbmin);
m_bbDrawer->end();
m_bbDrawer->begin(GL_LINE_LOOP);
m_bbDrawer->vertex(bbmax);
m_bbDrawer->vertex3f(bbmax[0], bbmin[1], bbmax[2]);
m_bbDrawer->vertex3f(bbmin[0], bbmin[1], bbmax[2]);
m_bbDrawer->vertex3f(bbmin[0], bbmax[1], bbmax[2]);