Commit af2b3121 authored by Sylvain Thery's avatar Sylvain Thery

Merge cgogn:~cgogn/CGoGN

parents 17d2ebb7 1d0228be
......@@ -7,4 +7,4 @@ ADD_SUBDIRECTORY(render)
ADD_SUBDIRECTORY(renderVector)
ADD_SUBDIRECTORY(renderExplod)
ADD_SUBDIRECTORY(subdivideSurface)
ADD_SUBDIRECTORY(surfaceDeformation)
#ADD_SUBDIRECTORY(surfaceDeformation)
......@@ -30,12 +30,12 @@ public:
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 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) {}
public slots:
void openComputeNormalDialog();
......
......@@ -27,12 +27,12 @@ public:
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 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) {}
public slots:
MapHandlerGen* importFromFile(const QString& fileName);
......
......@@ -27,12 +27,12 @@ public:
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 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) {}
public slots:
MapHandlerGen* importFromFile(const QString& fileName);
......
......@@ -89,12 +89,12 @@ public:
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 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) {}
void setRefreshingUI(bool b) { b_refreshingUI = b; }
......
......@@ -77,12 +77,12 @@ public:
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 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) {}
void setRefreshingUI(bool b) { b_refreshingUI = b; }
......
......@@ -83,6 +83,12 @@
</spacer>
</item>
</layout>
<zorder>mapList</zorder>
<zorder>label_3</zorder>
<zorder>list_vectorVBO</zorder>
<zorder>label</zorder>
<zorder>slider_vectorsScaleFactor</zorder>
<zorder>label_2</zorder>
</widget>
<resources/>
<connections/>
......
......@@ -71,12 +71,12 @@ public:
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 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) {}
void setRefreshingUI(bool b) { b_refreshingUI = b; }
......
......@@ -29,12 +29,12 @@ public:
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 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) {}
public slots:
void openSubdivideSurfaceDialog();
......
<?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_positionVBO">
<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>
......@@ -8,15 +8,66 @@ using namespace CGoGN;
using namespace SCHNApps;
struct PerMapParameterSet
{
PerMapParameterSet() {}
PerMapParameterSet(MapHandlerGen* mh);
VertexAttribute<PFP2::VEC3> positionAttribute;
CellMarker<VERTEX> lockingMarker;
bool setLockedVertices;
bool selecting;
PFP2::VEC3 selectionCenter;
PFP2::REAL selectionRadius;
bool dragging;
PFP2::REAL dragZ;
qglviewer::Vec dragPrevious;
std::vector<unsigned int> locked_vertices;
std::vector<unsigned int> handle_vertices;
};
struct ParameterSet
{
ParameterSet() : selectedMap(NULL)
{}
PerMapParameterSet& getCurrentMapParameterSet()
{
return perMap[selectedMap->getName()];
}
QHash<QString, PerMapParameterSet> perMap;
MapHandlerGen* selectedMap;
};
class SurfaceDeformationPlugin;
class SurfaceDeformationDockTab : public QWidget, public Ui::SurfaceDeformationWidget
{
public:
SurfaceDeformationDockTab(SurfaceDeformationPlugin* p) : plugin(p)
{
setupUi(this);
}
void refreshUI(ParameterSet* params);
private:
SurfaceDeformationPlugin* plugin;
};
class SurfaceDeformationPlugin : public Plugin
{
Q_OBJECT
Q_INTERFACES(CGoGN::SCHNApps::Plugin)
public:
SurfaceDeformationPlugin()
SurfaceDeformationPlugin() : b_refreshingUI(false)
{
setProvidesRendering(false);
setProvidesRendering(true);
}
~SurfaceDeformationPlugin()
......@@ -25,19 +76,36 @@ public:
virtual bool enable();
virtual void disable() {}
virtual void redraw(View *view) {}
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);
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) {}
void setRefreshingUI(bool b) { b_refreshingUI = b; }
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);
void changeSelectedMap(View* view, MapHandlerGen* map);
void changePositionAttribute(View* view, MapHandlerGen* map, VertexAttribute<PFP2::VEC3> attribute);
void cb_selectedMapChanged();
void cb_positionAttributeChanged(int index);
private:
RenderVectorDockTab* m_dockTab;
QHash<View*, ParameterSet*> h_viewParams;
bool b_refreshingUI;
};
#endif
#include "surfaceDeformation.h"
#include "Algo/Selection/raySelector.h"
#include "Algo/Selection/collector.h"
PerMapParameterSet::PerMapParameterSet(MapHandlerGen* mh) :
setLockedVertices(true),
selecting(false),
selectionRadius(0.1f),
dragging(false)
{
GenericMap* map = mh->getGenericMap();
AttributeContainer& cont = map->getAttributeContainer<VERTEX>();
std::vector<std::string> names;
std::vector<std::string> types;
cont.getAttributesNames(names);
cont.getAttributesTypes(types);
std::string vec3TypeName = nameOfType(PFP2::VEC3());
for(unsigned int i = 0; i < names.size(); ++i)
{
if(types[i] == vec3TypeName)
{
if(names[i] == "position") // try to select a position attribute named "position"
positionAttribute = mh->getAttribute<PFP2::VEC3>(names[i]);
}
}
if(!positionAttribute.isValid())
{
for(unsigned int i = 0; i < names.size(); ++i)
{
if(types[i] == vec3TypeName)
{
positionAttribute = mh->getAttribute<PFP2::VEC3>(names[i]);
break;
}
}
}
}
bool SurfaceDeformationPlugin::enable()
{
m_dockTab = new SurfaceDeformationDockTab(this);
addTabInDock(m_dockTab, "Surface Deformation");
connect(m_dockTab->mapList, SIGNAL(itemSelectionChanged()), this, SLOT(cb_selectedMapChanged()));
connect(m_dockTab->combo_positionAttribute, SIGNAL(currentIndexChanged(int)), this, SLOT(cb_positionAttributeChanged(int)));
connect(m_window, SIGNAL(viewAndPluginLinked(View*, Plugin*)), this, SLOT(viewLinked(View*, Plugin*)));
connect(m_window, SIGNAL(viewAndPluginUnlinked(View*, Plugin*)), this, SLOT(viewUnlinked(View*, Plugin*)));
connect(m_window, SIGNAL(currentViewChanged(View*)), this, SLOT(currentViewChanged(View*)));
return true;
}
void SurfaceDeformationPlugin::keyPress(View* view, QKeyEvent* event)
{
if(event->key() == Qt::Key_Shift)
{
view->setMouseTracking(true);
ParameterSet* params = h_viewParams[view];
PerMapParameterSet& perMap = params->getCurrentMapParameterSet();
perMap.selecting = true;
view->updateGL();
}
}
void SurfaceDeformationPlugin::keyRelease(View* view, QKeyEvent* event)
{
if(event->key() == Qt::Key_Shift)
{
view->setMouseTracking(false);
ParameterSet* params = h_viewParams[view];
PerMapParameterSet& perMap = params->getCurrentMapParameterSet();
perMap.selecting = false;
view->updateGL();
}
}
void SurfaceDeformationPlugin::mousePress(View* view, QMouseEvent* event)
{
if(event->button() == Qt::RightButton && event->modifiers() & Qt::ShiftModifier)
{
view->setMouseTracking(false) ;
ParameterSet* params = h_viewParams[view];
PerMapParameterSet& perMap = params->getCurrentMapParameterSet();
perMap.selecting = false ;
perMap.dragging = true ;
perMap.dragZ = 0;
for(unsigned int i = 0; i < perMap.handle_vertices.size(); ++i)
{
PFP::VEC3& p = perMap.positionAttribute[handle_vertices[i]] ;
qglviewer::Vec q = view->projectedCoordinatesOf(qglviewer::Vec(p[0],p[1],p[2]));
dragZ += q.z ;
}
dragZ /= handle_vertices.size() ;
qglviewer::Vec p(event->x(), event->y(), dragZ);
perMap.dragPrevious = view->unprojectedCoordinatesOf(p);
}
if(button == Qt::LeftButton && event->modifiers() & Qt::ShiftModifier)
{
ParameterSet* params = h_viewParams[view];
PerMapParameterSet& perMap = params->getCurrentMapParameterSet();
QPoint pixel(event->x(), event->y());
qglviewer::Vec orig;
qglviewer::Vec dir;
view->convertClickToLine(pixel, orig, dir);
PFP::VEC3 rayA(orig.x, orig.y, orig.z);
PFP::VEC3 AB(dir.x, dir.y, dir.z);
Dart d ;
PFP2::MAP map = static_cast<MapHandler<PFP2>*>(params->selectedMap)->getMap();
Algo::Selection::vertexRaySelection<PFP>(*map, position, rayA, AB, d) ;
if(d != NIL)
{
Algo::Surface::Selection::Collector_WithinSphere<PFP> neigh(*map, perMap.positionAttribute, perMap.selectionRadius) ;
neigh.collectAll(d) ;
const std::vector<Dart>& insideV = neigh.getInsideVertices() ;
if(perMap.setLockedVertices)
{
for(unsigned int i = 0; i < insideV.size(); ++i)
{
unsigned int v = map->getEmbedding<VERTEX>(insideV[i]) ;
if (!lockingMarker.isMarked(v))
{
locked_vertices.push_back(v) ;
lockingMarker.mark(v);
}
}
LinearSolving::resetSolver(solver, false) ;
}
else
{
for(unsigned int i = 0; i < insideV.size(); ++i)
{
unsigned int v = myMap.getEmbedding<VERTEX>(insideV[i]) ;
if(!handleMarker.isMarked(v))
{
handle_vertices.push_back(v) ;
handleMarker.mark(v);
}
if(!lockingMarker.isMarked(v))
{
locked_vertices.push_back(v) ;
lockingMarker.mark(v) ;
}
}
LinearSolving::resetSolver(solver, false) ;
}
view->updateGL() ;
}
}
}
void SurfaceDeformationPlugin::mouseRelease(View* view, QMouseEvent* event)
{
if(event->button() == Qt::RightButton)
{
ParameterSet* params = h_viewParams[view];
PerMapParameterSet& perMap = params->getCurrentMapParameterSet();
perMap.dragging = false ;
}
}
void SurfaceDeformationPlugin::mouseMove(View* view, QMouseEvent* event)
{
ParameterSet* params = h_viewParams[view];
PerMapParameterSet& perMap = params->getCurrentMapParameterSet();
if(perMap.dragging)
{
qglviewer::Vec p(event->x(), event->y(), perMap.dragZ);
qglviewer::Vec q = view->unprojectedCoordinatesOf(p);
qglviewer::Vec vec = q - perMap.dragPrevious;
PFP::VEC3 t(vec.x, vec.y, vec.z);
for(unsigned int i = 0; i < handle_vertices.size(); ++i)
perMap.positionAttribute[handle_vertices[i]] += t ;
perMap.dragPrevious = q ;
// matchDiffCoord() ;
// for(unsigned int i = 0; i < 2; ++i)
// asRigidAsPossible();
m_positionVBO->updateData(position);
view->updateGL();
}
else if(selecting)
{
QPoint pixel(event->x(), event->y());
qglviewer::Vec orig;
qglviewer::Vec dir;
view->convertClickToLine(pixel, orig, dir);
PFP::VEC3 rayA(orig.x, orig.y, orig.z);
PFP::VEC3 AB(dir.x, dir.y, dir.z);
Dart d ;
PFP2::MAP map = static_cast<MapHandler<PFP2>*>(params->selectedMap)->getMap();
Algo::Selection::vertexRaySelection<PFP2>(*map, position, rayA, AB, d) ;
if(d != NIL)
{
perMap.selectionCenter = perMap.positionAttribute[d] ;
view->updateGL() ;
}
}
}
void SurfaceDeformationPlugin::viewLinked(View* view, Plugin* plugin)
{
if(plugin == this)
{
ParameterSet* params = new ParameterSet();
h_viewParams.insert(view, params);
const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
foreach(MapHandlerGen* map, maps)
{
PerMapParameterSet p(map);
params->perMap.insert(map->getName(), p);
}
if (!maps.empty())
changeSelectedMap(view, maps[0]);
connect(view, SIGNAL(mapLinked(MapHandlerGen*)), this, SLOT(mapLinked(MapHandlerGen*)));
connect(view, SIGNAL(mapUnlinked(MapHandlerGen*)), this, SLOT(mapUnlinked(MapHandlerGen*)));
if(view->isCurrentView())
m_dockTab->refreshUI(params);
}
}
void SurfaceDeformationPlugin::viewUnlinked(View* view, Plugin* plugin)
{
if(plugin == this)
{
h_viewParams.remove(view);
disconnect(view, SIGNAL(mapLinked(MapHandlerGen*)), this, SLOT(mapLinked(MapHandlerGen*)));
disconnect(view, SIGNAL(mapUnlinked(MapHandlerGen*)), this, SLOT(mapUnlinked(MapHandlerGen*)));
}
}
void SurfaceDeformationPlugin::currentViewChanged(View* view)
{
if(isLinkedToView(view))
m_dockTab->refreshUI(h_viewParams[view]);
}
void SurfaceDeformationPlugin::mapLinked(MapHandlerGen* m)
{
View* view = static_cast<View*>(QObject::sender());