From 938b9d3a556eb9d0b6040570e5da4dc234ffe2e9 Mon Sep 17 00:00:00 2001 From: Sylvain Thery Date: Tue, 23 Jun 2015 15:18:53 +0200 Subject: [PATCH] bug selector remove, selection of polygonal faces --- .../surface_render/include/surface_render.h | 1 + .../surface_render/src/surface_render.cpp | 29 ++++- .../src/surface_render_dockTab.cpp | 3 + .../include/surface_selection.h | 2 + .../src/surface_selection.cpp | 115 +++++++++++++----- .../src/surface_selection_dockTab.cpp | 5 - SCHNApps/src/controlDock_mapTab.cpp | 2 + 7 files changed, 120 insertions(+), 37 deletions(-) diff --git a/SCHNApps/Plugins/surface_render/include/surface_render.h b/SCHNApps/Plugins/surface_render/include/surface_render.h index 8af5be60c..5937abf4c 100644 --- a/SCHNApps/Plugins/surface_render/include/surface_render.h +++ b/SCHNApps/Plugins/surface_render/include/surface_render.h @@ -105,6 +105,7 @@ private slots: // slots called from MapHandler signals void vboAdded(Utils::VBO* vbo); void vboRemoved(Utils::VBO* vbo); + void selectedMapBoundingBoxModified(); void schnappsClosing(); diff --git a/SCHNApps/Plugins/surface_render/src/surface_render.cpp b/SCHNApps/Plugins/surface_render/src/surface_render.cpp index a489584a9..7b0edbbeb 100644 --- a/SCHNApps/Plugins/surface_render/src/surface_render.cpp +++ b/SCHNApps/Plugins/surface_render/src/surface_render.cpp @@ -18,13 +18,13 @@ bool Surface_Render_Plugin::enable() m_schnapps->addPluginDockTab(this, m_dockTab, "Surface_Render"); m_flatShader = new CGoGN::Utils::ShaderFlat(); - //m_flatShader->setAmbiant(CGoGN::Geom::Vec4f(0.2f, 0.2f, 0.2f, 0.1f)); + m_flatShader->setAmbiant(CGoGN::Geom::Vec4f(0.2f, 0.2f, 0.2f, 0.1f)); m_flatShader->setExplode(1.0f); m_phongShader = new CGoGN::Utils::ShaderPhong(); - //m_phongShader->setAmbiant(CGoGN::Geom::Vec4f(0.2f, 0.2f, 0.2f, 0.1f)); - //m_phongShader->setSpecular(CGoGN::Geom::Vec4f(0.9f, 0.9f, 0.9f, 1.0f)); - //m_phongShader->setShininess(80.0f); + m_phongShader->setAmbiant(CGoGN::Geom::Vec4f(0.2f, 0.2f, 0.2f, 0.1f)); + m_phongShader->setSpecular(CGoGN::Geom::Vec4f(0.9f, 0.9f, 0.9f, 1.0f)); + m_phongShader->setShininess(80.0f); m_colorPerVertexShader = new CGoGN::Utils::ShaderColorPerVertex(); @@ -153,6 +153,13 @@ void Surface_Render_Plugin::selectedViewChanged(View *prev, View *cur) void Surface_Render_Plugin::selectedMapChanged(MapHandlerGen *prev, MapHandlerGen *cur) { DEBUG_SLOT(); + + if (prev) + disconnect(prev, SIGNAL(boundingBoxModified()), this, SLOT(selectedMapBoundingBoxModified())); + if (cur) + connect(cur, SIGNAL(boundingBoxModified()), this, SLOT(selectedMapBoundingBoxModified())); + + m_dockTab->updateMapParameters(); } @@ -161,6 +168,7 @@ void Surface_Render_Plugin::mapAdded(MapHandlerGen *map) DEBUG_SLOT(); connect(map, SIGNAL(vboAdded(Utils::VBO*)), this, SLOT(vboAdded(Utils::VBO*))); connect(map, SIGNAL(vboRemoved(Utils::VBO*)), this, SLOT(vboRemoved(Utils::VBO*))); + connect(map, SIGNAL(boundingBoxModified()), this, SLOT(selectedMapBoundingBoxModified())); } void Surface_Render_Plugin::mapRemoved(MapHandlerGen *map) @@ -168,6 +176,7 @@ void Surface_Render_Plugin::mapRemoved(MapHandlerGen *map) DEBUG_SLOT(); disconnect(map, SIGNAL(vboAdded(Utils::VBO*)), this, SLOT(vboAdded(Utils::VBO*))); disconnect(map, SIGNAL(vboRemoved(Utils::VBO*)), this, SLOT(vboRemoved(Utils::VBO*))); + disconnect(map, SIGNAL(boundingBoxModified()), this, SLOT(selectedMapBoundingBoxModified())); } @@ -235,6 +244,18 @@ void Surface_Render_Plugin::vboRemoved(Utils::VBO *vbo) } +void Surface_Render_Plugin::selectedMapBoundingBoxModified() +{ + MapHandlerGen* m = m_schnapps->getSelectedMap(); + + QList views = m->getLinkedViews(); + if (m) + foreach(View* v, views) + { + if (h_viewParameterSet.contains(v)) + h_viewParameterSet[v][m].basePSradius = m->getBBdiagSize() / (2 * std::sqrt(m->getNbOrbits(EDGE))); + } +} diff --git a/SCHNApps/Plugins/surface_render/src/surface_render_dockTab.cpp b/SCHNApps/Plugins/surface_render/src/surface_render_dockTab.cpp index 69fd7896e..8a1fb38f7 100644 --- a/SCHNApps/Plugins/surface_render/src/surface_render_dockTab.cpp +++ b/SCHNApps/Plugins/surface_render/src/surface_render_dockTab.cpp @@ -53,9 +53,12 @@ void Surface_Render_DockTab::positionVBOChanged(int index) MapHandlerGen* map = m_schnapps->getSelectedMap(); if (view && map) { + m_plugin->h_viewParameterSet[view][map].basePSradius = map->getBBdiagSize() / (2 * std::sqrt(map->getNbOrbits(EDGE))); m_plugin->h_viewParameterSet[view][map].positionVBO = map->getVBO(combo_positionVBO->currentText()); view->updateGL(); m_plugin->pythonRecording("changePositionVBO", "", view->getName(), map->getName(), combo_positionVBO->currentText()); +// TODO write this slot ? +// m_plugin->pythonRecording("changeVerticesBaseSize", "",view->getName(), map->getName(), h_viewParameterSet[view][map].basePSradius); } } } diff --git a/SCHNApps/Plugins/surface_selection/include/surface_selection.h b/SCHNApps/Plugins/surface_selection/include/surface_selection.h index c9996de8a..63e931f50 100644 --- a/SCHNApps/Plugins/surface_selection/include/surface_selection.h +++ b/SCHNApps/Plugins/surface_selection/include/surface_selection.h @@ -70,6 +70,8 @@ private slots: // slots called from SCHNApps signals void selectedMapChanged(MapHandlerGen* prev, MapHandlerGen* cur); void updateSelectedCellsRendering(); + + void updateRemovedSelector(unsigned int orbit, const QString& name); // slots called from MapHandler signals void selectedMapAttributeAdded(unsigned int orbit, const QString& name); diff --git a/SCHNApps/Plugins/surface_selection/src/surface_selection.cpp b/SCHNApps/Plugins/surface_selection/src/surface_selection.cpp index 5b92a7e09..e0146aea8 100644 --- a/SCHNApps/Plugins/surface_selection/src/surface_selection.cpp +++ b/SCHNApps/Plugins/surface_selection/src/surface_selection.cpp @@ -38,10 +38,10 @@ bool Surface_Selection_Plugin::enable() m_pointSprite = new CGoGN::Utils::PointSprite(); m_selectedVerticesVBO = new Utils::VBO(); - m_selectedEdgesDrawer = new Utils::Drawer(); + m_selectedEdgesDrawer = new Utils::Drawer(1); m_selectedFacesDrawer = new Utils::Drawer(); - m_selectingCellDrawer = new Utils::Drawer(); + m_selectingCellDrawer = new Utils::Drawer(1); m_selectionSphereVBO = new Utils::VBO(); @@ -60,6 +60,8 @@ bool Surface_Selection_Plugin::enable() connect(cur, SIGNAL(attributeModified(unsigned int, const QString&)), this, SLOT(selectedMapAttributeModified(unsigned int, const QString&))); connect(cur, SIGNAL(connectivityModified()), this, SLOT(selectedMapConnectivityModified())); connect(cur, SIGNAL(boundingBoxModified()), this, SLOT(selectedMapBoundingBoxModified())); + connect(cur, SIGNAL(cellSelectorRemoved(unsigned int, const QString&)), this, SLOT(updateRemovedSelector(unsigned int, const QString&))); + m_selectionRadiusBase = cur->getBBdiagSize() / 50.0f; h_parameterSet[cur].basePSradius = cur->getBBdiagSize() / (std::sqrt(cur->getNbOrbits(EDGE))); h_parameterSet[cur].verticesScaleFactor = m_dockTab->slider_verticesScaleFactor->value() / 50.0f; @@ -94,6 +96,9 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map) { if(map->isSelectedMap()) { + glEnable(GL_POLYGON_OFFSET_FILL); + glPolygonOffset(-1.0f, -1.0f); + const MapParameters& p = h_parameterSet[map]; if(p.positionAttribute.isValid()) { @@ -111,11 +116,9 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map) updateSelectedCellsRendering(); m_pointSprite->setAttributePosition(m_selectedVerticesVBO); -// m_pointSprite->setColor(CGoGN::Geom::Vec4f(1.0f, 0.0f, 0.0f, 1.0f)); const QColor& col = p.color; m_pointSprite->setColor(Geom::Vec4f(col.redF(), col.greenF(), col.blueF(), 0.0f)); m_pointSprite->setLightPosition(CGoGN::Geom::Vec3f(0.0f, 0.0f, 1.0f)); -// m_pointSprite->setSize(map->getBBdiagSize() / 75.0f); m_pointSprite->setSize(p.basePSradius*p.verticesScaleFactor); m_pointSprite->enableVertexAttribs(); @@ -136,14 +139,12 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map) switch(p.selectionMethod) { case NormalAngle : - case SingleCell : { -// m_pointSprite->setSize(map->getBBdiagSize() / 60.0f); - m_pointSprite->setSize(p.basePSradius*p.verticesScaleFactor); - } - case WithinSphere : { + case SingleCell : + m_pointSprite->setSize(p.basePSradius*p.verticesScaleFactor*2.0f); + break; + case WithinSphere : m_pointSprite->setSize(m_selectionRadiusBase * m_selectionRadiusCoeff); break; - } } m_pointSprite->enableVertexAttribs(); @@ -183,8 +184,7 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map) case WithinSphere : { PFP2::MAP* m = static_cast*>(map)->getMap(); std::vector selectionPoint; - selectionPoint.push_back((p.positionAttribute[m_selectingEdge.dart] + p.positionAttribute[m->phi1(m_selectingEdge.dart)])/2.0f); - // selectionPoint.push_back(p.positionAttribute[m_selectingEdge.dart]); + selectionPoint.push_back(p.positionAttribute[m_selectingEdge.dart]); m_selectionSphereVBO->updateData(selectionPoint); m_pointSprite->setAttributePosition(m_selectionSphereVBO); @@ -220,11 +220,15 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map) case SingleCell : { PFP2::MAP* m = static_cast*>(map)->getMap(); m_selectingCellDrawer->newList(GL_COMPILE_AND_EXECUTE); + m_selectingCellDrawer->lineWidth(6.0f); m_selectingCellDrawer->color3f(0.0f, 0.0f, 1.0f); - m_selectingCellDrawer->begin(GL_TRIANGLES); - m_selectingCellDrawer->vertex(p.positionAttribute[m_selectingFace.dart]); - m_selectingCellDrawer->vertex(p.positionAttribute[m->phi1(m_selectingFace.dart)]); - m_selectingCellDrawer->vertex(p.positionAttribute[m->phi_1(m_selectingFace.dart)]); + m_selectingCellDrawer->begin(GL_LINE_LOOP); + Dart d = m_selectingFace.dart; + do + { + m_selectingCellDrawer->vertex(p.positionAttribute[d]); + d = m->phi1(d); + } while (d != m_selectingFace.dart); m_selectingCellDrawer->end(); m_selectingCellDrawer->endList(); break; @@ -233,8 +237,7 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map) PFP2::MAP* m = static_cast*>(map)->getMap(); std::vector selectionPoint; - selectionPoint.push_back(Algo::Surface::Geometry::faceCentroid(*m, m_selectingFace, p.positionAttribute)); -// selectionPoint.push_back(p.positionAttribute[m_selectingFace.dart]); + selectionPoint.push_back(p.positionAttribute[m_selectingFace.dart]); m_selectionSphereVBO->updateData(selectionPoint); m_pointSprite->setAttributePosition(m_selectionSphereVBO); @@ -258,6 +261,7 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map) } } } + glDisable(GL_POLYGON_OFFSET_FILL); } void Surface_Selection_Plugin::keyPress(View* view, QKeyEvent* event) @@ -521,6 +525,7 @@ void Surface_Selection_Plugin::selectedMapChanged(MapHandlerGen *prev, MapHandle disconnect(prev, SIGNAL(attributeModified(unsigned int, const QString&)), this, SLOT(selectedMapAttributeModified(unsigned int, const QString&))); disconnect(prev, SIGNAL(connectivityModified()), this, SLOT(selectedMapConnectivityModified())); disconnect(prev, SIGNAL(boundingBoxModified()), this, SLOT(selectedMapBoundingBoxModified())); + disconnect(prev, SIGNAL(cellSelectorRemoved(unsigned int, const QString&)), this, SLOT(updateRemovedSelector(unsigned int, const QString&))); } if(cur) { @@ -528,6 +533,7 @@ void Surface_Selection_Plugin::selectedMapChanged(MapHandlerGen *prev, MapHandle connect(cur, SIGNAL(attributeModified(unsigned int, const QString&)), this, SLOT(selectedMapAttributeModified(unsigned int, const QString&))); connect(cur, SIGNAL(connectivityModified()), this, SLOT(selectedMapConnectivityModified())); connect(cur, SIGNAL(boundingBoxModified()), this, SLOT(selectedMapBoundingBoxModified())); + connect(cur, SIGNAL(cellSelectorRemoved(unsigned int, const QString&)), this, SLOT(updateRemovedSelector(unsigned int, const QString&))); m_selectionRadiusBase = cur->getBBdiagSize() / 50.0f; h_parameterSet[cur].basePSradius = cur->getBBdiagSize() / (std::sqrt(cur->getNbOrbits(EDGE))); h_parameterSet[cur].verticesScaleFactor = m_dockTab->slider_verticesScaleFactor->value() / 50.0f; @@ -585,14 +591,20 @@ void Surface_Selection_Plugin::updateSelectedCellsRendering() const std::vector& selectedCells = cs->getSelectedCells(); m_selectedFacesDrawer->newList(GL_COMPILE); -// m_selectedFacesDrawer->color3f(1.0f, 0.0f, 0.0f); m_selectedFacesDrawer->color3f(p.color.redF(), p.color.greenF(), p.color.blueF()); m_selectedFacesDrawer->begin(GL_TRIANGLES); for(std::vector::const_iterator f = selectedCells.begin(); f != selectedCells.end(); ++f) { - m_selectedFacesDrawer->vertex(p.positionAttribute[(*f).dart]); - m_selectedFacesDrawer->vertex(p.positionAttribute[m->phi1((*f).dart)]); - m_selectedFacesDrawer->vertex(p.positionAttribute[m->phi_1((*f).dart)]); + Dart d = m->phi1((*f).dart); + Dart e = m->phi1(d); + do + { + m_selectedFacesDrawer->vertex(p.positionAttribute[f->dart]); + m_selectedFacesDrawer->vertex(p.positionAttribute[d]); + m_selectedFacesDrawer->vertex(p.positionAttribute[e]); + d = e; + e = m->phi1(d); + } while (e != f->dart); } m_selectedFacesDrawer->end(); m_selectedFacesDrawer->endList(); @@ -604,6 +616,19 @@ void Surface_Selection_Plugin::updateSelectedCellsRendering() } +void Surface_Selection_Plugin::updateRemovedSelector(unsigned int orbit, const QString& name) +{ + updateSelectedCellsRendering(); + MapHandlerGen* m = m_schnapps->getSelectedMap(); + View* v = m_schnapps->getSelectedView(); + if (v && m) + { + if (v->isLinkedToMap(m)) + v->updateGL(); + } + + +} @@ -636,6 +661,8 @@ void Surface_Selection_Plugin::selectedMapBoundingBoxModified() { MapHandlerGen* map = static_cast(QObject::sender()); m_selectionRadiusBase = map->getBBdiagSize() / 50.0f; + h_parameterSet[map].basePSradius = map->getBBdiagSize() / (std::sqrt(map->getNbOrbits(EDGE))); + h_parameterSet[map].verticesScaleFactor = m_dockTab->slider_verticesScaleFactor->value() / 50.0f; } @@ -652,6 +679,12 @@ void Surface_Selection_Plugin::changePositionAttribute(const QString& map, const if(m->isSelectedMap()) m_dockTab->updateMapParameters(); } + //View* v = m_schnapps->getSelectedView(); + //if (v) + //{ + // if (v->isLinkedToMap(m)) + // v->updateGL(); + //} } void Surface_Selection_Plugin::changeNormalAttribute(const QString& map, const QString& name) @@ -664,6 +697,12 @@ void Surface_Selection_Plugin::changeNormalAttribute(const QString& map, const Q if(m->isSelectedMap()) m_dockTab->updateMapParameters(); } + //View* v = m_schnapps->getSelectedView(); + //if (v) + //{ + // if (v->isLinkedToMap(m)) + // v->updateGL(); + //} } void Surface_Selection_Plugin::changeSelectionMethod(const QString& map, unsigned int method) @@ -675,6 +714,12 @@ void Surface_Selection_Plugin::changeSelectionMethod(const QString& map, unsigne if(m->isSelectedMap()) m_dockTab->updateMapParameters(); } + //View* v = m_schnapps->getSelectedView(); + //if (v) + //{ + // if (v->isLinkedToMap(m)) + // v->updateGL(); + //} } void Surface_Selection_Plugin::changeVerticesScaleFactor(const QString& map, float f) @@ -687,6 +732,13 @@ void Surface_Selection_Plugin::changeVerticesScaleFactor(const QString& map, flo if (m->isSelectedMap()) m_dockTab->updateMapParameters(); } + + //View* v = m_schnapps->getSelectedView(); + //if (v) + //{ + // if (v->isLinkedToMap(m)) + // v->updateGL(); + //} } void Surface_Selection_Plugin::changeVerticesBaseSize(const QString& map, float f) @@ -699,6 +751,13 @@ void Surface_Selection_Plugin::changeVerticesBaseSize(const QString& map, float if (m->isSelectedMap()) m_dockTab->updateMapParameters(); } + + //View* v = m_schnapps->getSelectedView(); + //if (v) + //{ + // if (v->isLinkedToMap(m)) + // v->updateGL(); + //} } @@ -711,12 +770,12 @@ void Surface_Selection_Plugin::changeSelectedColor( const QString& map, const QS if (m->isSelectedMap()) m_dockTab->updateMapParameters(); - View* v = m_schnapps->getSelectedView(); - if (v) - { - if (v->isLinkedToMap(m)) - v->updateGL(); - } + // View* v = m_schnapps->getSelectedView(); + // if (v) + // { + // if (v->isLinkedToMap(m)) + // v->updateGL(); + // } } } diff --git a/SCHNApps/Plugins/surface_selection/src/surface_selection_dockTab.cpp b/SCHNApps/Plugins/surface_selection/src/surface_selection_dockTab.cpp index 52e12fba0..41863cf48 100644 --- a/SCHNApps/Plugins/surface_selection/src/surface_selection_dockTab.cpp +++ b/SCHNApps/Plugins/surface_selection/src/surface_selection_dockTab.cpp @@ -134,13 +134,8 @@ void Surface_Selection_DockTab::colorChanged(int i) View* view = m_schnapps->getSelectedView(); MapHandlerGen* map = m_schnapps->getSelectedMap(); - std::cout << "colorChanged: " << combo_color->color().name().toStdString() << std::endl; - std::cout << "colorChanged: " << i << std::endl; - - if (view && map ) { -// MapParameters& p = m_plugin->h_parameterSet[map]; QColor& col = m_plugin->h_parameterSet[map].color; if (col != combo_color->color()) { diff --git a/SCHNApps/src/controlDock_mapTab.cpp b/SCHNApps/src/controlDock_mapTab.cpp index 44e1c4085..61b53f1f7 100644 --- a/SCHNApps/src/controlDock_mapTab.cpp +++ b/SCHNApps/src/controlDock_mapTab.cpp @@ -297,6 +297,8 @@ void ControlDock_MapTab::removeSelector() } if (!items.empty()) { + if (m_selectedSelector[orbit]->getName() == items[0]->text()) + m_selectedSelector[orbit] = NULL; m_selectedMap->removeCellSelector(orbit, items[0]->text()); // RECORDING QTextStream* rec = m_schnapps->pythonStreamRecorder(); -- GitLab