From 643f47f717f79824bf299db9b7fed2885bbafe87 Mon Sep 17 00:00:00 2001 From: Pierre Kraemer Date: Tue, 14 Feb 2017 15:47:55 +0100 Subject: [PATCH 01/14] try to read existing settings in plugins --- schnapps/core/map_handler.h | 11 ++-- schnapps/core/plugin.cpp | 6 +- schnapps/core/plugin.h | 3 +- schnapps/core/schnapps.cpp | 6 +- schnapps/core/schnapps.h | 4 +- schnapps/core/settings.cpp | 38 ++++++------- schnapps/core/settings.h | 4 +- schnapps/plugins/import/import.cpp | 28 +++++---- schnapps/plugins/import/import.h | 7 ++- schnapps/plugins/selection/selection.cpp | 2 + schnapps/plugins/selection/selection.h | 6 +- .../dialog_compute_curvature.cpp | 57 +++++++++++++++++-- .../dialog_compute_curvature.h | 13 ++++- .../dialog_compute_normal.cpp | 19 ++++++- .../dialog_compute_normal.h | 8 ++- .../surface_differential_properties.cpp | 8 ++- .../surface_differential_properties.h | 13 +++-- .../plugins/surface_render/surface_render.cpp | 35 ++++++++---- .../plugins/surface_render/surface_render.h | 14 ++--- .../plugins/volume_render/volume_render.cpp | 19 ++++--- .../plugins/volume_render/volume_render.h | 7 +-- 21 files changed, 204 insertions(+), 104 deletions(-) diff --git a/schnapps/core/map_handler.h b/schnapps/core/map_handler.h index cefcd47..a8f7ca3 100644 --- a/schnapps/core/map_handler.h +++ b/schnapps/core/map_handler.h @@ -561,10 +561,13 @@ class MapHandler : public MapHandlerGen void set_bb_vertex_attribute(const QString& attribute_name) override { bb_vertex_attribute_ = get_map()->template get_attribute(attribute_name.toStdString()); - compute_bb(); - this->update_bb_drawer(); - emit(bb_vertex_attribute_changed(attribute_name)); - emit(bb_changed()); + if (bb_vertex_attribute_.is_valid()) + { + compute_bb(); + this->update_bb_drawer(); + emit(bb_vertex_attribute_changed(attribute_name)); + emit(bb_changed()); + } } void check_bb_vertex_attribute(cgogn::Orbit orbit, const QString& attribute_name) override diff --git a/schnapps/core/plugin.cpp b/schnapps/core/plugin.cpp index 227a879..2d8bbe0 100644 --- a/schnapps/core/plugin.cpp +++ b/schnapps/core/plugin.cpp @@ -29,12 +29,12 @@ namespace schnapps const QVariant Plugin::get_setting(const QString& name) const { - return get_schnapps()->get_setting(this->get_name(), name); + return schnapps_->get_setting(this->get_name(), name); } -QVariant* Plugin::add_setting(const QString& name, const QVariant& default_value) +QVariant Plugin::add_setting(const QString& name, const QVariant& default_value) { - return get_schnapps()->add_setting(this->get_name(), name, default_value); + return schnapps_->add_setting(this->get_name(), name, default_value); } Plugin::~Plugin() diff --git a/schnapps/core/plugin.h b/schnapps/core/plugin.h index 49b25c3..bf3ca3c 100644 --- a/schnapps/core/plugin.h +++ b/schnapps/core/plugin.h @@ -68,7 +68,8 @@ public slots: inline SCHNApps* get_schnapps() const { return schnapps_; } const QVariant get_setting(const QString& name) const; - QVariant* add_setting(const QString& name, const QVariant& default_value); + + QVariant add_setting(const QString& name, const QVariant& default_value); private: diff --git a/schnapps/core/schnapps.cpp b/schnapps/core/schnapps.cpp index 448a027..0e32c43 100644 --- a/schnapps/core/schnapps.cpp +++ b/schnapps/core/schnapps.cpp @@ -84,11 +84,11 @@ SCHNApps::SCHNApps(const QString& app_path, SCHNAppsWindow* window) : #else register_plugins_directory(app_path + QString("/../lib")); #endif - settings_ = Settings::from_file("settings.json"); + + settings_ = Settings::from_file(app_path + QString("/../lib/settings.json")); settings_->set_widget(window->settings_widget_.get()); for (const QVariant& plugin_dir_v : get_core_setting("Plugins paths").toList()) this->register_plugins_directory(plugin_dir_v.toString()); - for (const QVariant& plugin_v : get_core_setting("Load modules").toList()) this->enable_plugin(plugin_v.toString()); } @@ -98,9 +98,7 @@ SCHNApps::~SCHNApps() settings_->to_file("settings.json"); // first safely unload every plugins (this has to be done before the views get deleted) while(!plugins_.empty()) - { this->disable_plugin(plugins_.begin()->first); - } } /********************************************************* diff --git a/schnapps/core/schnapps.h b/schnapps/core/schnapps.h index 5a1fa15..21274b3 100644 --- a/schnapps/core/schnapps.h +++ b/schnapps/core/schnapps.h @@ -379,14 +379,14 @@ public slots: void schnapps_closing(); - public: + inline const QVariant get_setting(const QString& module_name, const QString& name) const { return settings_->get_setting(module_name, name); } - inline QVariant* add_setting(const QString& module_name, const QString& name, const QVariant& val) + inline QVariant add_setting(const QString& module_name, const QString& name, const QVariant& val) { return settings_->add_setting(module_name,name,val); } diff --git a/schnapps/core/settings.cpp b/schnapps/core/settings.cpp index e5be9e7..b0faf0d 100644 --- a/schnapps/core/settings.cpp +++ b/schnapps/core/settings.cpp @@ -39,41 +39,38 @@ std::unique_ptr Settings::from_file(const QString& setting_filename) QFile setting_file(setting_filename); if (setting_file.exists() && setting_file.open(QIODevice::ReadOnly)) { - QByteArray data = setting_file.readAll(); + QByteArray data = setting_file.readAll(); QJsonParseError parse_error; QJsonDocument doc = QJsonDocument::fromJson(data, &parse_error); if (parse_error.error != QJsonParseError::NoError) - { cgogn_log_warning("Settings(const QString&)") << "Error while reading the file \"" << setting_filename.toStdString() << "\". Error is : \"" << parse_error.errorString().toStdString() << "\"."; - } else { + else cgogn_log_info("Settings(const QString&)") << "Loaded setting file \"" << setting_filename.toStdString() << "\"."; - } const auto obj = doc.object(); - for(auto it = obj.constBegin(); it != obj.constEnd(); ++it) + for (auto it = obj.constBegin(); it != obj.constEnd(); ++it) settings->add_module(it.key(), it.value().toObject().toVariantMap()); - } else { - cgogn_log_warning("Settings::from_file()") << "Unable to read the file \"" << setting_filename.toStdString() << "\"."; } + else + cgogn_log_warning("Settings::from_file()") << "Unable to read the file \"" << setting_filename.toStdString() << "\"."; + return settings; } void Settings::add_module(const QString& module_name, const QVariantMap& module) { if (!map_.contains(module_name)) - { map_[module_name] = module; - } } Settings::~Settings() {} -QVariant* Settings::add_setting(const QString& module_name, const QString& setting_name, const QVariant& value) +QVariant Settings::add_setting(const QString& module_name, const QString& setting_name, const QVariant& value) { if (!map_[module_name].contains(setting_name)) map_[module_name][setting_name] = value; - return &map_[module_name][setting_name]; + return map_[module_name][setting_name]; } const QVariant Settings::get_setting(const QString& module_name, const QString& setting_name) const @@ -86,9 +83,9 @@ const QVariant Settings::get_setting(const QString& module_name, const QString& return setting_it.value(); else cgogn_log_debug("Settings::get_setting") << "Unable to find setting \"" << setting_name.toStdString() << "\" in module \"" << module_name.toStdString() << "\"."; - } else { - cgogn_log_debug("Settings::get_setting") << "Unable to find module \"" << module_name.toStdString() << "\"."; } + else + cgogn_log_debug("Settings::get_setting") << "Unable to find module \"" << module_name.toStdString() << "\"."; return QVariant(); } @@ -103,9 +100,9 @@ void Settings::to_file(const QString& filename) obj[it.key()] = QJsonObject::fromVariantMap(it.value()); QJsonDocument doc(obj); setting_file.write(doc.toJson()); - } else { - cgogn_log_info("Settings::to_file()") << "Unable to write in the file \"" << filename.toStdString() << "\"."; } + else + cgogn_log_info("Settings::to_file()") << "Unable to write in the file \"" << filename.toStdString() << "\"."; } void Settings::set_widget(QWidget* widget) @@ -118,21 +115,18 @@ void Settings::set_widget(QWidget* widget) void Settings::setting_changed(const QString& module_name, const QString& name, const QVariant& value) { if (!map_.contains(module_name)) - { cgogn_log_debug("Settings::setting_changed") << "Trying to modify a setting of a non-existing module \"" << module_name.toStdString() << "\"."; - } else + else { if (!map_[module_name].contains(name)) - { cgogn_log_debug("Settings::setting_changed") << "Trying to modify a non-existing setting \"" << name.toStdString() << "\" of the module \"" << module_name.toStdString() << "\"."; - } else { + else + { QVariant& v = map_[module_name][name]; if (v.type() != value.type()) - { cgogn_log_debug("Settings::setting_changed") << "Cannot replace a setting of type \"" << v.typeName() << "\" by another setting of type \"" << value.typeName() << "\"."; - } else { + else v = value; - } } } } diff --git a/schnapps/core/settings.h b/schnapps/core/settings.h index 6b76855..34e25d0 100644 --- a/schnapps/core/settings.h +++ b/schnapps/core/settings.h @@ -55,9 +55,9 @@ class SCHNAPPS_CORE_API Settings : public QObject * @param module_name * @param setting_name * @param value - * @return a pointer to the place where the data is stored. + * @return the setting value */ - QVariant* add_setting(const QString& module_name, const QString& setting_name, const QVariant& value); + QVariant add_setting(const QString& module_name, const QString& setting_name, const QVariant& value); const QVariant get_setting(const QString& module_name, const QString& setting_name) const; void to_file(const QString& filename); diff --git a/schnapps/plugins/import/import.cpp b/schnapps/plugins/import/import.cpp index cfb80b3..bf0795a 100644 --- a/schnapps/plugins/import/import.cpp +++ b/schnapps/plugins/import/import.cpp @@ -33,6 +33,7 @@ namespace schnapps { + namespace plugin_import { @@ -46,8 +47,15 @@ bool Plugin_Import::enable() // import_2D_image_action_ = schnapps_->add_menu_action("Surface;Import 2D Image", "import 2D image"); // connect(import_2D_image_action_, SIGNAL(triggered()), this, SLOT(import_2D_image_from_file_dialog())); - setting_bbox_name_ = add_setting("Bounding box attribute", "position"); - setting_vbo_names_ = add_setting("Compute VBO", QVariantList({"position", "normal", "color"})); + + setting_bbox_name_ = get_setting("Bounding box attribute"); + if (!setting_bbox_name_.isValid()) + setting_bbox_name_ = add_setting("Bounding box attribute", "position"); + + setting_vbo_names_ = get_setting("Compute VBO"); + if (!setting_vbo_names_.isValid()) + setting_vbo_names_ = add_setting("Compute VBO", QVariantList({"position", "normal", "color"})); + return true; } @@ -72,13 +80,10 @@ MapHandlerGen* Plugin_Import::import_surface_mesh_from_file(const QString& filen cgogn::io::import_surface(*map, filename.toStdString()); if (mhg->nb_cells(CellType::Vertex_Cell) > 0) { - if (setting_bbox_name_) - mh->set_bb_vertex_attribute(setting_bbox_name_->toString()); - - if (setting_vbo_names_) - for (const QVariant& var :setting_vbo_names_->toList()) - mhg->create_vbo(var.toString()); + mh->set_bb_vertex_attribute(setting_bbox_name_.toString()); + for (const QVariant& var : setting_vbo_names_.toList()) + mhg->create_vbo(var.toString()); } // for (unsigned int orbit = VERTEX; orbit <= VOLUME; orbit++) // { @@ -122,8 +127,10 @@ MapHandlerGen* Plugin_Import::import_volume_mesh_from_file(const QString& filena cgogn::io::import_volume(*map, filename.toStdString()); if (mhg->nb_cells(CellType::Vertex_Cell) > 0) { - mh->set_bb_vertex_attribute("position"); - mhg->create_vbo("position"); + mh->set_bb_vertex_attribute(setting_bbox_name_.toString()); + + for (const QVariant& var : setting_vbo_names_.toList()) + mhg->create_vbo(var.toString()); } } @@ -145,4 +152,5 @@ void Plugin_Import::import_volume_mesh_from_file_dialog() } } // namespace plugin_import + } // namespace schnapps diff --git a/schnapps/plugins/import/import.h b/schnapps/plugins/import/import.h index b3ef209..cd7af4b 100644 --- a/schnapps/plugins/import/import.h +++ b/schnapps/plugins/import/import.h @@ -28,7 +28,6 @@ #include #include - namespace schnapps { @@ -86,14 +85,16 @@ class SCHNAPPS_PLUGIN_IMPORT_API Plugin_Import : public PluginProcessing private: - QVariant* setting_bbox_name_; - QVariant* setting_vbo_names_; + QVariant setting_bbox_name_; + QVariant setting_vbo_names_; + QAction* import_surface_mesh_action_; QAction* import_volume_mesh_action_; // QAction* import_2D_image_action_; }; } // namespace plugin_import + } // namespace schnapps #endif // SCHNAPPS_PLUGIN_IMPORT_H_ diff --git a/schnapps/plugins/selection/selection.cpp b/schnapps/plugins/selection/selection.cpp index d31972f..36da7e7 100644 --- a/schnapps/plugins/selection/selection.cpp +++ b/schnapps/plugins/selection/selection.cpp @@ -30,6 +30,7 @@ namespace schnapps { + namespace plugin_selection { @@ -820,4 +821,5 @@ void Plugin_Selection::update_dock_tab() } } // namespace plugin_selection + } // namespace schnapps diff --git a/schnapps/plugins/selection/selection.h b/schnapps/plugins/selection/selection.h index 4031344..050d9b5 100644 --- a/schnapps/plugins/selection/selection.h +++ b/schnapps/plugins/selection/selection.h @@ -248,7 +248,9 @@ public slots: view->update(); } } + private: + void initialize_gl() { shader_point_sprite_param_selection_sphere_ = cgogn::rendering::ShaderPointSprite::generate_param(); @@ -282,9 +284,6 @@ public slots: drawer_rend_selected_volumes_ = drawer_selected_volumes_->generate_renderer(); } - -private: - MapHandlerGen* map_; std::unique_ptr> position_; std::unique_ptr> normal_; @@ -404,6 +403,7 @@ private slots: }; } // namespace plugin_selection + } // namespace schnapps #endif // SCHNAPPS_PLUGIN_SELECTION_H_ diff --git a/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.cpp b/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.cpp index a535455..6f67808 100644 --- a/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.cpp +++ b/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.cpp @@ -29,20 +29,50 @@ namespace schnapps { + namespace plugin_sdp { -ComputeCurvature_Dialog::ComputeCurvature_Dialog(SCHNApps* s) : +ComputeCurvature_Dialog::ComputeCurvature_Dialog(SCHNApps* s, Plugin_SurfaceDifferentialProperties* p) : schnapps_(s), + plugin_(p), selected_map_(nullptr) { setupUi(this); - Kmax_attribute_name->setText("Kmax"); - kmax_attribute_name->setText("kmax"); - Kmin_attribute_name->setText("Kmin"); - kmin_attribute_name->setText("kmin"); - Knormal_attribute_name->setText("Knormal"); + setting_auto_load_position_attribute_ = plugin_->get_setting("Auto load position attribute"); + if (!setting_auto_load_position_attribute_.isValid()) + setting_auto_load_position_attribute_ = plugin_->add_setting("Auto load position attribute", "position"); + + setting_auto_load_normal_attribute_ = plugin_->get_setting("Auto load normal attribute"); + if (!setting_auto_load_normal_attribute_.isValid()) + setting_auto_load_normal_attribute_ = plugin_->add_setting("Auto load normal attribute", "normal"); + + setting_auto_load_Kmax_attribute_ = plugin_->get_setting("Auto load Kmax attribute"); + if (!setting_auto_load_Kmax_attribute_.isValid()) + setting_auto_load_Kmax_attribute_ = plugin_->add_setting("Auto load Kmax attribute", "Kmax"); + + setting_auto_load_kmax_attribute_ = plugin_->get_setting("Auto load kmax attribute"); + if (!setting_auto_load_kmax_attribute_.isValid()) + setting_auto_load_kmax_attribute_ = plugin_->add_setting("Auto load kmax attribute", "kmax"); + + setting_auto_load_Kmin_attribute_ = plugin_->get_setting("Auto load Kmin attribute"); + if (!setting_auto_load_Kmin_attribute_.isValid()) + setting_auto_load_Kmin_attribute_ = plugin_->add_setting("Auto load Kmin attribute", "Kmin"); + + setting_auto_load_kmin_attribute_ = plugin_->get_setting("Auto load kmin attribute"); + if (!setting_auto_load_kmin_attribute_.isValid()) + setting_auto_load_kmin_attribute_ = plugin_->add_setting("Auto load kmin attribute", "kmin"); + + setting_auto_load_Knormal_attribute_ = plugin_->get_setting("Auto load Knormal attribute"); + if (!setting_auto_load_Knormal_attribute_.isValid()) + setting_auto_load_Knormal_attribute_ = plugin_->add_setting("Auto load Knormal attribute", "Knormal"); + + Kmax_attribute_name->setText(setting_auto_load_Kmax_attribute_.toString()); + kmax_attribute_name->setText(setting_auto_load_kmax_attribute_.toString()); + Kmin_attribute_name->setText(setting_auto_load_Kmin_attribute_.toString()); + kmin_attribute_name->setText(setting_auto_load_kmin_attribute_.toString()); + Knormal_attribute_name->setText(setting_auto_load_Knormal_attribute_.toString()); connect(schnapps_, SIGNAL(map_added(MapHandlerGen*)), this, SLOT(map_added(MapHandlerGen*))); connect(schnapps_, SIGNAL(map_removed(MapHandlerGen*)), this, SLOT(map_removed(MapHandlerGen*))); @@ -91,15 +121,29 @@ void ComputeCurvature_Dialog::selected_map_changed() if (type == vec3_type_name) { combo_positionAttribute->addItem(name); + if (name == setting_auto_load_position_attribute_.toString()) + combo_positionAttribute->setCurrentIndex(combo_positionAttribute->count() - 1); combo_normalAttribute->addItem(name); + if (name == setting_auto_load_normal_attribute_.toString()) + combo_normalAttribute->setCurrentIndex(combo_normalAttribute->count() - 1); combo_KmaxAttribute->addItem(name); + if (name == setting_auto_load_Kmax_attribute_.toString()) + combo_KmaxAttribute->setCurrentIndex(combo_KmaxAttribute->count() - 1); combo_KminAttribute->addItem(name); + if (name == setting_auto_load_Kmin_attribute_.toString()) + combo_KminAttribute->setCurrentIndex(combo_KminAttribute->count() - 1); combo_KnormalAttribute->addItem(name); + if (name == setting_auto_load_Knormal_attribute_.toString()) + combo_KnormalAttribute->setCurrentIndex(combo_KnormalAttribute->count() - 1); } else if (type == scalar_type_name) { combo_kmaxAttribute->addItem(name); + if (name == setting_auto_load_kmax_attribute_.toString()) + combo_kmaxAttribute->setCurrentIndex(combo_kmaxAttribute->count() - 1); combo_kminAttribute->addItem(name); + if (name == setting_auto_load_kmin_attribute_.toString()) + combo_kminAttribute->setCurrentIndex(combo_kminAttribute->count() - 1); } } } @@ -160,4 +204,5 @@ void ComputeCurvature_Dialog::selected_map_attribute_added(cgogn::Orbit orbit, c } } // namespace plugin_sdp + } // namespace schnapps diff --git a/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.h b/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.h index d540602..11f0529 100644 --- a/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.h +++ b/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.h @@ -47,13 +47,23 @@ class SCHNAPPS_PLUGIN_SDP_API ComputeCurvature_Dialog : public QDialog, public U friend class Plugin_SurfaceDifferentialProperties; public: - ComputeCurvature_Dialog(SCHNApps* s); + ComputeCurvature_Dialog(SCHNApps* s, Plugin_SurfaceDifferentialProperties* p); private: SCHNApps* schnapps_; + Plugin_SurfaceDifferentialProperties* plugin_; + MapHandler* selected_map_; + QVariant setting_auto_load_position_attribute_; + QVariant setting_auto_load_normal_attribute_; + QVariant setting_auto_load_Kmax_attribute_; + QVariant setting_auto_load_kmax_attribute_; + QVariant setting_auto_load_Kmin_attribute_; + QVariant setting_auto_load_kmin_attribute_; + QVariant setting_auto_load_Knormal_attribute_; + private slots: void selected_map_changed(); @@ -63,6 +73,7 @@ private slots: }; } // namespace plugin_sdp + } // namespace schnapps #endif // SCHNAPPS_PLUGIN_SURFACE_DIFFERENTIAL_PROPERTIES_DIALOG_COMPUTE_CURVATURE_H_ diff --git a/schnapps/plugins/surface_differential_properties/dialog_compute_normal.cpp b/schnapps/plugins/surface_differential_properties/dialog_compute_normal.cpp index 4a23a10..fe059ab 100644 --- a/schnapps/plugins/surface_differential_properties/dialog_compute_normal.cpp +++ b/schnapps/plugins/surface_differential_properties/dialog_compute_normal.cpp @@ -30,16 +30,26 @@ namespace schnapps { + namespace plugin_sdp { -ComputeNormal_Dialog::ComputeNormal_Dialog(SCHNApps* s) : +ComputeNormal_Dialog::ComputeNormal_Dialog(SCHNApps* s, Plugin_SurfaceDifferentialProperties* p) : schnapps_(s), + plugin_(p), selected_map_(nullptr) { setupUi(this); - normal_attribute_name->setText("normal"); + setting_auto_load_position_attribute_ = plugin_->get_setting("Auto load position attribute"); + if (!setting_auto_load_position_attribute_.isValid()) + setting_auto_load_position_attribute_ = plugin_->add_setting("Auto load position attribute", "position"); + + setting_auto_load_normal_attribute_ = plugin_->get_setting("Auto load normal attribute"); + if (!setting_auto_load_normal_attribute_.isValid()) + setting_auto_load_normal_attribute_ = plugin_->add_setting("Auto load normal attribute", "normal"); + + normal_attribute_name->setText(setting_auto_load_normal_attribute_.toString()); connect(schnapps_, SIGNAL(map_added(MapHandlerGen*)), this, SLOT(map_added(MapHandlerGen*))); connect(schnapps_, SIGNAL(map_removed(MapHandlerGen*)), this, SLOT(map_removed(MapHandlerGen*))); @@ -82,7 +92,11 @@ void ComputeNormal_Dialog::selected_map_changed() if (type == vec3_type_name) { combo_positionAttribute->addItem(name); + if (name == setting_auto_load_position_attribute_.toString()) + combo_positionAttribute->setCurrentIndex(combo_positionAttribute->count() - 1); combo_normalAttribute->addItem(name); + if (name == setting_auto_load_normal_attribute_.toString()) + combo_normalAttribute->setCurrentIndex(combo_normalAttribute->count() - 1); } } } @@ -134,4 +148,5 @@ void ComputeNormal_Dialog::selected_map_attribute_added(cgogn::Orbit orbit, cons } } // namespace plugin_sdp + } // namespace schnapps diff --git a/schnapps/plugins/surface_differential_properties/dialog_compute_normal.h b/schnapps/plugins/surface_differential_properties/dialog_compute_normal.h index 8887105..93b1e5c 100644 --- a/schnapps/plugins/surface_differential_properties/dialog_compute_normal.h +++ b/schnapps/plugins/surface_differential_properties/dialog_compute_normal.h @@ -47,13 +47,18 @@ class SCHNAPPS_PLUGIN_SDP_API ComputeNormal_Dialog : public QDialog, public Ui:: public: - ComputeNormal_Dialog(SCHNApps* s); + ComputeNormal_Dialog(SCHNApps* s, Plugin_SurfaceDifferentialProperties* p); private: SCHNApps* schnapps_; + Plugin_SurfaceDifferentialProperties* plugin_; + MapHandler* selected_map_; + QVariant setting_auto_load_position_attribute_; + QVariant setting_auto_load_normal_attribute_; + private slots: void selected_map_changed(); @@ -63,6 +68,7 @@ private slots: }; } // namespace plugin_sdp + } // namespace schnapps #endif // SCHNAPPS_PLUGIN_SURFACE_DIFFERENTIAL_PROPERTIES_DIALOG_COMPUTE_NORMAL_H_ diff --git a/schnapps/plugins/surface_differential_properties/surface_differential_properties.cpp b/schnapps/plugins/surface_differential_properties/surface_differential_properties.cpp index 3eb30f1..2f25ec8 100644 --- a/schnapps/plugins/surface_differential_properties/surface_differential_properties.cpp +++ b/schnapps/plugins/surface_differential_properties/surface_differential_properties.cpp @@ -33,13 +33,14 @@ namespace schnapps { + namespace plugin_sdp { bool Plugin_SurfaceDifferentialProperties::enable() { - compute_normal_dialog_ = new ComputeNormal_Dialog(schnapps_); - compute_curvature_dialog_ = new ComputeCurvature_Dialog(schnapps_); + compute_normal_dialog_ = new ComputeNormal_Dialog(schnapps_, this); + compute_curvature_dialog_ = new ComputeCurvature_Dialog(schnapps_, this); compute_normal_action_ = new QAction("Compute Normal", this); compute_curvature_action_ = new QAction("Compute Curvature", this); @@ -165,7 +166,7 @@ void Plugin_SurfaceDifferentialProperties::compute_normal_from_dialog() if (compute_normal_dialog_->enableVBO->isChecked()) { MapHandlerGen* mhg = schnapps_->get_map(map_name); - if (mhg != NULL) + if (mhg) mhg->create_vbo(normal_name); } } @@ -360,4 +361,5 @@ void Plugin_SurfaceDifferentialProperties::compute_curvature( } } // namespace plugin_sdp + } // namespace schnapps diff --git a/schnapps/plugins/surface_differential_properties/surface_differential_properties.h b/schnapps/plugins/surface_differential_properties/surface_differential_properties.h index 3f361e1..d6f3790 100644 --- a/schnapps/plugins/surface_differential_properties/surface_differential_properties.h +++ b/schnapps/plugins/surface_differential_properties/surface_differential_properties.h @@ -99,12 +99,12 @@ public slots: * @brief compute curvatures of a mesh * @param map_name name of 2d map * @param position_attribute_name name of input position attribute - * @param normal_attribute_name name of input normal attributes - * @param Kmax_attribute_name ?? result attribute name - * @param kmax_attribute_name ?? result attribute name - * @param Kmin_attribute_name ?? result attribute name - * @param kmin_attribute_name ?? result attribute name - * @param Knormal_attribute_name ?? result attribute aname + * @param normal_attribute_name name of input normal attribute + * @param Kmax_attribute_name name of output maximum curvature direction attribute + * @param kmax_attribute_name name of output maximum curvature magnitude attribute + * @param Kmin_attribute_name name of output minimum curvature direction attribute + * @param kmin_attribute_name name of output minimum curvature magnitude attribute + * @param Knormal_attribute_name name of output normal direction attribute * @param compute_kmean compute the mean curvature * @param compute_kgaussian compute the gaussian curvature * @param auto_update automatically update the output attributes when input attribute change. @@ -171,6 +171,7 @@ public slots: }; } // namespace plugin_sdp + } // namespace schnapps #endif // SCHNAPPS_PLUGIN_SURFACE_DIFFERENTIAL_PROPERTIES_H_ diff --git a/schnapps/plugins/surface_render/surface_render.cpp b/schnapps/plugins/surface_render/surface_render.cpp index 7167776..e76ac5a 100644 --- a/schnapps/plugins/surface_render/surface_render.cpp +++ b/schnapps/plugins/surface_render/surface_render.cpp @@ -30,6 +30,7 @@ namespace schnapps { + namespace plugin_surface_render { @@ -53,10 +54,21 @@ MapParameters& Plugin_SurfaceRender::get_parameters(View* view, MapHandlerGen* m bool Plugin_SurfaceRender::enable() { - setting_auto_enable_on_selected_view_ = add_setting("Auto enable on selected view", true); - setting_auto_load_position_attribute_ = add_setting("Auto load position attribute", "position"); - setting_auto_load_normal_attribute_ = add_setting("Auto load normal attribute", "normal"); - setting_auto_load_color_attribute_ = add_setting("Auto load color attribute", "color"); + setting_auto_enable_on_selected_view_ = get_setting("Auto enable on selected view"); + if (!setting_auto_enable_on_selected_view_.isValid()) + setting_auto_enable_on_selected_view_ = add_setting("Auto enable on selected view", true); + + setting_auto_load_position_attribute_ = get_setting("Auto load position attribute"); + if (!setting_auto_load_position_attribute_.isValid()) + setting_auto_load_position_attribute_ = add_setting("Auto load position attribute", "position"); + + setting_auto_load_normal_attribute_ = get_setting("Auto load normal attribute"); + if (!setting_auto_load_normal_attribute_.isValid()) + setting_auto_load_normal_attribute_ = add_setting("Auto load normal attribute", "normal"); + + setting_auto_load_color_attribute_ = get_setting("Auto load color attribute"); + if (!setting_auto_load_color_attribute_.isValid()) + setting_auto_load_color_attribute_ = add_setting("Auto load color attribute", "color"); dock_tab_ = new SurfaceRender_DockTab(this->schnapps_, this); schnapps_->add_plugin_dock_tab(this, dock_tab_, "Surface Render"); @@ -198,9 +210,9 @@ void Plugin_SurfaceRender::map_linked(MapHandlerGen *map) View* view = schnapps_->get_selected_view(); if (view) { - set_position_vbo(view->get_name(), map->get_name(), setting_auto_load_position_attribute_->toString()); - set_normal_vbo(view->get_name(), map->get_name(), setting_auto_load_normal_attribute_->toString()); - set_color_vbo(view->get_name(), map->get_name(), setting_auto_load_color_attribute_->toString()); + set_position_vbo(view->get_name(), map->get_name(), setting_auto_load_position_attribute_.toString()); + set_normal_vbo(view->get_name(), map->get_name(), setting_auto_load_normal_attribute_.toString()); + set_color_vbo(view->get_name(), map->get_name(), setting_auto_load_color_attribute_.toString()); } connect(map, SIGNAL(vbo_added(cgogn::rendering::VBO*)), this, SLOT(linked_map_vbo_added(cgogn::rendering::VBO*)), Qt::UniqueConnection); @@ -236,11 +248,11 @@ void Plugin_SurfaceRender::linked_map_vbo_added(cgogn::rendering::VBO* vbo) dock_tab_->add_color_vbo(vbo_name); if (view) { - if (!get_parameters(view, map).get_position_vbo() && vbo_name == setting_auto_load_position_attribute_->toString()) + if (!get_parameters(view, map).get_position_vbo() && vbo_name == setting_auto_load_position_attribute_.toString()) set_position_vbo(view->get_name(), map->get_name(), vbo_name); - if (!get_parameters(view, map).get_normal_vbo() && vbo_name == setting_auto_load_normal_attribute_->toString()) + if (!get_parameters(view, map).get_normal_vbo() && vbo_name == setting_auto_load_normal_attribute_.toString()) set_normal_vbo(view->get_name(), map->get_name(), vbo_name); - if (!get_parameters(view, map).get_color_vbo() && vbo_name == setting_auto_load_color_attribute_->toString()) + if (!get_parameters(view, map).get_color_vbo() && vbo_name == setting_auto_load_color_attribute_.toString()) set_color_vbo(view->get_name(), map->get_name(), vbo_name); } } @@ -309,7 +321,7 @@ void Plugin_SurfaceRender::viewer_initialized() void Plugin_SurfaceRender::enable_on_selected_view(Plugin* p) { - if ((this == p) && schnapps_->get_selected_view() && setting_auto_enable_on_selected_view_->toBool()) + if ((this == p) && schnapps_->get_selected_view() && setting_auto_enable_on_selected_view_.toBool()) schnapps_->get_selected_view()->link_plugin(this); } @@ -488,4 +500,5 @@ void Plugin_SurfaceRender::set_vertex_scale_factor(View* view, MapHandlerGen* ma } } // namespace plugin_surface_render + } // namespace schnapps diff --git a/schnapps/plugins/surface_render/surface_render.h b/schnapps/plugins/surface_render/surface_render.h index 48fa4a4..fbbd102 100644 --- a/schnapps/plugins/surface_render/surface_render.h +++ b/schnapps/plugins/surface_render/surface_render.h @@ -42,6 +42,7 @@ namespace schnapps { + namespace plugin_surface_render { @@ -84,7 +85,6 @@ struct SCHNAPPS_PLUGIN_SURFACE_RENDER_API MapParameters initialize_gl(); } - cgogn::rendering::VBO* get_position_vbo() const { return position_vbo_; } void set_position_vbo(cgogn::rendering::VBO* v) { @@ -182,6 +182,7 @@ struct SCHNAPPS_PLUGIN_SURFACE_RENDER_API MapParameters } private: + inline void initialize_gl() { shader_flat_param_ = cgogn::rendering::ShaderFlat::generate_param(); @@ -213,8 +214,6 @@ struct SCHNAPPS_PLUGIN_SURFACE_RENDER_API MapParameters set_color_vbo(color_vbo_); } -private: - std::unique_ptr shader_flat_param_; std::unique_ptr shader_flat_color_param_; std::unique_ptr shader_simple_color_param_; @@ -392,13 +391,14 @@ public slots: SurfaceRender_DockTab* dock_tab_; std::map> parameter_set_; - QVariant* setting_auto_enable_on_selected_view_; - QVariant* setting_auto_load_position_attribute_; - QVariant* setting_auto_load_normal_attribute_; - QVariant* setting_auto_load_color_attribute_; + QVariant setting_auto_enable_on_selected_view_; + QVariant setting_auto_load_position_attribute_; + QVariant setting_auto_load_normal_attribute_; + QVariant setting_auto_load_color_attribute_; }; } // namespace plugin_surface_render + } // namespace schnapps #endif // SCHNAPPS_PLUGIN_SURFACE_RENDER_H_ diff --git a/schnapps/plugins/volume_render/volume_render.cpp b/schnapps/plugins/volume_render/volume_render.cpp index 0ac83e2..353a58d 100644 --- a/schnapps/plugins/volume_render/volume_render.cpp +++ b/schnapps/plugins/volume_render/volume_render.cpp @@ -61,8 +61,13 @@ MapParameters& Plugin_VolumeRender::get_parameters(View* view, MapHandlerGen* ma bool Plugin_VolumeRender::enable() { - setting_auto_enable_on_selected_view_ = add_setting("Auto enable on selected view", true); - setting_auto_load_position_attribute_ = add_setting("Auto load position attribute", "position"); + setting_auto_enable_on_selected_view_ = get_setting("Auto enable on selected view"); + if (!setting_auto_enable_on_selected_view_.isValid()) + setting_auto_enable_on_selected_view_ = add_setting("Auto enable on selected view", true); + + setting_auto_load_position_attribute_ = get_setting("Auto load position attribute"); + if (!setting_auto_load_position_attribute_.isValid()) + setting_auto_load_position_attribute_ = add_setting("Auto load position attribute", "position"); dock_tab_ = new VolumeRender_DockTab(this->schnapps_, this); schnapps_->add_plugin_dock_tab(this, dock_tab_, "Volume Render"); @@ -259,7 +264,7 @@ void Plugin_VolumeRender::map_linked(MapHandlerGen* map) { View* view = schnapps_->get_selected_view(); if (view) - set_position_vbo(view->get_name(), map->get_name(), setting_auto_load_position_attribute_->toString()); + set_position_vbo(view->get_name(), map->get_name(), setting_auto_load_position_attribute_.toString()); connect(map, SIGNAL(vbo_added(cgogn::rendering::VBO*)), this, SLOT(linked_map_vbo_added(cgogn::rendering::VBO*)), Qt::UniqueConnection); connect(map, SIGNAL(vbo_removed(cgogn::rendering::VBO*)), this, SLOT(linked_map_vbo_removed(cgogn::rendering::VBO*)), Qt::UniqueConnection); @@ -296,7 +301,7 @@ void Plugin_VolumeRender::linked_map_vbo_added(cgogn::rendering::VBO* vbo) View* view = schnapps_->get_selected_view(); if (view) { - if (!get_parameters(view, map).get_position_vbo() && vbo_name == setting_auto_load_position_attribute_->toString()) + if (!get_parameters(view, map).get_position_vbo() && vbo_name == setting_auto_load_position_attribute_.toString()) set_position_vbo(view->get_name(), map->get_name(), vbo_name); } } @@ -310,9 +315,7 @@ void Plugin_VolumeRender::linked_map_vbo_removed(cgogn::rendering::VBO* vbo) if (map->is_selected_map()) { if (vbo->vector_dimension() == 3) - { dock_tab_->remove_position_vbo(QString::fromStdString(vbo->name())); - } } for (auto& it : parameter_set_) @@ -402,10 +405,8 @@ void Plugin_VolumeRender::viewer_initialized() void Plugin_VolumeRender::enable_on_selected_view(Plugin* p) { - if ((this == p) && schnapps_->get_selected_view() && setting_auto_enable_on_selected_view_->toBool()) - { + if ((this == p) && schnapps_->get_selected_view() && setting_auto_enable_on_selected_view_.toBool()) schnapps_->get_selected_view()->link_plugin(this); - } } void Plugin_VolumeRender::update_dock_tab() diff --git a/schnapps/plugins/volume_render/volume_render.h b/schnapps/plugins/volume_render/volume_render.h index dd900a3..0c017ee 100644 --- a/schnapps/plugins/volume_render/volume_render.h +++ b/schnapps/plugins/volume_render/volume_render.h @@ -47,7 +47,6 @@ #include #endif // (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) - namespace schnapps { @@ -355,12 +354,12 @@ public slots: VolumeRender_DockTab* dock_tab_; std::map> parameter_set_; - QVariant* setting_auto_enable_on_selected_view_; - QVariant* setting_auto_load_position_attribute_; + QVariant setting_auto_enable_on_selected_view_; + QVariant setting_auto_load_position_attribute_; }; } // namespace plugin_volume_render -} // namespace schnapps +} // namespace schnapps #endif // SCHNAPPS_PLUGIN_VOLUME_RENDER_H_ From 4c84a47db38932ae7ab21f65684fb18ea328584f Mon Sep 17 00:00:00 2001 From: Pierre Kraemer Date: Tue, 14 Feb 2017 16:34:08 +0100 Subject: [PATCH 02/14] add surface_modelisation plugin with decimation --- schnapps/core/types.h | 1 + schnapps/plugins/CMakeLists.txt | 1 + schnapps/plugins/meshgen/dll.h | 1 - .../CMakeLists.txt | 2 +- .../surface_differential_properties/dll.h | 1 - .../surface_differential_properties.h | 3 +- .../surface_modelisation/CMakeLists.txt | 43 ++++++ .../dialog_decimation.cpp | 141 ++++++++++++++++++ .../surface_modelisation/dialog_decimation.h | 73 +++++++++ .../surface_modelisation/dialog_decimation.ui | 104 +++++++++++++ schnapps/plugins/surface_modelisation/dll.h | 38 +++++ .../surface_modelisation.cpp | 111 ++++++++++++++ .../surface_modelisation.h | 99 ++++++++++++ schnapps/plugins/surface_render/dll.h | 1 - 14 files changed, 614 insertions(+), 5 deletions(-) create mode 100644 schnapps/plugins/surface_modelisation/CMakeLists.txt create mode 100644 schnapps/plugins/surface_modelisation/dialog_decimation.cpp create mode 100644 schnapps/plugins/surface_modelisation/dialog_decimation.h create mode 100644 schnapps/plugins/surface_modelisation/dialog_decimation.ui create mode 100644 schnapps/plugins/surface_modelisation/dll.h create mode 100644 schnapps/plugins/surface_modelisation/surface_modelisation.cpp create mode 100644 schnapps/plugins/surface_modelisation/surface_modelisation.h diff --git a/schnapps/core/types.h b/schnapps/core/types.h index 548290d..dc55bd1 100644 --- a/schnapps/core/types.h +++ b/schnapps/core/types.h @@ -28,6 +28,7 @@ #include #include #include + namespace cgogn { diff --git a/schnapps/plugins/CMakeLists.txt b/schnapps/plugins/CMakeLists.txt index aba8f44..0cdddbf 100644 --- a/schnapps/plugins/CMakeLists.txt +++ b/schnapps/plugins/CMakeLists.txt @@ -5,6 +5,7 @@ add_subdirectory(surface_differential_properties) add_subdirectory(surface_render) add_subdirectory(surface_render_vector) add_subdirectory(surface_render_scalar) +add_subdirectory(surface_modelisation) add_subdirectory(volume_render) add_subdirectory(image) add_subdirectory(meshgen) diff --git a/schnapps/plugins/meshgen/dll.h b/schnapps/plugins/meshgen/dll.h index 80b91fd..eb177d9 100644 --- a/schnapps/plugins/meshgen/dll.h +++ b/schnapps/plugins/meshgen/dll.h @@ -25,7 +25,6 @@ #ifndef SCHNAPPS_PLUGIN_MESHGEN_DLL_H_ #define SCHNAPPS_PLUGIN_MESHGEN_DLL_H_ - #ifdef WIN32 #ifndef SCHNAPPS_PLUGIN_MESHGEN_API #if defined SCHNAPPS_PLUGIN_MESHGEN_DLL_EXPORT diff --git a/schnapps/plugins/surface_differential_properties/CMakeLists.txt b/schnapps/plugins/surface_differential_properties/CMakeLists.txt index a2ee3f2..4e59539 100644 --- a/schnapps/plugins/surface_differential_properties/CMakeLists.txt +++ b/schnapps/plugins/surface_differential_properties/CMakeLists.txt @@ -3,7 +3,7 @@ project(plugin_surface_differential_properties ) find_package(cgogn_core REQUIRED) -find_package(cgogn_rendering REQUIRED) +find_package(cgogn_geometry REQUIRED) find_package(Qt5 COMPONENTS Widgets REQUIRED) find_package(QOGLViewer REQUIRED) diff --git a/schnapps/plugins/surface_differential_properties/dll.h b/schnapps/plugins/surface_differential_properties/dll.h index 4eb9b78..47f023c 100644 --- a/schnapps/plugins/surface_differential_properties/dll.h +++ b/schnapps/plugins/surface_differential_properties/dll.h @@ -23,7 +23,6 @@ #ifndef SCHNAPPS_PLUGIN_SDP_DLL_H_ #define SCHNAPPS_PLUGIN_SDP_DLL_H_ - #ifdef WIN32 #ifndef SCHNAPPS_PLUGIN_SDP_API #if defined SCHNAPPS_PLUGIN_SDP_DLL_EXPORT diff --git a/schnapps/plugins/surface_differential_properties/surface_differential_properties.h b/schnapps/plugins/surface_differential_properties/surface_differential_properties.h index d6f3790..0805555 100644 --- a/schnapps/plugins/surface_differential_properties/surface_differential_properties.h +++ b/schnapps/plugins/surface_differential_properties/surface_differential_properties.h @@ -39,12 +39,13 @@ class MapHandlerGen; namespace plugin_sdp { + /** * @brief Plugin that manages the computation of differential properties * - Normals * - Curvatures */ -class SCHNAPPS_PLUGIN_SDP_API Plugin_SurfaceDifferentialProperties: public PluginProcessing +class SCHNAPPS_PLUGIN_SDP_API Plugin_SurfaceDifferentialProperties : public PluginProcessing { Q_OBJECT Q_PLUGIN_METADATA(IID "SCHNApps.Plugin") diff --git a/schnapps/plugins/surface_modelisation/CMakeLists.txt b/schnapps/plugins/surface_modelisation/CMakeLists.txt new file mode 100644 index 0000000..6d71310 --- /dev/null +++ b/schnapps/plugins/surface_modelisation/CMakeLists.txt @@ -0,0 +1,43 @@ +project(plugin_surface_modelisation + LANGUAGES CXX +) + +find_package(cgogn_core REQUIRED) +find_package(cgogn_modeling REQUIRED) +find_package(Qt5 COMPONENTS Widgets REQUIRED) +find_package(QOGLViewer REQUIRED) + +set(HEADER_FILES + dll.h + surface_modelisation.h + dialog_decimation.h +) + +set(SOURCE_FILES + surface_modelisation.cpp + dialog_decimation.cpp +) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTOUIC ON) + +add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES}) + +set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_POSTFIX "_d") +target_compile_definitions(${PROJECT_NAME} PRIVATE "-DSCHNAPPS_PLUGIN_SURFACE_MODELISATION_DLL_EXPORT") + +target_include_directories(${PROJECT_NAME} PUBLIC + ${QOGLViewer_INCLUDE_DIRS} + $ + $ + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} +) + +target_link_libraries(${PROJECT_NAME} + schnapps_core + ${cgogn_core_LIBRARIES} + ${cgogn_modeling_LIBRARIES} + ${Qt5Widgets_LIBRARIES} + ${QOGLViewer_LIBRARIES} +) diff --git a/schnapps/plugins/surface_modelisation/dialog_decimation.cpp b/schnapps/plugins/surface_modelisation/dialog_decimation.cpp new file mode 100644 index 0000000..9e6b090 --- /dev/null +++ b/schnapps/plugins/surface_modelisation/dialog_decimation.cpp @@ -0,0 +1,141 @@ +/******************************************************************************* +* SCHNApps * +* Copyright (C) 2015, IGG Group, ICube, University of Strasbourg, France * +* * +* This library is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by the * +* Free Software Foundation; either version 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: http://cgogn.unistra.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#include + +#include + +#include +#include + +namespace schnapps +{ + +namespace plugin_surface_modelisation +{ + +Decimation_Dialog::Decimation_Dialog(SCHNApps* s, Plugin_SurfaceModelisation* p) : + schnapps_(s), + plugin_(p), + selected_map_(nullptr) +{ + setupUi(this); + + setting_auto_load_position_attribute_ = plugin_->get_setting("Auto load position attribute"); + if (!setting_auto_load_position_attribute_.isValid()) + setting_auto_load_position_attribute_ = plugin_->add_setting("Auto load position attribute", "position"); + + connect(schnapps_, SIGNAL(map_added(MapHandlerGen*)), this, SLOT(map_added(MapHandlerGen*))); + connect(schnapps_, SIGNAL(map_removed(MapHandlerGen*)), this, SLOT(map_removed(MapHandlerGen*))); + + connect(list_maps, SIGNAL(itemSelectionChanged()), this, SLOT(selected_map_changed())); + + schnapps_->foreach_map([this] (MapHandlerGen* map) { map_added(map); }); +} + +void Decimation_Dialog::selected_map_changed() +{ + if (selected_map_) + disconnect(selected_map_, SIGNAL(attribute_added(cgogn::Orbit, const QString&)), this, SLOT(selected_map_attribute_added(cgogn::Orbit, const QString&))); + + QList currentItems = list_maps->selectedItems(); + if (!currentItems.empty()) + { + combo_positionAttribute->clear(); + + const QString& map_name = currentItems[0]->text(); + MapHandlerGen* mhg = schnapps_->get_map(map_name); + selected_map_ = dynamic_cast*>(mhg); + + if (selected_map_) + { + const CMap2* map2 = selected_map_->get_map(); + if (map2->is_embedded()) + { + QString vec3_type_name = QString::fromStdString(cgogn::name_of_type(VEC3())); + + const CMap2::ChunkArrayContainer& container = map2->const_attribute_container(); + const std::vector& names = container.names(); + const std::vector& type_names = container.type_names(); + + for (std::size_t i = 0u; i < names.size(); ++i) + { + QString name = QString::fromStdString(names[i]); + QString type = QString::fromStdString(type_names[i]); + if (type == vec3_type_name) + { + combo_positionAttribute->addItem(name); + if (name == setting_auto_load_position_attribute_.toString()) + combo_positionAttribute->setCurrentIndex(combo_positionAttribute->count() - 1); + } + } + } + connect(selected_map_, SIGNAL(attribute_added(cgogn::Orbit, const QString&)), this, SLOT(selected_map_attribute_added(cgogn::Orbit, const QString&))); + } + } + else + selected_map_ = nullptr; +} + +void Decimation_Dialog::map_added(MapHandlerGen* map) +{ + if (map->dimension() == 2) + { + QListWidgetItem* item = new QListWidgetItem(map->get_name(), list_maps); + item->setCheckState(Qt::Unchecked); + } +} + +void Decimation_Dialog::map_removed(MapHandlerGen* map) +{ + QList items = list_maps->findItems(map->get_name(), Qt::MatchExactly); + if (!items.empty()) + delete items[0]; + + if (selected_map_ == map) + { + disconnect(selected_map_, SIGNAL(attribute_added(cgogn::Orbit, const QString&)), this, SLOT(selected_map_attribute_added(cgogn::Orbit, const QString&))); + selected_map_ = nullptr; + } +} + +void Decimation_Dialog::selected_map_attribute_added(cgogn::Orbit orbit, const QString& attribute_name) +{ + if (orbit == CMap2::Vertex::ORBIT) + { + QString vec3_type_name = QString::fromStdString(cgogn::name_of_type(VEC3())); + + const CMap2* map2 = selected_map_->get_map(); + const CMap2::ChunkArrayContainer& container = map2->const_attribute_container(); + QString attribute_type_name = QString::fromStdString(container.get_chunk_array(attribute_name.toStdString())->type_name()); + + if (attribute_type_name == vec3_type_name) + { + combo_positionAttribute->addItem(attribute_name); + } + } +} + +} // namespace plugin_surface_modelisation + +} // namespace schnapps diff --git a/schnapps/plugins/surface_modelisation/dialog_decimation.h b/schnapps/plugins/surface_modelisation/dialog_decimation.h new file mode 100644 index 0000000..3400167 --- /dev/null +++ b/schnapps/plugins/surface_modelisation/dialog_decimation.h @@ -0,0 +1,73 @@ +/******************************************************************************* +* SCHNApps * +* Copyright (C) 2015, IGG Group, ICube, University of Strasbourg, France * +* * +* This library is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by the * +* Free Software Foundation; either version 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: http://cgogn.unistra.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#ifndef SCHNAPPS_PLUGIN_SURFACE_MODELISATION_DIALOG_DECIMATION_H_ +#define SCHNAPPS_PLUGIN_SURFACE_MODELISATION_DIALOG_DECIMATION_H_ + +#include "dll.h" +#include + +#include + +namespace schnapps +{ + +class SCHNApps; + +namespace plugin_surface_modelisation +{ + +class Plugin_SurfaceModelisation; + +class SCHNAPPS_PLUGIN_SURFACE_MODELISATION_API Decimation_Dialog : public QDialog, public Ui::Decimation_Dialog +{ + Q_OBJECT + + friend class Plugin_SurfaceModelisation; + +public: + + Decimation_Dialog(SCHNApps* s, Plugin_SurfaceModelisation* p); + +private: + + SCHNApps* schnapps_; + Plugin_SurfaceModelisation* plugin_; + + MapHandler* selected_map_; + + QVariant setting_auto_load_position_attribute_; + +private slots: + + void selected_map_changed(); + void map_added(MapHandlerGen* map); + void map_removed(MapHandlerGen* map); + void selected_map_attribute_added(cgogn::Orbit orbit, const QString& attribute_name); +}; + +} // namespace plugin_surface_modelisation + +} // namespace schnapps + +#endif // SCHNAPPS_PLUGIN_SURFACE_MODELISATION_DIALOG_DECIMATION_H_ diff --git a/schnapps/plugins/surface_modelisation/dialog_decimation.ui b/schnapps/plugins/surface_modelisation/dialog_decimation.ui new file mode 100644 index 0000000..585b31d --- /dev/null +++ b/schnapps/plugins/surface_modelisation/dialog_decimation.ui @@ -0,0 +1,104 @@ + + +SCHNAPPS_PLUGIN_SURFACE_MODELISATION_API + Decimation_Dialog + + + + 0 + 0 + 472 + 292 + + + + Compute Normal + + + + + + + + + + + Position attribute : + + + + + + + + 0 + 0 + + + + + + + + + + + + Cancel + + + + + + + Apply + + + + + + + OK + + + + + + + + + + + button_ok + clicked() + Decimation_Dialog + accept() + + + 232 + 283 + + + 140 + 156 + + + + + button_cancel + clicked() + Decimation_Dialog + reject() + + + 52 + 283 + + + 140 + 156 + + + + + diff --git a/schnapps/plugins/surface_modelisation/dll.h b/schnapps/plugins/surface_modelisation/dll.h new file mode 100644 index 0000000..fdb05a3 --- /dev/null +++ b/schnapps/plugins/surface_modelisation/dll.h @@ -0,0 +1,38 @@ +/******************************************************************************* +* SCHNApps * +* Copyright (C) 2015, IGG Group, ICube, University of Strasbourg, France * +* This library is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by the * +* Free Software Foundation; either version 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: http://cgogn.unistra.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#ifndef SCHNAPPS_PLUGIN_SURFACE_MODELISATION_DLL_H_ +#define SCHNAPPS_PLUGIN_SURFACE_MODELISATION_DLL_H_ + +#ifdef WIN32 +#ifndef SCHNAPPS_PLUGIN_SURFACE_MODELISATION_API +#if defined SCHNAPPS_PLUGIN_SURFACE_MODELISATION_DLL_EXPORT +#define SCHNAPPS_PLUGIN_SURFACE_MODELISATION_API __declspec(dllexport) +#else +#define SCHNAPPS_PLUGIN_SURFACE_MODELISATION_API __declspec(dllimport) +#endif +#endif +#else +#define SCHNAPPS_PLUGIN_SURFACE_MODELISATION_API +#endif + +#endif // SCHNAPPS_PLUGIN_SURFACE_MODELISATION_DLL_H_ diff --git a/schnapps/plugins/surface_modelisation/surface_modelisation.cpp b/schnapps/plugins/surface_modelisation/surface_modelisation.cpp new file mode 100644 index 0000000..5601e3c --- /dev/null +++ b/schnapps/plugins/surface_modelisation/surface_modelisation.cpp @@ -0,0 +1,111 @@ +/******************************************************************************* +* SCHNApps * +* Copyright (C) 2015, IGG Group, ICube, University of Strasbourg, France * +* * +* This library is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by the * +* Free Software Foundation; either version 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: http://cgogn.unistra.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#include + +#include +#include + +#include + +namespace schnapps +{ + +namespace plugin_surface_modelisation +{ + +bool Plugin_SurfaceModelisation::enable() +{ + decimation_dialog_ = new Decimation_Dialog(schnapps_, this); + + decimation_action_ = new QAction("Decimation", this); + + decimation_action_ = schnapps_->add_menu_action("Surface;Modelisation;Decimation", "decimate mesh"); + + connect(decimation_action_, SIGNAL(triggered()), this, SLOT(open_decimation_dialog())); + + connect(decimation_dialog_, SIGNAL(accepted()), this, SLOT(decimate_from_dialog())); + connect(decimation_dialog_->button_apply, SIGNAL(clicked()), this, SLOT(decimate_from_dialog())); + + connect(schnapps_, SIGNAL(schnapps_closing()), this, SLOT(schnapps_closing())); + + return true; +} + +void Plugin_SurfaceModelisation::disable() +{ + disconnect(decimation_action_, SIGNAL(triggered()), this, SLOT(open_decimation_dialog())); + + disconnect(decimation_dialog_, SIGNAL(accepted()), this, SLOT(decimate_from_dialog())); + disconnect(decimation_dialog_->button_apply, SIGNAL(clicked()), this, SLOT(decimate_from_dialog())); + + disconnect(schnapps_, SIGNAL(schnapps_closing()), this, SLOT(schnapps_closing())); + + schnapps_->remove_menu_action(decimation_action_); + + delete decimation_dialog_; +} + +void Plugin_SurfaceModelisation::schnapps_closing() +{ + decimation_dialog_->close(); +} + +void Plugin_SurfaceModelisation::open_decimation_dialog() +{ + decimation_dialog_->show(); +} + +void Plugin_SurfaceModelisation::decimate_from_dialog() +{ + QList currentItems = decimation_dialog_->list_maps->selectedItems(); + if(!currentItems.empty()) + { + const QString& map_name = currentItems[0]->text(); + QString position_name = decimation_dialog_->combo_positionAttribute->currentText(); + decimate(map_name, position_name, 1000u); + } +} + +void Plugin_SurfaceModelisation::decimate( + const QString& map_name, + const QString& position_attribute_name, + uint32 nb) +{ + MapHandler* mh = dynamic_cast*>(schnapps_->get_map(map_name)); + if (!mh) + return; + + CMap2::VertexAttribute position = mh->get_attribute(position_attribute_name); + if (!position.is_valid()) + return; + + cgogn::modeling::decimate(*mh->get_map(), position, cgogn::modeling::EdgeTraversor_QEM_T, cgogn::modeling::EdgeApproximator_QEM_T, nb); + + mh->notify_connectivity_change(); + mh->notify_attribute_change(CMap2::Vertex::ORBIT, position_attribute_name); +} + +} // namespace plugin_surface_modelisation + +} // namespace schnapps diff --git a/schnapps/plugins/surface_modelisation/surface_modelisation.h b/schnapps/plugins/surface_modelisation/surface_modelisation.h new file mode 100644 index 0000000..cc19e3a --- /dev/null +++ b/schnapps/plugins/surface_modelisation/surface_modelisation.h @@ -0,0 +1,99 @@ +/******************************************************************************* +* SCHNApps * +* Copyright (C) 2015, IGG Group, ICube, University of Strasbourg, France * +* * +* This library is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by the * +* Free Software Foundation; either version 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: http://cgogn.unistra.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#ifndef SCHNAPPS_PLUGIN_SURFACE_MODELISATION_H_ +#define SCHNAPPS_PLUGIN_SURFACE_MODELISATION_H_ + +#include + +#include "dll.h" +#include + +#include + +namespace schnapps +{ + +class MapHandlerGen; + +namespace plugin_surface_modelisation +{ + +/** + * @brief Plugin that exposes some surface modelisation algorithms + */ +class SCHNAPPS_PLUGIN_SURFACE_MODELISATION_API Plugin_SurfaceModelisation : public PluginProcessing +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "SCHNApps.Plugin") + Q_INTERFACES(schnapps::Plugin) + +public: + + Plugin_SurfaceModelisation() {} + + ~Plugin_SurfaceModelisation() {} + +private: + + virtual bool enable(); + virtual void disable(); + +private slots: + + // slots called from SCHNApps signals + void schnapps_closing(); + + // slots called from action signals + void open_decimation_dialog(); + + // slots called from dialog signals + void decimate_from_dialog(); + +public slots: + + /** + * @brief compute the normals of a mesh + * @param map_name name of the 2d map (mesh) + * @param position_attribute_name name of position attribute used for computation + * @param normal_attribute_name name of result attribute + * @param auto_update automatically update the normal attribute when position attribute change. + */ + void decimate( + const QString& map_name, + const QString& position_attribute_name, + uint32_t nb + ); + +private: + + Decimation_Dialog* decimation_dialog_; + + QAction* decimation_action_; +}; + +} // namespace plugin_surface_modelisation + +} // namespace schnapps + +#endif // SCHNAPPS_PLUGIN_SURFACE_MODELISATION_H_ diff --git a/schnapps/plugins/surface_render/dll.h b/schnapps/plugins/surface_render/dll.h index a5cde24..8b0c644 100644 --- a/schnapps/plugins/surface_render/dll.h +++ b/schnapps/plugins/surface_render/dll.h @@ -23,7 +23,6 @@ #ifndef SCHNAPPS_PLUGIN_SURFACE_RENDER_DLL_H_ #define SCHNAPPS_PLUGIN_SURFACE_RENDER_DLL_H_ - #ifdef WIN32 #ifndef SCHNAPPS_PLUGIN_SURFACE_RENDER_API #if defined SCHNAPPS_PLUGIN_SURFACE_RENDER_DLL_EXPORT From fde0adc47ed6e1d010076510137bc5779a0fd89c Mon Sep 17 00:00:00 2001 From: Pierre Kraemer Date: Tue, 14 Feb 2017 17:06:09 +0100 Subject: [PATCH 03/14] specify nb vertices to keep in decimation dialog --- schnapps/core/control_dock_map_tab_widget.ui | 2 +- schnapps/core/map_handler.h | 17 +++++--- schnapps/plugins/import/import.h | 3 +- .../surface_modelisation/dialog_decimation.ui | 43 ++++++++++++++++--- .../surface_modelisation.cpp | 8 ++-- .../surface_modelisation.h | 2 +- 6 files changed, 57 insertions(+), 18 deletions(-) diff --git a/schnapps/core/control_dock_map_tab_widget.ui b/schnapps/core/control_dock_map_tab_widget.ui index c0165ef..4750c57 100644 --- a/schnapps/core/control_dock_map_tab_widget.ui +++ b/schnapps/core/control_dock_map_tab_widget.ui @@ -113,7 +113,7 @@ - 4 + 1 diff --git a/schnapps/core/map_handler.h b/schnapps/core/map_handler.h index a8f7ca3..c98e4f2 100644 --- a/schnapps/core/map_handler.h +++ b/schnapps/core/map_handler.h @@ -469,30 +469,32 @@ class MapHandler : public MapHandlerGen virtual void foreach_cell(CellType ct, const std::function& func) const override { const cgogn::Orbit orb = orbit(ct); - switch (orb) { + switch (orb) + { case CDart::ORBIT: get_map()->foreach_cell([&](CDart d) { func(d.dart); }); break; case Vertex::ORBIT: get_map()->foreach_cell([&](Vertex v) { func(v.dart); }); break; case Edge::ORBIT: get_map()->foreach_cell([&](Edge e) { func(e.dart); }); break; case Face::ORBIT: get_map()->foreach_cell([&](Face f) { func(f.dart); }); break; case Volume::ORBIT: get_map()->foreach_cell([&](Volume w) { func(w.dart); }); break; default: break; - } + } } virtual void parallel_foreach_cell(CellType ct, const std::function& func) const override { const cgogn::Orbit orb = orbit(ct); - switch (orb) { + switch (orb) + { case CDart::ORBIT: get_map()->parallel_foreach_cell([&](CDart d, uint32 th) { func(d.dart, th); }); break; case Vertex::ORBIT: get_map()->parallel_foreach_cell([&](Vertex v, uint32 th) { func(v.dart, th); }); break; case Edge::ORBIT: get_map()->parallel_foreach_cell([&](Edge e, uint32 th) { func(e.dart, th); }); break; case Face::ORBIT: get_map()->parallel_foreach_cell([&](Face f, uint32 th) { func(f.dart, th); }); break; case Volume::ORBIT: get_map()->parallel_foreach_cell([&](Volume w, uint32 th) { func(w.dart, th); }); break; default: break; - } + } } - virtual uint32 embedding(cgogn::Dart d,CellType ct) const override + virtual uint32 embedding(cgogn::Dart d, CellType ct) const override { return get_map()->embedding(d, orbit(ct)); } @@ -501,7 +503,8 @@ class MapHandler : public MapHandlerGen { const cgogn::Orbit orb = orbit(ct); const auto* map = get_map(); - switch (orb) { + switch (orb) + { case CDart::ORBIT: return d == e; case Vertex::ORBIT: return map->same_cell(Vertex(d), Vertex(e)); case Edge::ORBIT: return map->same_cell(Edge(d), Edge(e)); @@ -509,7 +512,7 @@ class MapHandler : public MapHandlerGen case Volume::ORBIT: return map->same_cell(Volume(d), Volume(e)); default: return false; - } + } } virtual std::pair vertices(cgogn::Dart edge) const override diff --git a/schnapps/plugins/import/import.h b/schnapps/plugins/import/import.h index cd7af4b..69de425 100644 --- a/schnapps/plugins/import/import.h +++ b/schnapps/plugins/import/import.h @@ -55,7 +55,7 @@ class SCHNAPPS_PLUGIN_IMPORT_API Plugin_Import : public PluginProcessing bool enable() override; void disable() override; - public slots: +public slots: /** * @brief import a surface mesh from a file @@ -71,6 +71,7 @@ class SCHNAPPS_PLUGIN_IMPORT_API Plugin_Import : public PluginProcessing MapHandlerGen* import_volume_mesh_from_file(const QString& filename); void import_volume_mesh_from_file_dialog(); + // /** // * @brief import a 2D image into a surface mesh from a file // * @param filename file name of mesh file diff --git a/schnapps/plugins/surface_modelisation/dialog_decimation.ui b/schnapps/plugins/surface_modelisation/dialog_decimation.ui index 585b31d..d53a8f3 100644 --- a/schnapps/plugins/surface_modelisation/dialog_decimation.ui +++ b/schnapps/plugins/surface_modelisation/dialog_decimation.ui @@ -1,23 +1,56 @@ -SCHNAPPS_PLUGIN_SURFACE_MODELISATION_API + SCHNAPPS_PLUGIN_SURFACE_MODELISATION_API Decimation_Dialog 0 0 - 472 - 292 + 274 + 416 - Compute Normal + Decimation - + + + + + + + % vertices to keep : + + + + + + + 1 + + + 100 + + + 80 + + + Qt::Horizontal + + + QSlider::TicksBelow + + + 10 + + + + + diff --git a/schnapps/plugins/surface_modelisation/surface_modelisation.cpp b/schnapps/plugins/surface_modelisation/surface_modelisation.cpp index 5601e3c..cb26921 100644 --- a/schnapps/plugins/surface_modelisation/surface_modelisation.cpp +++ b/schnapps/plugins/surface_modelisation/surface_modelisation.cpp @@ -83,14 +83,15 @@ void Plugin_SurfaceModelisation::decimate_from_dialog() { const QString& map_name = currentItems[0]->text(); QString position_name = decimation_dialog_->combo_positionAttribute->currentText(); - decimate(map_name, position_name, 1000u); + int v = decimation_dialog_->slider_percentVertices->value(); + decimate(map_name, position_name, (100 - v) / 100.); } } void Plugin_SurfaceModelisation::decimate( const QString& map_name, const QString& position_attribute_name, - uint32 nb) + double percentVerticesToRemove) { MapHandler* mh = dynamic_cast*>(schnapps_->get_map(map_name)); if (!mh) @@ -100,7 +101,8 @@ void Plugin_SurfaceModelisation::decimate( if (!position.is_valid()) return; - cgogn::modeling::decimate(*mh->get_map(), position, cgogn::modeling::EdgeTraversor_QEM_T, cgogn::modeling::EdgeApproximator_QEM_T, nb); + uint32 nbv = mh->nb_cells(Vertex_Cell); + cgogn::modeling::decimate(*mh->get_map(), position, cgogn::modeling::EdgeTraversor_QEM_T, cgogn::modeling::EdgeApproximator_QEM_T, percentVerticesToRemove * nbv); mh->notify_connectivity_change(); mh->notify_attribute_change(CMap2::Vertex::ORBIT, position_attribute_name); diff --git a/schnapps/plugins/surface_modelisation/surface_modelisation.h b/schnapps/plugins/surface_modelisation/surface_modelisation.h index cc19e3a..a04d6ed 100644 --- a/schnapps/plugins/surface_modelisation/surface_modelisation.h +++ b/schnapps/plugins/surface_modelisation/surface_modelisation.h @@ -82,7 +82,7 @@ public slots: void decimate( const QString& map_name, const QString& position_attribute_name, - uint32_t nb + double percentVerticesToRemove ); private: From 6dbafe54196a32787753b1e1590add17a2a5172f Mon Sep 17 00:00:00 2001 From: Pierre Kraemer Date: Wed, 15 Feb 2017 16:40:24 +0100 Subject: [PATCH 04/14] inverse control : UI calling plugin functionnality instead of plugin pulling UI parameters --- .../surface_modelisation/dialog_decimation.cpp | 16 ++++++++++++++++ .../surface_modelisation/dialog_decimation.h | 1 + .../surface_modelisation.cpp | 17 ----------------- .../surface_modelisation/surface_modelisation.h | 3 --- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/schnapps/plugins/surface_modelisation/dialog_decimation.cpp b/schnapps/plugins/surface_modelisation/dialog_decimation.cpp index 9e6b090..18fddc4 100644 --- a/schnapps/plugins/surface_modelisation/dialog_decimation.cpp +++ b/schnapps/plugins/surface_modelisation/dialog_decimation.cpp @@ -50,9 +50,25 @@ Decimation_Dialog::Decimation_Dialog(SCHNApps* s, Plugin_SurfaceModelisation* p) connect(list_maps, SIGNAL(itemSelectionChanged()), this, SLOT(selected_map_changed())); + connect(this, SIGNAL(accepted()), this, SLOT(decimate())); + connect(button_apply, SIGNAL(clicked()), this, SLOT(decimate())); + + schnapps_->foreach_map([this] (MapHandlerGen* map) { map_added(map); }); } +void Decimation_Dialog::decimate() +{ + QList currentItems = list_maps->selectedItems(); + if (!currentItems.empty()) + { + const QString& map_name = currentItems[0]->text(); + QString position_name = combo_positionAttribute->currentText(); + int v = slider_percentVertices->value(); + plugin_->decimate(map_name, position_name, (100 - v) / 100.); + } +} + void Decimation_Dialog::selected_map_changed() { if (selected_map_) diff --git a/schnapps/plugins/surface_modelisation/dialog_decimation.h b/schnapps/plugins/surface_modelisation/dialog_decimation.h index 3400167..2dd6290 100644 --- a/schnapps/plugins/surface_modelisation/dialog_decimation.h +++ b/schnapps/plugins/surface_modelisation/dialog_decimation.h @@ -60,6 +60,7 @@ class SCHNAPPS_PLUGIN_SURFACE_MODELISATION_API Decimation_Dialog : public QDialo private slots: + void decimate(); void selected_map_changed(); void map_added(MapHandlerGen* map); void map_removed(MapHandlerGen* map); diff --git a/schnapps/plugins/surface_modelisation/surface_modelisation.cpp b/schnapps/plugins/surface_modelisation/surface_modelisation.cpp index cb26921..19a3064 100644 --- a/schnapps/plugins/surface_modelisation/surface_modelisation.cpp +++ b/schnapps/plugins/surface_modelisation/surface_modelisation.cpp @@ -39,14 +39,9 @@ bool Plugin_SurfaceModelisation::enable() decimation_dialog_ = new Decimation_Dialog(schnapps_, this); decimation_action_ = new QAction("Decimation", this); - decimation_action_ = schnapps_->add_menu_action("Surface;Modelisation;Decimation", "decimate mesh"); connect(decimation_action_, SIGNAL(triggered()), this, SLOT(open_decimation_dialog())); - - connect(decimation_dialog_, SIGNAL(accepted()), this, SLOT(decimate_from_dialog())); - connect(decimation_dialog_->button_apply, SIGNAL(clicked()), this, SLOT(decimate_from_dialog())); - connect(schnapps_, SIGNAL(schnapps_closing()), this, SLOT(schnapps_closing())); return true; @@ -76,18 +71,6 @@ void Plugin_SurfaceModelisation::open_decimation_dialog() decimation_dialog_->show(); } -void Plugin_SurfaceModelisation::decimate_from_dialog() -{ - QList currentItems = decimation_dialog_->list_maps->selectedItems(); - if(!currentItems.empty()) - { - const QString& map_name = currentItems[0]->text(); - QString position_name = decimation_dialog_->combo_positionAttribute->currentText(); - int v = decimation_dialog_->slider_percentVertices->value(); - decimate(map_name, position_name, (100 - v) / 100.); - } -} - void Plugin_SurfaceModelisation::decimate( const QString& map_name, const QString& position_attribute_name, diff --git a/schnapps/plugins/surface_modelisation/surface_modelisation.h b/schnapps/plugins/surface_modelisation/surface_modelisation.h index a04d6ed..4ec87d5 100644 --- a/schnapps/plugins/surface_modelisation/surface_modelisation.h +++ b/schnapps/plugins/surface_modelisation/surface_modelisation.h @@ -67,9 +67,6 @@ private slots: // slots called from action signals void open_decimation_dialog(); - // slots called from dialog signals - void decimate_from_dialog(); - public slots: /** From 6d517354df81ef10c4a51f017891a37f3951d3b9 Mon Sep 17 00:00:00 2001 From: Pierre Kraemer Date: Wed, 15 Feb 2017 16:59:56 +0100 Subject: [PATCH 05/14] same inversion in SDP plugin --- schnapps/core/map_handler.h | 4 +- .../dialog_compute_curvature.cpp | 57 ++++++++++ .../dialog_compute_curvature.h | 3 +- .../dialog_compute_normal.cpp | 26 ++++- .../dialog_compute_normal.h | 3 +- .../surface_differential_properties.cpp | 101 +----------------- .../surface_differential_properties.h | 6 +- .../dialog_decimation.cpp | 1 - .../surface_modelisation/dialog_decimation.h | 2 - .../surface_modelisation.cpp | 4 - 10 files changed, 93 insertions(+), 114 deletions(-) diff --git a/schnapps/core/map_handler.h b/schnapps/core/map_handler.h index c98e4f2..64c2c97 100644 --- a/schnapps/core/map_handler.h +++ b/schnapps/core/map_handler.h @@ -676,8 +676,6 @@ class MapHandler : public MapHandlerGen return res; } -protected: - /********************************************************* * MANAGE VBOs *********************************************************/ @@ -887,6 +885,8 @@ class MapHandler : public MapHandlerGen } } +protected: + /********************************************************* * MANAGE CELLS SETS *********************************************************/ diff --git a/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.cpp b/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.cpp index 6f67808..9dd27f4 100644 --- a/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.cpp +++ b/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.cpp @@ -79,9 +79,66 @@ ComputeCurvature_Dialog::ComputeCurvature_Dialog(SCHNApps* s, Plugin_SurfaceDiff connect(list_maps, SIGNAL(itemSelectionChanged()), this, SLOT(selected_map_changed())); + connect(this, SIGNAL(accepted()), this, SLOT(compute_curvature())); + connect(button_apply, SIGNAL(clicked()), this, SLOT(compute_curvature())); + schnapps_->foreach_map([this] (MapHandlerGen* map) { map_added(map); }); } +void ComputeCurvature_Dialog::compute_curvature() +{ + QList currentItems = list_maps->selectedItems(); + if (!currentItems.empty()) + { + const QString& map_name = currentItems[0]->text(); + + QString position_name = combo_positionAttribute->currentText(); + QString normal_name = combo_normalAttribute->currentText(); + + QString Kmax_name; + if (Kmax_attribute_name->text().isEmpty()) + Kmax_name = combo_KmaxAttribute->currentText(); + else + Kmax_name = Kmax_attribute_name->text(); + + QString kmax_name; + if (kmax_attribute_name->text().isEmpty()) + kmax_name = combo_kmaxAttribute->currentText(); + else + kmax_name = kmax_attribute_name->text(); + + QString Kmin_name; + if (Kmin_attribute_name->text().isEmpty()) + Kmin_name = combo_KminAttribute->currentText(); + else + Kmin_name = Kmin_attribute_name->text(); + + QString kmin_name; + if (kmin_attribute_name->text().isEmpty()) + kmin_name = combo_kminAttribute->currentText(); + else + kmin_name = kmin_attribute_name->text(); + + QString Knormal_name; + if (Knormal_attribute_name->text().isEmpty()) + Knormal_name = combo_KnormalAttribute->currentText(); + else + Knormal_name = Knormal_attribute_name->text(); + + bool compute_kmean = check_computeKmean->checkState() == Qt::Checked; + bool compute_kgaussian = check_computeKgaussian->checkState() == Qt::Checked; + bool auto_update = currentItems[0]->checkState() == Qt::Checked; + + plugin_->compute_curvature( + map_name, + position_name, normal_name, + Kmax_name, kmax_name, Kmin_name, kmin_name, Knormal_name, + compute_kmean, compute_kgaussian, + auto_update + ); + } +} + void ComputeCurvature_Dialog::selected_map_changed() { if(selected_map_) diff --git a/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.h b/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.h index 11f0529..6fbe1ee 100644 --- a/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.h +++ b/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.h @@ -44,8 +44,6 @@ class SCHNAPPS_PLUGIN_SDP_API ComputeCurvature_Dialog : public QDialog, public U { Q_OBJECT - friend class Plugin_SurfaceDifferentialProperties; - public: ComputeCurvature_Dialog(SCHNApps* s, Plugin_SurfaceDifferentialProperties* p); @@ -66,6 +64,7 @@ class SCHNAPPS_PLUGIN_SDP_API ComputeCurvature_Dialog : public QDialog, public U private slots: + void compute_curvature(); void selected_map_changed(); void map_added(MapHandlerGen* map); void map_removed(MapHandlerGen* map); diff --git a/schnapps/plugins/surface_differential_properties/dialog_compute_normal.cpp b/schnapps/plugins/surface_differential_properties/dialog_compute_normal.cpp index fe059ab..47dc2fc 100644 --- a/schnapps/plugins/surface_differential_properties/dialog_compute_normal.cpp +++ b/schnapps/plugins/surface_differential_properties/dialog_compute_normal.cpp @@ -50,15 +50,39 @@ ComputeNormal_Dialog::ComputeNormal_Dialog(SCHNApps* s, Plugin_SurfaceDifferenti setting_auto_load_normal_attribute_ = plugin_->add_setting("Auto load normal attribute", "normal"); normal_attribute_name->setText(setting_auto_load_normal_attribute_.toString()); - connect(schnapps_, SIGNAL(map_added(MapHandlerGen*)), this, SLOT(map_added(MapHandlerGen*))); connect(schnapps_, SIGNAL(map_removed(MapHandlerGen*)), this, SLOT(map_removed(MapHandlerGen*))); connect(list_maps, SIGNAL(itemSelectionChanged()), this, SLOT(selected_map_changed())); + connect(this, SIGNAL(accepted()), this, SLOT(compute_normal())); + connect(button_apply, SIGNAL(clicked()), this, SLOT(compute_normal())); + schnapps_->foreach_map([this] (MapHandlerGen* map) { map_added(map); }); } +void ComputeNormal_Dialog::compute_normal() +{ + QList currentItems = list_maps->selectedItems(); + if (!currentItems.empty()) + { + const QString& map_name = currentItems[0]->text(); + + QString position_name = combo_positionAttribute->currentText(); + + QString normal_name; + if (normal_attribute_name->text().isEmpty()) + normal_name = combo_normalAttribute->currentText(); + else + normal_name = normal_attribute_name->text(); + + bool create_vbo = enableVBO->isChecked(); + bool auto_update = currentItems[0]->checkState() == Qt::Checked; + + plugin_->compute_normal(map_name, position_name, normal_name, create_vbo, auto_update); + } +} + void ComputeNormal_Dialog::selected_map_changed() { if (selected_map_) diff --git a/schnapps/plugins/surface_differential_properties/dialog_compute_normal.h b/schnapps/plugins/surface_differential_properties/dialog_compute_normal.h index 93b1e5c..b77a179 100644 --- a/schnapps/plugins/surface_differential_properties/dialog_compute_normal.h +++ b/schnapps/plugins/surface_differential_properties/dialog_compute_normal.h @@ -43,8 +43,6 @@ class SCHNAPPS_PLUGIN_SDP_API ComputeNormal_Dialog : public QDialog, public Ui:: { Q_OBJECT - friend class Plugin_SurfaceDifferentialProperties; - public: ComputeNormal_Dialog(SCHNApps* s, Plugin_SurfaceDifferentialProperties* p); @@ -61,6 +59,7 @@ class SCHNAPPS_PLUGIN_SDP_API ComputeNormal_Dialog : public QDialog, public Ui:: private slots: + void compute_normal(); void selected_map_changed(); void map_added(MapHandlerGen* map); void map_removed(MapHandlerGen* map); diff --git a/schnapps/plugins/surface_differential_properties/surface_differential_properties.cpp b/schnapps/plugins/surface_differential_properties/surface_differential_properties.cpp index 2f25ec8..92226b7 100644 --- a/schnapps/plugins/surface_differential_properties/surface_differential_properties.cpp +++ b/schnapps/plugins/surface_differential_properties/surface_differential_properties.cpp @@ -51,12 +51,6 @@ bool Plugin_SurfaceDifferentialProperties::enable() connect(compute_normal_action_, SIGNAL(triggered()), this, SLOT(open_compute_normal_dialog())); connect(compute_curvature_action_, SIGNAL(triggered()), this, SLOT(open_compute_curvature_dialog())); - connect(compute_normal_dialog_, SIGNAL(accepted()), this, SLOT(compute_normal_from_dialog())); - connect(compute_normal_dialog_->button_apply, SIGNAL(clicked()), this, SLOT(compute_normal_from_dialog())); - - connect(compute_curvature_dialog_, SIGNAL(accepted()), this, SLOT(compute_curvature_from_dialog())); - connect(compute_curvature_dialog_->button_apply, SIGNAL(clicked()), this, SLOT(compute_curvature_from_dialog())); - connect(schnapps_, SIGNAL(map_added(MapHandlerGen*)), this, SLOT(map_added(MapHandlerGen*))); connect(schnapps_, SIGNAL(map_removed(MapHandlerGen*)), this, SLOT(map_removed(MapHandlerGen*))); @@ -72,12 +66,6 @@ void Plugin_SurfaceDifferentialProperties::disable() disconnect(compute_normal_action_, SIGNAL(triggered()), this, SLOT(open_compute_normal_dialog())); disconnect(compute_curvature_action_, SIGNAL(triggered()), this, SLOT(open_compute_curvature_dialog())); - disconnect(compute_normal_dialog_, SIGNAL(accepted()), this, SLOT(compute_normal_from_dialog())); - disconnect(compute_normal_dialog_->button_apply, SIGNAL(clicked()), this, SLOT(compute_normal_from_dialog())); - - disconnect(compute_curvature_dialog_, SIGNAL(accepted()), this, SLOT(compute_curvature_from_dialog())); - disconnect(compute_curvature_dialog_->button_apply, SIGNAL(clicked()), this, SLOT(compute_curvature_from_dialog())); - disconnect(schnapps_, SIGNAL(map_added(MapHandlerGen*)), this, SLOT(map_added(MapHandlerGen*))); disconnect(schnapps_, SIGNAL(map_removed(MapHandlerGen*)), this, SLOT(map_removed(MapHandlerGen*))); @@ -143,93 +131,11 @@ void Plugin_SurfaceDifferentialProperties::open_compute_curvature_dialog() compute_curvature_dialog_->show(); } -void Plugin_SurfaceDifferentialProperties::compute_normal_from_dialog() -{ - QList currentItems = compute_normal_dialog_->list_maps->selectedItems(); - if(!currentItems.empty()) - { - const QString& map_name = currentItems[0]->text(); - - QString position_name = compute_normal_dialog_->combo_positionAttribute->currentText(); - - QString normal_name; - if (compute_normal_dialog_->normal_attribute_name->text().isEmpty()) - normal_name = compute_normal_dialog_->combo_normalAttribute->currentText(); - else - normal_name = compute_normal_dialog_->normal_attribute_name->text(); - - bool auto_update = currentItems[0]->checkState() == Qt::Checked; - - compute_normal(map_name, position_name, normal_name, auto_update); - - // create VBO if asked - if (compute_normal_dialog_->enableVBO->isChecked()) - { - MapHandlerGen* mhg = schnapps_->get_map(map_name); - if (mhg) - mhg->create_vbo(normal_name); - } - } -} - -void Plugin_SurfaceDifferentialProperties::compute_curvature_from_dialog() -{ - QList currentItems = compute_curvature_dialog_->list_maps->selectedItems(); - if (!currentItems.empty()) - { - const QString& map_name = currentItems[0]->text(); - - QString position_name = compute_curvature_dialog_->combo_positionAttribute->currentText(); - QString normal_name = compute_curvature_dialog_->combo_normalAttribute->currentText(); - - QString Kmax_name; - if (compute_curvature_dialog_->Kmax_attribute_name->text().isEmpty()) - Kmax_name = compute_curvature_dialog_->combo_KmaxAttribute->currentText(); - else - Kmax_name = compute_curvature_dialog_->Kmax_attribute_name->text(); - - QString kmax_name; - if (compute_curvature_dialog_->kmax_attribute_name->text().isEmpty()) - kmax_name = compute_curvature_dialog_->combo_kmaxAttribute->currentText(); - else - kmax_name = compute_curvature_dialog_->kmax_attribute_name->text(); - - QString Kmin_name; - if (compute_curvature_dialog_->Kmin_attribute_name->text().isEmpty()) - Kmin_name = compute_curvature_dialog_->combo_KminAttribute->currentText(); - else - Kmin_name = compute_curvature_dialog_->Kmin_attribute_name->text(); - - QString kmin_name; - if (compute_curvature_dialog_->kmin_attribute_name->text().isEmpty()) - kmin_name = compute_curvature_dialog_->combo_kminAttribute->currentText(); - else - kmin_name = compute_curvature_dialog_->kmin_attribute_name->text(); - - QString Knormal_name; - if (compute_curvature_dialog_->Knormal_attribute_name->text().isEmpty()) - Knormal_name = compute_curvature_dialog_->combo_KnormalAttribute->currentText(); - else - Knormal_name = compute_curvature_dialog_->Knormal_attribute_name->text(); - - bool compute_kmean = compute_curvature_dialog_->check_computeKmean->checkState() == Qt::Checked; - bool compute_kgaussian = compute_curvature_dialog_->check_computeKgaussian->checkState() == Qt::Checked; - bool auto_update = currentItems[0]->checkState() == Qt::Checked; - - compute_curvature( - map_name, - position_name, normal_name, - Kmax_name, kmax_name, Kmin_name, kmin_name, Knormal_name, - compute_kmean, compute_kgaussian, - auto_update - ); - } -} - void Plugin_SurfaceDifferentialProperties::compute_normal( const QString& map_name, const QString& position_attribute_name, const QString& normal_attribute_name, + bool create_vbo, bool auto_update) { MapHandler* mh = dynamic_cast*>(schnapps_->get_map(map_name)); @@ -243,7 +149,7 @@ void Plugin_SurfaceDifferentialProperties::compute_normal( CMap2::VertexAttribute normal = mh->get_attribute(normal_attribute_name); if (!normal.is_valid()) { -// if there is another attribute with the same name but with a different type, we remove it. + // if there is another attribute with the same name but with a different type, we remove it if (mh->has_attribute(CMap2::Vertex::ORBIT, normal_attribute_name)) mh->remove_attribute(CellType::Vertex_Cell, normal_attribute_name); normal = mh->add_attribute(normal_attribute_name); @@ -251,6 +157,9 @@ void Plugin_SurfaceDifferentialProperties::compute_normal( cgogn::geometry::compute_normal(*mh->get_map(), position, normal); + if (create_vbo) + mh->create_vbo(normal_attribute_name); + compute_normal_last_parameters_[map_name] = ComputeNormalParameters(position_attribute_name, normal_attribute_name, auto_update); diff --git a/schnapps/plugins/surface_differential_properties/surface_differential_properties.h b/schnapps/plugins/surface_differential_properties/surface_differential_properties.h index 0805555..8042a61 100644 --- a/schnapps/plugins/surface_differential_properties/surface_differential_properties.h +++ b/schnapps/plugins/surface_differential_properties/surface_differential_properties.h @@ -76,10 +76,6 @@ private slots: void open_compute_normal_dialog(); void open_compute_curvature_dialog(); - // slots called from dialogs signals - void compute_normal_from_dialog(); - void compute_curvature_from_dialog(); - public slots: /** @@ -87,12 +83,14 @@ public slots: * @param map_name name of the 2d map (mesh) * @param position_attribute_name name of position attribute used for computation * @param normal_attribute_name name of result attribute + * @param create_vbo create a vbo for the computed normal attribute * @param auto_update automatically update the normal attribute when position attribute change. */ void compute_normal( const QString& map_name, const QString& position_attribute_name = "position", const QString& normal_attribute_name = "normal", + bool create_vbo = true, bool auto_update = true ); diff --git a/schnapps/plugins/surface_modelisation/dialog_decimation.cpp b/schnapps/plugins/surface_modelisation/dialog_decimation.cpp index 18fddc4..8c1d3d1 100644 --- a/schnapps/plugins/surface_modelisation/dialog_decimation.cpp +++ b/schnapps/plugins/surface_modelisation/dialog_decimation.cpp @@ -53,7 +53,6 @@ Decimation_Dialog::Decimation_Dialog(SCHNApps* s, Plugin_SurfaceModelisation* p) connect(this, SIGNAL(accepted()), this, SLOT(decimate())); connect(button_apply, SIGNAL(clicked()), this, SLOT(decimate())); - schnapps_->foreach_map([this] (MapHandlerGen* map) { map_added(map); }); } diff --git a/schnapps/plugins/surface_modelisation/dialog_decimation.h b/schnapps/plugins/surface_modelisation/dialog_decimation.h index 2dd6290..a2f9671 100644 --- a/schnapps/plugins/surface_modelisation/dialog_decimation.h +++ b/schnapps/plugins/surface_modelisation/dialog_decimation.h @@ -43,8 +43,6 @@ class SCHNAPPS_PLUGIN_SURFACE_MODELISATION_API Decimation_Dialog : public QDialo { Q_OBJECT - friend class Plugin_SurfaceModelisation; - public: Decimation_Dialog(SCHNApps* s, Plugin_SurfaceModelisation* p); diff --git a/schnapps/plugins/surface_modelisation/surface_modelisation.cpp b/schnapps/plugins/surface_modelisation/surface_modelisation.cpp index 19a3064..c526179 100644 --- a/schnapps/plugins/surface_modelisation/surface_modelisation.cpp +++ b/schnapps/plugins/surface_modelisation/surface_modelisation.cpp @@ -50,10 +50,6 @@ bool Plugin_SurfaceModelisation::enable() void Plugin_SurfaceModelisation::disable() { disconnect(decimation_action_, SIGNAL(triggered()), this, SLOT(open_decimation_dialog())); - - disconnect(decimation_dialog_, SIGNAL(accepted()), this, SLOT(decimate_from_dialog())); - disconnect(decimation_dialog_->button_apply, SIGNAL(clicked()), this, SLOT(decimate_from_dialog())); - disconnect(schnapps_, SIGNAL(schnapps_closing()), this, SLOT(schnapps_closing())); schnapps_->remove_menu_action(decimation_action_); From e1821c364d1e4c4da10fed1f3c9c4c412dc8c443 Mon Sep 17 00:00:00 2001 From: Pierre Kraemer Date: Wed, 15 Feb 2017 17:40:45 +0100 Subject: [PATCH 06/14] surface_modelisation: add subdivision --- .../surface_differential_properties.cpp | 9 +- .../surface_modelisation/CMakeLists.txt | 2 + .../dialog_subdivision.cpp | 166 ++++++++++++++++++ .../surface_modelisation/dialog_subdivision.h | 73 ++++++++ .../dialog_subdivision.ui | 64 +++++++ .../surface_modelisation.cpp | 62 ++++++- .../surface_modelisation.h | 19 +- 7 files changed, 384 insertions(+), 11 deletions(-) create mode 100644 schnapps/plugins/surface_modelisation/dialog_subdivision.cpp create mode 100644 schnapps/plugins/surface_modelisation/dialog_subdivision.h create mode 100644 schnapps/plugins/surface_modelisation/dialog_subdivision.ui diff --git a/schnapps/plugins/surface_differential_properties/surface_differential_properties.cpp b/schnapps/plugins/surface_differential_properties/surface_differential_properties.cpp index 92226b7..d95ea2b 100644 --- a/schnapps/plugins/surface_differential_properties/surface_differential_properties.cpp +++ b/schnapps/plugins/surface_differential_properties/surface_differential_properties.cpp @@ -42,9 +42,6 @@ bool Plugin_SurfaceDifferentialProperties::enable() compute_normal_dialog_ = new ComputeNormal_Dialog(schnapps_, this); compute_curvature_dialog_ = new ComputeCurvature_Dialog(schnapps_, this); - compute_normal_action_ = new QAction("Compute Normal", this); - compute_curvature_action_ = new QAction("Compute Curvature", this); - compute_normal_action_ = schnapps_->add_menu_action("Surface;Differential Properties;Compute Normal", "compute vertex normals"); compute_curvature_action_ = schnapps_->add_menu_action("Surface;Differential Properties;Compute Curvature", "compute vertex curvatures"); @@ -63,13 +60,13 @@ bool Plugin_SurfaceDifferentialProperties::enable() void Plugin_SurfaceDifferentialProperties::disable() { - disconnect(compute_normal_action_, SIGNAL(triggered()), this, SLOT(open_compute_normal_dialog())); - disconnect(compute_curvature_action_, SIGNAL(triggered()), this, SLOT(open_compute_curvature_dialog())); + disconnect(schnapps_, SIGNAL(schnapps_closing()), this, SLOT(schnapps_closing())); disconnect(schnapps_, SIGNAL(map_added(MapHandlerGen*)), this, SLOT(map_added(MapHandlerGen*))); disconnect(schnapps_, SIGNAL(map_removed(MapHandlerGen*)), this, SLOT(map_removed(MapHandlerGen*))); - disconnect(schnapps_, SIGNAL(schnapps_closing()), this, SLOT(schnapps_closing())); + disconnect(compute_normal_action_, SIGNAL(triggered()), this, SLOT(open_compute_normal_dialog())); + disconnect(compute_curvature_action_, SIGNAL(triggered()), this, SLOT(open_compute_curvature_dialog())); schnapps_->remove_menu_action(compute_normal_action_); schnapps_->remove_menu_action(compute_curvature_action_); diff --git a/schnapps/plugins/surface_modelisation/CMakeLists.txt b/schnapps/plugins/surface_modelisation/CMakeLists.txt index 6d71310..feec7ed 100644 --- a/schnapps/plugins/surface_modelisation/CMakeLists.txt +++ b/schnapps/plugins/surface_modelisation/CMakeLists.txt @@ -11,11 +11,13 @@ set(HEADER_FILES dll.h surface_modelisation.h dialog_decimation.h + dialog_subdivision.h ) set(SOURCE_FILES surface_modelisation.cpp dialog_decimation.cpp + dialog_subdivision.cpp ) set(CMAKE_AUTOMOC ON) diff --git a/schnapps/plugins/surface_modelisation/dialog_subdivision.cpp b/schnapps/plugins/surface_modelisation/dialog_subdivision.cpp new file mode 100644 index 0000000..4fe9e32 --- /dev/null +++ b/schnapps/plugins/surface_modelisation/dialog_subdivision.cpp @@ -0,0 +1,166 @@ +/******************************************************************************* +* SCHNApps * +* Copyright (C) 2015, IGG Group, ICube, University of Strasbourg, France * +* * +* This library is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by the * +* Free Software Foundation; either version 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: http://cgogn.unistra.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#include + +#include + +#include +#include + +namespace schnapps +{ + +namespace plugin_surface_modelisation +{ + +Subdivision_Dialog::Subdivision_Dialog(SCHNApps* s, Plugin_SurfaceModelisation* p) : + schnapps_(s), + plugin_(p), + selected_map_(nullptr) +{ + setupUi(this); + + setting_auto_load_position_attribute_ = plugin_->get_setting("Auto load position attribute"); + if (!setting_auto_load_position_attribute_.isValid()) + setting_auto_load_position_attribute_ = plugin_->add_setting("Auto load position attribute", "position"); + + connect(schnapps_, SIGNAL(map_added(MapHandlerGen*)), this, SLOT(map_added(MapHandlerGen*))); + connect(schnapps_, SIGNAL(map_removed(MapHandlerGen*)), this, SLOT(map_removed(MapHandlerGen*))); + + connect(list_maps, SIGNAL(itemSelectionChanged()), this, SLOT(selected_map_changed())); + + connect(button_loop, SIGNAL(clicked()), this, SLOT(subdivide_loop())); + connect(button_catmull_clark, SIGNAL(clicked()), this, SLOT(subdivide_catmull_clark())); + + schnapps_->foreach_map([this] (MapHandlerGen* map) { map_added(map); }); +} + +void Subdivision_Dialog::subdivide_loop() +{ + QList currentItems = list_maps->selectedItems(); + if (!currentItems.empty()) + { + const QString& map_name = currentItems[0]->text(); + QString position_name = combo_positionAttribute->currentText(); + plugin_->subdivide_loop(map_name, position_name); + } +} + +void Subdivision_Dialog::subdivide_catmull_clark() +{ + QList currentItems = list_maps->selectedItems(); + if (!currentItems.empty()) + { + const QString& map_name = currentItems[0]->text(); + QString position_name = combo_positionAttribute->currentText(); + plugin_->subdivide_catmull_clark(map_name, position_name); + } +} + +void Subdivision_Dialog::selected_map_changed() +{ + if (selected_map_) + disconnect(selected_map_, SIGNAL(attribute_added(cgogn::Orbit, const QString&)), this, SLOT(selected_map_attribute_added(cgogn::Orbit, const QString&))); + + QList currentItems = list_maps->selectedItems(); + if (!currentItems.empty()) + { + combo_positionAttribute->clear(); + + const QString& map_name = currentItems[0]->text(); + MapHandlerGen* mhg = schnapps_->get_map(map_name); + selected_map_ = dynamic_cast*>(mhg); + + if (selected_map_) + { + const CMap2* map2 = selected_map_->get_map(); + if (map2->is_embedded()) + { + QString vec3_type_name = QString::fromStdString(cgogn::name_of_type(VEC3())); + + const CMap2::ChunkArrayContainer& container = map2->const_attribute_container(); + const std::vector& names = container.names(); + const std::vector& type_names = container.type_names(); + + for (std::size_t i = 0u; i < names.size(); ++i) + { + QString name = QString::fromStdString(names[i]); + QString type = QString::fromStdString(type_names[i]); + if (type == vec3_type_name) + { + combo_positionAttribute->addItem(name); + if (name == setting_auto_load_position_attribute_.toString()) + combo_positionAttribute->setCurrentIndex(combo_positionAttribute->count() - 1); + } + } + } + connect(selected_map_, SIGNAL(attribute_added(cgogn::Orbit, const QString&)), this, SLOT(selected_map_attribute_added(cgogn::Orbit, const QString&))); + } + } + else + selected_map_ = nullptr; +} + +void Subdivision_Dialog::map_added(MapHandlerGen* map) +{ + if (map->dimension() == 2) + { + QListWidgetItem* item = new QListWidgetItem(map->get_name(), list_maps); + item->setCheckState(Qt::Unchecked); + } +} + +void Subdivision_Dialog::map_removed(MapHandlerGen* map) +{ + QList items = list_maps->findItems(map->get_name(), Qt::MatchExactly); + if (!items.empty()) + delete items[0]; + + if (selected_map_ == map) + { + disconnect(selected_map_, SIGNAL(attribute_added(cgogn::Orbit, const QString&)), this, SLOT(selected_map_attribute_added(cgogn::Orbit, const QString&))); + selected_map_ = nullptr; + } +} + +void Subdivision_Dialog::selected_map_attribute_added(cgogn::Orbit orbit, const QString& attribute_name) +{ + if (orbit == CMap2::Vertex::ORBIT) + { + QString vec3_type_name = QString::fromStdString(cgogn::name_of_type(VEC3())); + + const CMap2* map2 = selected_map_->get_map(); + const CMap2::ChunkArrayContainer& container = map2->const_attribute_container(); + QString attribute_type_name = QString::fromStdString(container.get_chunk_array(attribute_name.toStdString())->type_name()); + + if (attribute_type_name == vec3_type_name) + { + combo_positionAttribute->addItem(attribute_name); + } + } +} + +} // namespace plugin_surface_modelisation + +} // namespace schnapps diff --git a/schnapps/plugins/surface_modelisation/dialog_subdivision.h b/schnapps/plugins/surface_modelisation/dialog_subdivision.h new file mode 100644 index 0000000..0198961 --- /dev/null +++ b/schnapps/plugins/surface_modelisation/dialog_subdivision.h @@ -0,0 +1,73 @@ +/******************************************************************************* +* SCHNApps * +* Copyright (C) 2015, IGG Group, ICube, University of Strasbourg, France * +* * +* This library is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by the * +* Free Software Foundation; either version 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: http://cgogn.unistra.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#ifndef SCHNAPPS_PLUGIN_SURFACE_MODELISATION_DIALOG_SUBDIVISION_H_ +#define SCHNAPPS_PLUGIN_SURFACE_MODELISATION_DIALOG_SUBDIVISION_H_ + +#include "dll.h" +#include + +#include + +namespace schnapps +{ + +class SCHNApps; + +namespace plugin_surface_modelisation +{ + +class Plugin_SurfaceModelisation; + +class SCHNAPPS_PLUGIN_SURFACE_MODELISATION_API Subdivision_Dialog : public QDialog, public Ui::Subdivision_Dialog +{ + Q_OBJECT + +public: + + Subdivision_Dialog(SCHNApps* s, Plugin_SurfaceModelisation* p); + +private: + + SCHNApps* schnapps_; + Plugin_SurfaceModelisation* plugin_; + + MapHandler* selected_map_; + + QVariant setting_auto_load_position_attribute_; + +private slots: + + void subdivide_loop(); + void subdivide_catmull_clark(); + void selected_map_changed(); + void map_added(MapHandlerGen* map); + void map_removed(MapHandlerGen* map); + void selected_map_attribute_added(cgogn::Orbit orbit, const QString& attribute_name); +}; + +} // namespace plugin_surface_modelisation + +} // namespace schnapps + +#endif // SCHNAPPS_PLUGIN_SURFACE_MODELISATION_DIALOG_SUBDIVISION_H_ diff --git a/schnapps/plugins/surface_modelisation/dialog_subdivision.ui b/schnapps/plugins/surface_modelisation/dialog_subdivision.ui new file mode 100644 index 0000000..80bdfa1 --- /dev/null +++ b/schnapps/plugins/surface_modelisation/dialog_subdivision.ui @@ -0,0 +1,64 @@ + + + SCHNAPPS_PLUGIN_SURFACE_MODELISATION_API + Subdivision_Dialog + + + + 0 + 0 + 274 + 246 + + + + Subdivision + + + + + + + + + + + Position attribute : + + + + + + + + 0 + 0 + + + + + + + + + + + + Loop + + + + + + + Catmull-Clark + + + + + + + + + + diff --git a/schnapps/plugins/surface_modelisation/surface_modelisation.cpp b/schnapps/plugins/surface_modelisation/surface_modelisation.cpp index c526179..1d555f5 100644 --- a/schnapps/plugins/surface_modelisation/surface_modelisation.cpp +++ b/schnapps/plugins/surface_modelisation/surface_modelisation.cpp @@ -24,9 +24,13 @@ #include #include +#include +#include #include #include +#include +#include namespace schnapps { @@ -37,11 +41,14 @@ namespace plugin_surface_modelisation bool Plugin_SurfaceModelisation::enable() { decimation_dialog_ = new Decimation_Dialog(schnapps_, this); + subdivision_dialog_ = new Subdivision_Dialog(schnapps_, this); - decimation_action_ = new QAction("Decimation", this); decimation_action_ = schnapps_->add_menu_action("Surface;Modelisation;Decimation", "decimate mesh"); + subdivision_action_ = schnapps_->add_menu_action("Surface;Modelisation;Subdivision", "subdivide mesh"); connect(decimation_action_, SIGNAL(triggered()), this, SLOT(open_decimation_dialog())); + connect(subdivision_action_, SIGNAL(triggered()), this, SLOT(open_subdivision_dialog())); + connect(schnapps_, SIGNAL(schnapps_closing()), this, SLOT(schnapps_closing())); return true; @@ -49,12 +56,16 @@ bool Plugin_SurfaceModelisation::enable() void Plugin_SurfaceModelisation::disable() { - disconnect(decimation_action_, SIGNAL(triggered()), this, SLOT(open_decimation_dialog())); disconnect(schnapps_, SIGNAL(schnapps_closing()), this, SLOT(schnapps_closing())); + disconnect(decimation_action_, SIGNAL(triggered()), this, SLOT(open_decimation_dialog())); + disconnect(subdivision_action_, SIGNAL(triggered()), this, SLOT(open_subdivision_dialog())); + schnapps_->remove_menu_action(decimation_action_); + schnapps_->remove_menu_action(subdivision_action_); delete decimation_dialog_; + delete subdivision_dialog_; } void Plugin_SurfaceModelisation::schnapps_closing() @@ -67,6 +78,11 @@ void Plugin_SurfaceModelisation::open_decimation_dialog() decimation_dialog_->show(); } +void Plugin_SurfaceModelisation::open_subdivision_dialog() +{ + subdivision_dialog_->show(); +} + void Plugin_SurfaceModelisation::decimate( const QString& map_name, const QString& position_attribute_name, @@ -83,8 +99,50 @@ void Plugin_SurfaceModelisation::decimate( uint32 nbv = mh->nb_cells(Vertex_Cell); cgogn::modeling::decimate(*mh->get_map(), position, cgogn::modeling::EdgeTraversor_QEM_T, cgogn::modeling::EdgeApproximator_QEM_T, percentVerticesToRemove * nbv); + schnapps_->get_selected_view()->get_current_camera()->disable_views_bb_fitting(); + mh->notify_connectivity_change(); + mh->notify_attribute_change(CMap2::Vertex::ORBIT, position_attribute_name); + schnapps_->get_selected_view()->get_current_camera()->enable_views_bb_fitting(); +} + +void Plugin_SurfaceModelisation::subdivide_loop( + const QString& map_name, + const QString& position_attribute_name) +{ + MapHandler* mh = dynamic_cast*>(schnapps_->get_map(map_name)); + if (!mh) + return; + + CMap2::VertexAttribute position = mh->get_attribute(position_attribute_name); + if (!position.is_valid()) + return; + + cgogn::modeling::loop(*mh->get_map(), position); + + schnapps_->get_selected_view()->get_current_camera()->disable_views_bb_fitting(); + mh->notify_connectivity_change(); + mh->notify_attribute_change(CMap2::Vertex::ORBIT, position_attribute_name); + schnapps_->get_selected_view()->get_current_camera()->enable_views_bb_fitting(); +} + +void Plugin_SurfaceModelisation::subdivide_catmull_clark( + const QString& map_name, + const QString& position_attribute_name) +{ + MapHandler* mh = dynamic_cast*>(schnapps_->get_map(map_name)); + if (!mh) + return; + + CMap2::VertexAttribute position = mh->get_attribute(position_attribute_name); + if (!position.is_valid()) + return; + + cgogn::modeling::catmull_clark(*mh->get_map(), position); + + schnapps_->get_selected_view()->get_current_camera()->disable_views_bb_fitting(); mh->notify_connectivity_change(); mh->notify_attribute_change(CMap2::Vertex::ORBIT, position_attribute_name); + schnapps_->get_selected_view()->get_current_camera()->enable_views_bb_fitting(); } } // namespace plugin_surface_modelisation diff --git a/schnapps/plugins/surface_modelisation/surface_modelisation.h b/schnapps/plugins/surface_modelisation/surface_modelisation.h index 4ec87d5..6543071 100644 --- a/schnapps/plugins/surface_modelisation/surface_modelisation.h +++ b/schnapps/plugins/surface_modelisation/surface_modelisation.h @@ -28,6 +28,7 @@ #include "dll.h" #include +#include #include @@ -66,15 +67,15 @@ private slots: // slots called from action signals void open_decimation_dialog(); + void open_subdivision_dialog(); public slots: /** - * @brief compute the normals of a mesh + * @brief decimate a mesh through edge collapses * @param map_name name of the 2d map (mesh) * @param position_attribute_name name of position attribute used for computation - * @param normal_attribute_name name of result attribute - * @param auto_update automatically update the normal attribute when position attribute change. + * @param percentVerticesToRemove % of the number of vertices to remove */ void decimate( const QString& map_name, @@ -82,11 +83,23 @@ public slots: double percentVerticesToRemove ); + void subdivide_loop( + const QString& map_name, + const QString& position_attribute_name + ); + + void subdivide_catmull_clark( + const QString& map_name, + const QString& position_attribute_name + ); + private: Decimation_Dialog* decimation_dialog_; + Subdivision_Dialog* subdivision_dialog_; QAction* decimation_action_; + QAction* subdivision_action_; }; } // namespace plugin_surface_modelisation From c2f68d9dc8cf2d9d7cab2e0bda128411038a9d6f Mon Sep 17 00:00:00 2001 From: Pierre Kraemer Date: Fri, 17 Feb 2017 13:55:31 +0100 Subject: [PATCH 07/14] missing dialog closing --- schnapps/plugins/surface_modelisation/surface_modelisation.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/schnapps/plugins/surface_modelisation/surface_modelisation.cpp b/schnapps/plugins/surface_modelisation/surface_modelisation.cpp index 1d555f5..a9e896f 100644 --- a/schnapps/plugins/surface_modelisation/surface_modelisation.cpp +++ b/schnapps/plugins/surface_modelisation/surface_modelisation.cpp @@ -71,6 +71,7 @@ void Plugin_SurfaceModelisation::disable() void Plugin_SurfaceModelisation::schnapps_closing() { decimation_dialog_->close(); + subdivision_dialog_->close(); } void Plugin_SurfaceModelisation::open_decimation_dialog() From ec204b2e199a1402550b6ba15379476c6fe3861a Mon Sep 17 00:00:00 2001 From: Pierre Kraemer Date: Fri, 17 Feb 2017 15:44:31 +0100 Subject: [PATCH 08/14] shallow water simulation plugin v1 --- schnapps/plugins/CMakeLists.txt | 1 + schnapps/plugins/empty_plugin/dll.h | 1 - .../plugins/empty_plugin/empty_plugin.cpp | 9 +- schnapps/plugins/empty_plugin/empty_plugin.h | 15 +- .../plugins/selection/selection_dock_tab.cpp | 4 - schnapps/plugins/shallow_water/CMakeLists.txt | 43 +++ schnapps/plugins/shallow_water/dll.h | 38 +++ .../plugins/shallow_water/shallow_water.cpp | 248 ++++++++++++++++++ .../plugins/shallow_water/shallow_water.h | 124 +++++++++ .../plugins/shallow_water/shallow_water.ui | 49 ++++ .../shallow_water/shallow_water_dock_tab.cpp | 59 +++++ .../shallow_water/shallow_water_dock_tab.h | 66 +++++ .../plugins/surface_render/surface_render.h | 1 - .../surface_render_scalar.cpp | 2 + .../surface_render_scalar.h | 5 +- .../surface_render_scalar_dock_tab.cpp | 2 + .../surface_render_scalar_dock_tab.h | 1 + 17 files changed, 650 insertions(+), 18 deletions(-) create mode 100644 schnapps/plugins/shallow_water/CMakeLists.txt create mode 100644 schnapps/plugins/shallow_water/dll.h create mode 100644 schnapps/plugins/shallow_water/shallow_water.cpp create mode 100644 schnapps/plugins/shallow_water/shallow_water.h create mode 100644 schnapps/plugins/shallow_water/shallow_water.ui create mode 100644 schnapps/plugins/shallow_water/shallow_water_dock_tab.cpp create mode 100644 schnapps/plugins/shallow_water/shallow_water_dock_tab.h diff --git a/schnapps/plugins/CMakeLists.txt b/schnapps/plugins/CMakeLists.txt index 0cdddbf..3f3f395 100644 --- a/schnapps/plugins/CMakeLists.txt +++ b/schnapps/plugins/CMakeLists.txt @@ -13,4 +13,5 @@ add_subdirectory(extract_surface) add_subdirectory(attribute_editor) add_subdirectory(volume_modelisation) add_subdirectory(merge_plugin) +add_subdirectory(shallow_water) add_subdirectory(empty_plugin) diff --git a/schnapps/plugins/empty_plugin/dll.h b/schnapps/plugins/empty_plugin/dll.h index 3b451da..b3d0288 100644 --- a/schnapps/plugins/empty_plugin/dll.h +++ b/schnapps/plugins/empty_plugin/dll.h @@ -23,7 +23,6 @@ #ifndef SCHNAPPS_PLUGIN_EMPTY_PLUGIN_DLL_H_ #define SCHNAPPS_PLUGIN_EMPTY_PLUGIN_DLL_H_ - #ifdef WIN32 #ifndef SCHNAPPS_PLUGIN_EMPTY_PLUGIN_API #if defined SCHNAPPS_PLUGIN_EMPTY_PLUGIN_DLL_EXPORT diff --git a/schnapps/plugins/empty_plugin/empty_plugin.cpp b/schnapps/plugins/empty_plugin/empty_plugin.cpp index 64e545f..909d789 100644 --- a/schnapps/plugins/empty_plugin/empty_plugin.cpp +++ b/schnapps/plugins/empty_plugin/empty_plugin.cpp @@ -30,20 +30,21 @@ namespace schnapps namespace plugin_empty_plugin { -EmptyPlugin::EmptyPlugin() +Plugin_EmptyPlugin::Plugin_EmptyPlugin() {} -EmptyPlugin::~EmptyPlugin() +Plugin_EmptyPlugin::~Plugin_EmptyPlugin() {} -bool EmptyPlugin::enable() +bool Plugin_EmptyPlugin::enable() { return true; } -void EmptyPlugin::disable() +void Plugin_EmptyPlugin::disable() { } } // namespace plugin_empty_plugin + } // namespace schnapps diff --git a/schnapps/plugins/empty_plugin/empty_plugin.h b/schnapps/plugins/empty_plugin/empty_plugin.h index dc35c51..fface2c 100644 --- a/schnapps/plugins/empty_plugin/empty_plugin.h +++ b/schnapps/plugins/empty_plugin/empty_plugin.h @@ -37,9 +37,9 @@ namespace plugin_empty_plugin /** * @brief Empty plugin example */ -class SCHNAPPS_PLUGIN_EMPTY_PLUGIN_API EmptyPlugin : public PluginProcessing +class SCHNAPPS_PLUGIN_EMPTY_PLUGIN_API Plugin_EmptyPlugin : public PluginProcessing // OR -//class SCHNAPPS_PLUGIN_EMPTY_PLUGIN_API EmptyPlugin : public PluginInteraction +//class SCHNAPPS_PLUGIN_EMPTY_PLUGIN_API Plugin_EmptyPlugin : public PluginInteraction { Q_OBJECT Q_PLUGIN_METADATA(IID "SCHNApps.Plugin") @@ -47,19 +47,22 @@ class SCHNAPPS_PLUGIN_EMPTY_PLUGIN_API EmptyPlugin : public PluginProcessing public: - EmptyPlugin(); - ~EmptyPlugin() override; + Plugin_EmptyPlugin(); + ~Plugin_EmptyPlugin() override; private: bool enable() override; void disable() override; - public slots: - private slots: +public slots: + +private slots: + }; } // namespace plugin_empty_plugin + } // namespace schnapps #endif // SCHNAPPS_PLUGIN_EMPTY_PLUGIN_EMPTY_PLUGIN_H_ diff --git a/schnapps/plugins/selection/selection_dock_tab.cpp b/schnapps/plugins/selection/selection_dock_tab.cpp index be74f46..d6fb4cc 100644 --- a/schnapps/plugins/selection/selection_dock_tab.cpp +++ b/schnapps/plugins/selection/selection_dock_tab.cpp @@ -53,10 +53,6 @@ Selection_DockTab::Selection_DockTab(SCHNApps* s, Plugin_Selection* p) : connect(button_clear, SIGNAL(clicked()), this, SLOT(clear_clicked())); } - - - - void Selection_DockTab::position_attribute_changed(int index) { if (!updating_ui_) diff --git a/schnapps/plugins/shallow_water/CMakeLists.txt b/schnapps/plugins/shallow_water/CMakeLists.txt new file mode 100644 index 0000000..c31f776 --- /dev/null +++ b/schnapps/plugins/shallow_water/CMakeLists.txt @@ -0,0 +1,43 @@ +project(plugin_shallow_water + LANGUAGES CXX +) + +find_package(cgogn_core REQUIRED) +find_package(cgogn_modeling REQUIRED) +find_package(cgogn_geometry REQUIRED) +find_package(Qt5 COMPONENTS Core Widgets REQUIRED) + +set(HEADER_FILES + dll.h + shallow_water.h + shallow_water_dock_tab.h +) + +set(SOURCE_FILES + shallow_water.cpp + shallow_water_dock_tab.cpp +) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTOUIC ON) + +add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES}) + +set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_POSTFIX "_d") +target_compile_definitions(${PROJECT_NAME} PRIVATE "-DSCHNAPPS_PLUGIN_SHALLOW_WATER_DLL_EXPORT") + +target_include_directories(${PROJECT_NAME} PUBLIC + $ + $ + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} +) + +target_link_libraries(${PROJECT_NAME} + schnapps_core + ${cgogn_core_LIBRARIES} + ${cgogn_modeling_LIBRARIES} + ${cgogn_geoemtry_LIBRARIES} + ${Qt5Core_LIBRARIES} + ${Qt5Widgets_LIBRARIES} +) diff --git a/schnapps/plugins/shallow_water/dll.h b/schnapps/plugins/shallow_water/dll.h new file mode 100644 index 0000000..53e8554 --- /dev/null +++ b/schnapps/plugins/shallow_water/dll.h @@ -0,0 +1,38 @@ +/******************************************************************************* +* SCHNApps * +* Copyright (C) 2015, IGG Group, ICube, University of Strasbourg, France * +* This library is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by the * +* Free Software Foundation; either version 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: http://cgogn.unistra.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#ifndef SCHNAPPS_PLUGIN_SHALLOW_WATER_DLL_H_ +#define SCHNAPPS_PLUGIN_SHALLOW_WATER_DLL_H_ + +#ifdef WIN32 +#ifndef SCHNAPPS_PLUGIN_SHALLOW_WATER_API +#if defined SCHNAPPS_PLUGIN_SHALLOW_WATER_DLL_EXPORT +#define SCHNAPPS_PLUGIN_SHALLOW_WATER_API __declspec(dllexport) +#else +#define SCHNAPPS_PLUGIN_SHALLOW_WATER_API __declspec(dllimport) +#endif +#endif +#else +#define SCHNAPPS_PLUGIN_SHALLOW_WATER_API +#endif + +#endif // SCHNAPPS_PLUGIN_SHALLOW_WATER_DLL_H_ diff --git a/schnapps/plugins/shallow_water/shallow_water.cpp b/schnapps/plugins/shallow_water/shallow_water.cpp new file mode 100644 index 0000000..6333844 --- /dev/null +++ b/schnapps/plugins/shallow_water/shallow_water.cpp @@ -0,0 +1,248 @@ +/******************************************************************************* +* SCHNApps * +* Copyright (C) 2016, IGG Group, ICube, University of Strasbourg, France * +* * +* This library is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by the * +* Free Software Foundation; either version 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: http://cgogn.unistra.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#include +#include +#include + +#include +#include +#include + +namespace schnapps +{ + +namespace plugin_shallow_water +{ + +bool Plugin_ShallowWater::enable() +{ + dock_tab_ = new ShallowWater_DockTab(this->schnapps_, this); + schnapps_->add_plugin_dock_tab(this, dock_tab_, "Shallow Water"); + + connect(schnapps_, SIGNAL(selected_view_changed(View*, View*)), this, SLOT(update_dock_tab())); + + update_dock_tab(); + + return true; +} + +void Plugin_ShallowWater::disable() +{ + schnapps_->remove_plugin_dock_tab(this, dock_tab_); + delete dock_tab_; +} + +void Plugin_ShallowWater::draw(View*, const QMatrix4x4& proj, const QMatrix4x4& mv) +{ + +} + +void Plugin_ShallowWater::view_linked(View*) +{ + update_dock_tab(); +} + +void Plugin_ShallowWater::view_unlinked(View*) +{ + update_dock_tab(); +} + +void Plugin_ShallowWater::init() +{ + map_ = static_cast*>(schnapps_->add_map("shallow_water", 2)); + CMap2* map2 = static_cast(map_->get_map()); + + position_ = map_->add_attribute("position"); + h_ = map_->add_attribute("hauteur"); + q_ = map_->add_attribute("debit"); + centroid_ = map_->add_attribute("centroid"); + + cgogn::modeling::SquareGrid grid(*map2, 200, 1); + grid.embed_into_grid(position_, 200.0f, 5.0f, 0.0f); + + cgogn::geometry::compute_centroid(*map2, position_, centroid_); + + map2->parallel_foreach_cell([&] (CMap2::Face f, uint32) + { + CMap2::Edge e1(f.dart); + CMap2::Edge e2(map2->phi1(f.dart)); + if (map2->is_incident_to_boundary(e1)) + { + length_[f] = cgogn::geometry::length(*map2, e1, position_); + phi_[f] = cgogn::geometry::length(*map2, e2, position_); + } + else + { + phi_[f] = cgogn::geometry::length(*map2, e1, position_); + length_[f] = cgogn::geometry::length(*map2, e2, position_); + } + + if (centroid_[f][0] < 0) + h_[f] = 10.; + else + h_[f] = 1.; + + q_[f] = 0.; + }); +} + +void Plugin_ShallowWater::start() +{ + CMap2* map2 = static_cast(map_->get_map()); + + SCALAR dt = 0.01; + SCALAR t = 0.; + + while (t < 5.) + { + f1_[boundaryL_] = 0.; + f2_[boundaryL_] = 5e-1 * 9.81 * phi_[0] * pow(h_[0], 2.); + s0L_[boundaryL_] = 0.; + s0R_[boundaryL_] = 0.; + + map2->parallel_foreach_cell( + [&] (CMap2::Edge e, uint32) + { + CMap2::Face f1(e.dart); + CMap2::Face f2(map2->phi2(e.dart)); + struct Flux F = Solv_HLL(0., 0., phi_[f1], phi_[f2], h_[f1], h_[f2], q_[f1], q_[f2], 1e-3, 9.81); + f1_[e] = F.F1; + f2_[e] = F.F2; + s0L_[e] = F.S0L; + s0R_[e] = F.S0R; + }, + [&] (CMap2::Edge e) { return !map2->is_incident_to_boundary(e); } + ); + + f1_[boundaryR_] = 0.; + f2_[boundaryR_] = 0.; + s0L_[boundaryR_] = 0.; + s0R_[boundaryR_] = 0.; + + map2->parallel_foreach_cell( + [&] (CMap2::Face f, uint32) + { +// h_tmp_[f] = h_[f] + (dt / (length_[f] * phi_[f])) * (F1[i] - F1[i+1]); +// q_tmp_[f] = q_[i] + (dt / (length_[f] * phi_[f])) * (F2[i] - s0L[i] - (F2[i+1] - s0R[i+1])); + } + ); + + map2->swap_attributes(h_, h_tmp_); + map2->swap_attributes(q_, q_tmp_); + + t += dt; + + for (View* v : this->get_linked_views()) + v->update(); + } +} + +void Plugin_ShallowWater::update_dock_tab() +{ + View* view = schnapps_->get_selected_view(); + if (view->is_linked_to_plugin(this)) + schnapps_->enable_plugin_tab_widgets(this); + else + schnapps_->disable_plugin_tab_widgets(this); +} + +struct Plugin_ShallowWater::Flux Plugin_ShallowWater::Solv_HLL( + SCALAR zbL, SCALAR zbR, + SCALAR PhiL, SCALAR PhiR, + SCALAR hL, SCALAR hR, + SCALAR qL, SCALAR qR, + SCALAR hmin, SCALAR g +) +/* Calcul du flux à l'interface avec le solveur HLL*/ +{ + struct Flux F; + + if (((hL > hmin) && (hR > hmin)) || + ((hL <= hmin) && (zbR + hR >= zbL)) || + ((hR <= hmin) && (zbL + hL >= zbR))) + { + /* There is water in both cells or one of the cells can fill the other one */ + SCALAR L1L; + SCALAR L1R; + SCALAR L2L; + SCALAR L2R; + SCALAR L1LR; + SCALAR L2LR; + SCALAR PhiLR; + SCALAR zL; + SCALAR zR; + + L1L = qL/std::max(hmin,hL) - sqrt(g * hL); + L1R = qR/std::max(hmin,hR) - sqrt(g * hR); + L2L = qL/std::max(hmin,hL) + sqrt(g * hL); + L2R = qR/std::max(hmin,hR) + sqrt(g * hR); + L1LR = std::min(0e1,std::min(L1L,L1R)); + L2LR = std::max(0e1,std::max(L2L,L2R)); + zL = hL + zbL; + zR = hR + zbR; + PhiLR = std::min(PhiL, PhiR); + + F.F1 = PhiLR * (L2LR * qL - L1LR * qR + L1LR * L2LR * (zR - zL)) / (L2LR - L1LR); + F.F2 = (L2LR * PhiL * (pow(qL,2)/std::max(hmin,hL) + 5e-1 * g * pow(hL,2)) - + L1LR * PhiR * (pow(qR,2)/std::max(hmin,hR) + 5e-1 * g * pow(hR,2)) + + L1LR * L2LR * (PhiR * qR - PhiL * qL)) / (L2LR - L1LR); + + F.S0L = g * L1LR * (5e-1 * (PhiL * pow(hL,2) - PhiR * pow(hR,2)) - 5e-1 * PhiLR * (hL + hR) * (zL - zR)) / (L2LR - L1LR); + F.S0R = g * L2LR * (5e-1 * (PhiR * pow(hR,2) - PhiL * pow(hL,2)) - 5e-1 * PhiLR * (hL + hR) * (zR - zL)) / (L2LR - L1LR); + } + else if ((hL < hmin) && (zbR + hR < zbL)) + { + /* Impossible exchange - Cell L Empty + * The cell L is empty and the water level in the cell R is below zbL + * Filling is impossible */ + F.F1 = 0; + F.F2 = 0; + F.S0L = 0; + F.S0R = 5e-1 * g * PhiR * pow(hR,2); + } + else if ((hR < hmin) && (zbL + hL < zbR)) + { + /* Impossible exchange - Cell R Empty + * The cell R is empty and the water level in the cell L is below zbR + * Filling is impossible */ + F.F1 = 0; + F.F2 = 0; + F.S0L = - 5e-1 * g * PhiL * pow(hL,2); + F.S0R = 0; + } + else + { + /* Both cells below hmin: exchange is impossible */ + F.F1 = 0; + F.F2 = 0; + F.S0L = 0; + F.S0R = 0; + } + + return F; +} + +} // namespace plugin_shallow_water + +} // namespace schnapps diff --git a/schnapps/plugins/shallow_water/shallow_water.h b/schnapps/plugins/shallow_water/shallow_water.h new file mode 100644 index 0000000..dd6dbf3 --- /dev/null +++ b/schnapps/plugins/shallow_water/shallow_water.h @@ -0,0 +1,124 @@ +/******************************************************************************* +* SCHNApps * +* Copyright (C) 2016, IGG Group, ICube, University of Strasbourg, France * +* * +* This library is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by the * +* Free Software Foundation; either version 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: http://cgogn.unistra.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#ifndef SCHNAPPS_PLUGIN_SHALLOW_WATER_H_ +#define SCHNAPPS_PLUGIN_SHALLOW_WATER_H_ + +#include "dll.h" +#include +#include + +#include + +namespace schnapps +{ + +namespace plugin_shallow_water +{ + +/** +* @brief Shallow water simulation +*/ +class SCHNAPPS_PLUGIN_SHALLOW_WATER_API Plugin_ShallowWater : public PluginInteraction +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "SCHNApps.Plugin") + Q_INTERFACES(schnapps::Plugin) + +public: + + Plugin_ShallowWater() {} + ~Plugin_ShallowWater() override {} + +private: + + bool enable() override; + void disable() override; + + void draw(View*, const QMatrix4x4& proj, const QMatrix4x4& mv) override; + void draw_map(View* view, MapHandlerGen* map, const QMatrix4x4& proj, const QMatrix4x4& mv) override {} + + void keyPress(View*, QKeyEvent*) override {} + void keyRelease(View*, QKeyEvent*) override {} + void mousePress(View*, QMouseEvent*) override {} + void mouseRelease(View*, QMouseEvent*) override {} + void mouseMove(View*, QMouseEvent*) override {} + void wheelEvent(View*, QWheelEvent*) override {} + void resizeGL(View* /*view*/, int /*width*/, int /*height*/) override {} + + void view_linked(View*) override; + void view_unlinked(View*) override; + +public slots: + + void init(); + void start(); + +private slots: + + void update_dock_tab(); + +private: + + struct Flux + { + SCALAR F1; + SCALAR F2; + SCALAR S0L; + SCALAR S0R; + }; + + struct Flux Solv_HLL( + SCALAR zbL, SCALAR zbR, + SCALAR PhiL, SCALAR PhiR, + SCALAR hL, SCALAR hR, + SCALAR qL, SCALAR qR, + SCALAR hmin, SCALAR g + ); + + ShallowWater_DockTab* dock_tab_; + + MapHandler* map_; + CMap2::Edge boundaryL_, boundaryR_; + + CMap2::VertexAttribute position_; // vertices position + + CMap2::FaceAttribute h_; // water height + CMap2::FaceAttribute q_; // water flow + CMap2::FaceAttribute h_tmp_; + CMap2::FaceAttribute q_tmp_; + CMap2::FaceAttribute centroid_; // cell centroid + CMap2::FaceAttribute length_; // cell length + CMap2::FaceAttribute phi_; // cell width + + CMap2::EdgeAttribute f1_; + CMap2::EdgeAttribute f2_; + CMap2::EdgeAttribute s0L_; + CMap2::EdgeAttribute s0R_; +}; + +} // namespace plugin_shallow_water + +} // namespace schnapps + +#endif // SCHNAPPS_PLUGIN_SHALLOW_WATER_H_ diff --git a/schnapps/plugins/shallow_water/shallow_water.ui b/schnapps/plugins/shallow_water/shallow_water.ui new file mode 100644 index 0000000..aa9b3a9 --- /dev/null +++ b/schnapps/plugins/shallow_water/shallow_water.ui @@ -0,0 +1,49 @@ + + +SCHNAPPS_PLUGIN_SHALLOW_WATER_API + ShallowWater_TabWidget + + + + 0 + 0 + 240 + 600 + + + + Form + + + + + + Qt::Vertical + + + + 156 + 161 + + + + + + + + Init + + + + + + + Start + + + + + + + + diff --git a/schnapps/plugins/shallow_water/shallow_water_dock_tab.cpp b/schnapps/plugins/shallow_water/shallow_water_dock_tab.cpp new file mode 100644 index 0000000..50b0e54 --- /dev/null +++ b/schnapps/plugins/shallow_water/shallow_water_dock_tab.cpp @@ -0,0 +1,59 @@ +/******************************************************************************* +* SCHNApps * +* Copyright (C) 2015, IGG Group, ICube, University of Strasbourg, France * +* * +* This library is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by the * +* Free Software Foundation; either version 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: http://cgogn.unistra.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#include +#include + +#include +#include +#include + +namespace schnapps +{ + +namespace plugin_shallow_water +{ + +ShallowWater_DockTab::ShallowWater_DockTab(SCHNApps* s, Plugin_ShallowWater* p) : + schnapps_(s), + plugin_(p) +{ + setupUi(this); + + connect(button_init, SIGNAL(clicked()), this, SLOT(init())); + connect(button_start_stop, SIGNAL(clicked()), this, SLOT(start())); +} + +void ShallowWater_DockTab::init() +{ + plugin_->init(); +} + +void ShallowWater_DockTab::start() +{ + plugin_->start(); +} + +} // namespace plugin_shallow_water + +} // namespace schnapps diff --git a/schnapps/plugins/shallow_water/shallow_water_dock_tab.h b/schnapps/plugins/shallow_water/shallow_water_dock_tab.h new file mode 100644 index 0000000..fa767ff --- /dev/null +++ b/schnapps/plugins/shallow_water/shallow_water_dock_tab.h @@ -0,0 +1,66 @@ +/******************************************************************************* +* SCHNApps * +* Copyright (C) 2015, IGG Group, ICube, University of Strasbourg, France * +* * +* This library is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by the * +* Free Software Foundation; either version 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: http://cgogn.unistra.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#ifndef SCHNAPPS_PLUGIN_SHALLOW_WATER_DOCK_TAB_H_ +#define SCHNAPPS_PLUGIN_SHALLOW_WATER_DOCK_TAB_H_ + +#include "dll.h" +#include + +namespace schnapps +{ + +class SCHNApps; +class MapHandlerGen; + +namespace plugin_shallow_water +{ + +class Plugin_ShallowWater; + +class SCHNAPPS_PLUGIN_SHALLOW_WATER_API ShallowWater_DockTab : public QWidget, public Ui::ShallowWater_TabWidget +{ + Q_OBJECT + + friend class Plugin_ShallowWater; + +public: + + ShallowWater_DockTab(SCHNApps* s, Plugin_ShallowWater* p); + +private: + + SCHNApps* schnapps_; + Plugin_ShallowWater* plugin_; + +private slots: + + void init(); + void start(); +}; + +} // namespace plugin_shallow_water + +} // namespace schnapps + +#endif // SCHNAPPS_PLUGIN_SHALLOW_WATER_DOCK_TAB_H_ diff --git a/schnapps/plugins/surface_render/surface_render.h b/schnapps/plugins/surface_render/surface_render.h index fbbd102..c391fdd 100644 --- a/schnapps/plugins/surface_render/surface_render.h +++ b/schnapps/plugins/surface_render/surface_render.h @@ -281,7 +281,6 @@ class SCHNAPPS_PLUGIN_SURFACE_RENDER_API Plugin_SurfaceRender : public PluginInt void wheelEvent(View*, QWheelEvent*) override {} void resizeGL(View* /*view*/, int /*width*/, int /*height*/) override {} - void view_linked(View*) override; void view_unlinked(View*) override; diff --git a/schnapps/plugins/surface_render_scalar/surface_render_scalar.cpp b/schnapps/plugins/surface_render_scalar/surface_render_scalar.cpp index 572cace..7df5ed3 100644 --- a/schnapps/plugins/surface_render_scalar/surface_render_scalar.cpp +++ b/schnapps/plugins/surface_render_scalar/surface_render_scalar.cpp @@ -31,6 +31,7 @@ namespace schnapps { + namespace plugin_surface_render_scalar { @@ -282,4 +283,5 @@ void Plugin_SurfaceRenderScalar::set_nb_iso_levels(View* view, MapHandlerGen* ma } } // namespace plugin_surface_render_scalar + } // namespace schnapps diff --git a/schnapps/plugins/surface_render_scalar/surface_render_scalar.h b/schnapps/plugins/surface_render_scalar/surface_render_scalar.h index a5f9c3e..e9388e4 100644 --- a/schnapps/plugins/surface_render_scalar/surface_render_scalar.h +++ b/schnapps/plugins/surface_render_scalar/surface_render_scalar.h @@ -36,6 +36,7 @@ namespace schnapps { + namespace plugin_surface_render_scalar { @@ -123,6 +124,7 @@ struct SCHNAPPS_PLUGIN_SURFACE_RENDER_SCALAR_API MapParameters } private: + void initialize_gl() { shader_scalar_per_vertex_param_ = cgogn::rendering::ShaderScalarPerVertex::generate_param(); @@ -137,8 +139,6 @@ struct SCHNAPPS_PLUGIN_SURFACE_RENDER_SCALAR_API MapParameters set_scalar_vbo(scalar_vbo_); } -private: - MapHandler* map_; std::unique_ptr shader_scalar_per_vertex_param_; @@ -253,6 +253,7 @@ public slots: }; } // namespace plugin_surface_render_scalar + } // namespace schnapps #endif // SCHNAPPS_PLUGIN_SURFACE_RENDER_SCALAR_H_ diff --git a/schnapps/plugins/surface_render_scalar/surface_render_scalar_dock_tab.cpp b/schnapps/plugins/surface_render_scalar/surface_render_scalar_dock_tab.cpp index a800c12..6670039 100644 --- a/schnapps/plugins/surface_render_scalar/surface_render_scalar_dock_tab.cpp +++ b/schnapps/plugins/surface_render_scalar/surface_render_scalar_dock_tab.cpp @@ -30,6 +30,7 @@ namespace schnapps { + namespace plugin_surface_render_scalar { @@ -231,4 +232,5 @@ void SurfaceRenderScalar_DockTab::update_map_parameters(MapHandlerGen* map, cons } } // namespace plugin_surface_render_scalar + } // namespace schnapps diff --git a/schnapps/plugins/surface_render_scalar/surface_render_scalar_dock_tab.h b/schnapps/plugins/surface_render_scalar/surface_render_scalar_dock_tab.h index c150772..a007c89 100644 --- a/schnapps/plugins/surface_render_scalar/surface_render_scalar_dock_tab.h +++ b/schnapps/plugins/surface_render_scalar/surface_render_scalar_dock_tab.h @@ -77,6 +77,7 @@ private slots: }; } // namespace plugin_surface_render_scalar + } // namespace schnapps #endif // SCHNAPPS_PLUGIN_SURFACE_RENDER_SCALAR_DOCK_TAB_H_ From 6e3499d5884117f3e420db8a7f18535be5ab0483 Mon Sep 17 00:00:00 2001 From: Pierre Kraemer Date: Tue, 28 Feb 2017 18:13:53 +0100 Subject: [PATCH 09/14] save settings to the right file on destruct --- schnapps/core/schnapps.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/schnapps/core/schnapps.cpp b/schnapps/core/schnapps.cpp index 0e32c43..1779f54 100644 --- a/schnapps/core/schnapps.cpp +++ b/schnapps/core/schnapps.cpp @@ -80,12 +80,12 @@ SCHNApps::SCHNApps(const QString& app_path, SCHNAppsWindow* window) : root_splitter_->addWidget(first_view_); #ifdef WIN32 - register_plugins_directory(app_path); + register_plugins_directory(app_path_); #else - register_plugins_directory(app_path + QString("/../lib")); + register_plugins_directory(app_path_ + QString("/../lib")); #endif - settings_ = Settings::from_file(app_path + QString("/../lib/settings.json")); + settings_ = Settings::from_file(app_path_ + QString("/../lib/settings.json")); settings_->set_widget(window->settings_widget_.get()); for (const QVariant& plugin_dir_v : get_core_setting("Plugins paths").toList()) this->register_plugins_directory(plugin_dir_v.toString()); @@ -95,9 +95,9 @@ SCHNApps::SCHNApps(const QString& app_path, SCHNAppsWindow* window) : SCHNApps::~SCHNApps() { - settings_->to_file("settings.json"); + settings_->to_file(app_path_ + QString("/../lib/settings.json")); // first safely unload every plugins (this has to be done before the views get deleted) - while(!plugins_.empty()) + while (!plugins_.empty()) this->disable_plugin(plugins_.begin()->first); } From 49e794a28d7023a4f5826445241c2266938c95b8 Mon Sep 17 00:00:00 2001 From: Pierre Kraemer Date: Tue, 28 Feb 2017 18:14:28 +0100 Subject: [PATCH 10/14] first functional version --- .../plugins/shallow_water/shallow_water.cpp | 112 ++++++++++++++++-- .../plugins/shallow_water/shallow_water.h | 4 +- 2 files changed, 105 insertions(+), 11 deletions(-) diff --git a/schnapps/plugins/shallow_water/shallow_water.cpp b/schnapps/plugins/shallow_water/shallow_water.cpp index 6333844..d2048db 100644 --- a/schnapps/plugins/shallow_water/shallow_water.cpp +++ b/schnapps/plugins/shallow_water/shallow_water.cpp @@ -70,16 +70,32 @@ void Plugin_ShallowWater::view_unlinked(View*) void Plugin_ShallowWater::init() { + const unsigned int nbc = 200u; + map_ = static_cast*>(schnapps_->add_map("shallow_water", 2)); CMap2* map2 = static_cast(map_->get_map()); position_ = map_->add_attribute("position"); + + water_height_ = map_->add_attribute("water_height"); + h_ = map_->add_attribute("hauteur"); + h_tmp_ = map_->add_attribute("hauteur_tmp"); q_ = map_->add_attribute("debit"); + q_tmp_ = map_->add_attribute("debit_tmp"); centroid_ = map_->add_attribute("centroid"); + length_ = map_->add_attribute("length"); + phi_ = map_->add_attribute("phi"); - cgogn::modeling::SquareGrid grid(*map2, 200, 1); - grid.embed_into_grid(position_, 200.0f, 5.0f, 0.0f); + f1_ = map_->add_attribute("f1"); + f2_ = map_->add_attribute("f2"); + s0L_ = map_->add_attribute("s0L"); + s0R_ = map_->add_attribute("s0R"); + + cgogn::modeling::SquareGrid grid(*map2, nbc, 1); + grid.embed_into_grid(position_, float(nbc), 5.0f, 0.0f); + boundaryL_ = CMap2::Edge(grid.vertex_table_[nbc+1].dart); + boundaryR_ = CMap2::Edge(grid.vertex_table_[nbc].dart); cgogn::geometry::compute_centroid(*map2, position_, centroid_); @@ -98,13 +114,27 @@ void Plugin_ShallowWater::init() length_[f] = cgogn::geometry::length(*map2, e2, position_); } + // left half of the cells has initial water height of 10 if (centroid_[f][0] < 0) h_[f] = 10.; + // right half of the cells has initial water height of 1 else h_[f] = 1.; + // initial water flow is 0 for all cells q_[f] = 0.; }); + + map2->parallel_foreach_cell([&] (CMap2::Vertex v, uint32) + { + SCALAR h = 0; + uint32 nbf = 0; + map2->foreach_incident_face(v, [&] (CMap2::Face f) { h += h_[f]; ++nbf; }); + h /= nbf; + water_height_[v] = h; + }); + + map_->notify_attribute_change(CMap2::Vertex::ORBIT, "water_height"); } void Plugin_ShallowWater::start() @@ -117,16 +147,25 @@ void Plugin_ShallowWater::start() while (t < 5.) { f1_[boundaryL_] = 0.; - f2_[boundaryL_] = 5e-1 * 9.81 * phi_[0] * pow(h_[0], 2.); + f2_[boundaryL_] = 5e-1 * 9.81 * phi_[0] * (h_[0] * h_[0]); s0L_[boundaryL_] = 0.; s0R_[boundaryL_] = 0.; map2->parallel_foreach_cell( [&] (CMap2::Edge e, uint32) { - CMap2::Face f1(e.dart); - CMap2::Face f2(map2->phi2(e.dart)); - struct Flux F = Solv_HLL(0., 0., phi_[f1], phi_[f2], h_[f1], h_[f2], q_[f1], q_[f2], 1e-3, 9.81); + CMap2::Face fL, fR; + if (position_[CMap2::Vertex(e.dart)][0] < position_[CMap2::Vertex(map2->phi_1(e.dart))][0]) + { + fL = CMap2::Face(map2->phi2(e.dart)); + fR = CMap2::Face(e.dart); + } + else + { + fL = CMap2::Face(e.dart); + fR = CMap2::Face(map2->phi2(e.dart)); + } + struct Flux F = Solv_HLL(0., 0., phi_[fL], phi_[fR], h_[fL], h_[fR], q_[fL], q_[fR], 1e-3, 9.81); f1_[e] = F.F1; f2_[e] = F.F2; s0L_[e] = F.S0L; @@ -135,16 +174,58 @@ void Plugin_ShallowWater::start() [&] (CMap2::Edge e) { return !map2->is_incident_to_boundary(e); } ); - f1_[boundaryR_] = 0.; - f2_[boundaryR_] = 0.; + f1_[boundaryR_] = f1_[CMap2::Edge(map2->phi1(map2->phi1(boundaryR_.dart)))]; + f2_[boundaryR_] = f2_[CMap2::Edge(map2->phi1(map2->phi1(boundaryR_.dart)))]; s0L_[boundaryR_] = 0.; s0R_[boundaryR_] = 0.; map2->parallel_foreach_cell( [&] (CMap2::Face f, uint32) { -// h_tmp_[f] = h_[f] + (dt / (length_[f] * phi_[f])) * (F1[i] - F1[i+1]); -// q_tmp_[f] = q_[i] + (dt / (length_[f] * phi_[f])) * (F2[i] - s0L[i] - (F2[i+1] - s0R[i+1])); + CMap2::Edge eL, eR; + CMap2::Edge e(f.dart); + if (map2->is_incident_to_boundary(e)) + { + if (map2->same_cell(e, boundaryL_)) + { + eL = e; + eR = CMap2::Edge(map2->phi1(map2->phi1(eL.dart))); + } + else if (map2->same_cell(e, boundaryR_)) + { + eR = e; + eL = CMap2::Edge(map2->phi1(map2->phi1(eR.dart))); + } + else + { + if (position_[CMap2::Vertex(f.dart)][0] < position_[CMap2::Vertex(map2->phi1(f.dart))][0]) + { + eL = CMap2::Edge(map2->phi_1(f.dart)); + eR = CMap2::Edge(map2->phi1(f.dart)); + } + else + { + eL = CMap2::Edge(map2->phi1(f.dart)); + eR = CMap2::Edge(map2->phi_1(f.dart)); + } + } + } + else + { + if (position_[CMap2::Vertex(f.dart)][0] < position_[CMap2::Vertex(map2->phi_1(f.dart))][0]) + { + eL = CMap2::Edge(f.dart); + eR = CMap2::Edge(map2->phi1(map2->phi1(f.dart))); + } + else + { + eL = CMap2::Edge(map2->phi1(map2->phi1(f.dart))); + eR = CMap2::Edge(f.dart); + } + } + + h_tmp_[f] = h_[f] + (dt / (length_[f] * phi_[f])) * (f1_[eL] - f1_[eR]); + q_tmp_[f] = q_[f] + (dt / (length_[f] * phi_[f])) * (f2_[eL] - s0L_[eL] - (f2_[eR] - s0R_[eR])); } ); @@ -153,6 +234,17 @@ void Plugin_ShallowWater::start() t += dt; + map2->parallel_foreach_cell([&] (CMap2::Vertex v, uint32) + { + SCALAR h = 0; + uint32 nbf = 0; + map2->foreach_incident_face(v, [&] (CMap2::Face f) { h += h_[f]; ++nbf; }); + h /= nbf; + water_height_[v] = h; + }); + + map_->notify_attribute_change(CMap2::Vertex::ORBIT, "water_height"); + for (View* v : this->get_linked_views()) v->update(); } diff --git a/schnapps/plugins/shallow_water/shallow_water.h b/schnapps/plugins/shallow_water/shallow_water.h index dd6dbf3..6620500 100644 --- a/schnapps/plugins/shallow_water/shallow_water.h +++ b/schnapps/plugins/shallow_water/shallow_water.h @@ -103,9 +103,11 @@ private slots: CMap2::VertexAttribute position_; // vertices position + CMap2::VertexAttribute water_height_; + CMap2::FaceAttribute h_; // water height - CMap2::FaceAttribute q_; // water flow CMap2::FaceAttribute h_tmp_; + CMap2::FaceAttribute q_; // water flow CMap2::FaceAttribute q_tmp_; CMap2::FaceAttribute centroid_; // cell centroid CMap2::FaceAttribute length_; // cell length From 7862c08b83e308a27a8b037f4713bd0b3d226945 Mon Sep 17 00:00:00 2001 From: Pierre Kraemer Date: Wed, 1 Mar 2017 11:27:16 +0100 Subject: [PATCH 11/14] display water height --- .../plugins/shallow_water/shallow_water.cpp | 318 ++++++++++-------- .../plugins/shallow_water/shallow_water.h | 10 + 2 files changed, 189 insertions(+), 139 deletions(-) diff --git a/schnapps/plugins/shallow_water/shallow_water.cpp b/schnapps/plugins/shallow_water/shallow_water.cpp index d2048db..98decdb 100644 --- a/schnapps/plugins/shallow_water/shallow_water.cpp +++ b/schnapps/plugins/shallow_water/shallow_water.cpp @@ -44,40 +44,15 @@ bool Plugin_ShallowWater::enable() update_dock_tab(); - return true; -} - -void Plugin_ShallowWater::disable() -{ - schnapps_->remove_plugin_dock_tab(this, dock_tab_); - delete dock_tab_; -} - -void Plugin_ShallowWater::draw(View*, const QMatrix4x4& proj, const QMatrix4x4& mv) -{ - -} - -void Plugin_ShallowWater::view_linked(View*) -{ - update_dock_tab(); -} - -void Plugin_ShallowWater::view_unlinked(View*) -{ - update_dock_tab(); -} - -void Plugin_ShallowWater::init() -{ const unsigned int nbc = 200u; map_ = static_cast*>(schnapps_->add_map("shallow_water", 2)); - CMap2* map2 = static_cast(map_->get_map()); + map2_ = static_cast(map_->get_map()); position_ = map_->add_attribute("position"); water_height_ = map_->add_attribute("water_height"); + water_position_ = map_->add_attribute("water_position"); h_ = map_->add_attribute("hauteur"); h_tmp_ = map_->add_attribute("hauteur_tmp"); @@ -92,32 +67,78 @@ void Plugin_ShallowWater::init() s0L_ = map_->add_attribute("s0L"); s0R_ = map_->add_attribute("s0R"); - cgogn::modeling::SquareGrid grid(*map2, nbc, 1); + cgogn::modeling::SquareGrid grid(*map2_, nbc, 1); grid.embed_into_grid(position_, float(nbc), 5.0f, 0.0f); + + map2_->copy_attribute(water_position_, position_); + boundaryL_ = CMap2::Edge(grid.vertex_table_[nbc+1].dart); boundaryR_ = CMap2::Edge(grid.vertex_table_[nbc].dart); - cgogn::geometry::compute_centroid(*map2, position_, centroid_); + cgogn::geometry::compute_centroid(*map2_, position_, centroid_); - map2->parallel_foreach_cell([&] (CMap2::Face f, uint32) + map2_->parallel_foreach_cell([&] (CMap2::Face f, uint32) { CMap2::Edge e1(f.dart); - CMap2::Edge e2(map2->phi1(f.dart)); - if (map2->is_incident_to_boundary(e1)) + CMap2::Edge e2(map2_->phi1(f.dart)); + if (map2_->is_incident_to_boundary(e1)) { - length_[f] = cgogn::geometry::length(*map2, e1, position_); - phi_[f] = cgogn::geometry::length(*map2, e2, position_); + length_[f] = cgogn::geometry::length(*map2_, e1, position_); + phi_[f] = cgogn::geometry::length(*map2_, e2, position_); } else { - phi_[f] = cgogn::geometry::length(*map2, e1, position_); - length_[f] = cgogn::geometry::length(*map2, e2, position_); + phi_[f] = cgogn::geometry::length(*map2_, e1, position_); + length_[f] = cgogn::geometry::length(*map2_, e2, position_); } + }); + + timer_ = new QTimer(this); + connect(timer_, SIGNAL(timeout()), this, SLOT(execute_time_step())); + + return true; +} + +void Plugin_ShallowWater::disable() +{ + schnapps_->remove_plugin_dock_tab(this, dock_tab_); + schnapps_->remove_map("shallow_water"); + delete dock_tab_; +} + +void Plugin_ShallowWater::draw(View*, const QMatrix4x4& proj, const QMatrix4x4& mv) +{ + +} + +void Plugin_ShallowWater::view_linked(View*) +{ + update_dock_tab(); +} + +void Plugin_ShallowWater::view_unlinked(View*) +{ + update_dock_tab(); +} - // left half of the cells has initial water height of 10 - if (centroid_[f][0] < 0) +void Plugin_ShallowWater::init() +{ + map2_->parallel_foreach_cell([&] (CMap2::Face f, uint32) + { + if (centroid_[f][0] < -75.) + h_[f] = 10.; + else if (centroid_[f][0] < -50.) + h_[f] = 1.; + else if (centroid_[f][0] < -25.) + h_[f] = 10.; + else if (centroid_[f][0] < -0.) + h_[f] = 1.; + else if (centroid_[f][0] < 25.) + h_[f] = 10.; + else if (centroid_[f][0] < 50.) + h_[f] = 1.; + else if (centroid_[f][0] < 75.) h_[f] = 10.; - // right half of the cells has initial water height of 1 else h_[f] = 1.; @@ -125,129 +146,148 @@ void Plugin_ShallowWater::init() q_[f] = 0.; }); - map2->parallel_foreach_cell([&] (CMap2::Vertex v, uint32) + map2_->parallel_foreach_cell([&] (CMap2::Vertex v, uint32) { SCALAR h = 0; uint32 nbf = 0; - map2->foreach_incident_face(v, [&] (CMap2::Face f) { h += h_[f]; ++nbf; }); + map2_->foreach_incident_face(v, [&] (CMap2::Face f) { h += h_[f]; ++nbf; }); h /= nbf; water_height_[v] = h; + water_position_[v][2] = h; }); map_->notify_attribute_change(CMap2::Vertex::ORBIT, "water_height"); + map_->notify_attribute_change(CMap2::Vertex::ORBIT, "water_position"); } void Plugin_ShallowWater::start() { - CMap2* map2 = static_cast(map_->get_map()); + t_ = 0.; + dt_ = 0.05; + timer_->start(0); +} - SCALAR dt = 0.01; - SCALAR t = 0.; +void Plugin_ShallowWater::execute_time_step() +{ + f1_[boundaryL_] = 0.; + f2_[boundaryL_] = 5e-1 * 9.81 * phi_[0] * (h_[0] * h_[0]); + s0L_[boundaryL_] = 0.; + s0R_[boundaryL_] = 0.; - while (t < 5.) + map2_->parallel_foreach_cell( + [&] (CMap2::Edge e, uint32) + { + std::pair faces = get_LR_faces(e); + CMap2::Face fL = faces.first; + CMap2::Face fR = faces.second; + struct Flux F = Solv_HLL(0., 0., phi_[fL], phi_[fR], h_[fL], h_[fR], q_[fL], q_[fR], 1e-3, 9.81); + f1_[e] = F.F1; + f2_[e] = F.F2; + s0L_[e] = F.S0L; + s0R_[e] = F.S0R; + }, + [&] (CMap2::Edge e) { return !map2_->is_incident_to_boundary(e); } + ); + + f1_[boundaryR_] = f1_[CMap2::Edge(map2_->phi1(map2_->phi1(boundaryR_.dart)))]; + f2_[boundaryR_] = f2_[CMap2::Edge(map2_->phi1(map2_->phi1(boundaryR_.dart)))]; + s0L_[boundaryR_] = s0L_[CMap2::Edge(map2_->phi1(map2_->phi1(boundaryR_.dart)))]; + s0R_[boundaryR_] = s0R_[CMap2::Edge(map2_->phi1(map2_->phi1(boundaryR_.dart)))]; + + map2_->parallel_foreach_cell( + [&] (CMap2::Face f, uint32) + { + std::pair edges = get_LR_edges(f); + CMap2::Edge eL = edges.first; + CMap2::Edge eR = edges.second; + h_tmp_[f] = h_[f] + (dt_ / (length_[f] * phi_[f])) * (f1_[eL] - f1_[eR]); + q_tmp_[f] = q_[f] + (dt_ / (length_[f] * phi_[f])) * (f2_[eL] - s0L_[eL] - (f2_[eR] - s0R_[eR])); + } + ); + + map2_->swap_attributes(h_, h_tmp_); + map2_->swap_attributes(q_, q_tmp_); + + map2_->parallel_foreach_cell([&] (CMap2::Vertex v, uint32) { - f1_[boundaryL_] = 0.; - f2_[boundaryL_] = 5e-1 * 9.81 * phi_[0] * (h_[0] * h_[0]); - s0L_[boundaryL_] = 0.; - s0R_[boundaryL_] = 0.; + SCALAR h = 0; + uint32 nbf = 0; + map2_->foreach_incident_face(v, [&] (CMap2::Face f) { h += h_[f]; ++nbf; }); + h /= nbf; + water_height_[v] = h; + water_position_[v][2] = h; + }); - map2->parallel_foreach_cell( - [&] (CMap2::Edge e, uint32) + map_->notify_attribute_change(CMap2::Vertex::ORBIT, "water_height"); + map_->notify_attribute_change(CMap2::Vertex::ORBIT, "water_position"); + + t_ += dt_; + if (t_ > 30.) + timer_->stop(); +} + +std::pair Plugin_ShallowWater::get_LR_edges(CMap2::Face f) +{ + CMap2::Edge eL, eR; + CMap2::Edge e(f.dart); + if (map2_->is_incident_to_boundary(e)) + { + if (map2_->same_cell(e, boundaryL_)) + { + eL = e; + eR = CMap2::Edge(map2_->phi1(map2_->phi1(eL.dart))); + } + else if (map2_->same_cell(e, boundaryR_)) + { + eR = e; + eL = CMap2::Edge(map2_->phi1(map2_->phi1(eR.dart))); + } + else + { + if (position_[CMap2::Vertex(f.dart)][0] < position_[CMap2::Vertex(map2_->phi1(f.dart))][0]) { - CMap2::Face fL, fR; - if (position_[CMap2::Vertex(e.dart)][0] < position_[CMap2::Vertex(map2->phi_1(e.dart))][0]) - { - fL = CMap2::Face(map2->phi2(e.dart)); - fR = CMap2::Face(e.dart); - } - else - { - fL = CMap2::Face(e.dart); - fR = CMap2::Face(map2->phi2(e.dart)); - } - struct Flux F = Solv_HLL(0., 0., phi_[fL], phi_[fR], h_[fL], h_[fR], q_[fL], q_[fR], 1e-3, 9.81); - f1_[e] = F.F1; - f2_[e] = F.F2; - s0L_[e] = F.S0L; - s0R_[e] = F.S0R; - }, - [&] (CMap2::Edge e) { return !map2->is_incident_to_boundary(e); } - ); - - f1_[boundaryR_] = f1_[CMap2::Edge(map2->phi1(map2->phi1(boundaryR_.dart)))]; - f2_[boundaryR_] = f2_[CMap2::Edge(map2->phi1(map2->phi1(boundaryR_.dart)))]; - s0L_[boundaryR_] = 0.; - s0R_[boundaryR_] = 0.; - - map2->parallel_foreach_cell( - [&] (CMap2::Face f, uint32) + eL = CMap2::Edge(map2_->phi_1(f.dart)); + eR = CMap2::Edge(map2_->phi1(f.dart)); + } + else { - CMap2::Edge eL, eR; - CMap2::Edge e(f.dart); - if (map2->is_incident_to_boundary(e)) - { - if (map2->same_cell(e, boundaryL_)) - { - eL = e; - eR = CMap2::Edge(map2->phi1(map2->phi1(eL.dart))); - } - else if (map2->same_cell(e, boundaryR_)) - { - eR = e; - eL = CMap2::Edge(map2->phi1(map2->phi1(eR.dart))); - } - else - { - if (position_[CMap2::Vertex(f.dart)][0] < position_[CMap2::Vertex(map2->phi1(f.dart))][0]) - { - eL = CMap2::Edge(map2->phi_1(f.dart)); - eR = CMap2::Edge(map2->phi1(f.dart)); - } - else - { - eL = CMap2::Edge(map2->phi1(f.dart)); - eR = CMap2::Edge(map2->phi_1(f.dart)); - } - } - } - else - { - if (position_[CMap2::Vertex(f.dart)][0] < position_[CMap2::Vertex(map2->phi_1(f.dart))][0]) - { - eL = CMap2::Edge(f.dart); - eR = CMap2::Edge(map2->phi1(map2->phi1(f.dart))); - } - else - { - eL = CMap2::Edge(map2->phi1(map2->phi1(f.dart))); - eR = CMap2::Edge(f.dart); - } - } - - h_tmp_[f] = h_[f] + (dt / (length_[f] * phi_[f])) * (f1_[eL] - f1_[eR]); - q_tmp_[f] = q_[f] + (dt / (length_[f] * phi_[f])) * (f2_[eL] - s0L_[eL] - (f2_[eR] - s0R_[eR])); + eL = CMap2::Edge(map2_->phi1(f.dart)); + eR = CMap2::Edge(map2_->phi_1(f.dart)); } - ); - - map2->swap_attributes(h_, h_tmp_); - map2->swap_attributes(q_, q_tmp_); - - t += dt; - - map2->parallel_foreach_cell([&] (CMap2::Vertex v, uint32) + } + } + else + { + if (position_[CMap2::Vertex(f.dart)][0] < position_[CMap2::Vertex(map2_->phi_1(f.dart))][0]) + { + eL = CMap2::Edge(f.dart); + eR = CMap2::Edge(map2_->phi1(map2_->phi1(f.dart))); + } + else { - SCALAR h = 0; - uint32 nbf = 0; - map2->foreach_incident_face(v, [&] (CMap2::Face f) { h += h_[f]; ++nbf; }); - h /= nbf; - water_height_[v] = h; - }); + eL = CMap2::Edge(map2_->phi1(map2_->phi1(f.dart))); + eR = CMap2::Edge(f.dart); + } + } - map_->notify_attribute_change(CMap2::Vertex::ORBIT, "water_height"); + return std::make_pair(eL, eR); +} - for (View* v : this->get_linked_views()) - v->update(); +std::pair Plugin_ShallowWater::get_LR_faces(CMap2::Edge e) +{ + CMap2::Face fL, fR; + if (position_[CMap2::Vertex(e.dart)][0] < position_[CMap2::Vertex(map2_->phi_1(e.dart))][0]) + { + fL = CMap2::Face(map2_->phi2(e.dart)); + fR = CMap2::Face(e.dart); + } + else + { + fL = CMap2::Face(e.dart); + fR = CMap2::Face(map2_->phi2(e.dart)); } + + return std::make_pair(fL, fR); } void Plugin_ShallowWater::update_dock_tab() diff --git a/schnapps/plugins/shallow_water/shallow_water.h b/schnapps/plugins/shallow_water/shallow_water.h index 6620500..5d9ad23 100644 --- a/schnapps/plugins/shallow_water/shallow_water.h +++ b/schnapps/plugins/shallow_water/shallow_water.h @@ -77,6 +77,7 @@ public slots: private slots: void update_dock_tab(); + void execute_time_step(); private: @@ -96,14 +97,23 @@ private slots: SCALAR hmin, SCALAR g ); + std::pair get_LR_edges(CMap2::Face f); + std::pair get_LR_faces(CMap2::Edge e); + ShallowWater_DockTab* dock_tab_; + SCALAR t_; + SCALAR dt_; + QTimer* timer_; + MapHandler* map_; + CMap2* map2_; CMap2::Edge boundaryL_, boundaryR_; CMap2::VertexAttribute position_; // vertices position CMap2::VertexAttribute water_height_; + CMap2::VertexAttribute water_position_; CMap2::FaceAttribute h_; // water height CMap2::FaceAttribute h_tmp_; From de3b9b15019aba8bdd270bbcaa0f3fabedf86339 Mon Sep 17 00:00:00 2001 From: Pierre Kraemer Date: Thu, 2 Mar 2017 11:27:25 +0100 Subject: [PATCH 12/14] use some alternative type names + update min/max in render scalar when attribute changed --- schnapps/core/map_handler.h | 2 ++ schnapps/core/schnapps.cpp | 4 ++-- schnapps/plugins/export/export.cpp | 8 ++++--- .../extract_surface/extract_surface.cpp | 4 ++-- schnapps/plugins/import/import.cpp | 4 ++-- schnapps/plugins/meshgen/cgal/c3t3_import.cpp | 6 ++--- schnapps/plugins/meshgen/cgal/c3t3_import.h | 7 +++--- .../cgal/cgogn_surface_to_cgal_polyhedron.cpp | 5 ++-- .../cgal/cgogn_surface_to_cgal_polyhedron.h | 15 ++++++++---- schnapps/plugins/meshgen/meshgen_dialog.cpp | 6 ++--- schnapps/plugins/selection/selection.cpp | 4 ++-- schnapps/plugins/selection/selection.h | 8 +++---- .../plugins/shallow_water/shallow_water.cpp | 7 +++--- .../plugins/shallow_water/shallow_water.h | 2 +- .../dialog_compute_curvature.cpp | 2 +- .../dialog_compute_curvature.h | 2 +- .../dialog_compute_normal.cpp | 2 +- .../dialog_compute_normal.h | 2 +- .../surface_differential_properties.cpp | 4 ++-- .../dialog_decimation.cpp | 2 +- .../surface_modelisation/dialog_decimation.h | 2 +- .../dialog_subdivision.cpp | 2 +- .../surface_modelisation/dialog_subdivision.h | 2 +- .../surface_modelisation.cpp | 6 ++--- .../surface_render_scalar.cpp | 24 ++++++++++++++++++- .../surface_render_scalar.h | 6 +++-- .../surface_render_vector.cpp | 2 +- .../surface_render_vector.h | 2 +- 28 files changed, 89 insertions(+), 53 deletions(-) diff --git a/schnapps/core/map_handler.h b/schnapps/core/map_handler.h index 64c2c97..552a1a6 100644 --- a/schnapps/core/map_handler.h +++ b/schnapps/core/map_handler.h @@ -54,7 +54,9 @@ class SCHNAPPS_CORE_API MapHandlerGen : public QObject friend class View; public: + EIGEN_MAKE_ALIGNED_OPERATOR_NEW + template using ChunkArrayContainer = MapBaseData::ChunkArrayContainer; using ChunkArrayGen = cgogn::MapBaseData::ChunkArrayGen; diff --git a/schnapps/core/schnapps.cpp b/schnapps/core/schnapps.cpp index 1779f54..ed1655c 100644 --- a/schnapps/core/schnapps.cpp +++ b/schnapps/core/schnapps.cpp @@ -340,11 +340,11 @@ MapHandlerGen* SCHNApps::add_map(const QString &name, unsigned int dimension) switch(dimension) { case 2 : { - maps_.insert(std::make_pair(final_name, cgogn::make_unique>(final_name, this))); + maps_.insert(std::make_pair(final_name, cgogn::make_unique(final_name, this))); break; } case 3 : { - maps_.insert(std::make_pair(final_name, cgogn::make_unique>(final_name, this))); + maps_.insert(std::make_pair(final_name, cgogn::make_unique(final_name, this))); break; } } diff --git a/schnapps/plugins/export/export.cpp b/schnapps/plugins/export/export.cpp index 13e6347..e0981ed 100644 --- a/schnapps/plugins/export/export.cpp +++ b/schnapps/plugins/export/export.cpp @@ -61,12 +61,14 @@ void Plugin_Export::export_mesh() if (mhg) { std::vector> other_attributes; - if (MapHandler* m2h = dynamic_cast*>(mhg)) + if (CMap2Handler* m2h = dynamic_cast(mhg)) { CMap2& cmap2 = *m2h->get_map(); cgogn::io::export_surface(cmap2, *(this->export_params_)); - } else { - if (MapHandler* m3h = dynamic_cast*>(mhg)) + } + else + { + if (CMap3Handler* m3h = dynamic_cast(mhg)) { CMap3& cmap3 = *m3h->get_map(); cgogn::io::export_volume(cmap3, *(this->export_params_)); diff --git a/schnapps/plugins/extract_surface/extract_surface.cpp b/schnapps/plugins/extract_surface/extract_surface.cpp index 4c4a065..eb5c82e 100644 --- a/schnapps/plugins/extract_surface/extract_surface.cpp +++ b/schnapps/plugins/extract_surface/extract_surface.cpp @@ -67,8 +67,8 @@ void Plugin_ExtractSurface::extract_surface_dialog() void Plugin_ExtractSurface::extract_surface(MapHandlerGen* in_map3, MapHandlerGen* out_map2, const QString& pos_att_name) { - MapHandler* mh3_in = dynamic_cast*>(in_map3); - MapHandler* mh2_out = dynamic_cast*>(out_map2); + CMap3Handler* mh3_in = dynamic_cast(in_map3); + CMap2Handler* mh2_out = dynamic_cast(out_map2); if (!mh3_in || !mh2_out || pos_att_name.isEmpty()) return; diff --git a/schnapps/plugins/import/import.cpp b/schnapps/plugins/import/import.cpp index bf0795a..da9e125 100644 --- a/schnapps/plugins/import/import.cpp +++ b/schnapps/plugins/import/import.cpp @@ -74,7 +74,7 @@ MapHandlerGen* Plugin_Import::import_surface_mesh_from_file(const QString& filen MapHandlerGen* mhg = schnapps_->add_map(fi.baseName(), 2); if (mhg) { - MapHandler* mh = static_cast*>(mhg); + CMap2Handler* mh = static_cast(mhg); CMap2* map = mh->get_map(); cgogn::io::import_surface(*map, filename.toStdString()); @@ -121,7 +121,7 @@ MapHandlerGen* Plugin_Import::import_volume_mesh_from_file(const QString& filena MapHandlerGen* mhg = schnapps_->add_map(fi.baseName(), 3); if (mhg) { - MapHandler* mh = static_cast*>(mhg); + CMap3Handler* mh = static_cast(mhg); CMap3* map = mh->get_map(); cgogn::io::import_volume(*map, filename.toStdString()); diff --git a/schnapps/plugins/meshgen/cgal/c3t3_import.cpp b/schnapps/plugins/meshgen/cgal/c3t3_import.cpp index 140650b..4f0e24c 100644 --- a/schnapps/plugins/meshgen/cgal/c3t3_import.cpp +++ b/schnapps/plugins/meshgen/cgal/c3t3_import.cpp @@ -34,9 +34,8 @@ namespace schnapps namespace plugin_meshgen { -SCHNAPPS_PLUGIN_MESHGEN_API void tetrahedralize(const CGALParameters& param, MapHandler* input_surface_map, const CMap2::VertexAttribute& position_attribute, MapHandler* output_volume_map) +SCHNAPPS_PLUGIN_MESHGEN_API void tetrahedralize(const CGALParameters& param, CMap2Handler* input_surface_map, const CMap2::VertexAttribute& position_attribute, CMap3Handler* output_volume_map) { - using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; using Polyhedron = CGAL::Polyhedron_3; using Domain = CGAL::Polyhedral_mesh_domain_3; @@ -65,7 +64,7 @@ SCHNAPPS_PLUGIN_MESHGEN_API void tetrahedralize(const CGALParameters& param, Map } } -SCHNAPPS_PLUGIN_MESHGEN_API void tetrahedralize(const CGALParameters& param, const plugin_image::Image3D* im, MapHandler* output_volume_map) +SCHNAPPS_PLUGIN_MESHGEN_API void tetrahedralize(const CGALParameters& param, const plugin_image::Image3D* im, CMap3Handler* output_volume_map) { using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; #if CGAL_VERSION_NR >= CGAL_VERSION_NUMBER(4,8,0) @@ -113,4 +112,5 @@ SCHNAPPS_PLUGIN_MESHGEN_API void tetrahedralize(const CGALParameters& param, con } } // namespace plugin_meshgen + } // namespace schnapps diff --git a/schnapps/plugins/meshgen/cgal/c3t3_import.h b/schnapps/plugins/meshgen/cgal/c3t3_import.h index 6ea55c3..f4a90d0 100644 --- a/schnapps/plugins/meshgen/cgal/c3t3_import.h +++ b/schnapps/plugins/meshgen/cgal/c3t3_import.h @@ -116,11 +116,11 @@ void import_c3t3(const C3T3& c3t3_in, MapHandler* map_out) } -SCHNAPPS_PLUGIN_MESHGEN_API void tetrahedralize(const CGALParameters& param, MapHandler* input_surface_map, const CMap2::VertexAttribute& position_attribute, MapHandler* output_volume_map); -SCHNAPPS_PLUGIN_MESHGEN_API void tetrahedralize(const CGALParameters& param, const plugin_image::Image3D* im, MapHandler* output_volume_map); +SCHNAPPS_PLUGIN_MESHGEN_API void tetrahedralize(const CGALParameters& param, CMap2Handler* input_surface_map, const CMap2::VertexAttribute& position_attribute, CMap3Handler* output_volume_map); +SCHNAPPS_PLUGIN_MESHGEN_API void tetrahedralize(const CGALParameters& param, const plugin_image::Image3D* im, CMap3Handler* output_volume_map); template -void tetrahedralize(const CGALParameters& param, Domain_& dom, CGAL::Mesh_criteria_3::type>& criteria, MapHandler* output_volume_map) +void tetrahedralize(const CGALParameters& param, Domain_& dom, CGAL::Mesh_criteria_3::type>& criteria, CMap3Handler* output_volume_map) { using namespace CGAL::parameters; using Triangulation_ = typename CGAL::Mesh_triangulation_3::type; @@ -169,6 +169,7 @@ void tetrahedralize(const CGALParameters& param, Domain_& dom, CGAL::Mesh_criter } } // namespace plugin_meshgen + } // namespace schnapps #endif // SCHNAPPS_PLUGIN_MESHGEN_C3T3_IMPORT_H diff --git a/schnapps/plugins/meshgen/cgal/cgogn_surface_to_cgal_polyhedron.cpp b/schnapps/plugins/meshgen/cgal/cgogn_surface_to_cgal_polyhedron.cpp index 0005e7c..57cfaec 100644 --- a/schnapps/plugins/meshgen/cgal/cgogn_surface_to_cgal_polyhedron.cpp +++ b/schnapps/plugins/meshgen/cgal/cgogn_surface_to_cgal_polyhedron.cpp @@ -33,7 +33,7 @@ namespace schnapps namespace plugin_meshgen { -PolyhedronBuilder::PolyhedronBuilder(MapHandler* mh, const CMap2::VertexAttribute& position_attribute) : +PolyhedronBuilder::PolyhedronBuilder(CMap2Handler* mh, const CMap2::VertexAttribute& position_attribute) : map_(mh), position_attribute_(position_attribute) {} @@ -73,7 +73,7 @@ void PolyhedronBuilder::operator()(HalfedgeDS& hds) map_->remove_attribute(id_attribute); } -SCHNAPPS_PLUGIN_MESHGEN_API std::unique_ptr> build_polyhedron(MapHandler* mh, const CMap2::VertexAttribute& position_attribute) +SCHNAPPS_PLUGIN_MESHGEN_API std::unique_ptr> build_polyhedron(CMap2Handler* mh, const CMap2::VertexAttribute& position_attribute) { if (!mh || !position_attribute.is_valid()) return nullptr; @@ -84,4 +84,5 @@ SCHNAPPS_PLUGIN_MESHGEN_API std::unique_ptr::HalfedgeDS> { +class SCHNAPPS_PLUGIN_MESHGEN_API PolyhedronBuilder : public CGAL::Modifier_base::HalfedgeDS> +{ public: + using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; using Polyhedron = CGAL::Polyhedron_3 ; using HalfedgeDS = Polyhedron::HalfedgeDS; using Vertex = HalfedgeDS::Vertex; using Point = Vertex::Point ; - PolyhedronBuilder(MapHandler* mh, const CMap2::VertexAttribute& position_attribute); - void operator()( HalfedgeDS& hds); + PolyhedronBuilder(CMap2Handler* mh, const CMap2::VertexAttribute& position_attribute); + void operator()(HalfedgeDS& hds); + private: - MapHandler* map_; + + CMap2Handler* map_; const CMap2::VertexAttribute position_attribute_; }; -SCHNAPPS_PLUGIN_MESHGEN_API std::unique_ptr> build_polyhedron(MapHandler* mh, const CMap2::VertexAttribute& position_attribute); +SCHNAPPS_PLUGIN_MESHGEN_API std::unique_ptr> build_polyhedron(CMap2Handler* mh, const CMap2::VertexAttribute& position_attribute); } // namespace plugin_meshgen + } // namespace schnapps #endif // SCHNAPPS_PLUGIN_MESHGEN_CGOGN_SURFACE_TO_CGAL_POLYHEDRON_H diff --git a/schnapps/plugins/meshgen/meshgen_dialog.cpp b/schnapps/plugins/meshgen/meshgen_dialog.cpp index adb9db0..c1cca1b 100644 --- a/schnapps/plugins/meshgen/meshgen_dialog.cpp +++ b/schnapps/plugins/meshgen/meshgen_dialog.cpp @@ -140,13 +140,13 @@ void VolumeMeshFromSurfaceDialog::generator_changed(const QString& generator) void VolumeMeshFromSurfaceDialog::map_added(MapHandlerGen* mhg) { - if (mhg && dynamic_cast*>(mhg)) + if (mhg && dynamic_cast(mhg)) export_dialog_->comboBoxMapSelection->addItem(mhg->get_name()); } void VolumeMeshFromSurfaceDialog::map_removed(MapHandlerGen* mhg) { - if (mhg && dynamic_cast*>(mhg)) + if (mhg && dynamic_cast(mhg)) export_dialog_->comboBoxMapSelection->removeItem(export_dialog_->comboBoxMapSelection->findText(mhg->get_name())); } @@ -170,7 +170,7 @@ void VolumeMeshFromSurfaceDialog::selected_map_changed(QString map_name) MapHandlerGen* mhg = schnapps_->get_map(map_name); QSignalBlocker blocker(export_dialog_->comboBox_generator); export_dialog_->comboBox_generator->clear(); - if (mhg && dynamic_cast*>(mhg)) + if (mhg && dynamic_cast(mhg)) { QStringList list; list << "-select-" << "cgal" << "netgen" << "tetgen"; diff --git a/schnapps/plugins/selection/selection.cpp b/schnapps/plugins/selection/selection.cpp index 36da7e7..31868bb 100644 --- a/schnapps/plugins/selection/selection.cpp +++ b/schnapps/plugins/selection/selection.cpp @@ -420,8 +420,8 @@ void Plugin_Selection::mouseMove(View* view, QMouseEvent* event) VEC3 A(P.x, P.y, P.z); VEC3 B(Q.x, Q.y, Q.z); - CMap2* map2 = map->dimension() == 2 ? static_cast*>(map)->get_map() : nullptr; - CMap3* map3 = map->dimension() == 3 ? static_cast*>(map)->get_map() : nullptr; + CMap2* map2 = map->dimension() == 2 ? static_cast(map)->get_map() : nullptr; + CMap3* map3 = map->dimension() == 3 ? static_cast(map)->get_map() : nullptr; switch(p.cells_set_->get_cell_type()) { diff --git a/schnapps/plugins/selection/selection.h b/schnapps/plugins/selection/selection.h index 050d9b5..0a651ae 100644 --- a/schnapps/plugins/selection/selection.h +++ b/schnapps/plugins/selection/selection.h @@ -100,9 +100,9 @@ struct SCHNAPPS_PLUGIN_SELECTION_API MapParameters : public QObject void set_position_attribute(const QString& attribute_name) { if (map_->dimension() == 2) - position_ = cgogn::make_unique>(dynamic_cast(map_)->get_attribute::Vertex::ORBIT>(attribute_name)); + position_ = cgogn::make_unique>(dynamic_cast(map_)->get_attribute(attribute_name)); else - position_ = cgogn::make_unique>(dynamic_cast(map_)->get_attribute::Vertex::ORBIT>(attribute_name)); + position_ = cgogn::make_unique>(dynamic_cast(map_)->get_attribute(attribute_name)); } const MapHandlerGen::Attribute_T& get_normal_attribute() const { return *normal_; } @@ -110,9 +110,9 @@ struct SCHNAPPS_PLUGIN_SELECTION_API MapParameters : public QObject void set_normal_attribute(const QString& attribute_name) { if (map_->dimension() == 2) - normal_ = cgogn::make_unique>(dynamic_cast(map_)->get_attribute::Vertex::ORBIT>(attribute_name)); + normal_ = cgogn::make_unique>(dynamic_cast(map_)->get_attribute(attribute_name)); else - normal_ = cgogn::make_unique>(dynamic_cast(map_)->get_attribute::Vertex::ORBIT>(attribute_name)); + normal_ = cgogn::make_unique>(dynamic_cast(map_)->get_attribute(attribute_name)); } const QColor& get_color() const { return color_; } diff --git a/schnapps/plugins/shallow_water/shallow_water.cpp b/schnapps/plugins/shallow_water/shallow_water.cpp index 98decdb..5d651b3 100644 --- a/schnapps/plugins/shallow_water/shallow_water.cpp +++ b/schnapps/plugins/shallow_water/shallow_water.cpp @@ -46,7 +46,7 @@ bool Plugin_ShallowWater::enable() const unsigned int nbc = 200u; - map_ = static_cast*>(schnapps_->add_map("shallow_water", 2)); + map_ = static_cast(schnapps_->add_map("shallow_water", 2)); map2_ = static_cast(map_->get_map()); position_ = map_->add_attribute("position"); @@ -68,7 +68,7 @@ bool Plugin_ShallowWater::enable() s0R_ = map_->add_attribute("s0R"); cgogn::modeling::SquareGrid grid(*map2_, nbc, 1); - grid.embed_into_grid(position_, float(nbc), 5.0f, 0.0f); + grid.embed_into_grid(position_, float(nbc), 25.0f, 0.0f); map2_->copy_attribute(water_position_, position_); @@ -164,7 +164,8 @@ void Plugin_ShallowWater::start() { t_ = 0.; dt_ = 0.05; - timer_->start(0); + if (!timer_->isActive()) + timer_->start(0); } void Plugin_ShallowWater::execute_time_step() diff --git a/schnapps/plugins/shallow_water/shallow_water.h b/schnapps/plugins/shallow_water/shallow_water.h index 5d9ad23..8cc1b3b 100644 --- a/schnapps/plugins/shallow_water/shallow_water.h +++ b/schnapps/plugins/shallow_water/shallow_water.h @@ -106,7 +106,7 @@ private slots: SCALAR dt_; QTimer* timer_; - MapHandler* map_; + CMap2Handler* map_; CMap2* map2_; CMap2::Edge boundaryL_, boundaryR_; diff --git a/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.cpp b/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.cpp index 9dd27f4..e30e31e 100644 --- a/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.cpp +++ b/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.cpp @@ -157,7 +157,7 @@ void ComputeCurvature_Dialog::selected_map_changed() const QString& map_name = currentItems[0]->text(); MapHandlerGen* mhg = schnapps_->get_map(map_name); - selected_map_ = dynamic_cast*>(mhg); + selected_map_ = dynamic_cast(mhg); if (selected_map_) { diff --git a/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.h b/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.h index 6fbe1ee..1425230 100644 --- a/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.h +++ b/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.h @@ -52,7 +52,7 @@ class SCHNAPPS_PLUGIN_SDP_API ComputeCurvature_Dialog : public QDialog, public U SCHNApps* schnapps_; Plugin_SurfaceDifferentialProperties* plugin_; - MapHandler* selected_map_; + CMap2Handler* selected_map_; QVariant setting_auto_load_position_attribute_; QVariant setting_auto_load_normal_attribute_; diff --git a/schnapps/plugins/surface_differential_properties/dialog_compute_normal.cpp b/schnapps/plugins/surface_differential_properties/dialog_compute_normal.cpp index 47dc2fc..1f02fb6 100644 --- a/schnapps/plugins/surface_differential_properties/dialog_compute_normal.cpp +++ b/schnapps/plugins/surface_differential_properties/dialog_compute_normal.cpp @@ -96,7 +96,7 @@ void ComputeNormal_Dialog::selected_map_changed() const QString& map_name = currentItems[0]->text(); MapHandlerGen* mhg = schnapps_->get_map(map_name); - selected_map_ = dynamic_cast*>(mhg); + selected_map_ = dynamic_cast(mhg); if (selected_map_) { diff --git a/schnapps/plugins/surface_differential_properties/dialog_compute_normal.h b/schnapps/plugins/surface_differential_properties/dialog_compute_normal.h index b77a179..b20810a 100644 --- a/schnapps/plugins/surface_differential_properties/dialog_compute_normal.h +++ b/schnapps/plugins/surface_differential_properties/dialog_compute_normal.h @@ -52,7 +52,7 @@ class SCHNAPPS_PLUGIN_SDP_API ComputeNormal_Dialog : public QDialog, public Ui:: SCHNApps* schnapps_; Plugin_SurfaceDifferentialProperties* plugin_; - MapHandler* selected_map_; + CMap2Handler* selected_map_; QVariant setting_auto_load_position_attribute_; QVariant setting_auto_load_normal_attribute_; diff --git a/schnapps/plugins/surface_differential_properties/surface_differential_properties.cpp b/schnapps/plugins/surface_differential_properties/surface_differential_properties.cpp index d95ea2b..5eaa7b2 100644 --- a/schnapps/plugins/surface_differential_properties/surface_differential_properties.cpp +++ b/schnapps/plugins/surface_differential_properties/surface_differential_properties.cpp @@ -135,7 +135,7 @@ void Plugin_SurfaceDifferentialProperties::compute_normal( bool create_vbo, bool auto_update) { - MapHandler* mh = dynamic_cast*>(schnapps_->get_map(map_name)); + CMap2Handler* mh = dynamic_cast(schnapps_->get_map(map_name)); if (!mh) return; @@ -176,7 +176,7 @@ void Plugin_SurfaceDifferentialProperties::compute_curvature( bool compute_kgaussian, bool auto_update) { - MapHandler* mh = dynamic_cast*>(schnapps_->get_map(map_name)); + CMap2Handler* mh = dynamic_cast(schnapps_->get_map(map_name)); if (!mh) return; diff --git a/schnapps/plugins/surface_modelisation/dialog_decimation.cpp b/schnapps/plugins/surface_modelisation/dialog_decimation.cpp index 8c1d3d1..437c792 100644 --- a/schnapps/plugins/surface_modelisation/dialog_decimation.cpp +++ b/schnapps/plugins/surface_modelisation/dialog_decimation.cpp @@ -80,7 +80,7 @@ void Decimation_Dialog::selected_map_changed() const QString& map_name = currentItems[0]->text(); MapHandlerGen* mhg = schnapps_->get_map(map_name); - selected_map_ = dynamic_cast*>(mhg); + selected_map_ = dynamic_cast(mhg); if (selected_map_) { diff --git a/schnapps/plugins/surface_modelisation/dialog_decimation.h b/schnapps/plugins/surface_modelisation/dialog_decimation.h index a2f9671..a5bd2ca 100644 --- a/schnapps/plugins/surface_modelisation/dialog_decimation.h +++ b/schnapps/plugins/surface_modelisation/dialog_decimation.h @@ -52,7 +52,7 @@ class SCHNAPPS_PLUGIN_SURFACE_MODELISATION_API Decimation_Dialog : public QDialo SCHNApps* schnapps_; Plugin_SurfaceModelisation* plugin_; - MapHandler* selected_map_; + CMap2Handler* selected_map_; QVariant setting_auto_load_position_attribute_; diff --git a/schnapps/plugins/surface_modelisation/dialog_subdivision.cpp b/schnapps/plugins/surface_modelisation/dialog_subdivision.cpp index 4fe9e32..aabb8c6 100644 --- a/schnapps/plugins/surface_modelisation/dialog_subdivision.cpp +++ b/schnapps/plugins/surface_modelisation/dialog_subdivision.cpp @@ -90,7 +90,7 @@ void Subdivision_Dialog::selected_map_changed() const QString& map_name = currentItems[0]->text(); MapHandlerGen* mhg = schnapps_->get_map(map_name); - selected_map_ = dynamic_cast*>(mhg); + selected_map_ = dynamic_cast(mhg); if (selected_map_) { diff --git a/schnapps/plugins/surface_modelisation/dialog_subdivision.h b/schnapps/plugins/surface_modelisation/dialog_subdivision.h index 0198961..98b26bd 100644 --- a/schnapps/plugins/surface_modelisation/dialog_subdivision.h +++ b/schnapps/plugins/surface_modelisation/dialog_subdivision.h @@ -52,7 +52,7 @@ class SCHNAPPS_PLUGIN_SURFACE_MODELISATION_API Subdivision_Dialog : public QDial SCHNApps* schnapps_; Plugin_SurfaceModelisation* plugin_; - MapHandler* selected_map_; + CMap2Handler* selected_map_; QVariant setting_auto_load_position_attribute_; diff --git a/schnapps/plugins/surface_modelisation/surface_modelisation.cpp b/schnapps/plugins/surface_modelisation/surface_modelisation.cpp index a9e896f..17bce20 100644 --- a/schnapps/plugins/surface_modelisation/surface_modelisation.cpp +++ b/schnapps/plugins/surface_modelisation/surface_modelisation.cpp @@ -89,7 +89,7 @@ void Plugin_SurfaceModelisation::decimate( const QString& position_attribute_name, double percentVerticesToRemove) { - MapHandler* mh = dynamic_cast*>(schnapps_->get_map(map_name)); + CMap2Handler* mh = dynamic_cast(schnapps_->get_map(map_name)); if (!mh) return; @@ -110,7 +110,7 @@ void Plugin_SurfaceModelisation::subdivide_loop( const QString& map_name, const QString& position_attribute_name) { - MapHandler* mh = dynamic_cast*>(schnapps_->get_map(map_name)); + CMap2Handler* mh = dynamic_cast(schnapps_->get_map(map_name)); if (!mh) return; @@ -130,7 +130,7 @@ void Plugin_SurfaceModelisation::subdivide_catmull_clark( const QString& map_name, const QString& position_attribute_name) { - MapHandler* mh = dynamic_cast*>(schnapps_->get_map(map_name)); + CMap2Handler* mh = dynamic_cast(schnapps_->get_map(map_name)); if (!mh) return; diff --git a/schnapps/plugins/surface_render_scalar/surface_render_scalar.cpp b/schnapps/plugins/surface_render_scalar/surface_render_scalar.cpp index 7df5ed3..ed3d3af 100644 --- a/schnapps/plugins/surface_render_scalar/surface_render_scalar.cpp +++ b/schnapps/plugins/surface_render_scalar/surface_render_scalar.cpp @@ -43,7 +43,7 @@ MapParameters& Plugin_SurfaceRenderScalar::get_parameters(View* view, MapHandler if (view_param_set.count(map) == 0) { MapParameters& p = view_param_set[map]; - p.map_ = static_cast*>(map); + p.map_ = static_cast(map); return p; } else @@ -122,6 +122,7 @@ void Plugin_SurfaceRenderScalar::map_linked(MapHandlerGen *map) connect(map, SIGNAL(vbo_added(cgogn::rendering::VBO*)), this, SLOT(linked_map_vbo_added(cgogn::rendering::VBO*)), Qt::UniqueConnection); connect(map, SIGNAL(vbo_removed(cgogn::rendering::VBO*)), this, SLOT(linked_map_vbo_removed(cgogn::rendering::VBO*)), Qt::UniqueConnection); connect(map, SIGNAL(bb_changed()), this, SLOT(linked_map_bb_changed()), Qt::UniqueConnection); + connect(map, SIGNAL(attribute_changed(cgogn::Orbit, const QString&)), this, SLOT(linked_map_attribute_changed(cgogn::Orbit, QString)), Qt::UniqueConnection); } } @@ -134,6 +135,7 @@ void Plugin_SurfaceRenderScalar::map_unlinked(MapHandlerGen *map) disconnect(map, SIGNAL(vbo_added(cgogn::rendering::VBO*)), this, SLOT(linked_map_vbo_added(cgogn::rendering::VBO*))); disconnect(map, SIGNAL(vbo_removed(cgogn::rendering::VBO*)), this, SLOT(linked_map_vbo_removed(cgogn::rendering::VBO*))); disconnect(map, SIGNAL(bb_changed()), this, SLOT(linked_map_bb_changed())); + disconnect(map, SIGNAL(attribute_changed(cgogn::Orbit, const QString&)), this, SLOT(linked_map_attribute_changed(cgogn::Orbit, QString))); } } @@ -181,6 +183,26 @@ void Plugin_SurfaceRenderScalar::linked_map_bb_changed() } +void Plugin_SurfaceRenderScalar::linked_map_attribute_changed(cgogn::Orbit orbit, const QString& attribute_name) +{ + if (orbit == CMap2::Vertex::ORBIT) + { + MapHandlerGen* map = static_cast(sender()); + + for (auto& it : parameter_set_) + { + std::map& view_param_set = it.second; + if (view_param_set.count(map) > 0ul) + { + MapParameters& p = view_param_set[map]; + cgogn::rendering::VBO* vbo = p.get_scalar_vbo(); + if (vbo && QString::fromStdString(vbo->name()) == attribute_name) + p.set_scalar_vbo(vbo); + } + } + } +} + void Plugin_SurfaceRenderScalar::viewer_initialized() { View* view = dynamic_cast(sender()); diff --git a/schnapps/plugins/surface_render_scalar/surface_render_scalar.h b/schnapps/plugins/surface_render_scalar/surface_render_scalar.h index e9388e4..639cbdc 100644 --- a/schnapps/plugins/surface_render_scalar/surface_render_scalar.h +++ b/schnapps/plugins/surface_render_scalar/surface_render_scalar.h @@ -73,7 +73,7 @@ struct SCHNAPPS_PLUGIN_SURFACE_RENDER_SCALAR_API MapParameters scalar_vbo_ = v; if (scalar_vbo_ && scalar_vbo_->vector_dimension() == 1) { - const MapHandler::VertexAttribute& attr = map_->template get_attribute::Vertex::ORBIT>(QString::fromStdString(scalar_vbo_->name())); + const CMap2::VertexAttribute& attr = map_->template get_attribute(QString::fromStdString(scalar_vbo_->name())); if (!attr.is_valid()) { cgogn_log_warning("plugin_surface_render_scalar|MapParameters::set_scalar_vbo") << "The attribute \"" << scalar_vbo_->name() << "\" is not valid. Its data should be of type " << cgogn::name_of_type(SCALAR()) << "."; @@ -139,7 +139,7 @@ struct SCHNAPPS_PLUGIN_SURFACE_RENDER_SCALAR_API MapParameters set_scalar_vbo(scalar_vbo_); } - MapHandler* map_; + CMap2Handler* map_; std::unique_ptr shader_scalar_per_vertex_param_; @@ -200,6 +200,8 @@ private slots: void linked_map_vbo_added(cgogn::rendering::VBO* vbo); void linked_map_vbo_removed(cgogn::rendering::VBO* vbo); void linked_map_bb_changed(); + void linked_map_attribute_changed(cgogn::Orbit orbit, const QString& attribute_name); + void viewer_initialized(); void update_dock_tab(); diff --git a/schnapps/plugins/surface_render_vector/surface_render_vector.cpp b/schnapps/plugins/surface_render_vector/surface_render_vector.cpp index 0690be2..6b5a278 100644 --- a/schnapps/plugins/surface_render_vector/surface_render_vector.cpp +++ b/schnapps/plugins/surface_render_vector/surface_render_vector.cpp @@ -39,7 +39,7 @@ MapParameters& Plugin_SurfaceRenderVector::get_parameters(View* view, MapHandler if (view_param_set.count(map) == 0) { MapParameters& p = view_param_set[map]; - p.map_ = static_cast*>(map); + p.map_ = static_cast(map); return p; } else diff --git a/schnapps/plugins/surface_render_vector/surface_render_vector.h b/schnapps/plugins/surface_render_vector/surface_render_vector.h index 5760a8d..4e9de4e 100644 --- a/schnapps/plugins/surface_render_vector/surface_render_vector.h +++ b/schnapps/plugins/surface_render_vector/surface_render_vector.h @@ -172,7 +172,7 @@ struct SCHNAPPS_PLUGIN_SURFACE_RENDER_VECTOR_API MapParameters private: - MapHandler* map_; + CMap2Handler* map_; std::vector> shader_vector_per_vertex_param_list_; From 5958cd5b9d613bbd81be9aaef6c87c851b9c2eb2 Mon Sep 17 00:00:00 2001 From: Pierre Kraemer Date: Thu, 2 Mar 2017 23:27:27 +0100 Subject: [PATCH 13/14] start using real type instead of QVariant for settings --- schnapps/plugins/import/import.cpp | 26 ++++--- schnapps/plugins/import/import.h | 4 +- .../dialog_compute_curvature.cpp | 73 ++++++++++--------- .../dialog_compute_curvature.h | 14 ++-- 4 files changed, 63 insertions(+), 54 deletions(-) diff --git a/schnapps/plugins/import/import.cpp b/schnapps/plugins/import/import.cpp index da9e125..16cd740 100644 --- a/schnapps/plugins/import/import.cpp +++ b/schnapps/plugins/import/import.cpp @@ -48,13 +48,15 @@ bool Plugin_Import::enable() // import_2D_image_action_ = schnapps_->add_menu_action("Surface;Import 2D Image", "import 2D image"); // connect(import_2D_image_action_, SIGNAL(triggered()), this, SLOT(import_2D_image_from_file_dialog())); - setting_bbox_name_ = get_setting("Bounding box attribute"); - if (!setting_bbox_name_.isValid()) - setting_bbox_name_ = add_setting("Bounding box attribute", "position"); + if (get_setting("Bounding box attribute").isValid()) + setting_bbox_name_ = get_setting("Bounding box attribute").toString(); + else + setting_bbox_name_ = add_setting("Bounding box attribute", "position").toString(); - setting_vbo_names_ = get_setting("Compute VBO"); - if (!setting_vbo_names_.isValid()) - setting_vbo_names_ = add_setting("Compute VBO", QVariantList({"position", "normal", "color"})); + if (get_setting("Compute VBO").isValid()) + setting_vbo_names_ = get_setting("Compute VBO").toStringList(); + else + setting_vbo_names_ = add_setting("Compute VBO", QStringList({"position", "normal", "color"})).toStringList(); return true; } @@ -80,10 +82,10 @@ MapHandlerGen* Plugin_Import::import_surface_mesh_from_file(const QString& filen cgogn::io::import_surface(*map, filename.toStdString()); if (mhg->nb_cells(CellType::Vertex_Cell) > 0) { - mh->set_bb_vertex_attribute(setting_bbox_name_.toString()); + mh->set_bb_vertex_attribute(setting_bbox_name_); - for (const QVariant& var : setting_vbo_names_.toList()) - mhg->create_vbo(var.toString()); + for (const QString& vbo_name : setting_vbo_names_) + mhg->create_vbo(vbo_name); } // for (unsigned int orbit = VERTEX; orbit <= VOLUME; orbit++) // { @@ -127,10 +129,10 @@ MapHandlerGen* Plugin_Import::import_volume_mesh_from_file(const QString& filena cgogn::io::import_volume(*map, filename.toStdString()); if (mhg->nb_cells(CellType::Vertex_Cell) > 0) { - mh->set_bb_vertex_attribute(setting_bbox_name_.toString()); + mh->set_bb_vertex_attribute(setting_bbox_name_); - for (const QVariant& var : setting_vbo_names_.toList()) - mhg->create_vbo(var.toString()); + for (const QString& vbo_name : setting_vbo_names_) + mhg->create_vbo(vbo_name); } } diff --git a/schnapps/plugins/import/import.h b/schnapps/plugins/import/import.h index 69de425..1e4cf9b 100644 --- a/schnapps/plugins/import/import.h +++ b/schnapps/plugins/import/import.h @@ -86,8 +86,8 @@ public slots: private: - QVariant setting_bbox_name_; - QVariant setting_vbo_names_; + QString setting_bbox_name_; + QStringList setting_vbo_names_; QAction* import_surface_mesh_action_; QAction* import_volume_mesh_action_; diff --git a/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.cpp b/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.cpp index e30e31e..1a8b441 100644 --- a/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.cpp +++ b/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.cpp @@ -40,39 +40,46 @@ ComputeCurvature_Dialog::ComputeCurvature_Dialog(SCHNApps* s, Plugin_SurfaceDiff { setupUi(this); - setting_auto_load_position_attribute_ = plugin_->get_setting("Auto load position attribute"); - if (!setting_auto_load_position_attribute_.isValid()) - setting_auto_load_position_attribute_ = plugin_->add_setting("Auto load position attribute", "position"); + if (plugin_->get_setting("Auto load position attribute").isValid()) + setting_auto_load_position_attribute_ = plugin_->get_setting("Auto load position attribute").toString(); + else + setting_auto_load_position_attribute_ = plugin_->add_setting("Auto load position attribute", "position").toString(); - setting_auto_load_normal_attribute_ = plugin_->get_setting("Auto load normal attribute"); - if (!setting_auto_load_normal_attribute_.isValid()) - setting_auto_load_normal_attribute_ = plugin_->add_setting("Auto load normal attribute", "normal"); + if (plugin_->get_setting("Auto load normal attribute").isValid()) + setting_auto_load_normal_attribute_ = plugin_->get_setting("Auto load normal attribute").toString(); + else + setting_auto_load_normal_attribute_ = plugin_->add_setting("Auto load normal attribute", "normal").toString(); - setting_auto_load_Kmax_attribute_ = plugin_->get_setting("Auto load Kmax attribute"); - if (!setting_auto_load_Kmax_attribute_.isValid()) - setting_auto_load_Kmax_attribute_ = plugin_->add_setting("Auto load Kmax attribute", "Kmax"); + if (plugin_->get_setting("Auto load Kmax attribute").isValid()) + setting_auto_load_Kmax_attribute_ = plugin_->get_setting("Auto load Kmax attribute").toString(); + else + setting_auto_load_Kmax_attribute_ = plugin_->add_setting("Auto load Kmax attribute", "Kmax").toString(); - setting_auto_load_kmax_attribute_ = plugin_->get_setting("Auto load kmax attribute"); - if (!setting_auto_load_kmax_attribute_.isValid()) - setting_auto_load_kmax_attribute_ = plugin_->add_setting("Auto load kmax attribute", "kmax"); + if (plugin_->get_setting("Auto load kmax attribute").isValid()) + setting_auto_load_kmax_attribute_ = plugin_->get_setting("Auto load kmax attribute").toString(); + else + setting_auto_load_kmax_attribute_ = plugin_->add_setting("Auto load kmax attribute", "kmax").toString(); - setting_auto_load_Kmin_attribute_ = plugin_->get_setting("Auto load Kmin attribute"); - if (!setting_auto_load_Kmin_attribute_.isValid()) - setting_auto_load_Kmin_attribute_ = plugin_->add_setting("Auto load Kmin attribute", "Kmin"); + if (plugin_->get_setting("Auto load Kmin attribute").isValid()) + setting_auto_load_Kmin_attribute_ = plugin_->get_setting("Auto load Kmin attribute").toString(); + else + setting_auto_load_Kmin_attribute_ = plugin_->add_setting("Auto load Kmin attribute", "Kmin").toString(); - setting_auto_load_kmin_attribute_ = plugin_->get_setting("Auto load kmin attribute"); - if (!setting_auto_load_kmin_attribute_.isValid()) - setting_auto_load_kmin_attribute_ = plugin_->add_setting("Auto load kmin attribute", "kmin"); + if (plugin_->get_setting("Auto load kmin attribute").isValid()) + setting_auto_load_kmin_attribute_ = plugin_->get_setting("Auto load kmin attribute").toString(); + else + setting_auto_load_kmin_attribute_ = plugin_->add_setting("Auto load kmin attribute", "kmin").toString(); - setting_auto_load_Knormal_attribute_ = plugin_->get_setting("Auto load Knormal attribute"); - if (!setting_auto_load_Knormal_attribute_.isValid()) - setting_auto_load_Knormal_attribute_ = plugin_->add_setting("Auto load Knormal attribute", "Knormal"); + if (plugin_->get_setting("Auto load Knormal attribute").isValid()) + setting_auto_load_Knormal_attribute_ = plugin_->get_setting("Auto load Knormal attribute").toString(); + else + setting_auto_load_Knormal_attribute_ = plugin_->add_setting("Auto load Knormal attribute", "Knormal").toString(); - Kmax_attribute_name->setText(setting_auto_load_Kmax_attribute_.toString()); - kmax_attribute_name->setText(setting_auto_load_kmax_attribute_.toString()); - Kmin_attribute_name->setText(setting_auto_load_Kmin_attribute_.toString()); - kmin_attribute_name->setText(setting_auto_load_kmin_attribute_.toString()); - Knormal_attribute_name->setText(setting_auto_load_Knormal_attribute_.toString()); + Kmax_attribute_name->setText(setting_auto_load_Kmax_attribute_); + kmax_attribute_name->setText(setting_auto_load_kmax_attribute_); + Kmin_attribute_name->setText(setting_auto_load_Kmin_attribute_); + kmin_attribute_name->setText(setting_auto_load_kmin_attribute_); + Knormal_attribute_name->setText(setting_auto_load_Knormal_attribute_); connect(schnapps_, SIGNAL(map_added(MapHandlerGen*)), this, SLOT(map_added(MapHandlerGen*))); connect(schnapps_, SIGNAL(map_removed(MapHandlerGen*)), this, SLOT(map_removed(MapHandlerGen*))); @@ -178,28 +185,28 @@ void ComputeCurvature_Dialog::selected_map_changed() if (type == vec3_type_name) { combo_positionAttribute->addItem(name); - if (name == setting_auto_load_position_attribute_.toString()) + if (name == setting_auto_load_position_attribute_) combo_positionAttribute->setCurrentIndex(combo_positionAttribute->count() - 1); combo_normalAttribute->addItem(name); - if (name == setting_auto_load_normal_attribute_.toString()) + if (name == setting_auto_load_normal_attribute_) combo_normalAttribute->setCurrentIndex(combo_normalAttribute->count() - 1); combo_KmaxAttribute->addItem(name); - if (name == setting_auto_load_Kmax_attribute_.toString()) + if (name == setting_auto_load_Kmax_attribute_) combo_KmaxAttribute->setCurrentIndex(combo_KmaxAttribute->count() - 1); combo_KminAttribute->addItem(name); - if (name == setting_auto_load_Kmin_attribute_.toString()) + if (name == setting_auto_load_Kmin_attribute_) combo_KminAttribute->setCurrentIndex(combo_KminAttribute->count() - 1); combo_KnormalAttribute->addItem(name); - if (name == setting_auto_load_Knormal_attribute_.toString()) + if (name == setting_auto_load_Knormal_attribute_) combo_KnormalAttribute->setCurrentIndex(combo_KnormalAttribute->count() - 1); } else if (type == scalar_type_name) { combo_kmaxAttribute->addItem(name); - if (name == setting_auto_load_kmax_attribute_.toString()) + if (name == setting_auto_load_kmax_attribute_) combo_kmaxAttribute->setCurrentIndex(combo_kmaxAttribute->count() - 1); combo_kminAttribute->addItem(name); - if (name == setting_auto_load_kmin_attribute_.toString()) + if (name == setting_auto_load_kmin_attribute_) combo_kminAttribute->setCurrentIndex(combo_kminAttribute->count() - 1); } } diff --git a/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.h b/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.h index 1425230..48b8c4c 100644 --- a/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.h +++ b/schnapps/plugins/surface_differential_properties/dialog_compute_curvature.h @@ -54,13 +54,13 @@ class SCHNAPPS_PLUGIN_SDP_API ComputeCurvature_Dialog : public QDialog, public U CMap2Handler* selected_map_; - QVariant setting_auto_load_position_attribute_; - QVariant setting_auto_load_normal_attribute_; - QVariant setting_auto_load_Kmax_attribute_; - QVariant setting_auto_load_kmax_attribute_; - QVariant setting_auto_load_Kmin_attribute_; - QVariant setting_auto_load_kmin_attribute_; - QVariant setting_auto_load_Knormal_attribute_; + QString setting_auto_load_position_attribute_; + QString setting_auto_load_normal_attribute_; + QString setting_auto_load_Kmax_attribute_; + QString setting_auto_load_kmax_attribute_; + QString setting_auto_load_Kmin_attribute_; + QString setting_auto_load_kmin_attribute_; + QString setting_auto_load_Knormal_attribute_; private slots: From 4ca9fc5d048e93f93ba95bcd8db3c07ef211ec46 Mon Sep 17 00:00:00 2001 From: Pierre Kraemer Date: Mon, 6 Mar 2017 09:02:19 +0100 Subject: [PATCH 14/14] use real type instead of QVariant for plugin settings --- .../dialog_compute_normal.cpp | 20 +++++---- .../dialog_compute_normal.h | 4 +- .../dialog_decimation.cpp | 9 ++-- .../surface_modelisation/dialog_decimation.h | 2 +- .../dialog_subdivision.cpp | 9 ++-- .../surface_modelisation/dialog_subdivision.h | 2 +- .../plugins/surface_render/surface_render.cpp | 42 ++++++++++--------- .../plugins/surface_render/surface_render.h | 8 ++-- .../plugins/volume_render/volume_render.cpp | 20 +++++---- .../plugins/volume_render/volume_render.h | 22 +++++----- 10 files changed, 75 insertions(+), 63 deletions(-) diff --git a/schnapps/plugins/surface_differential_properties/dialog_compute_normal.cpp b/schnapps/plugins/surface_differential_properties/dialog_compute_normal.cpp index 1f02fb6..54d9950 100644 --- a/schnapps/plugins/surface_differential_properties/dialog_compute_normal.cpp +++ b/schnapps/plugins/surface_differential_properties/dialog_compute_normal.cpp @@ -41,15 +41,17 @@ ComputeNormal_Dialog::ComputeNormal_Dialog(SCHNApps* s, Plugin_SurfaceDifferenti { setupUi(this); - setting_auto_load_position_attribute_ = plugin_->get_setting("Auto load position attribute"); - if (!setting_auto_load_position_attribute_.isValid()) - setting_auto_load_position_attribute_ = plugin_->add_setting("Auto load position attribute", "position"); + if (plugin_->get_setting("Auto load position attribute").isValid()) + setting_auto_load_position_attribute_ = plugin_->get_setting("Auto load position attribute").toString(); + else + setting_auto_load_position_attribute_ = plugin_->add_setting("Auto load position attribute", "position").toString(); - setting_auto_load_normal_attribute_ = plugin_->get_setting("Auto load normal attribute"); - if (!setting_auto_load_normal_attribute_.isValid()) - setting_auto_load_normal_attribute_ = plugin_->add_setting("Auto load normal attribute", "normal"); + if (plugin_->get_setting("Auto load normal attribute").isValid()) + setting_auto_load_normal_attribute_ = plugin_->get_setting("Auto load normal attribute").toString(); + else + setting_auto_load_normal_attribute_ = plugin_->add_setting("Auto load normal attribute", "normal").toString(); - normal_attribute_name->setText(setting_auto_load_normal_attribute_.toString()); + normal_attribute_name->setText(setting_auto_load_normal_attribute_); connect(schnapps_, SIGNAL(map_added(MapHandlerGen*)), this, SLOT(map_added(MapHandlerGen*))); connect(schnapps_, SIGNAL(map_removed(MapHandlerGen*)), this, SLOT(map_removed(MapHandlerGen*))); @@ -116,10 +118,10 @@ void ComputeNormal_Dialog::selected_map_changed() if (type == vec3_type_name) { combo_positionAttribute->addItem(name); - if (name == setting_auto_load_position_attribute_.toString()) + if (name == setting_auto_load_position_attribute_) combo_positionAttribute->setCurrentIndex(combo_positionAttribute->count() - 1); combo_normalAttribute->addItem(name); - if (name == setting_auto_load_normal_attribute_.toString()) + if (name == setting_auto_load_normal_attribute_) combo_normalAttribute->setCurrentIndex(combo_normalAttribute->count() - 1); } } diff --git a/schnapps/plugins/surface_differential_properties/dialog_compute_normal.h b/schnapps/plugins/surface_differential_properties/dialog_compute_normal.h index b20810a..c6c7752 100644 --- a/schnapps/plugins/surface_differential_properties/dialog_compute_normal.h +++ b/schnapps/plugins/surface_differential_properties/dialog_compute_normal.h @@ -54,8 +54,8 @@ class SCHNAPPS_PLUGIN_SDP_API ComputeNormal_Dialog : public QDialog, public Ui:: CMap2Handler* selected_map_; - QVariant setting_auto_load_position_attribute_; - QVariant setting_auto_load_normal_attribute_; + QString setting_auto_load_position_attribute_; + QString setting_auto_load_normal_attribute_; private slots: diff --git a/schnapps/plugins/surface_modelisation/dialog_decimation.cpp b/schnapps/plugins/surface_modelisation/dialog_decimation.cpp index 437c792..30f4672 100644 --- a/schnapps/plugins/surface_modelisation/dialog_decimation.cpp +++ b/schnapps/plugins/surface_modelisation/dialog_decimation.cpp @@ -41,9 +41,10 @@ Decimation_Dialog::Decimation_Dialog(SCHNApps* s, Plugin_SurfaceModelisation* p) { setupUi(this); - setting_auto_load_position_attribute_ = plugin_->get_setting("Auto load position attribute"); - if (!setting_auto_load_position_attribute_.isValid()) - setting_auto_load_position_attribute_ = plugin_->add_setting("Auto load position attribute", "position"); + if (plugin_->get_setting("Auto load position attribute").isValid()) + setting_auto_load_position_attribute_ = plugin_->get_setting("Auto load position attribute").toString(); + else + setting_auto_load_position_attribute_ = plugin_->add_setting("Auto load position attribute", "position").toString(); connect(schnapps_, SIGNAL(map_added(MapHandlerGen*)), this, SLOT(map_added(MapHandlerGen*))); connect(schnapps_, SIGNAL(map_removed(MapHandlerGen*)), this, SLOT(map_removed(MapHandlerGen*))); @@ -100,7 +101,7 @@ void Decimation_Dialog::selected_map_changed() if (type == vec3_type_name) { combo_positionAttribute->addItem(name); - if (name == setting_auto_load_position_attribute_.toString()) + if (name == setting_auto_load_position_attribute_) combo_positionAttribute->setCurrentIndex(combo_positionAttribute->count() - 1); } } diff --git a/schnapps/plugins/surface_modelisation/dialog_decimation.h b/schnapps/plugins/surface_modelisation/dialog_decimation.h index a5bd2ca..9798174 100644 --- a/schnapps/plugins/surface_modelisation/dialog_decimation.h +++ b/schnapps/plugins/surface_modelisation/dialog_decimation.h @@ -54,7 +54,7 @@ class SCHNAPPS_PLUGIN_SURFACE_MODELISATION_API Decimation_Dialog : public QDialo CMap2Handler* selected_map_; - QVariant setting_auto_load_position_attribute_; + QString setting_auto_load_position_attribute_; private slots: diff --git a/schnapps/plugins/surface_modelisation/dialog_subdivision.cpp b/schnapps/plugins/surface_modelisation/dialog_subdivision.cpp index aabb8c6..3e51ae0 100644 --- a/schnapps/plugins/surface_modelisation/dialog_subdivision.cpp +++ b/schnapps/plugins/surface_modelisation/dialog_subdivision.cpp @@ -41,9 +41,10 @@ Subdivision_Dialog::Subdivision_Dialog(SCHNApps* s, Plugin_SurfaceModelisation* { setupUi(this); - setting_auto_load_position_attribute_ = plugin_->get_setting("Auto load position attribute"); - if (!setting_auto_load_position_attribute_.isValid()) - setting_auto_load_position_attribute_ = plugin_->add_setting("Auto load position attribute", "position"); + if (plugin_->get_setting("Auto load position attribute").isValid()) + setting_auto_load_position_attribute_ = plugin_->get_setting("Auto load position attribute").toString(); + else + setting_auto_load_position_attribute_ = plugin_->add_setting("Auto load position attribute", "position").toString(); connect(schnapps_, SIGNAL(map_added(MapHandlerGen*)), this, SLOT(map_added(MapHandlerGen*))); connect(schnapps_, SIGNAL(map_removed(MapHandlerGen*)), this, SLOT(map_removed(MapHandlerGen*))); @@ -110,7 +111,7 @@ void Subdivision_Dialog::selected_map_changed() if (type == vec3_type_name) { combo_positionAttribute->addItem(name); - if (name == setting_auto_load_position_attribute_.toString()) + if (name == setting_auto_load_position_attribute_) combo_positionAttribute->setCurrentIndex(combo_positionAttribute->count() - 1); } } diff --git a/schnapps/plugins/surface_modelisation/dialog_subdivision.h b/schnapps/plugins/surface_modelisation/dialog_subdivision.h index 98b26bd..04d5255 100644 --- a/schnapps/plugins/surface_modelisation/dialog_subdivision.h +++ b/schnapps/plugins/surface_modelisation/dialog_subdivision.h @@ -54,7 +54,7 @@ class SCHNAPPS_PLUGIN_SURFACE_MODELISATION_API Subdivision_Dialog : public QDial CMap2Handler* selected_map_; - QVariant setting_auto_load_position_attribute_; + QString setting_auto_load_position_attribute_; private slots: diff --git a/schnapps/plugins/surface_render/surface_render.cpp b/schnapps/plugins/surface_render/surface_render.cpp index e76ac5a..a44cf57 100644 --- a/schnapps/plugins/surface_render/surface_render.cpp +++ b/schnapps/plugins/surface_render/surface_render.cpp @@ -54,21 +54,25 @@ MapParameters& Plugin_SurfaceRender::get_parameters(View* view, MapHandlerGen* m bool Plugin_SurfaceRender::enable() { - setting_auto_enable_on_selected_view_ = get_setting("Auto enable on selected view"); - if (!setting_auto_enable_on_selected_view_.isValid()) - setting_auto_enable_on_selected_view_ = add_setting("Auto enable on selected view", true); + if (get_setting("Auto enable on selected view").isValid()) + setting_auto_enable_on_selected_view_ = get_setting("Auto enable on selected view").toBool(); + else + setting_auto_enable_on_selected_view_ = add_setting("Auto enable on selected view", true).toBool(); - setting_auto_load_position_attribute_ = get_setting("Auto load position attribute"); - if (!setting_auto_load_position_attribute_.isValid()) - setting_auto_load_position_attribute_ = add_setting("Auto load position attribute", "position"); + if (get_setting("Auto load position attribute").isValid()) + setting_auto_load_position_attribute_ = get_setting("Auto load position attribute").toString(); + else + setting_auto_load_position_attribute_ = add_setting("Auto load position attribute", "position").toString(); - setting_auto_load_normal_attribute_ = get_setting("Auto load normal attribute"); - if (!setting_auto_load_normal_attribute_.isValid()) - setting_auto_load_normal_attribute_ = add_setting("Auto load normal attribute", "normal"); + if (get_setting("Auto load normal attribute").isValid()) + setting_auto_load_normal_attribute_ = get_setting("Auto load normal attribute").toString(); + else + setting_auto_load_normal_attribute_ = add_setting("Auto load normal attribute", "normal").toString(); - setting_auto_load_color_attribute_ = get_setting("Auto load color attribute"); - if (!setting_auto_load_color_attribute_.isValid()) - setting_auto_load_color_attribute_ = add_setting("Auto load color attribute", "color"); + if (get_setting("Auto load color attribute").isValid()) + setting_auto_load_color_attribute_ = get_setting("Auto load color attribute").toString(); + else + setting_auto_load_color_attribute_ = add_setting("Auto load color attribute", "color").toString(); dock_tab_ = new SurfaceRender_DockTab(this->schnapps_, this); schnapps_->add_plugin_dock_tab(this, dock_tab_, "Surface Render"); @@ -210,9 +214,9 @@ void Plugin_SurfaceRender::map_linked(MapHandlerGen *map) View* view = schnapps_->get_selected_view(); if (view) { - set_position_vbo(view->get_name(), map->get_name(), setting_auto_load_position_attribute_.toString()); - set_normal_vbo(view->get_name(), map->get_name(), setting_auto_load_normal_attribute_.toString()); - set_color_vbo(view->get_name(), map->get_name(), setting_auto_load_color_attribute_.toString()); + set_position_vbo(view->get_name(), map->get_name(), setting_auto_load_position_attribute_); + set_normal_vbo(view->get_name(), map->get_name(), setting_auto_load_normal_attribute_); + set_color_vbo(view->get_name(), map->get_name(), setting_auto_load_color_attribute_); } connect(map, SIGNAL(vbo_added(cgogn::rendering::VBO*)), this, SLOT(linked_map_vbo_added(cgogn::rendering::VBO*)), Qt::UniqueConnection); @@ -248,11 +252,11 @@ void Plugin_SurfaceRender::linked_map_vbo_added(cgogn::rendering::VBO* vbo) dock_tab_->add_color_vbo(vbo_name); if (view) { - if (!get_parameters(view, map).get_position_vbo() && vbo_name == setting_auto_load_position_attribute_.toString()) + if (!get_parameters(view, map).get_position_vbo() && vbo_name == setting_auto_load_position_attribute_) set_position_vbo(view->get_name(), map->get_name(), vbo_name); - if (!get_parameters(view, map).get_normal_vbo() && vbo_name == setting_auto_load_normal_attribute_.toString()) + if (!get_parameters(view, map).get_normal_vbo() && vbo_name == setting_auto_load_normal_attribute_) set_normal_vbo(view->get_name(), map->get_name(), vbo_name); - if (!get_parameters(view, map).get_color_vbo() && vbo_name == setting_auto_load_color_attribute_.toString()) + if (!get_parameters(view, map).get_color_vbo() && vbo_name == setting_auto_load_color_attribute_) set_color_vbo(view->get_name(), map->get_name(), vbo_name); } } @@ -321,7 +325,7 @@ void Plugin_SurfaceRender::viewer_initialized() void Plugin_SurfaceRender::enable_on_selected_view(Plugin* p) { - if ((this == p) && schnapps_->get_selected_view() && setting_auto_enable_on_selected_view_.toBool()) + if ((this == p) && schnapps_->get_selected_view() && setting_auto_enable_on_selected_view_) schnapps_->get_selected_view()->link_plugin(this); } diff --git a/schnapps/plugins/surface_render/surface_render.h b/schnapps/plugins/surface_render/surface_render.h index c391fdd..a2bb1b3 100644 --- a/schnapps/plugins/surface_render/surface_render.h +++ b/schnapps/plugins/surface_render/surface_render.h @@ -390,10 +390,10 @@ public slots: SurfaceRender_DockTab* dock_tab_; std::map> parameter_set_; - QVariant setting_auto_enable_on_selected_view_; - QVariant setting_auto_load_position_attribute_; - QVariant setting_auto_load_normal_attribute_; - QVariant setting_auto_load_color_attribute_; + bool setting_auto_enable_on_selected_view_; + QString setting_auto_load_position_attribute_; + QString setting_auto_load_normal_attribute_; + QString setting_auto_load_color_attribute_; }; } // namespace plugin_surface_render diff --git a/schnapps/plugins/volume_render/volume_render.cpp b/schnapps/plugins/volume_render/volume_render.cpp index 353a58d..5fdaf5e 100644 --- a/schnapps/plugins/volume_render/volume_render.cpp +++ b/schnapps/plugins/volume_render/volume_render.cpp @@ -61,13 +61,15 @@ MapParameters& Plugin_VolumeRender::get_parameters(View* view, MapHandlerGen* ma bool Plugin_VolumeRender::enable() { - setting_auto_enable_on_selected_view_ = get_setting("Auto enable on selected view"); - if (!setting_auto_enable_on_selected_view_.isValid()) - setting_auto_enable_on_selected_view_ = add_setting("Auto enable on selected view", true); + if (get_setting("Auto enable on selected view").isValid()) + setting_auto_enable_on_selected_view_ = get_setting("Auto enable on selected view").toBool(); + else + setting_auto_enable_on_selected_view_ = add_setting("Auto enable on selected view", true).toBool(); - setting_auto_load_position_attribute_ = get_setting("Auto load position attribute"); - if (!setting_auto_load_position_attribute_.isValid()) - setting_auto_load_position_attribute_ = add_setting("Auto load position attribute", "position"); + if (get_setting("Auto load position attribute").isValid()) + setting_auto_load_position_attribute_ = get_setting("Auto load position attribute").toString(); + else + setting_auto_load_position_attribute_ = add_setting("Auto load position attribute", "position").toString(); dock_tab_ = new VolumeRender_DockTab(this->schnapps_, this); schnapps_->add_plugin_dock_tab(this, dock_tab_, "Volume Render"); @@ -264,7 +266,7 @@ void Plugin_VolumeRender::map_linked(MapHandlerGen* map) { View* view = schnapps_->get_selected_view(); if (view) - set_position_vbo(view->get_name(), map->get_name(), setting_auto_load_position_attribute_.toString()); + set_position_vbo(view->get_name(), map->get_name(), setting_auto_load_position_attribute_); connect(map, SIGNAL(vbo_added(cgogn::rendering::VBO*)), this, SLOT(linked_map_vbo_added(cgogn::rendering::VBO*)), Qt::UniqueConnection); connect(map, SIGNAL(vbo_removed(cgogn::rendering::VBO*)), this, SLOT(linked_map_vbo_removed(cgogn::rendering::VBO*)), Qt::UniqueConnection); @@ -301,7 +303,7 @@ void Plugin_VolumeRender::linked_map_vbo_added(cgogn::rendering::VBO* vbo) View* view = schnapps_->get_selected_view(); if (view) { - if (!get_parameters(view, map).get_position_vbo() && vbo_name == setting_auto_load_position_attribute_.toString()) + if (!get_parameters(view, map).get_position_vbo() && vbo_name == setting_auto_load_position_attribute_) set_position_vbo(view->get_name(), map->get_name(), vbo_name); } } @@ -405,7 +407,7 @@ void Plugin_VolumeRender::viewer_initialized() void Plugin_VolumeRender::enable_on_selected_view(Plugin* p) { - if ((this == p) && schnapps_->get_selected_view() && setting_auto_enable_on_selected_view_.toBool()) + if ((this == p) && schnapps_->get_selected_view() && setting_auto_enable_on_selected_view_) schnapps_->get_selected_view()->link_plugin(this); } diff --git a/schnapps/plugins/volume_render/volume_render.h b/schnapps/plugins/volume_render/volume_render.h index 0c017ee..211719a 100644 --- a/schnapps/plugins/volume_render/volume_render.h +++ b/schnapps/plugins/volume_render/volume_render.h @@ -27,6 +27,10 @@ #define SCHNAPPS_PLUGIN_VOLUME_RENDER_H_ #include "dll.h" + +#include +#include + #include #include #include @@ -34,9 +38,6 @@ #include -#include -#include - #include #include #include @@ -141,9 +142,9 @@ struct SCHNAPPS_PLUGIN_VOLUME_RENDER_API MapParameters { transparency_factor_ = transparency_factor_ % 255; face_color_.setAlpha(transparency_factor_); - } else { - face_color_.setAlpha(255); } + else + face_color_.setAlpha(255); set_face_color(face_color_); } @@ -160,7 +161,9 @@ struct SCHNAPPS_PLUGIN_VOLUME_RENDER_API MapParameters float32 d = -(position.dot(axis_z)); volume_drawer_rend_->set_clipping_plane(QVector4D(axis_z[0], axis_z[1], axis_z[2], d)); topo_drawer_rend_->set_clipping_plane(QVector4D(axis_z[0], axis_z[1], axis_z[2], d)); - } else { + } + else + { volume_drawer_rend_->set_clipping_plane(QVector4D(0, 0, 0, 0)); topo_drawer_rend_->set_clipping_plane(QVector4D(0, 0, 0, 0)); } @@ -177,9 +180,8 @@ struct SCHNAPPS_PLUGIN_VOLUME_RENDER_API MapParameters } private: - void initialize_gl(); -private: + void initialize_gl(); MapHandler* map_; @@ -354,8 +356,8 @@ public slots: VolumeRender_DockTab* dock_tab_; std::map> parameter_set_; - QVariant setting_auto_enable_on_selected_view_; - QVariant setting_auto_load_position_attribute_; + bool setting_auto_enable_on_selected_view_; + QString setting_auto_load_position_attribute_; }; } // namespace plugin_volume_render