From 7bb2d10378c33000ac7cec5f8d5d5a5a1344d9ad Mon Sep 17 00:00:00 2001 From: Pierre Kraemer Date: Thu, 14 Feb 2013 17:07:30 +0100 Subject: [PATCH] SCHNApps: first version of attributes auto update --- .../include/computeNormalDialog.h | 2 - .../include/differentialProperties.h | 25 ++++-- .../src/computeNormalDialog.cpp | 9 -- .../src/differentialProperties.cpp | 59 +++++++++--- .../importSurface/include/importSurface.h | 10 ++- .../importSurface/src/importSurface.cpp | 17 +++- .../importVolume/include/importVolume.h | 10 ++- .../Plugins/importVolume/src/importVolume.cpp | 17 +++- .../include/subdivideSurface.h | 23 +++-- .../subdivideSurface/src/subdivideSurface.cpp | 90 +++++++++++++------ .../src/surfaceDeformation.cpp | 2 - SCHNApps/bin/init.py | 2 +- SCHNApps/include/mapHandler.h | 10 ++- 13 files changed, 204 insertions(+), 72 deletions(-) diff --git a/SCHNApps/Plugins/differentialProperties/include/computeNormalDialog.h b/SCHNApps/Plugins/differentialProperties/include/computeNormalDialog.h index eefab71f..9a65c05f 100644 --- a/SCHNApps/Plugins/differentialProperties/include/computeNormalDialog.h +++ b/SCHNApps/Plugins/differentialProperties/include/computeNormalDialog.h @@ -28,8 +28,6 @@ public slots: void addMapToList(MapHandlerGen* m); void removeMapFromList(MapHandlerGen* m); void addAttributeToList(unsigned int orbit, const QString& nameAttr); - - void attributeModified(unsigned int orbit, QString nameAttr); }; } // namespace SCHNApps diff --git a/SCHNApps/Plugins/differentialProperties/include/differentialProperties.h b/SCHNApps/Plugins/differentialProperties/include/differentialProperties.h index a56f0b2c..df89ff45 100644 --- a/SCHNApps/Plugins/differentialProperties/include/differentialProperties.h +++ b/SCHNApps/Plugins/differentialProperties/include/differentialProperties.h @@ -38,18 +38,22 @@ public: virtual void wheelEvent(View* view, QWheelEvent* event) {} public slots: + void mapAdded(MapHandlerGen* map); + void mapRemoved(MapHandlerGen* map); + void attributeModified(unsigned int orbit, QString nameAttr); + void openComputeNormalDialog(); void openComputeCurvatureDialog(); void computeNormalFromDialog(); void computeCurvatureFromDialog(); - void computeNormal( - const QString& mapName, + void computeNormal(const QString& mapName, const QString& positionAttributeName = "position", const QString& normalAttributeName = "normal", - bool createNormalVBO = true - ); + bool createNormalVBO = true, + bool autoUpdateNormal = true); + void computeCurvature( const QString& mapName, const QString& positionAttributeName = "position", @@ -63,7 +67,12 @@ public slots: bool createkmaxVBO = true, bool createKminVBO = true, bool createkminVBO = true, - bool createKnormalVBO = true + bool createKnormalVBO = true, + bool autoUpdateKmax = true, + bool autoUpdatekmax = true, + bool autoUpdateKmin = true, + bool autoUpdatekmin = true, + bool autoUpdateKnormal = true ); private: @@ -76,9 +85,13 @@ private: struct ComputeNormalParameters { ComputeNormalParameters() {} - ComputeNormalParameters(QString p, QString n) : positionName(p), normalName(n) {} + ComputeNormalParameters(QString p, QString n, bool vbo, bool update) : + positionName(p), normalName(n), createVBO(vbo), autoUpdate(update) + {} QString positionName; QString normalName; + bool createVBO; + bool autoUpdate; }; QHash computeNormalLastParameters; }; diff --git a/SCHNApps/Plugins/differentialProperties/src/computeNormalDialog.cpp b/SCHNApps/Plugins/differentialProperties/src/computeNormalDialog.cpp index 20878ce3..2f126497 100644 --- a/SCHNApps/Plugins/differentialProperties/src/computeNormalDialog.cpp +++ b/SCHNApps/Plugins/differentialProperties/src/computeNormalDialog.cpp @@ -105,15 +105,6 @@ void ComputeNormalDialog::addAttributeToList(unsigned int orbit, const QString& } } -void ComputeNormalDialog::attributeModified(unsigned int orbit, QString nameAttr) -{ - MapHandlerGen* map = static_cast(QObject::sender()); -// if(orbit == VERTEX && nameAttr == ) -// { - -// } -} - } // namespace SCHNApps } // namespace CGoGN diff --git a/SCHNApps/Plugins/differentialProperties/src/differentialProperties.cpp b/SCHNApps/Plugins/differentialProperties/src/differentialProperties.cpp index 673c2e91..a110195b 100644 --- a/SCHNApps/Plugins/differentialProperties/src/differentialProperties.cpp +++ b/SCHNApps/Plugins/differentialProperties/src/differentialProperties.cpp @@ -25,9 +25,36 @@ bool DifferentialPropertiesPlugin::enable() connect(m_computeCurvatureDialog, SIGNAL(accepted()), this, SLOT(computeCurvatureFromDialog())); connect(m_computeCurvatureDialog->button_apply, SIGNAL(clicked()), this, SLOT(computeCurvatureFromDialog())); + connect(m_window, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(mapAdded(MapHandlerGen*))); + connect(m_window, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(mapRemoved(MapHandlerGen*))); + return true; } +void DifferentialPropertiesPlugin::mapAdded(MapHandlerGen *map) +{ + connect(map, SIGNAL(attributeModified(unsigned int, QString)), this, SLOT(attributeModified(unsigned int, QString))); +} + +void DifferentialPropertiesPlugin::mapRemoved(MapHandlerGen *map) +{ + disconnect(map, SIGNAL(attributeModified(unsigned int, QString)), this, SLOT(attributeModified(unsigned int, QString))); +} + +void DifferentialPropertiesPlugin::attributeModified(unsigned int orbit, QString nameAttr) +{ + if(orbit == VERTEX) + { + MapHandlerGen* map = static_cast(QObject::sender()); + if(computeNormalLastParameters.contains(map->getName())) + { + ComputeNormalParameters& params = computeNormalLastParameters[map->getName()]; + if(params.positionName == nameAttr && params.autoUpdate) + computeNormal(map->getName(), params.positionName, params.normalName, params.createVBO); + } + } +} + void DifferentialPropertiesPlugin::openComputeNormalDialog() { m_computeNormalDialog->show(); @@ -46,6 +73,7 @@ void DifferentialPropertiesPlugin::computeNormalFromDialog() const QString& mapName = currentItems[0]->text(); QString positionName = m_computeNormalDialog->combo_positionAttribute->currentText(); + QString normalName; if(m_computeNormalDialog->normalAttributeName->text().isEmpty()) normalName = m_computeNormalDialog->combo_normalAttribute->currentText(); @@ -54,7 +82,9 @@ void DifferentialPropertiesPlugin::computeNormalFromDialog() bool createVBO = (m_computeNormalDialog->check_createVBO->checkState() == Qt::Checked); - computeNormal(mapName, positionName, normalName, createVBO); + bool autoUpdate = (currentItems[0]->checkState() == Qt::Checked); + + computeNormal(mapName, positionName, normalName, createVBO, autoUpdate); } } @@ -73,39 +103,34 @@ void DifferentialPropertiesPlugin::computeCurvatureFromDialog() KmaxName = m_computeCurvatureDialog->combo_KmaxAttribute->currentText(); else KmaxName = m_computeCurvatureDialog->KmaxAttributeName->text(); + bool KmaxVBO = (m_computeCurvatureDialog->check_KmaxCreateVBO->checkState() == Qt::Checked); QString kmaxName; if(m_computeCurvatureDialog->kmaxAttributeName->text().isEmpty()) kmaxName = m_computeCurvatureDialog->combo_kmaxAttribute->currentText(); else kmaxName = m_computeCurvatureDialog->kmaxAttributeName->text(); + bool kmaxVBO = (m_computeCurvatureDialog->check_kmaxCreateVBO->checkState() == Qt::Checked); QString KminName; if(m_computeCurvatureDialog->KminAttributeName->text().isEmpty()) KminName = m_computeCurvatureDialog->combo_KminAttribute->currentText(); else KminName = m_computeCurvatureDialog->KminAttributeName->text(); + bool KminVBO = (m_computeCurvatureDialog->check_KminCreateVBO->checkState() == Qt::Checked); QString kminName; if(m_computeCurvatureDialog->kminAttributeName->text().isEmpty()) kminName = m_computeCurvatureDialog->combo_kminAttribute->currentText(); else kminName = m_computeCurvatureDialog->kminAttributeName->text(); + bool kminVBO = (m_computeCurvatureDialog->check_kminCreateVBO->checkState() == Qt::Checked); QString KnormalName; if(m_computeCurvatureDialog->KnormalAttributeName->text().isEmpty()) KnormalName = m_computeCurvatureDialog->combo_KnormalAttribute->currentText(); else KnormalName = m_computeCurvatureDialog->KnormalAttributeName->text(); - - bool KmaxVBO = (m_computeCurvatureDialog->check_KmaxCreateVBO->checkState() == Qt::Checked); - - bool kmaxVBO = (m_computeCurvatureDialog->check_kmaxCreateVBO->checkState() == Qt::Checked); - - bool KminVBO = (m_computeCurvatureDialog->check_KminCreateVBO->checkState() == Qt::Checked); - - bool kminVBO = (m_computeCurvatureDialog->check_kminCreateVBO->checkState() == Qt::Checked); - bool KnormalVBO = (m_computeCurvatureDialog->check_KnormalCreateVBO->checkState() == Qt::Checked); computeCurvature( @@ -119,7 +144,8 @@ void DifferentialPropertiesPlugin::computeNormal( const QString& mapName, const QString& positionAttributeName, const QString& normalAttributeName, - bool createNormalVBO) + bool createNormalVBO, + bool autoUpdateNormal) { MapHandler* mh = static_cast*>(m_window->getMap(mapName)); if(mh == NULL) @@ -140,7 +166,9 @@ void DifferentialPropertiesPlugin::computeNormal( mh->createVBO(normal); computeNormalLastParameters[mapName] = - ComputeNormalParameters(positionAttributeName, normalAttributeName) ; + ComputeNormalParameters(positionAttributeName, normalAttributeName, createNormalVBO, autoUpdateNormal) ; + + mh->notifyAttributeModification(normal); QList views = mh->getLinkedViews(); foreach(View* view, views) @@ -160,7 +188,12 @@ void DifferentialPropertiesPlugin::computeCurvature( bool createkmaxVBO, bool createKminVBO, bool createkminVBO, - bool createKnormalVBO) + bool createKnormalVBO, + bool autoUpdateKmax, + bool autoUpdatekmax, + bool autoUpdateKmin, + bool autoUpdatekmin, + bool autoUpdateKnormal) { MapHandler* mh = static_cast*>(m_window->getMap(mapName)); if(mh == NULL) diff --git a/SCHNApps/Plugins/importSurface/include/importSurface.h b/SCHNApps/Plugins/importSurface/include/importSurface.h index d7a08004..e9e2cbcb 100644 --- a/SCHNApps/Plugins/importSurface/include/importSurface.h +++ b/SCHNApps/Plugins/importSurface/include/importSurface.h @@ -4,9 +4,11 @@ #include "plugin.h" -using namespace CGoGN; -using namespace SCHNApps; +namespace CGoGN +{ +namespace SCHNApps +{ class ImportSurfacePlugin : public Plugin { @@ -42,4 +44,8 @@ private: QAction* importAction; }; +} // namespace SCHNApps + +} // namespace CGoGN + #endif diff --git a/SCHNApps/Plugins/importSurface/src/importSurface.cpp b/SCHNApps/Plugins/importSurface/src/importSurface.cpp index b88ddff3..0c52a138 100644 --- a/SCHNApps/Plugins/importSurface/src/importSurface.cpp +++ b/SCHNApps/Plugins/importSurface/src/importSurface.cpp @@ -7,6 +7,12 @@ #include #include +namespace CGoGN +{ + +namespace SCHNApps +{ + bool ImportSurfacePlugin::enable() { importAction = new QAction("import", this); @@ -30,12 +36,15 @@ MapHandlerGen* ImportSurfacePlugin::importFromFile(const QString& fileName) Algo::Surface::Import::importMesh(*map, fileName.toStdString(), attrNames); // get vertex position attribute - VertexAttribute position = map->getAttribute(attrNames[0]); - mh->registerAttribute(position); + VertexAttribute position = map->getAttribute(attrNames[0]); + mh->registerAttribute(position); // create VBO for vertex position attribute mh->createVBO(position); + // update corresponding VBO & emit attribute update signal + mh->notifyAttributeModification(position); + // compute map bounding box mh->updateBB(position); } @@ -56,3 +65,7 @@ Q_EXPORT_PLUGIN2(ImportSurfacePlugin, ImportSurfacePlugin) #else Q_EXPORT_PLUGIN2(ImportSurfacePluginD, ImportSurfacePlugin) #endif + +} // namespace SCHNApps + +} // namespace CGoGN diff --git a/SCHNApps/Plugins/importVolume/include/importVolume.h b/SCHNApps/Plugins/importVolume/include/importVolume.h index 0f5e3c90..d35c926f 100644 --- a/SCHNApps/Plugins/importVolume/include/importVolume.h +++ b/SCHNApps/Plugins/importVolume/include/importVolume.h @@ -4,9 +4,11 @@ #include "plugin.h" -using namespace CGoGN; -using namespace SCHNApps; +namespace CGoGN +{ +namespace SCHNApps +{ class ImportVolumePlugin : public Plugin { @@ -42,4 +44,8 @@ private: QAction* importAction; }; +} // namespace SCHNApps + +} // namespace CGoGN + #endif diff --git a/SCHNApps/Plugins/importVolume/src/importVolume.cpp b/SCHNApps/Plugins/importVolume/src/importVolume.cpp index 51297ab8..24f9cecd 100644 --- a/SCHNApps/Plugins/importVolume/src/importVolume.cpp +++ b/SCHNApps/Plugins/importVolume/src/importVolume.cpp @@ -7,6 +7,12 @@ #include #include +namespace CGoGN +{ + +namespace SCHNApps +{ + bool ImportVolumePlugin::enable() { importAction = new QAction("import", this); @@ -30,12 +36,15 @@ MapHandlerGen* ImportVolumePlugin::importFromFile(const QString& fileName) Algo::Volume::Import::importMesh(*map, fileName.toStdString(), attrNames); // get vertex position attribute - VertexAttribute position = map->getAttribute(attrNames[0]); - mh->registerAttribute(position); + VertexAttribute position = map->getAttribute(attrNames[0]); + mh->registerAttribute(position); // create VBO for vertex position attribute mh->createVBO(position); + // update corresponding VBO & emit attribute update signal + mh->notifyAttributeModification(position); + // compute map bounding box mh->updateBB(position); } @@ -56,3 +65,7 @@ Q_EXPORT_PLUGIN2(ImportVolumePlugin, ImportVolumePlugin) #else Q_EXPORT_PLUGIN2(ImportVolumePluginD, ImportVolumePlugin) #endif + +} // namespace SCHNApps + +} // namespace CGoGN diff --git a/SCHNApps/Plugins/subdivideSurface/include/subdivideSurface.h b/SCHNApps/Plugins/subdivideSurface/include/subdivideSurface.h index e4ed1121..3253a1be 100644 --- a/SCHNApps/Plugins/subdivideSurface/include/subdivideSurface.h +++ b/SCHNApps/Plugins/subdivideSurface/include/subdivideSurface.h @@ -38,11 +38,24 @@ public: public slots: void openSubdivideSurfaceDialog(); - void subdivideSurface(); - - void loopSubdivision(PFP2::MAP* map, VertexAttribute& position); - void CCSubdivision(PFP2::MAP* map, VertexAttribute& position); - void trianguleFaces(PFP2::MAP* map, VertexAttribute& position); + void subdivideSurfaceFromDialog(); + + void loopSubdivision( + const QString& mapName, + const QString& positionAttributeName = "position" + ); + void CCSubdivision( + const QString& mapName, + const QString& positionAttributeName = "position" + ); + void trianguleFaces( + const QString& mapName, + const QString& positionAttributeName = "position" + ); + +// void loopSubdivision(PFP2::MAP* map, VertexAttribute& position); +// void CCSubdivision(PFP2::MAP* map, VertexAttribute& position); +// void trianguleFaces(PFP2::MAP* map, VertexAttribute& position); private: SubdivideSurfaceDialog* m_subdivideSurfaceDialog; diff --git a/SCHNApps/Plugins/subdivideSurface/src/subdivideSurface.cpp b/SCHNApps/Plugins/subdivideSurface/src/subdivideSurface.cpp index 9ba5642b..2328eb93 100644 --- a/SCHNApps/Plugins/subdivideSurface/src/subdivideSurface.cpp +++ b/SCHNApps/Plugins/subdivideSurface/src/subdivideSurface.cpp @@ -20,8 +20,8 @@ bool SubdivideSurfacePlugin::enable() connect(m_subdivideSurfaceAction, SIGNAL(triggered()), this, SLOT(openSubdivideSurfaceDialog())); - connect(m_subdivideSurfaceDialog, SIGNAL(accepted()), this, SLOT(subdivideSurface())); - connect(m_subdivideSurfaceDialog->button_apply, SIGNAL(clicked()), this, SLOT(subdivideSurface())); + connect(m_subdivideSurfaceDialog, SIGNAL(accepted()), this, SLOT(subdivideSurfaceFromDialog())); + connect(m_subdivideSurfaceDialog->button_apply, SIGNAL(clicked()), this, SLOT(subdivideSurfaceFromDialog())); return true; } @@ -31,50 +31,90 @@ void SubdivideSurfacePlugin::openSubdivideSurfaceDialog() m_subdivideSurfaceDialog->show(); } -void SubdivideSurfacePlugin::subdivideSurface() +void SubdivideSurfacePlugin::subdivideSurfaceFromDialog() { QList currentItems = m_subdivideSurfaceDialog->mapList->selectedItems(); if(!currentItems.empty()) { - const QString& mapname = currentItems[0]->text(); - MapHandler* mh = static_cast*>(m_window->getMap(mapname)); - PFP2::MAP* map = mh->getMap(); - - std::string positionName = m_subdivideSurfaceDialog->combo_positionAttribute->currentText().toStdString(); - VertexAttribute position = map->getAttribute(positionName); + const QString& mapName = currentItems[0]->text(); + const QString& positionName = m_subdivideSurfaceDialog->combo_positionAttribute->currentText(); if(m_subdivideSurfaceDialog->radio_Loop->isChecked()) - loopSubdivision(map, position); + loopSubdivision(mapName, positionName); else if(m_subdivideSurfaceDialog->radio_CC->isChecked()) - CCSubdivision(map, position); + CCSubdivision(mapName, positionName); else if(m_subdivideSurfaceDialog->radio_trianguleFaces->isChecked()) - trianguleFaces(map, position); - - mh->setPrimitiveDirty(Algo::Render::GL2::POINTS); - mh->setPrimitiveDirty(Algo::Render::GL2::LINES); - mh->setPrimitiveDirty(Algo::Render::GL2::TRIANGLES); - - mh->updateVBO(position); - - QList views = mh->getLinkedViews(); - foreach(View* view, views) - view->updateGL(); + trianguleFaces(mapName, positionName); } } -void SubdivideSurfacePlugin::loopSubdivision(PFP2::MAP* map, VertexAttribute& position) +void SubdivideSurfacePlugin::loopSubdivision( + const QString& mapName, + const QString& positionAttributeName) { + MapHandler* mh = static_cast*>(m_window->getMap(mapName)); + if(mh == NULL) + return; + + VertexAttribute position = mh->getAttribute(positionAttributeName); + if(!position.isValid()) + return; + + PFP2::MAP* map = mh->getMap(); Algo::Surface::Modelisation::LoopSubdivision(*map, position); + + mh->notifyAttributeModification(position); + mh->notifyConnectivityModification(); + + QList views = mh->getLinkedViews(); + foreach(View* view, views) + view->updateGL(); } -void SubdivideSurfacePlugin::CCSubdivision(PFP2::MAP* map, VertexAttribute& position) +void SubdivideSurfacePlugin::CCSubdivision( + const QString& mapName, + const QString& positionAttributeName) { + MapHandler* mh = static_cast*>(m_window->getMap(mapName)); + if(mh == NULL) + return; + + VertexAttribute position = mh->getAttribute(positionAttributeName); + if(!position.isValid()) + return; + + PFP2::MAP* map = mh->getMap(); Algo::Surface::Modelisation::CatmullClarkSubdivision(*map, position); + + mh->notifyAttributeModification(position); + mh->notifyConnectivityModification(); + + QList views = mh->getLinkedViews(); + foreach(View* view, views) + view->updateGL(); } -void SubdivideSurfacePlugin::trianguleFaces(PFP2::MAP* map, VertexAttribute& position) +void SubdivideSurfacePlugin::trianguleFaces( + const QString& mapName, + const QString& positionAttributeName) { + MapHandler* mh = static_cast*>(m_window->getMap(mapName)); + if(mh == NULL) + return; + + VertexAttribute position = mh->getAttribute(positionAttributeName); + if(!position.isValid()) + return; + + PFP2::MAP* map = mh->getMap(); Algo::Surface::Modelisation::trianguleFaces(*map, position); + + mh->notifyAttributeModification(position); + mh->notifyConnectivityModification(); + + QList views = mh->getLinkedViews(); + foreach(View* view, views) + view->updateGL(); } #ifndef DEBUG diff --git a/SCHNApps/Plugins/surfaceDeformation/src/surfaceDeformation.cpp b/SCHNApps/Plugins/surfaceDeformation/src/surfaceDeformation.cpp index 393ffd25..e086091c 100644 --- a/SCHNApps/Plugins/surfaceDeformation/src/surfaceDeformation.cpp +++ b/SCHNApps/Plugins/surfaceDeformation/src/surfaceDeformation.cpp @@ -193,7 +193,6 @@ void SurfaceDeformationPlugin::keyPress(View* view, QKeyEvent* event) { asRigidAsPossible(view, map); PerMapParameterSet* perMap = params->perMap[map->getName()]; - params->selectedMap->updateVBO(perMap->positionAttribute); params->selectedMap->notifyAttributeModification(perMap->positionAttribute); view->updateGL(); } @@ -319,7 +318,6 @@ void SurfaceDeformationPlugin::mouseMove(View* view, QMouseEvent* event) // matchDiffCoord(view, map); asRigidAsPossible(view, params->selectedMap); - params->selectedMap->updateVBO(perMap->positionAttribute); params->selectedMap->notifyAttributeModification(perMap->positionAttribute); view->updateGL(); diff --git a/SCHNApps/bin/init.py b/SCHNApps/bin/init.py index 0b19f79a..86a7b517 100644 --- a/SCHNApps/bin/init.py +++ b/SCHNApps/bin/init.py @@ -1,6 +1,6 @@ importPlugin = schnapps.loadPlugin("ImportSurface"); renderPlugin = schnapps.loadPlugin("Render"); -renderVectorPlugin = schnapps.loadPlugin("RenderVector"); +renderVectorPlugin = schnapps.loadPlugin("RenderVectorD"); differentialPropertiesPlugin = schnapps.loadPlugin("DifferentialProperties"); subdivisionPlugin = schnapps.loadPlugin("SubdivideSurface"); surfaceDeformationPlugin = schnapps.loadPlugin("SurfaceDeformation"); diff --git a/SCHNApps/include/mapHandler.h b/SCHNApps/include/mapHandler.h index 01c834fa..d5d897ca 100644 --- a/SCHNApps/include/mapHandler.h +++ b/SCHNApps/include/mapHandler.h @@ -71,11 +71,19 @@ public: template inline void notifyAttributeModification(const AttributeHandler& attr) { - emit(attributeModified(ORBIT, QString::fromStdString(attr.name()))); + QString nameAttr = QString::fromStdString(attr.name()); + if(h_vbo.contains(nameAttr)) + h_vbo[nameAttr]->updateData(attr); + + emit(attributeModified(ORBIT, nameAttr)); } inline void notifyConnectivityModification() { + m_render->setPrimitiveDirty(Algo::Render::GL2::POINTS); + m_render->setPrimitiveDirty(Algo::Render::GL2::LINES); + m_render->setPrimitiveDirty(Algo::Render::GL2::TRIANGLES); + emit(connectivityModified()); } -- GitLab