Commit dd6f4b63 authored by Pierre Kraemer's avatar Pierre Kraemer

add surface deformation (not finished)

parent 02c85dd9
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Surface_Deformation_TabWidget</class>
<widget class="QWidget" name="Surface_Deformation_TabWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>180</width>
<height>545</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="9" column="0" colspan="2">
<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>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Locked selector :</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QComboBox" name="combo_lockedSelector">
<item>
<property name="text">
<string>- select selector -</string>
</property>
</item>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>Handle selector :</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="QComboBox" name="combo_handleSelector">
<item>
<property name="text">
<string>- select selector -</string>
</property>
</item>
</widget>
</item>
<item row="0" column="1">
<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="7" column="0" colspan="2">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="QPushButton" name="button_start_stop">
<property name="text">
<string>Start</string>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>combo_positionAttribute</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>
#ifndef _SURFACE_DEFORMATION_PLUGIN_H_
#define _SURFACE_DEFORMATION_PLUGIN_H_
#include "plugin_interaction.h"
#include "surface_deformation_dockTab.h"
#include "mapHandler.h"
#include "Container/fakeAttribute.h"
#include "NL/nl.h"
#include "Algo/LinearSolving/basic.h"
#include "Eigen/Dense"
namespace CGoGN
{
namespace SCHNApps
{
typedef NoTypeNameAttribute<Eigen::Matrix3f> Eigen_Matrix3f;
struct MapParameters
{
MapParameters();
~MapParameters();
void start(MapHandlerGen* mh);
void stop(MapHandlerGen* mh);
VertexAttribute<PFP2::VEC3> positionAttribute;
CellSelector<VERTEX>* lockedSelector;
CellSelector<VERTEX>* handleSelector;
bool initialized;
VertexAttribute<PFP2::VEC3> positionInit;
VertexAttribute<PFP2::VEC3> diffCoord;
VertexAttribute<Eigen_Matrix3f> vertexRotationMatrix;
VertexAttribute<PFP2::VEC3> rotatedDiffCoord;
VertexAttribute<unsigned int> vIndex;
unsigned int nb_vertices;
NLContext nlContext;
};
class Surface_Deformation_Plugin : public PluginInteraction
{
Q_OBJECT
Q_INTERFACES(CGoGN::SCHNApps::Plugin)
friend class Surface_Deformation_DockTab;
public:
Surface_Deformation_Plugin() :
m_dragging(false)
{}
~Surface_Deformation_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);
void selectedCellsChanged();
public slots:
// slots for Python calls
void changePositionAttribute(const QString& map, const QString& name);
void changeLockedSelector(const QString& map, const QString& name);
void changeHandleSelector(const QString& map, const QString& name);
protected:
void toggleMapDeformation(MapHandlerGen* map);
void matchDiffCoord(MapHandlerGen* map);
void asRigidAsPossible(MapHandlerGen* map);
protected:
Surface_Deformation_DockTab* m_dockTab;
QHash<MapHandlerGen*, MapParameters> h_parameterSet;
bool m_dragging;
PFP2::REAL m_dragZ;
qglviewer::Vec m_dragPrevious;
};
} // namespace SCHNApps
} // namespace CGoGN
#endif
#ifndef _SURFACE_DEFORMATION_DOCK_TAB_H_
#define _SURFACE_DEFORMATION_DOCK_TAB_H_
#include "ui_surface_deformation.h"
namespace CGoGN
{
namespace SCHNApps
{
class SCHNApps;
class Surface_Deformation_Plugin;
struct MapParameters;
class Surface_Deformation_DockTab : public QWidget, public Ui::Surface_Deformation_TabWidget
{
Q_OBJECT
friend class Surface_Deformation_Plugin;
public:
Surface_Deformation_DockTab(SCHNApps* s, Surface_Deformation_Plugin* p);
private:
SCHNApps* m_schnapps;
Surface_Deformation_Plugin* m_plugin;
bool b_updatingUI;
private slots:
void positionAttributeChanged(int index);
void lockedSelectorChanged(int index);
void handleSelectorChanged(int index);
void startStopButtonClicked();
private:
void addVertexAttribute(const QString& nameAttr);
void addVertexSelector(const QString& name);
void removeVertexSelector(const QString& name);
void mapParametersInitialized(bool b);
void updateMapParameters();
};
} // namespace SCHNApps
} // namespace CGoGN
#endif
#include "surface_deformation_dockTab.h"
#include "surface_deformation.h"
#include "schnapps.h"
#include "mapHandler.h"
namespace CGoGN
{
namespace SCHNApps
{
Surface_Deformation_DockTab::Surface_Deformation_DockTab(SCHNApps* s, Surface_Deformation_Plugin* p) :
m_schnapps(s),
m_plugin(p),
b_updatingUI(false)
{
setupUi(this);
connect(combo_positionAttribute, SIGNAL(currentIndexChanged(int)), this, SLOT(positionAttributeChanged(int)));
connect(combo_lockedSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(lockedSelectorChanged(int)));
connect(combo_handleSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(handleSelectorChanged(int)));
connect(button_start_stop, SIGNAL(clicked()), this, SLOT(startStopButtonClicked()));
}
void Surface_Deformation_DockTab::positionAttributeChanged(int index)
{
if(!b_updatingUI)
{
MapHandlerGen* map = m_schnapps->getSelectedMap();
if(map)
{
if(index == 0)
;
else
m_plugin->h_parameterSet[map].positionAttribute = map->getAttribute<PFP2::VEC3, VERTEX>(combo_positionAttribute->currentText());
}
}
}
void Surface_Deformation_DockTab::lockedSelectorChanged(int index)
{
if(!b_updatingUI)
{
MapHandlerGen* map = m_schnapps->getSelectedMap();
if(map)
m_plugin->h_parameterSet[map].lockedSelector = map->getCellSelector<VERTEX>(combo_lockedSelector->currentText());
}
}
void Surface_Deformation_DockTab::handleSelectorChanged(int index)
{
if(!b_updatingUI)
{
MapHandlerGen* map = m_schnapps->getSelectedMap();
if(map)
m_plugin->h_parameterSet[map].handleSelector = map->getCellSelector<VERTEX>(combo_handleSelector->currentText());
}
}
void Surface_Deformation_DockTab::startStopButtonClicked()
{
if(!b_updatingUI)
{
MapHandlerGen* map = m_schnapps->getSelectedMap();
if(map)
m_plugin->toggleMapDeformation(map);
}
}
void Surface_Deformation_DockTab::addVertexAttribute(const QString& name)
{
b_updatingUI = true;
QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));
const QString& typeAttr = m_schnapps->getSelectedMap()->getAttributeTypeName(VERTEX, name);
if(typeAttr == vec3TypeName)
combo_positionAttribute->addItem(name);
b_updatingUI = false;
}
void Surface_Deformation_DockTab::addVertexSelector(const QString& name)
{
b_updatingUI = true;
combo_lockedSelector->addItem(name);
combo_handleSelector->addItem(name);
b_updatingUI = false;
}
void Surface_Deformation_DockTab::removeVertexSelector(const QString& name)
{
b_updatingUI = true;
int curIndex = combo_lockedSelector->currentIndex();
int index = combo_lockedSelector->findText(name, Qt::MatchExactly);
if(curIndex == index)
combo_lockedSelector->setCurrentIndex(0);
combo_lockedSelector->removeItem(index);
curIndex = combo_handleSelector->currentIndex();
index = combo_handleSelector->findText(name, Qt::MatchExactly);
if(curIndex == index)
combo_handleSelector->setCurrentIndex(0);
combo_handleSelector->removeItem(index);
b_updatingUI = false;
}
void Surface_Deformation_DockTab::mapParametersInitialized(bool b)
{
combo_positionAttribute->setEnabled(!b);
combo_lockedSelector->setEnabled(!b);
combo_handleSelector->setEnabled(!b);
if(b) button_start_stop->setText("Stop");
else button_start_stop->setText("Start");
}
void Surface_Deformation_DockTab::updateMapParameters()
{
b_updatingUI = true;
combo_positionAttribute->clear();
combo_positionAttribute->addItem("- select attribute -");
combo_lockedSelector->clear();
combo_lockedSelector->addItem("- select selector -");
combo_handleSelector->clear();
combo_handleSelector->addItem("- select selector -");
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;
}
}
i = 1;
const CellSelectorSet& selectors = map->getCellSelectorSet(VERTEX);
for(CellSelectorSet::const_iterator it = selectors.constBegin(); it != selectors.constEnd(); ++it)
{
combo_lockedSelector->addItem(it.key());
if(p.lockedSelector && it.key() == p.lockedSelector->getName())
combo_lockedSelector->setCurrentIndex(i);
combo_handleSelector->addItem(it.key());
if(p.handleSelector && it.key() == p.handleSelector->getName())
combo_handleSelector->setCurrentIndex(i);
++i;
}
if(p.initialized)
button_start_stop->setText("Stop");
else
button_start_stop->setText("Start");
}
}
} // namespace SCHNApps
} // namespace CGoGN
......@@ -74,7 +74,7 @@ private slots:
void mapRemoved(MapHandlerGen* map);
// slots called from MapHandler signals
void attributeAdded(unsigned int orbit, const QString& nameAttr);
void attributeAdded(unsigned int orbit, const QString& name);
public slots:
// slots for Python calls
......
......@@ -39,7 +39,7 @@ private slots:
void facesScaleFactorChanged(int i);
private:
void addAttributeToList(unsigned int orbit, const QString& nameAttr);
void addVertexAttribute(const QString& name);
void updateMapParameters();
};
......
......@@ -80,11 +80,11 @@ void Surface_RenderTopo_Plugin::mapRemoved(MapHandlerGen* map)
void Surface_RenderTopo_Plugin::attributeAdded(unsigned int orbit, const QString& nameAttr)
void Surface_RenderTopo_Plugin::attributeAdded(unsigned int orbit, const QString& name)
{
MapHandlerGen* map = static_cast<MapHandlerGen*>(QObject::sender());
if(map == m_schnapps->getSelectedMap())
m_dockTab->addAttributeToList(orbit, nameAttr);
if(orbit == VERTEX && map == m_schnapps->getSelectedMap())
m_dockTab->addVertexAttribute(name);
}
......
......@@ -40,7 +40,10 @@ void Surface_RenderTopo_DockTab::positionAttributeChanged(int index)
MapHandlerGen* map = m_schnapps->getSelectedMap();
if(view && map)
{
m_plugin->h_viewParameterSet[view][map].positionAttribute = map->getAttribute<PFP2::VEC3, VERTEX>(combo_positionAttribute->currentText());
if(index == 0)
;
else
m_plugin->h_viewParameterSet[view][map].positionAttribute = map->getAttribute<PFP2::VEC3, VERTEX>(combo_positionAttribute->currentText());
view->updateGL();
}
}
......@@ -162,6 +165,16 @@ void Surface_RenderTopo_DockTab::edgesScaleFactorChanged(int i)
void Surface_RenderTopo_DockTab::addVertexAttribute(const QString& name)
{
b_updatingUI = true;
QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));
const QString& typeAttr = m_schnapps->getSelectedMap()->getAttributeTypeName(VERTEX, name);
if(typeAttr == vec3TypeName)
combo_positionAttribute->addItem(name);
b_updatingUI = false;
}
void Surface_RenderTopo_DockTab::updateMapParameters()
{
b_updatingUI = true;
......@@ -205,16 +218,6 @@ void Surface_RenderTopo_DockTab::updateMapParameters()
b_updatingUI = false;
}
void Surface_RenderTopo_DockTab::addAttributeToList(unsigned int orbit, const QString& nameAttr)
{
b_updatingUI = true;
QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));
const QString& typeAttr = m_schnapps->getSelectedMap()->getAttributeTypeName(orbit, nameAttr);
if(typeAttr == vec3TypeName)
combo_positionAttribute->addItem(nameAttr);
b_updatingUI = false;
}
} // namespace SCHNApps
} // namespace CGoGN
......@@ -58,10 +58,11 @@ private slots:
void mapRemoved(MapHandlerGen* map);
// slots called from MapHandler signals
void attributeAdded(unsigned int orbit, const QString& nameAttr);
void attributeAdded(unsigned int orbit, const QString& name);
public slots:
// slots for Python calls
void changePositionAttribute(const QString& view, const QString& map, const QString& name);
protected:
Surface_Selection_DockTab* m_dockTab;
......
......@@ -31,7 +31,7 @@ private slots:
void positionAttributeChanged(int index);
private:
void addAttributeToList(unsigned int orbit, const QString& nameAttr);
void addVertexAttribute(const QString& name);
void updateMapParameters();
};
......
......@@ -62,7 +62,7 @@ void Surface_Selection_Plugin::draw(View *view)
void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map)
{
if(map == m_schnapps->getSelectedMap())
if(map->isSelectedMap())
{
const MapParameters& p = h_viewParameterSet[view][map];
if(p.positionAttribute.isValid())
......@@ -269,11 +269,27 @@ void Surface_Selection_Plugin::mapRemoved(MapHandlerGen* map)
void Surface_Selection_Plugin::attributeAdded(unsigned int orbit, const QString& nameAttr)
void Surface_Selection_Plugin::attributeAdded(unsigned int orbit, const QString& name)
{
MapHandlerGen* map = static_cast<MapHandlerGen*>(QObject::sender());
if(map == m_schnapps->getSelectedMap())
m_dockTab->addAttributeToList(orbit, nameAttr);
if(orbit == VERTEX && map->isSelectedMap())
m_dockTab->addVertexAttribute(name);
}
void Surface_Selection_Plugin::changePositionAttribute(const QString& view, const QString& map, const QString& name)
{
View* v = m_schnapps->getView(view);
MapHandlerGen* m = m_schnapps->getMap(map);
if(v && m)
{
h_viewParameterSet[v][m].positionAttribute = m->getAttribute<PFP2::VEC3, VERTEX>(name);
if(v->isSelectedView() && m->isSelectedMap())
m_dockTab->updateMapParameters();
}
}
#ifndef DEBUG
......
......@@ -41,6 +41,16 @@ void Surface_Selection_DockTab::positionAttributeChanged(int index)
void Surface_Selection_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_Selection_DockTab::updateMapParameters()
{
b_updatingUI = true;
......@@ -75,16 +85,6 @@ void Surface_Selection_DockTab::updateMapParameters()
b_updatingUI = false;
}
void Surface_Selection_DockTab::addAttributeToList(unsigned int orbit, const QString& nameAttr)
{
b_updatingUI = true;
QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));
const QString& typeAttr = m_schnapps->getSelectedMap()->getAttributeTypeName(orbit, nameAttr);
if(typeAttr == vec3TypeName)
combo_positionAttribute->addItem(nameAttr);
b_updatingUI = false;
}
} // namespace SCHNApps
} // namespace CGoGN
......@@ -146,7 +146,11 @@ public slots:
void removeCellSelector(unsigned int orbit, const QString& name);
CellSelectorGen* getCellSelector(unsigned int orbit, const QString& name) const;
const QMap<QString, CellSelectorGen*>& getCellSelectorSet(unsigned int orbit) const { return m_cellSelectors[orbit]; }
const CellSelectorSet& getCellSelectorSet(unsigned int orbit) const { return m_cellSelectors[orbit]; }
public:
template <unsigned int ORBIT>
CellSelector<ORBIT>* getCellSelector(const QString& name) const;
/*********************************************************
* MANAGE LINKED VIEWS
......@@ -193,7 +197,7 @@ protected:
VBOSet m_vbo;
AttributeSet m_attribs[NB_ORBITS];
QMap<QString, CellSelectorGen*> m_cellSelectors[NB_ORBITS];
CellSelectorSet m_cellSelectors[NB_ORBITS];
};
......
......@@ -44,6 +44,15 @@ inline QString MapHandlerGen::getAttributeTypeName(unsigned int orbit, const QSt
return "";
}
template <unsigned int ORBIT>
CellSelector<ORBIT>* MapHandlerGen::getCellSelector(const QString& name) const
{
if (m_cellSelectors[ORBIT].contains(name))
return static_cast<CellSelector<VERTEX>*>(m_cellSelectors[ORBIT][name]);
else
return NULL;
}
......
......@@ -46,6 +46,7 @@ typedef QMap<QString, Camera*> CameraSet;
typedef QMap<QString, MapHandlerGen*> MapSet;
typedef QMap<QString, Utils::VBO*> VBOSet;
typedef QMap<QString, QString> AttributeSet;
typedef QMap<QString, CellSelectorGen*> CellSelectorSet;
typedef QMap<QString, Utils::GLSLShader*> ShaderSet;
typedef QMap<QString, Texture*> TextureSet;
......
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