From c3d604f7c829f9fc25c1cfc00f63e47a56591aa3 Mon Sep 17 00:00:00 2001 From: Pierre Kraemer Date: Thu, 5 Mar 2015 23:48:02 +0100 Subject: [PATCH] SCHNApps: Surface_selection: debug crash when selecting cell on MacOS --- .../include/surface_selection.h | 6 +- .../src/surface_selection.cpp | 58 ++++++++++++------- 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/SCHNApps/Plugins/surface_selection/include/surface_selection.h b/SCHNApps/Plugins/surface_selection/include/surface_selection.h index 4b2f56fa..87be21dd 100644 --- a/SCHNApps/Plugins/surface_selection/include/surface_selection.h +++ b/SCHNApps/Plugins/surface_selection/include/surface_selection.h @@ -47,7 +47,7 @@ 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); @@ -97,6 +97,10 @@ protected: Utils::Drawer* m_selectingCellDrawer; + bool m_selectedVertices_dirty; + bool m_selectedEdges_dirty; + bool m_selectedFaces_dirty; + // WithinSphere parameters Utils::VBO* m_selectionSphereVBO; PFP2::REAL m_selectionRadiusBase; diff --git a/SCHNApps/Plugins/surface_selection/src/surface_selection.cpp b/SCHNApps/Plugins/surface_selection/src/surface_selection.cpp index 63c458fe..5e568e82 100644 --- a/SCHNApps/Plugins/surface_selection/src/surface_selection.cpp +++ b/SCHNApps/Plugins/surface_selection/src/surface_selection.cpp @@ -18,6 +18,9 @@ namespace SCHNApps Surface_Selection_Plugin::Surface_Selection_Plugin() : m_selecting(false), + m_selectedVertices_dirty(false), + m_selectedEdges_dirty(false), + m_selectedFaces_dirty(false), m_selectionRadiusBase(1), m_selectionRadiusCoeff(1), m_normalAngleThreshold(10) @@ -79,10 +82,6 @@ void Surface_Selection_Plugin::disable() disconnect(m_schnapps, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(mapRemoved(MapHandlerGen*))); } -void Surface_Selection_Plugin::draw(View *view) -{ -} - void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map) { if(map->isSelectedMap()) @@ -98,14 +97,20 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map) switch(orbit) { case VERTEX : { - m_pointSprite->setAttributePosition(m_selectedVerticesVBO); - m_pointSprite->setSize(20 * map->getBBdiagSize() / nbCells); - m_pointSprite->setColor(CGoGN::Geom::Vec4f(1.0f, 0.0f, 0.0f, 1.0f)); - m_pointSprite->setLightPosition(CGoGN::Geom::Vec3f(0.0f, 0.0f, 1.0f)); + if (selector->getNbSelectedCells() > 0) + { + if (m_selectedVertices_dirty) + updateSelectedCellsRendering(); - m_pointSprite->enableVertexAttribs(); - glDrawArrays(GL_POINTS, 0, selector->getNbSelectedCells()); - m_pointSprite->disableVertexAttribs(); + m_pointSprite->setAttributePosition(m_selectedVerticesVBO); + m_pointSprite->setColor(CGoGN::Geom::Vec4f(1.0f, 0.0f, 0.0f, 1.0f)); + m_pointSprite->setLightPosition(CGoGN::Geom::Vec3f(0.0f, 0.0f, 1.0f)); + m_pointSprite->setSize(20 * map->getBBdiagSize() / nbCells); + + m_pointSprite->enableVertexAttribs(); + glDrawArrays(GL_POINTS, 0, selector->getNbSelectedCells()); + m_pointSprite->disableVertexAttribs(); + } if(m_selecting && m_selectingVertex.valid()) { @@ -140,7 +145,12 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map) break; } case EDGE : { - m_selectedEdgesDrawer->callList(); + if (selector->getNbSelectedCells() > 0) + { + if (m_selectedEdges_dirty) + updateSelectedCellsRendering(); + m_selectedEdgesDrawer->callList(); + } if(m_selecting && m_selectingEdge.valid()) { @@ -182,7 +192,12 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map) break; } case FACE : { - m_selectedFacesDrawer->callList(); + if (selector->getNbSelectedCells() > 0) + { + if (m_selectedFaces_dirty) + updateSelectedCellsRendering(); + m_selectedFacesDrawer->callList(); + } if(m_selecting && m_selectingFace.valid()) { @@ -269,6 +284,7 @@ void Surface_Selection_Plugin::mousePress(View* view, QMouseEvent* event) CellSelector* cs = static_cast*>(selector); if(m_selectingVertex.valid()) { + m_selectedVertices_dirty = true; switch(p.selectionMethod) { case SingleCell : { @@ -300,7 +316,6 @@ void Surface_Selection_Plugin::mousePress(View* view, QMouseEvent* event) break; } } - updateSelectedCellsRendering(); } break; } @@ -308,6 +323,7 @@ void Surface_Selection_Plugin::mousePress(View* view, QMouseEvent* event) CellSelector* cs = static_cast*>(selector); if(m_selectingEdge.valid()) { + m_selectedEdges_dirty = true; switch(p.selectionMethod) { case SingleCell : { @@ -339,7 +355,6 @@ void Surface_Selection_Plugin::mousePress(View* view, QMouseEvent* event) break; } } - updateSelectedCellsRendering(); } break; } @@ -347,6 +362,7 @@ void Surface_Selection_Plugin::mousePress(View* view, QMouseEvent* event) CellSelector* cs = static_cast*>(selector); if(m_selectingFace.valid()) { + m_selectedFaces_dirty = true; switch(p.selectionMethod) { case SingleCell : { @@ -378,7 +394,6 @@ void Surface_Selection_Plugin::mousePress(View* view, QMouseEvent* event) break; } } - updateSelectedCellsRendering(); } break; } @@ -494,11 +509,13 @@ void Surface_Selection_Plugin::selectedMapChanged(MapHandlerGen *prev, MapHandle void Surface_Selection_Plugin::updateSelectedCellsRendering() { MapHandlerGen* map = m_schnapps->getSelectedMap(); + const MapParameters& p = h_parameterSet[map]; if(p.positionAttribute.isValid()) { unsigned int orbit = m_schnapps->getCurrentOrbit(); CellSelectorGen* selector = m_schnapps->getSelectedSelector(orbit); + switch(orbit) { case VERTEX : { @@ -508,6 +525,7 @@ void Surface_Selection_Plugin::updateSelectedCellsRendering() for(std::vector::const_iterator v = selectedCells.begin(); v != selectedCells.end(); ++v) selectedPoints.push_back(p.positionAttribute[*v]); m_selectedVerticesVBO->updateData(selectedPoints); + m_selectedVertices_dirty = false; break; } case EDGE : { @@ -527,6 +545,7 @@ void Surface_Selection_Plugin::updateSelectedCellsRendering() } m_selectedEdgesDrawer->end(); m_selectedEdgesDrawer->endList(); + m_selectedEdges_dirty = false; break; } case FACE : { @@ -546,16 +565,11 @@ void Surface_Selection_Plugin::updateSelectedCellsRendering() } m_selectedFacesDrawer->end(); m_selectedFacesDrawer->endList(); + m_selectedFaces_dirty = false; break; } } } - - foreach(View* view, l_views) - { - if(view->isLinkedToMap(map)) - view->updateGL(); - } } -- GitLab