diff --git a/SCHNApps/Plugins/surface_deformation/include/surface_deformation.h b/SCHNApps/Plugins/surface_deformation/include/surface_deformation.h index be225eba0a630f132517aebb5385a232a93df575..7a5b517fcba33b87775530685e50c7847a8963d0 100644 --- a/SCHNApps/Plugins/surface_deformation/include/surface_deformation.h +++ b/SCHNApps/Plugins/surface_deformation/include/surface_deformation.h @@ -55,6 +55,7 @@ class Surface_Deformation_Plugin : public PluginInteraction public: Surface_Deformation_Plugin() : + m_draginit(false), m_dragging(false) {} @@ -64,12 +65,12 @@ public: virtual bool enable(); virtual void disable(); - virtual void draw(View *view) {} + 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 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) {} @@ -104,6 +105,7 @@ protected: Surface_Deformation_DockTab* m_dockTab; QHash h_parameterSet; + bool m_draginit; bool m_dragging; PFP2::REAL m_dragZ; qglviewer::Vec m_dragPrevious; diff --git a/SCHNApps/Plugins/surface_deformation/src/surface_deformation.cpp b/SCHNApps/Plugins/surface_deformation/src/surface_deformation.cpp index 004aa775b1a53b87daf755873dcbf997cb2609d8..edfaad2f455e7b2338da595d3b50b4bb62cb617b 100644 --- a/SCHNApps/Plugins/surface_deformation/src/surface_deformation.cpp +++ b/SCHNApps/Plugins/surface_deformation/src/surface_deformation.cpp @@ -126,6 +126,10 @@ void Surface_Deformation_Plugin::disable() 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) { switch(event->key()) @@ -133,8 +137,21 @@ void Surface_Deformation_Plugin::keyPress(View* view, QKeyEvent* event) case Qt::Key_D : { MapHandlerGen* mh = m_schnapps->getSelectedMap(); const MapParameters& p = h_parameterSet[mh]; - if(p.handleSelector && !p.handleSelector->getSelectedCells().empty()) - m_dragging = !m_dragging; + if(!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; } case Qt::Key_R : { @@ -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& handle = p.handleSelector->getSelectedCells(); - - m_dragZ = 0; - for(std::vector::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) { if(m_dragging) { MapHandlerGen* mh = m_schnapps->getSelectedMap(); + MapParameters& p = h_parameterSet[mh]; const std::vector& handle = p.handleSelector->getSelectedCells(); - qglviewer::Vec pp(event->x(), event->y(), m_dragZ); - qglviewer::Vec qq = view->camera()->unprojectedCoordinatesOf(pp); + if(!m_draginit) + { + m_dragZ = 0; + for(std::vector::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; - PFP2::VEC3 t(vec.x, vec.y, vec.z); - for(std::vector::const_iterator it = handle.begin(); it != handle.end(); ++it) - p.positionAttribute[*it] += t; + qglviewer::Vec pp(event->x(), event->y(), m_dragZ); + m_dragPrevious = view->camera()->unprojectedCoordinatesOf(pp); - 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::const_iterator it = handle.begin(); it != handle.end(); ++it) + p.positionAttribute[*it] += t; -// matchDiffCoord(mh); -// asRigidAsPossible(mh); + m_dragPrevious = qq; - mh->notifyAttributeModification(p.positionAttribute); +// matchDiffCoord(map); + if(p.initialized) + asRigidAsPossible(mh); + + mh->notifyAttributeModification(p.positionAttribute); + static_cast*>(mh)->updateBB(p.positionAttribute); + } view->updateGL(); } @@ -271,7 +288,6 @@ void Surface_Deformation_Plugin::selectedCellsChanged() { // nlMakeCurrent(perMap->nlContext) ; // nlReset(NL_FALSE) ; - } @@ -484,18 +500,18 @@ void Surface_Deformation_Plugin::asRigidAsPossible(MapHandlerGen* mh) nlMakeCurrent(p.nlContext); if(nlGetCurrentState() == NL_STATE_INITIAL) - nlBegin(NL_SYSTEM) ; + nlBegin(NL_SYSTEM); for(int coord = 0; coord < 3; ++coord) { - LinearSolving::setupVariables(*map, p.vIndex, p.lockedSelector->getMarker(), p.positionAttribute, coord) ; - nlBegin(NL_MATRIX) ; - // LinearSolving::addRowsRHS_Laplacian_Cotan(*map, p.vIndex, p.edgeWeight, p.vertexArea, p.rotatedDiffCoord, coord) ; - LinearSolving::addRowsRHS_Laplacian_Topo(*map, p.vIndex, p.rotatedDiffCoord, coord) ; - nlEnd(NL_MATRIX) ; - nlEnd(NL_SYSTEM) ; - nlSolve() ; - LinearSolving::getResult(*map, p.vIndex, p.positionAttribute, coord) ; - nlReset(NL_TRUE) ; + LinearSolving::setupVariables(*map, p.vIndex, p.lockedSelector->getMarker(), p.positionAttribute, coord); + nlBegin(NL_MATRIX); + // LinearSolving::addRowsRHS_Laplacian_Cotan(*map, p.vIndex, p.edgeWeight, p.vertexArea, p.rotatedDiffCoord, coord); + LinearSolving::addRowsRHS_Laplacian_Topo(*map, p.vIndex, p.rotatedDiffCoord, coord); + nlEnd(NL_MATRIX); + nlEnd(NL_SYSTEM); + nlSolve(); + LinearSolving::getResult(*map, p.vIndex, p.positionAttribute, coord); + nlReset(NL_TRUE); } } } diff --git a/SCHNApps/Plugins/surface_deformation/src/surface_deformation_dockTab.cpp b/SCHNApps/Plugins/surface_deformation/src/surface_deformation_dockTab.cpp index c6e0a9917d4b6455868877d1563a60dabb8486a0..73e26fda30ae8e02bbddf39486fd85bf348f34fa 100644 --- a/SCHNApps/Plugins/surface_deformation/src/surface_deformation_dockTab.cpp +++ b/SCHNApps/Plugins/surface_deformation/src/surface_deformation_dockTab.cpp @@ -113,11 +113,13 @@ void Surface_Deformation_DockTab::removeVertexSelector(const QString& name) void Surface_Deformation_DockTab::mapParametersInitialized(bool b) { + b_updatingUI = true; 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"); + b_updatingUI = false; } void Surface_Deformation_DockTab::updateMapParameters() @@ -173,6 +175,8 @@ void Surface_Deformation_DockTab::updateMapParameters() else button_start_stop->setText("Start"); } + + b_updatingUI = false; } } // namespace SCHNApps diff --git a/SCHNApps/include/mapHandler.hpp b/SCHNApps/include/mapHandler.hpp index 59e7190742612195f739c407ea26bd4f30311797..f95dfe7841a14d247b4e0cf15e41335c24e9a5ef 100644 --- a/SCHNApps/include/mapHandler.hpp +++ b/SCHNApps/include/mapHandler.hpp @@ -48,7 +48,7 @@ template CellSelector* MapHandlerGen::getCellSelector(const QString& name) const { if (m_cellSelectors[ORBIT].contains(name)) - return static_cast*>(m_cellSelectors[ORBIT][name]); + return static_cast*>(m_cellSelectors[ORBIT][name]); else return NULL; }