Commit 09585b63 authored by Sylvain Thery's avatar Sylvain Thery

Merge cgogn:~cgogn/CGoGN

parents ac226cdf 130a4ba4
......@@ -9,3 +9,4 @@ ADD_SUBDIRECTORY(surface_differentialProperties)
ADD_SUBDIRECTORY(surface_subdivision)
ADD_SUBDIRECTORY(surface_selection)
ADD_SUBDIRECTORY(surface_deformation)
ADD_SUBDIRECTORY(surface_modelisation)
......@@ -136,34 +136,41 @@ void Surface_Deformation_Plugin::keyPress(View* view, QKeyEvent* event)
{
case Qt::Key_D : {
MapHandlerGen* mh = m_schnapps->getSelectedMap();
const MapParameters& p = h_parameterSet[mh];
if(!m_dragging)
if(mh)
{
if(p.handleSelector && !p.handleSelector->getSelectedCells().empty())
const MapParameters& p = h_parameterSet[mh];
if(!m_dragging)
{
m_dragging = true;
if(p.handleSelector && !p.handleSelector->getSelectedCells().empty())
{
m_dragging = true;
m_draginit = false;
view->setMouseTracking(true);
}
}
else
{
m_dragging = false;
m_draginit = false;
view->setMouseTracking(true);
view->setMouseTracking(false);
}
}
else
{
m_dragging = false;
m_draginit = false;
view->setMouseTracking(false);
}
break;
}
case Qt::Key_R : {
// ParameterSet* params = h_viewParams[view];
// MapHandlerGen* map = params->selectedMap;
// if(map)
// {
// asRigidAsPossible(view, map);
// PerMapParameterSet* perMap = params->perMap[map->getName()];
// params->selectedMap->notifyAttributeModification(perMap->positionAttribute);
// view->updateGL();
// }
MapHandlerGen* mh = m_schnapps->getSelectedMap();
if(mh)
{
const MapParameters& p = h_parameterSet[mh];
if(p.initialized)
{
asRigidAsPossible(mh);
mh->notifyAttributeModification(p.positionAttribute);
static_cast<MapHandler<PFP2>*>(mh)->updateBB(p.positionAttribute);
view->updateGL();
}
}
break;
}
}
......@@ -208,10 +215,11 @@ void Surface_Deformation_Plugin::mouseMove(View* view, QMouseEvent* event)
// matchDiffCoord(map);
if(p.initialized)
{
asRigidAsPossible(mh);
mh->notifyAttributeModification(p.positionAttribute);
static_cast<MapHandler<PFP2>*>(mh)->updateBB(p.positionAttribute);
mh->notifyAttributeModification(p.positionAttribute);
static_cast<MapHandler<PFP2>*>(mh)->updateBB(p.positionAttribute);
}
}
view->updateGL();
......
......@@ -86,14 +86,17 @@ void Dialog_ComputeNormal::removeMapFromList(MapHandlerGen* map)
void Dialog_ComputeNormal::addAttributeToList(unsigned int orbit, const QString& nameAttr)
{
QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));
if(orbit == VERTEX)
{
QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));
const QString& typeAttr = m_selectedMap->getAttributeTypeName(orbit, nameAttr);
const QString& typeAttr = m_selectedMap->getAttributeTypeName(orbit, nameAttr);
if(typeAttr == vec3TypeName)
{
combo_positionAttribute->addItem(nameAttr);
combo_normalAttribute->addItem(nameAttr);
if(typeAttr == vec3TypeName)
{
combo_positionAttribute->addItem(nameAttr);
combo_normalAttribute->addItem(nameAttr);
}
}
}
......
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>345</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Position :</string>
</property>
</widget>
</item>
<item row="0" column="1" 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="1" column="0" colspan="2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Vertex selector :</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QComboBox" name="combo_vertexSelector">
<item>
<property name="text">
<string>- select selector -</string>
</property>
</item>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Edge selector :</string>
</property>
</widget>
</item>
<item row="2" column="1" 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">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Face selector :</string>
</property>
</widget>
</item>
<item row="3" column="1" 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="4">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="5" column="0" colspan="4">
<widget class="QPushButton" name="button_createEmptyMap">
<property name="text">
<string>Create empty map</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="4">
<widget class="QPushButton" name="button_addCube">
<property name="text">
<string>Add cube</string>
</property>
</widget>
</item>
<item row="7" column="0" colspan="4">
<widget class="QPushButton" name="button_flipEdge">
<property name="text">
<string>Flip edge</string>
</property>
</widget>
</item>
<item row="8" 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>
</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 createEmptyMap();
void addCube(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 createEmptyMapButtonClicked();
void addCubeButtonClicked();
void flipEdgeButtonClicked();
private:
void addVertexAttribute(const QString& name);
void addVertexSelector(const QString& name);
void removeVertexSelector(const QString& name);
void addEdgeSelector(const QString& name);
void removeEdgeSelector(const QString& name);
void addFaceSelector(const QString& name);
void removeFaceSelector(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&)));
connect(map, SIGNAL(cellSelectorAdded(unsigned int, const QString&)), this, SLOT(cellSelectorAdded(unsigned int, const QString&)));
connect(map, SIGNAL(cellSelectorRemoved(unsigned int, const QString&)), this, SLOT(cellSelectorRemoved(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::cellSelectorAdded(unsigned int orbit, const QString& name)
{
MapHandlerGen* map = static_cast<MapHandlerGen*>(QObject::sender());
if(map->isSelectedMap())
{
switch(orbit)
{
case VERTEX :
m_dockTab->addVertexSelector(name);
break;
case EDGE :
m_dockTab->addEdgeSelector(name);
break;
case FACE :
m_dockTab->addFaceSelector(name);
break;
}
}
}
void Surface_Modelisation_Plugin::cellSelectorRemoved(unsigned int orbit, const QString& name)
{
MapHandlerGen* map = static_cast<MapHandlerGen*>(QObject::sender());
if(map->isSelectedMap())
{
switch(orbit)
{
case VERTEX :
m_dockTab->removeVertexSelector(name);
break;
case EDGE :
m_dockTab->removeEdgeSelector(name);
break;
case FACE :
m_dockTab->removeFaceSelector(name);
break;
}
}
}
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::createEmptyMap()
{
MapHandlerGen* mhg = m_schnapps->addMap("map", 2);
if(mhg)
{
MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(mhg);
// add vertex position attribute
VertexAttribute<PFP2::VEC3> position = mh->addAttribute<PFP2::VEC3, VERTEX>("position");
// update corresponding VBO & emit attribute update signal
mh->notifyAttributeModification(position);
}