Commit f17551a4 authored by Pierre Kraemer's avatar Pierre Kraemer
Browse files

deformation plugin OK (interaction not finished..)

parent dd6f4b63
...@@ -55,6 +55,7 @@ class Surface_Deformation_Plugin : public PluginInteraction ...@@ -55,6 +55,7 @@ class Surface_Deformation_Plugin : public PluginInteraction
public: public:
Surface_Deformation_Plugin() : Surface_Deformation_Plugin() :
m_draginit(false),
m_dragging(false) m_dragging(false)
{} {}
...@@ -64,12 +65,12 @@ public: ...@@ -64,12 +65,12 @@ public:
virtual bool enable(); virtual bool enable();
virtual void disable(); virtual void disable();
virtual void draw(View *view) {} virtual void draw(View *view);
virtual void drawMap(View* view, MapHandlerGen* map) {} virtual void drawMap(View* view, MapHandlerGen* map) {}
virtual void keyPress(View* view, QKeyEvent* event); virtual void keyPress(View* view, QKeyEvent* event);
virtual void keyRelease(View* view, QKeyEvent* event) {} virtual void keyRelease(View* view, QKeyEvent* event) {}
virtual void mousePress(View* view, QMouseEvent* event); virtual void mousePress(View* view, QMouseEvent* event) {}
virtual void mouseRelease(View* view, QMouseEvent* event) {} virtual void mouseRelease(View* view, QMouseEvent* event) {}
virtual void mouseMove(View* view, QMouseEvent* event); virtual void mouseMove(View* view, QMouseEvent* event);
virtual void wheelEvent(View* view, QWheelEvent* event) {} virtual void wheelEvent(View* view, QWheelEvent* event) {}
...@@ -104,6 +105,7 @@ protected: ...@@ -104,6 +105,7 @@ protected:
Surface_Deformation_DockTab* m_dockTab; Surface_Deformation_DockTab* m_dockTab;
QHash<MapHandlerGen*, MapParameters> h_parameterSet; QHash<MapHandlerGen*, MapParameters> h_parameterSet;
bool m_draginit;
bool m_dragging; bool m_dragging;
PFP2::REAL m_dragZ; PFP2::REAL m_dragZ;
qglviewer::Vec m_dragPrevious; qglviewer::Vec m_dragPrevious;
......
...@@ -126,6 +126,10 @@ void Surface_Deformation_Plugin::disable() ...@@ -126,6 +126,10 @@ void Surface_Deformation_Plugin::disable()
disconnect(m_schnapps, SIGNAL(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)), this, SLOT(selectedMapChanged(MapHandlerGen*, MapHandlerGen*))); disconnect(m_schnapps, SIGNAL(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)), this, SLOT(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)));
} }
void Surface_Deformation_Plugin::draw(View *view)
{
}
void Surface_Deformation_Plugin::keyPress(View* view, QKeyEvent* event) void Surface_Deformation_Plugin::keyPress(View* view, QKeyEvent* event)
{ {
switch(event->key()) switch(event->key())
...@@ -133,8 +137,21 @@ void Surface_Deformation_Plugin::keyPress(View* view, QKeyEvent* event) ...@@ -133,8 +137,21 @@ void Surface_Deformation_Plugin::keyPress(View* view, QKeyEvent* event)
case Qt::Key_D : { case Qt::Key_D : {
MapHandlerGen* mh = m_schnapps->getSelectedMap(); MapHandlerGen* mh = m_schnapps->getSelectedMap();
const MapParameters& p = h_parameterSet[mh]; const MapParameters& p = h_parameterSet[mh];
if(p.handleSelector && !p.handleSelector->getSelectedCells().empty()) if(!m_dragging)
m_dragging = !m_dragging; {
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(false);
}
break; break;
} }
case Qt::Key_R : { case Qt::Key_R : {
...@@ -152,50 +169,50 @@ void Surface_Deformation_Plugin::keyPress(View* view, QKeyEvent* event) ...@@ -152,50 +169,50 @@ void Surface_Deformation_Plugin::keyPress(View* view, QKeyEvent* event)
} }
} }
void Surface_Deformation_Plugin::mousePress(View* view, QMouseEvent* event)
{
if(event->button() == Qt::LeftButton && m_dragging)
{
MapHandlerGen* mh = m_schnapps->getSelectedMap();
const MapParameters& p = h_parameterSet[mh];
const std::vector<Dart>& handle = p.handleSelector->getSelectedCells();
m_dragZ = 0;
for(std::vector<Dart>::const_iterator it = handle.begin(); it != handle.end(); ++it)
{
const PFP2::VEC3& pp = p.positionAttribute[*it];
qglviewer::Vec q = view->camera()->projectedCoordinatesOf(qglviewer::Vec(pp[0],pp[1],pp[2]));
m_dragZ += q.z;
}
m_dragZ /= handle.size();
qglviewer::Vec pp(event->x(), event->y(), m_dragZ);
m_dragPrevious = view->camera()->unprojectedCoordinatesOf(pp);
}
}
void Surface_Deformation_Plugin::mouseMove(View* view, QMouseEvent* event) void Surface_Deformation_Plugin::mouseMove(View* view, QMouseEvent* event)
{ {
if(m_dragging) if(m_dragging)
{ {
MapHandlerGen* mh = m_schnapps->getSelectedMap(); MapHandlerGen* mh = m_schnapps->getSelectedMap();
MapParameters& p = h_parameterSet[mh]; MapParameters& p = h_parameterSet[mh];
const std::vector<Dart>& handle = p.handleSelector->getSelectedCells(); const std::vector<Dart>& handle = p.handleSelector->getSelectedCells();
qglviewer::Vec pp(event->x(), event->y(), m_dragZ); if(!m_draginit)
qglviewer::Vec qq = view->camera()->unprojectedCoordinatesOf(pp); {
m_dragZ = 0;
for(std::vector<Dart>::const_iterator it = handle.begin(); it != handle.end(); ++it)
{
const PFP2::VEC3& pp = p.positionAttribute[*it];
qglviewer::Vec q = view->camera()->projectedCoordinatesOf(qglviewer::Vec(pp[0],pp[1],pp[2]));
m_dragZ += q.z;
}
m_dragZ /= handle.size();
qglviewer::Vec vec = qq - m_dragPrevious; qglviewer::Vec pp(event->x(), event->y(), m_dragZ);
PFP2::VEC3 t(vec.x, vec.y, vec.z); m_dragPrevious = view->camera()->unprojectedCoordinatesOf(pp);
for(std::vector<Dart>::const_iterator it = handle.begin(); it != handle.end(); ++it)
p.positionAttribute[*it] += t;
m_dragPrevious = qq; m_draginit = true;
}
else
{
qglviewer::Vec pp(event->x(), event->y(), m_dragZ);
qglviewer::Vec qq = view->camera()->unprojectedCoordinatesOf(pp);
qglviewer::Vec vec = qq - m_dragPrevious;
PFP2::VEC3 t(vec.x, vec.y, vec.z);
for(std::vector<Dart>::const_iterator it = handle.begin(); it != handle.end(); ++it)
p.positionAttribute[*it] += t;
// matchDiffCoord(mh); m_dragPrevious = qq;
// asRigidAsPossible(mh);
mh->notifyAttributeModification(p.positionAttribute); // matchDiffCoord(map);
if(p.initialized)
asRigidAsPossible(mh);
mh->notifyAttributeModification(p.positionAttribute);
static_cast<MapHandler<PFP2>*>(mh)->updateBB(p.positionAttribute);
}
view->updateGL(); view->updateGL();
} }
...@@ -271,7 +288,6 @@ void Surface_Deformation_Plugin::selectedCellsChanged() ...@@ -271,7 +288,6 @@ void Surface_Deformation_Plugin::selectedCellsChanged()
{ {
// nlMakeCurrent(perMap->nlContext) ; // nlMakeCurrent(perMap->nlContext) ;
// nlReset(NL_FALSE) ; // nlReset(NL_FALSE) ;
} }
...@@ -484,18 +500,18 @@ void Surface_Deformation_Plugin::asRigidAsPossible(MapHandlerGen* mh) ...@@ -484,18 +500,18 @@ void Surface_Deformation_Plugin::asRigidAsPossible(MapHandlerGen* mh)
nlMakeCurrent(p.nlContext); nlMakeCurrent(p.nlContext);
if(nlGetCurrentState() == NL_STATE_INITIAL) if(nlGetCurrentState() == NL_STATE_INITIAL)
nlBegin(NL_SYSTEM) ; nlBegin(NL_SYSTEM);
for(int coord = 0; coord < 3; ++coord) for(int coord = 0; coord < 3; ++coord)
{ {
LinearSolving::setupVariables<PFP2>(*map, p.vIndex, p.lockedSelector->getMarker(), p.positionAttribute, coord) ; LinearSolving::setupVariables<PFP2>(*map, p.vIndex, p.lockedSelector->getMarker(), p.positionAttribute, coord);
nlBegin(NL_MATRIX) ; nlBegin(NL_MATRIX);
// LinearSolving::addRowsRHS_Laplacian_Cotan<PFP2>(*map, p.vIndex, p.edgeWeight, p.vertexArea, p.rotatedDiffCoord, coord) ; // LinearSolving::addRowsRHS_Laplacian_Cotan<PFP2>(*map, p.vIndex, p.edgeWeight, p.vertexArea, p.rotatedDiffCoord, coord);
LinearSolving::addRowsRHS_Laplacian_Topo<PFP2>(*map, p.vIndex, p.rotatedDiffCoord, coord) ; LinearSolving::addRowsRHS_Laplacian_Topo<PFP2>(*map, p.vIndex, p.rotatedDiffCoord, coord);
nlEnd(NL_MATRIX) ; nlEnd(NL_MATRIX);
nlEnd(NL_SYSTEM) ; nlEnd(NL_SYSTEM);
nlSolve() ; nlSolve();
LinearSolving::getResult<PFP2>(*map, p.vIndex, p.positionAttribute, coord) ; LinearSolving::getResult<PFP2>(*map, p.vIndex, p.positionAttribute, coord);
nlReset(NL_TRUE) ; nlReset(NL_TRUE);
} }
} }
} }
......
...@@ -113,11 +113,13 @@ void Surface_Deformation_DockTab::removeVertexSelector(const QString& name) ...@@ -113,11 +113,13 @@ void Surface_Deformation_DockTab::removeVertexSelector(const QString& name)
void Surface_Deformation_DockTab::mapParametersInitialized(bool b) void Surface_Deformation_DockTab::mapParametersInitialized(bool b)
{ {
b_updatingUI = true;
combo_positionAttribute->setEnabled(!b); combo_positionAttribute->setEnabled(!b);
combo_lockedSelector->setEnabled(!b); combo_lockedSelector->setEnabled(!b);
combo_handleSelector->setEnabled(!b); combo_handleSelector->setEnabled(!b);
if(b) button_start_stop->setText("Stop"); if(b) button_start_stop->setText("Stop");
else button_start_stop->setText("Start"); else button_start_stop->setText("Start");
b_updatingUI = false;
} }
void Surface_Deformation_DockTab::updateMapParameters() void Surface_Deformation_DockTab::updateMapParameters()
...@@ -173,6 +175,8 @@ void Surface_Deformation_DockTab::updateMapParameters() ...@@ -173,6 +175,8 @@ void Surface_Deformation_DockTab::updateMapParameters()
else else
button_start_stop->setText("Start"); button_start_stop->setText("Start");
} }
b_updatingUI = false;
} }
} // namespace SCHNApps } // namespace SCHNApps
......
...@@ -48,7 +48,7 @@ template <unsigned int ORBIT> ...@@ -48,7 +48,7 @@ template <unsigned int ORBIT>
CellSelector<ORBIT>* MapHandlerGen::getCellSelector(const QString& name) const CellSelector<ORBIT>* MapHandlerGen::getCellSelector(const QString& name) const
{ {
if (m_cellSelectors[ORBIT].contains(name)) if (m_cellSelectors[ORBIT].contains(name))
return static_cast<CellSelector<VERTEX>*>(m_cellSelectors[ORBIT][name]); return static_cast<CellSelector<ORBIT>*>(m_cellSelectors[ORBIT][name]);
else else
return NULL; return NULL;
} }
......
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