Commit 734a59a7 authored by Pierre Kraemer's avatar Pierre Kraemer
Browse files

SCHNApps: debug surface deformation

parent 9a08b7b1
...@@ -7,5 +7,5 @@ ADD_SUBDIRECTORY(render) ...@@ -7,5 +7,5 @@ ADD_SUBDIRECTORY(render)
ADD_SUBDIRECTORY(renderVector) ADD_SUBDIRECTORY(renderVector)
ADD_SUBDIRECTORY(renderExplod) ADD_SUBDIRECTORY(renderExplod)
ADD_SUBDIRECTORY(subdivideSurface) ADD_SUBDIRECTORY(subdivideSurface)
#ADD_SUBDIRECTORY(surfaceDeformation) ADD_SUBDIRECTORY(surfaceDeformation)
#ADD_SUBDIRECTORY(renderTopoSurface) #ADD_SUBDIRECTORY(renderTopoSurface)
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="combo_positionVBO"> <widget class="QComboBox" name="combo_positionAttribute">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
......
...@@ -2,27 +2,34 @@ ...@@ -2,27 +2,34 @@
#define _SURFACEDEFORMATION_PLUGIN_H_ #define _SURFACEDEFORMATION_PLUGIN_H_
#include "plugin.h" #include "plugin.h"
#include "mapHandler.h"
#include "ui_surfaceDeformation.h"
#include "Utils/drawer.h"
using namespace CGoGN; using namespace CGoGN;
using namespace SCHNApps; using namespace SCHNApps;
enum SelectionMode
{
LOCKED,
HANDLE
};
struct PerMapParameterSet struct PerMapParameterSet
{ {
PerMapParameterSet() {} PerMapParameterSet() {}
PerMapParameterSet(MapHandlerGen* mh); PerMapParameterSet(MapHandlerGen* mh);
~PerMapParameterSet();
VertexAttribute<PFP2::VEC3> positionAttribute; VertexAttribute<PFP2::VEC3> positionAttribute;
CellMarker<VERTEX> lockingMarker; CellMarker<VERTEX>* lockingMarker;
bool setLockedVertices; CellMarker<VERTEX>* handleMarker;
bool selecting; SelectionMode verticesSelectionMode;
PFP2::VEC3 selectionCenter;
PFP2::REAL selectionRadius;
bool dragging;
PFP2::REAL dragZ;
qglviewer::Vec dragPrevious;
std::vector<unsigned int> locked_vertices; std::vector<unsigned int> locked_vertices;
std::vector<unsigned int> handle_vertices; std::vector<unsigned int> handle_vertices;
}; };
...@@ -32,12 +39,12 @@ struct ParameterSet ...@@ -32,12 +39,12 @@ struct ParameterSet
ParameterSet() : selectedMap(NULL) ParameterSet() : selectedMap(NULL)
{} {}
PerMapParameterSet& getCurrentMapParameterSet() PerMapParameterSet* getCurrentMapParameterSet()
{ {
return perMap[selectedMap->getName()]; return perMap[selectedMap->getName()];
} }
QHash<QString, PerMapParameterSet> perMap; QHash<QString, PerMapParameterSet*> perMap;
MapHandlerGen* selectedMap; MapHandlerGen* selectedMap;
}; };
...@@ -65,7 +72,10 @@ class SurfaceDeformationPlugin : public Plugin ...@@ -65,7 +72,10 @@ class SurfaceDeformationPlugin : public Plugin
Q_INTERFACES(CGoGN::SCHNApps::Plugin) Q_INTERFACES(CGoGN::SCHNApps::Plugin)
public: public:
SurfaceDeformationPlugin() : b_refreshingUI(false) SurfaceDeformationPlugin() :
b_refreshingUI(false),
selecting(false),
dragging(false)
{ {
setProvidesRendering(true); setProvidesRendering(true);
} }
...@@ -74,7 +84,7 @@ public: ...@@ -74,7 +84,7 @@ public:
{} {}
virtual bool enable(); virtual bool enable();
virtual void disable() {} virtual void disable();
virtual void redraw(View *view); virtual void redraw(View *view);
...@@ -95,17 +105,31 @@ public slots: ...@@ -95,17 +105,31 @@ public slots:
void mapLinked(MapHandlerGen* m); void mapLinked(MapHandlerGen* m);
void mapUnlinked(MapHandlerGen* m); void mapUnlinked(MapHandlerGen* m);
void attributeAdded();
void changeSelectedMap(View* view, MapHandlerGen* map); void changeSelectedMap(View* view, MapHandlerGen* map);
void changePositionAttribute(View* view, MapHandlerGen* map, VertexAttribute<PFP2::VEC3> attribute); void changePositionAttribute(View* view, MapHandlerGen* map, VertexAttribute<PFP2::VEC3> attribute);
void changeVerticesSelectionMode(View* view, MapHandlerGen* map, SelectionMode m);
void cb_selectedMapChanged(); void cb_selectedMapChanged();
void cb_positionAttributeChanged(int index); void cb_positionAttributeChanged(int index);
void cb_selectLockedVertices(bool b);
void cb_selectHandleVertices(bool b);
private: private:
RenderVectorDockTab* m_dockTab; SurfaceDeformationDockTab* m_dockTab;
QHash<View*, ParameterSet*> h_viewParams; QHash<View*, ParameterSet*> h_viewParams;
Utils::Drawer* m_drawer;
bool b_refreshingUI; bool b_refreshingUI;
bool selecting;
PFP2::VEC3 selectionCenter;
PFP2::REAL selectionRadius;
bool dragging;
PFP2::REAL dragZ;
qglviewer::Vec dragPrevious;
}; };
#endif #endif
...@@ -3,14 +3,18 @@ ...@@ -3,14 +3,18 @@
#include "Algo/Selection/raySelector.h" #include "Algo/Selection/raySelector.h"
#include "Algo/Selection/collector.h" #include "Algo/Selection/collector.h"
#include <QKeyEvent>
#include <QMouseEvent>
PerMapParameterSet::PerMapParameterSet(MapHandlerGen* mh) : PerMapParameterSet::PerMapParameterSet(MapHandlerGen* mh) :
setLockedVertices(true), verticesSelectionMode(LOCKED)
selecting(false),
selectionRadius(0.1f),
dragging(false)
{ {
GenericMap* map = mh->getGenericMap(); GenericMap* map = mh->getGenericMap();
lockingMarker = new CellMarker<VERTEX>(*map);
handleMarker = new CellMarker<VERTEX>(*map);
AttributeContainer& cont = map->getAttributeContainer<VERTEX>(); AttributeContainer& cont = map->getAttributeContainer<VERTEX>();
std::vector<std::string> names; std::vector<std::string> names;
...@@ -23,7 +27,7 @@ PerMapParameterSet::PerMapParameterSet(MapHandlerGen* mh) : ...@@ -23,7 +27,7 @@ PerMapParameterSet::PerMapParameterSet(MapHandlerGen* mh) :
if(types[i] == vec3TypeName) if(types[i] == vec3TypeName)
{ {
if(names[i] == "position") // try to select a position attribute named "position" if(names[i] == "position") // try to select a position attribute named "position"
positionAttribute = mh->getAttribute<PFP2::VEC3>(names[i]); positionAttribute = mh->getAttribute<PFP2::VEC3, VERTEX>(QString::fromStdString(names[i]));
} }
} }
...@@ -33,13 +37,19 @@ PerMapParameterSet::PerMapParameterSet(MapHandlerGen* mh) : ...@@ -33,13 +37,19 @@ PerMapParameterSet::PerMapParameterSet(MapHandlerGen* mh) :
{ {
if(types[i] == vec3TypeName) if(types[i] == vec3TypeName)
{ {
positionAttribute = mh->getAttribute<PFP2::VEC3>(names[i]); positionAttribute = mh->getAttribute<PFP2::VEC3, VERTEX>(QString::fromStdString(names[i]));
break; break;
} }
} }
} }
} }
PerMapParameterSet::~PerMapParameterSet()
{
delete lockingMarker;
delete handleMarker;
}
bool SurfaceDeformationPlugin::enable() bool SurfaceDeformationPlugin::enable()
{ {
...@@ -48,22 +58,85 @@ bool SurfaceDeformationPlugin::enable() ...@@ -48,22 +58,85 @@ bool SurfaceDeformationPlugin::enable()
connect(m_dockTab->mapList, SIGNAL(itemSelectionChanged()), this, SLOT(cb_selectedMapChanged())); 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_dockTab->combo_positionAttribute, SIGNAL(currentIndexChanged(int)), this, SLOT(cb_positionAttributeChanged(int)));
connect(m_dockTab->radio_locked, SIGNAL(toggled(bool)), this, SLOT(cb_selectLockedVertices(bool)));
connect(m_dockTab->radio_handle, SIGNAL(toggled(bool)), this, SLOT(cb_selectHandleVertices(bool)));
connect(m_window, SIGNAL(viewAndPluginLinked(View*, Plugin*)), this, SLOT(viewLinked(View*, Plugin*))); 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(viewAndPluginUnlinked(View*, Plugin*)), this, SLOT(viewUnlinked(View*, Plugin*)));
connect(m_window, SIGNAL(currentViewChanged(View*)), this, SLOT(currentViewChanged(View*))); connect(m_window, SIGNAL(currentViewChanged(View*)), this, SLOT(currentViewChanged(View*)));
Utils::ShaderColorPerVertex* s = new Utils::ShaderColorPerVertex();
registerShader(s);
m_drawer = new Utils::Drawer();
registerShader(m_drawer->getShader());
return true; return true;
} }
void SurfaceDeformationPlugin::disable()
{
delete m_drawer;
}
void SurfaceDeformationPlugin::redraw(View* view)
{
if(selecting)
{
glDisable(GL_LIGHTING) ;
m_drawer->newList(GL_COMPILE_AND_EXECUTE) ;
m_drawer->lineWidth(2.0f) ;
m_drawer->begin(GL_LINES) ;
m_drawer->color3f(0.0f, 0.0f, 1.0f) ;
m_drawer->vertex(selectionCenter) ;
m_drawer->vertex(selectionCenter + selectionRadius * PFP2::VEC3(1,0,0)) ;
m_drawer->vertex(selectionCenter) ;
m_drawer->vertex(selectionCenter + selectionRadius * PFP2::VEC3(-1,0,0)) ;
m_drawer->vertex(selectionCenter) ;
m_drawer->vertex(selectionCenter + selectionRadius * PFP2::VEC3(0,1,0)) ;
m_drawer->vertex(selectionCenter) ;
m_drawer->vertex(selectionCenter + selectionRadius * PFP2::VEC3(0,-1,0)) ;
m_drawer->vertex(selectionCenter) ;
m_drawer->vertex(selectionCenter + selectionRadius * PFP2::VEC3(0,0,1)) ;
m_drawer->vertex(selectionCenter) ;
m_drawer->vertex(selectionCenter + selectionRadius * PFP2::VEC3(0,0,-1)) ;
m_drawer->end() ;
m_drawer->endList() ;
}
ParameterSet* params = h_viewParams[view];
MapHandlerGen* mh = params->selectedMap;
if(mh)
{
PerMapParameterSet* perMap = params->perMap[mh->getName()];
if(!perMap->locked_vertices.empty() || !perMap->handle_vertices.empty())
{
glDisable(GL_LIGHTING) ;
m_drawer->newList(GL_COMPILE_AND_EXECUTE) ;
m_drawer->pointSize(4.0f) ;
m_drawer->begin(GL_POINTS) ;
m_drawer->color3f(1.0f, 0.0f, 0.0f) ;
for(unsigned int i = 0; i < perMap->locked_vertices.size(); ++i)
{
if (!perMap->handleMarker->isMarked(perMap->locked_vertices[i]))
m_drawer->vertex(perMap->positionAttribute[perMap->locked_vertices[i]]) ;
}
m_drawer->color3f(0.0f, 0.0f, 1.0f) ;
for(unsigned int i = 0; i < perMap->handle_vertices.size(); ++i)
m_drawer->vertex(perMap->positionAttribute[perMap->handle_vertices[i]]) ;
m_drawer->end() ;
m_drawer->endList() ;
}
}
}
void SurfaceDeformationPlugin::keyPress(View* view, QKeyEvent* event) void SurfaceDeformationPlugin::keyPress(View* view, QKeyEvent* event)
{ {
if(event->key() == Qt::Key_Shift) if(event->key() == Qt::Key_Shift)
{ {
view->setMouseTracking(true); view->setMouseTracking(true);
ParameterSet* params = h_viewParams[view]; selecting = true;
PerMapParameterSet& perMap = params->getCurrentMapParameterSet();
perMap.selecting = true;
view->updateGL(); view->updateGL();
} }
} }
...@@ -73,127 +146,122 @@ void SurfaceDeformationPlugin::keyRelease(View* view, QKeyEvent* event) ...@@ -73,127 +146,122 @@ void SurfaceDeformationPlugin::keyRelease(View* view, QKeyEvent* event)
if(event->key() == Qt::Key_Shift) if(event->key() == Qt::Key_Shift)
{ {
view->setMouseTracking(false); view->setMouseTracking(false);
ParameterSet* params = h_viewParams[view]; selecting = false;
PerMapParameterSet& perMap = params->getCurrentMapParameterSet();
perMap.selecting = false;
view->updateGL(); view->updateGL();
} }
} }
void SurfaceDeformationPlugin::mousePress(View* view, QMouseEvent* event) void SurfaceDeformationPlugin::mousePress(View* view, QMouseEvent* event)
{ {
if(event->button() == Qt::RightButton && event->modifiers() & Qt::ShiftModifier) if(event->button() == Qt::LeftButton && selecting)
{ {
view->setMouseTracking(false) ;
ParameterSet* params = h_viewParams[view]; ParameterSet* params = h_viewParams[view];
PerMapParameterSet& perMap = params->getCurrentMapParameterSet(); 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()); QPoint pixel(event->x(), event->y());
qglviewer::Vec orig; qglviewer::Vec orig;
qglviewer::Vec dir; qglviewer::Vec dir;
view->convertClickToLine(pixel, orig, dir); view->camera()->convertClickToLine(pixel, orig, dir);
PFP::VEC3 rayA(orig.x, orig.y, orig.z); PFP2::VEC3 rayA(orig.x, orig.y, orig.z);
PFP::VEC3 AB(dir.x, dir.y, dir.z); PFP2::VEC3 AB(dir.x, dir.y, dir.z);
Dart d ; Dart d ;
PFP2::MAP map = static_cast<MapHandler<PFP2>*>(params->selectedMap)->getMap(); PFP2::MAP* map = static_cast<MapHandler<PFP2>*>(params->selectedMap)->getMap();
Algo::Selection::vertexRaySelection<PFP>(*map, position, rayA, AB, d) ; Algo::Selection::vertexRaySelection<PFP2>(*map, perMap->positionAttribute, rayA, AB, d) ;
if(d != NIL) if(d != NIL)
{ {
Algo::Surface::Selection::Collector_WithinSphere<PFP> neigh(*map, perMap.positionAttribute, perMap.selectionRadius) ; Algo::Surface::Selection::Collector_WithinSphere<PFP2> neigh(*map, perMap->positionAttribute, selectionRadius) ;
neigh.collectAll(d) ; neigh.collectAll(d) ;
const std::vector<Dart>& insideV = neigh.getInsideVertices() ; const std::vector<Dart>& insideV = neigh.getInsideVertices() ;
if(perMap.setLockedVertices) if(perMap->verticesSelectionMode == LOCKED)
{ {
for(unsigned int i = 0; i < insideV.size(); ++i) for(unsigned int i = 0; i < insideV.size(); ++i)
{ {
unsigned int v = map->getEmbedding<VERTEX>(insideV[i]) ; unsigned int v = map->getEmbedding<VERTEX>(insideV[i]) ;
if (!lockingMarker.isMarked(v)) if (!perMap->lockingMarker->isMarked(v))
{ {
locked_vertices.push_back(v) ; perMap->locked_vertices.push_back(v) ;
lockingMarker.mark(v); perMap->lockingMarker->mark(v);
} }
} }
LinearSolving::resetSolver(solver, false) ;
} }
else else
{ {
for(unsigned int i = 0; i < insideV.size(); ++i) for(unsigned int i = 0; i < insideV.size(); ++i)
{ {
unsigned int v = myMap.getEmbedding<VERTEX>(insideV[i]) ; unsigned int v = map->getEmbedding<VERTEX>(insideV[i]) ;
if(!handleMarker.isMarked(v)) if(!perMap->handleMarker->isMarked(v))
{ {
handle_vertices.push_back(v) ; perMap->handle_vertices.push_back(v) ;
handleMarker.mark(v); perMap->handleMarker->mark(v);
} }
if(!lockingMarker.isMarked(v)) if(!perMap->lockingMarker->isMarked(v))
{ {
locked_vertices.push_back(v) ; perMap->locked_vertices.push_back(v) ;
lockingMarker.mark(v) ; perMap->lockingMarker->mark(v) ;
} }
} }
LinearSolving::resetSolver(solver, false) ;
} }
view->updateGL() ; view->updateGL() ;
} }
} }
else if(event->button() == Qt::RightButton && event->modifiers() & Qt::ShiftModifier)
{
view->setMouseTracking(false) ;
ParameterSet* params = h_viewParams[view];
PerMapParameterSet* perMap = params->getCurrentMapParameterSet();
selecting = false ;
dragging = true ;
dragZ = 0;
for(unsigned int i = 0; i < perMap->handle_vertices.size(); ++i)
{
const PFP2::VEC3& p = perMap->positionAttribute[perMap->handle_vertices[i]] ;
qglviewer::Vec q = view->camera()->projectedCoordinatesOf(qglviewer::Vec(p[0],p[1],p[2]));
dragZ += q.z ;
}
dragZ /= perMap->handle_vertices.size() ;
qglviewer::Vec p(event->x(), event->y(), dragZ);
dragPrevious = view->camera()->unprojectedCoordinatesOf(p);
}
} }
void SurfaceDeformationPlugin::mouseRelease(View* view, QMouseEvent* event) void SurfaceDeformationPlugin::mouseRelease(View* view, QMouseEvent* event)
{ {
if(event->button() == Qt::RightButton) if(event->button() == Qt::RightButton)
{ {
ParameterSet* params = h_viewParams[view]; dragging = false ;
PerMapParameterSet& perMap = params->getCurrentMapParameterSet();
perMap.dragging = false ;
} }
} }
void SurfaceDeformationPlugin::mouseMove(View* view, QMouseEvent* event) void SurfaceDeformationPlugin::mouseMove(View* view, QMouseEvent* event)
{ {
ParameterSet* params = h_viewParams[view]; ParameterSet* params = h_viewParams[view];
PerMapParameterSet& perMap = params->getCurrentMapParameterSet(); PerMapParameterSet* perMap = params->getCurrentMapParameterSet();
if(perMap.dragging)
if(dragging)
{ {
qglviewer::Vec p(event->x(), event->y(), perMap.dragZ); qglviewer::Vec p(event->x(), event->y(), dragZ);
qglviewer::Vec q = view->unprojectedCoordinatesOf(p); qglviewer::Vec q = view->camera()->unprojectedCoordinatesOf(p);
qglviewer::Vec vec = q - perMap.dragPrevious; qglviewer::Vec vec = q - dragPrevious;
PFP::VEC3 t(vec.x, vec.y, vec.z); PFP2::VEC3 t(vec.x, vec.y, vec.z);
for(unsigned int i = 0; i < handle_vertices.size(); ++i) for(unsigned int i = 0; i < perMap->handle_vertices.size(); ++i)
perMap.positionAttribute[handle_vertices[i]] += t ; perMap->positionAttribute[perMap->handle_vertices[i]] += t ;
perMap.dragPrevious = q ; dragPrevious = q ;
// matchDiffCoord() ; // matchDiffCoord() ;
// for(unsigned int i = 0; i < 2; ++i) // for(unsigned int i = 0; i < 2; ++i)
// asRigidAsPossible(); // asRigidAsPossible();