Commit 02c85dd9 authored by Pierre Kraemer's avatar Pierre Kraemer

non functional version of plugin surface deformation

parent 3cd5f660
cmake_minimum_required(VERSION 2.8)
ADD_SUBDIRECTORY(surface_import)
ADD_SUBDIRECTORY(surface_differentialProperties)
ADD_SUBDIRECTORY(surface_subdivision)
ADD_SUBDIRECTORY(surface_selection)
ADD_SUBDIRECTORY(surface_render)
ADD_SUBDIRECTORY(surface_renderVector)
ADD_SUBDIRECTORY(surface_renderScalar)
ADD_SUBDIRECTORY(surface_renderTopo)
ADD_SUBDIRECTORY(surface_differentialProperties)
ADD_SUBDIRECTORY(surface_subdivision)
ADD_SUBDIRECTORY(surface_selection)
ADD_SUBDIRECTORY(surface_deformation)
cmake_minimum_required(VERSION 2.8)
SET( PLUGIN_NAME SurfaceDeformation )
SET( PLUGIN_NAME Surface_Deformation )
SET( PLUGIN_ROOT_DIR ${SCHNApps_ROOT_DIR}/Plugins/surfaceDeformation )
SET( PLUGIN_ROOT_DIR ${SCHNApps_ROOT_DIR}/Plugins/surface_deformation )
INCLUDE_DIRECTORIES(
${PLUGIN_ROOT_DIR}/include
......@@ -25,8 +25,8 @@ file(
SET(
PLUGIN_QOBJECT_FILES
${PLUGIN_ROOT_DIR}/include/surfaceDeformation.h
${PLUGIN_ROOT_DIR}/include/surfaceDeformationDockTab.h
${PLUGIN_ROOT_DIR}/include/surface_deformation.h
${PLUGIN_ROOT_DIR}/include/surface_deformation_dockTab.h
)
include( ${SCHNApps_ROOT_DIR}/Plugins/plugins_cmake.txt )
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SurfaceDeformationWidget</class>
<widget class="QWidget" name="SurfaceDeformationWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>189</width>
<height>545</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</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_2">
<property name="text">
<string>Position :</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="combo_positionAttribute">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Select Vertices</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QRadioButton" name="radio_locked">
<property name="text">
<string>locked</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radio_handle">
<property name="text">
<string>handle</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<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>
</layout>
<zorder>mapList</zorder>
<zorder>label_2</zorder>
<zorder>groupBox</zorder>
</widget>
<resources/>
<connections/>
</ui>
#ifndef _SURFACEDEFORMATION_PLUGIN_H_
#define _SURFACEDEFORMATION_PLUGIN_H_
#include "plugin.h"
#include "surfaceDeformationDockTab.h"
#include "mapHandler.h"
#include "Utils/pointSprite.h"
#include "Container/fakeAttribute.h"
#include "NL/nl.h"
#include "Algo/LinearSolving/basic.h"
#include "Eigen/Dense"
namespace CGoGN
{
namespace SCHNApps
{
enum SelectionMode
{
LOCKED,
HANDLE
};
typedef NoNameIOAttribute<Eigen::Matrix3f> Eigen_Matrix3f ;
struct PerMapParameterSet
{
PerMapParameterSet(MapHandlerGen* mh);
~PerMapParameterSet();
void initParameters();
MapHandlerGen* mh;
VertexAttribute<PFP2::VEC3> positionAttribute;
CellMarker<VERTEX>* lockingMarker;
CellMarker<VERTEX>* handleMarker;
SelectionMode verticesSelectionMode;
std::vector<PFP2::VEC3> lockedVertices;
std::vector<PFP2::VEC3> handleVertices;
std::vector<unsigned int> handleVerticesId;
Utils::VBO* lockedVerticesVBO;
Utils::VBO* handleVerticesVBO;
VertexAttribute<PFP2::VEC3> positionInit;
VertexAttribute<PFP2::VEC3> vertexNormal;
EdgeAttribute<PFP2::REAL> edgeAngle;
EdgeAttribute<PFP2::REAL> edgeWeight;
VertexAttribute<PFP2::REAL> vertexArea;
VertexAttribute<PFP2::VEC3> diffCoord;
VertexAttribute<Eigen_Matrix3f> vertexRotationMatrix;
VertexAttribute<PFP2::VEC3> rotatedDiffCoord;
VertexAttribute<unsigned int> vIndex;
unsigned int nb_vertices;
NLContext nlContext;
};
struct ParameterSet
{
ParameterSet() : selectedMap(NULL)
{}
PerMapParameterSet* getCurrentMapParameterSet()
{
if(selectedMap)
return perMap[selectedMap->getName()];
else
return NULL;
}
QHash<QString, PerMapParameterSet*> perMap;
MapHandlerGen* selectedMap;
};
class SurfaceDeformationPlugin : public Plugin
{
Q_OBJECT
Q_INTERFACES(CGoGN::SCHNApps::Plugin)
public:
SurfaceDeformationPlugin() :
selecting(false),
dragging(false)
{
setProvidesRendering(true);
}
~SurfaceDeformationPlugin()
{}
virtual bool enable();
virtual void disable();
virtual void redraw(View *view);
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);
protected:
SurfaceDeformationDockTab* m_dockTab;
QHash<View*, ParameterSet*> h_viewParams;
Utils::PointSprite* m_pointSprite;
Utils::VBO* selectionSphereVBO;
bool selecting;
PFP2::VEC3 selectionCenter;
PFP2::REAL selectionRadius;
bool dragging;
PFP2::REAL dragZ;
qglviewer::Vec dragPrevious;
public slots:
void viewLinked(View* view, Plugin* plugin);
void viewUnlinked(View* view, Plugin* plugin);
void currentViewChanged(View* view);
void mapLinked(MapHandlerGen* m);
void mapUnlinked(MapHandlerGen* m);
protected:
void addManagedMap(View *v, MapHandlerGen* m);
void removeManagedMap(View *v, MapHandlerGen* m);
public slots:
void changeSelectedMap(View* view, MapHandlerGen* map);
void changePositionAttribute(View* view, MapHandlerGen* map, VertexAttribute<PFP2::VEC3> attribute, bool fromUI = false);
void changeVerticesSelectionMode(View* view, MapHandlerGen* map, SelectionMode m, bool fromUI = false);
protected:
void matchDiffCoord(View* view, MapHandlerGen* map);
void asRigidAsPossible(View* view, MapHandlerGen* map);
};
} // namespace SCHNApps
} // namespace CGoGN
#endif
#ifndef _SURFACE_DEFORMATION_DOCK_TAB_H_
#define _SURFACE_DEFORMATION_DOCK_TAB_H_
#include "ui_surfaceDeformation.h"
namespace CGoGN
{
namespace SCHNApps
{
class Window;
class SurfaceDeformationPlugin;
struct ParameterSet;
class SurfaceDeformationDockTab : public QWidget, public Ui::SurfaceDeformationWidget
{
Q_OBJECT
public:
SurfaceDeformationDockTab(Window* w, SurfaceDeformationPlugin* p);
private:
Window* m_window;
SurfaceDeformationPlugin* m_plugin;
ParameterSet* m_currentParams;
bool b_refreshingUI;
public slots:
void refreshUI(ParameterSet* params);
void selectedMapChanged();
void positionAttributeChanged(int index);
void selectLockedVertices(bool b);
void selectHandleVertices(bool b);
void addAttributeToList(unsigned int orbit, const QString& nameAttr);
};
} // namespace SCHNApps
} // namespace CGoGN
#endif
#include "surfaceDeformationDockTab.h"
#include "surfaceDeformation.h"
#include "window.h"
#include "mapHandler.h"
namespace CGoGN
{
namespace SCHNApps
{
SurfaceDeformationDockTab::SurfaceDeformationDockTab(Window* w, SurfaceDeformationPlugin* p) :
m_window(w),
m_plugin(p),
b_refreshingUI(false)
{
setupUi(this);
connect(mapList, SIGNAL(itemSelectionChanged()), this, SLOT(selectedMapChanged()));
connect(combo_positionAttribute, SIGNAL(currentIndexChanged(int)), this, SLOT(positionAttributeChanged(int)));
connect(radio_locked, SIGNAL(toggled(bool)), this, SLOT(selectLockedVertices(bool)));
connect(radio_handle, SIGNAL(toggled(bool)), this, SLOT(selectHandleVertices(bool)));
}
void SurfaceDeformationDockTab::refreshUI(ParameterSet* params)
{
m_currentParams = params;
b_refreshingUI = true;
mapList->clear();
combo_positionAttribute->clear();
MapHandlerGen* mh = params->selectedMap;
QHash<QString, PerMapParameterSet*>::const_iterator i = params->perMap.constBegin();
while (i != params->perMap.constEnd())
{
mapList->addItem(i.key());
if(mh != NULL && i.key() == mh->getName())
{
QList<QListWidgetItem*> item = mapList->findItems(mh->getName(), Qt::MatchExactly);
item[0]->setSelected(true);
PerMapParameterSet* p = params->perMap[mh->getName()];
QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));
unsigned int j = 0;
const AttributeHash& attribs = mh->getAttributesList(VERTEX);
for(AttributeHash::const_iterator i = attribs.constBegin(); i != attribs.constEnd(); ++i)
{
if(i.value() == vec3TypeName)
{
combo_positionAttribute->addItem(i.key());
if(i.key() == QString::fromStdString(p->positionAttribute.name()))
combo_positionAttribute->setCurrentIndex(j);
++j;
}
}
radio_locked->setChecked(p->verticesSelectionMode == LOCKED);
radio_handle->setChecked(p->verticesSelectionMode == HANDLE);
}
++i;
}
b_refreshingUI = false;
}
void SurfaceDeformationDockTab::selectedMapChanged()
{
if(!b_refreshingUI)
{
QList<QListWidgetItem*> currentItems = mapList->selectedItems();
if(!currentItems.empty())
m_plugin->changeSelectedMap(m_window->getCurrentView(), m_window->getMap(currentItems[0]->text()));
}
}
void SurfaceDeformationDockTab::positionAttributeChanged(int index)
{
if(!b_refreshingUI)
{
View* view = m_window->getCurrentView();
MapHandlerGen* map = m_currentParams->selectedMap;
if(map)
m_plugin->changePositionAttribute(view, map, map->getAttribute<PFP2::VEC3, VERTEX>(combo_positionAttribute->currentText()), true);
}
}
void SurfaceDeformationDockTab::selectLockedVertices(bool b)
{
if(!b_refreshingUI)
{
View* view = m_window->getCurrentView();
MapHandlerGen* map = m_currentParams->selectedMap;
if(map)
m_plugin->changeVerticesSelectionMode(view, map, LOCKED, true);
}
}
void SurfaceDeformationDockTab::selectHandleVertices(bool b)
{
if(!b_refreshingUI)
{
View* view = m_window->getCurrentView();
MapHandlerGen* map = m_currentParams->selectedMap;
if(map)
m_plugin->changeVerticesSelectionMode(view, map, HANDLE, true);
}
}
void SurfaceDeformationDockTab::addAttributeToList(unsigned int orbit, const QString& nameAttr)
{
QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));
const QString& typeAttr = m_currentParams->selectedMap->getAttributeTypeName(orbit, nameAttr);
if(typeAttr == vec3TypeName)
{
combo_positionAttribute->addItem(nameAttr);
}
}
} // namespace SCHNApps
} // namespace CGoGN
......@@ -25,7 +25,7 @@ public:
{}
virtual bool enable();
virtual void disable() {}
virtual void disable();
private slots:
void mapAdded(MapHandlerGen* map);
......
......@@ -37,6 +37,21 @@ bool Surface_DifferentialProperties_Plugin::enable()
return true;
}
void Surface_DifferentialProperties_Plugin::disable()
{
disconnect(m_computeNormalAction, SIGNAL(triggered()), this, SLOT(openComputeNormalDialog()));
disconnect(m_computeCurvatureAction, SIGNAL(triggered()), this, SLOT(openComputeCurvatureDialog()));
disconnect(m_computeNormalDialog, SIGNAL(accepted()), this, SLOT(computeNormalFromDialog()));
disconnect(m_computeNormalDialog->button_apply, SIGNAL(clicked()), this, SLOT(computeNormalFromDialog()));
disconnect(m_computeCurvatureDialog, SIGNAL(accepted()), this, SLOT(computeCurvatureFromDialog()));
disconnect(m_computeCurvatureDialog->button_apply, SIGNAL(clicked()), this, SLOT(computeCurvatureFromDialog()));
disconnect(m_schnapps, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(mapAdded(MapHandlerGen*)));
disconnect(m_schnapps, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(mapRemoved(MapHandlerGen*)));
}
void Surface_DifferentialProperties_Plugin::mapAdded(MapHandlerGen *map)
{
connect(map, SIGNAL(attributeModified(unsigned int, QString)), this, SLOT(attributeModified(unsigned int, QString)));
......
......@@ -55,6 +55,11 @@ void Surface_Render_Plugin::disable()
delete m_simpleColorShader;
delete m_pointSprite;
disconnect(m_schnapps, SIGNAL(selectedViewChanged(View*, View*)), this, SLOT(selectedViewChanged(View*, View*)));
disconnect(m_schnapps, SIGNAL(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)), this, SLOT(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)));
disconnect(m_schnapps, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(mapAdded(MapHandlerGen*)));
disconnect(m_schnapps, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(mapRemoved(MapHandlerGen*)));
foreach(MapHandlerGen* map, m_schnapps->getMapSet().values())
mapRemoved(map);
}
......
......@@ -34,6 +34,11 @@ void Surface_RenderScalar_Plugin::disable()
{
delete m_scalarShader;
disconnect(m_schnapps, SIGNAL(selectedViewChanged(View*, View*)), this, SLOT(selectedViewChanged(View*, View*)));
disconnect(m_schnapps, SIGNAL(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)), this, SLOT(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)));
disconnect(m_schnapps, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(mapAdded(MapHandlerGen*)));
disconnect(m_schnapps, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(mapRemoved(MapHandlerGen*)));
foreach(MapHandlerGen* map, m_schnapps->getMapSet().values())
mapRemoved(map);
}
......
......@@ -28,6 +28,11 @@ bool Surface_RenderTopo_Plugin::enable()
void Surface_RenderTopo_Plugin::disable()
{
disconnect(m_schnapps, SIGNAL(selectedViewChanged(View*, View*)), this, SLOT(selectedViewChanged(View*, View*)));
disconnect(m_schnapps, SIGNAL(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)), this, SLOT(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)));
disconnect(m_schnapps, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(mapAdded(MapHandlerGen*)));
disconnect(m_schnapps, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(mapRemoved(MapHandlerGen*)));
foreach(MapHandlerGen* map, m_schnapps->getMapSet().values())
mapRemoved(map);
}
......
......@@ -35,6 +35,11 @@ void Surface_RenderVector_Plugin::disable()
{
delete m_vectorShader;
disconnect(m_schnapps, SIGNAL(selectedViewChanged(View*, View*)), this, SLOT(selectedViewChanged(View*, View*)));
disconnect(m_schnapps, SIGNAL(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)), this, SLOT(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)));
disconnect(m_schnapps, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(mapAdded(MapHandlerGen*)));
disconnect(m_schnapps, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(mapRemoved(MapHandlerGen*)));
foreach(MapHandlerGen* map, m_schnapps->getMapSet().values())
mapRemoved(map);
}
......
......@@ -49,6 +49,11 @@ void Surface_Selection_Plugin::disable()
{
delete m_selectionSphereVBO;
delete m_pointSprite;
disconnect(m_schnapps, SIGNAL(selectedViewChanged(View*, View*)), this, SLOT(selectedViewChanged(View*, View*)));
disconnect(m_schnapps, SIGNAL(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)), this, SLOT(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)));
disconnect(m_schnapps, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(mapAdded(MapHandlerGen*)));
disconnect(m_schnapps, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(mapRemoved(MapHandlerGen*)));
}
void Surface_Selection_Plugin::draw(View *view)
......@@ -106,7 +111,7 @@ void Surface_Selection_Plugin::keyPress(View* view, QKeyEvent* event)
{
view->setMouseTracking(true);
m_selecting = true;
view->updateGL();
// view->updateGL();
}
}
......@@ -116,7 +121,7 @@ void Surface_Selection_Plugin::keyRelease(View* view, QKeyEvent* event)
{
view->setMouseTracking(false);
m_selecting = false;
view->updateGL();
// view->updateGL();
}
}
......
......@@ -24,7 +24,7 @@ public:
{}
virtual bool enable();
virtual void disable() {}
virtual void disable();
private slots:
void openSubdivisionDialog();
......
......@@ -26,6 +26,14 @@ bool Surface_Subdivision_Plugin::enable()
return true;
}
void Surface_Subdivision_Plugin::disable()
{
disconnect(m_subdivisionAction, SIGNAL(triggered()), this, SLOT(openSubdivisionDialog()));
disconnect(m_subdivisionDialog, SIGNAL(accepted()), this, SLOT(subdivideFromDialog()));
disconnect(m_subdivisionDialog->button_apply, SIGNAL(clicked()), this, SLOT(subdivideFromDialog()));
}
void Surface_Subdivision_Plugin::openSubdivisionDialog()
{
m_subdivisionDialog->show();
......
......@@ -63,6 +63,8 @@ public:
inline unsigned int getOrbit() { return ORBIT; }
inline const CellMarker<ORBIT>& getMarker() { return m_cm; }
inline void select(Dart d, bool emitSignal = true)
{
unsigned int v = m_map.getEmbedding<ORBIT>(d);
......