From f43d9d2b18cb6c734b80ecaad61e12ec171bc905 Mon Sep 17 00:00:00 2001 From: Karsten Rink <karsten.rink@ufz.de> Date: Wed, 16 Mar 2011 17:22:51 +0100 Subject: [PATCH] added mesh quality selection dialog --- DataView/CMakeLists.txt | 3 + DataView/MshModel.cpp | 8 +- DataView/MshQualitySelection.ui | 101 +++++++++++++++++++++++++ DataView/MshQualitySelectionDialog.cpp | 39 ++++++++++ DataView/MshQualitySelectionDialog.h | 38 ++++++++++ Gui/mainwindow.cpp | 12 ++- Gui/mainwindow.h | 1 + VtkVis/VtkVisPipeline.cpp | 25 ++++-- VtkVis/VtkVisPipeline.h | 3 +- 9 files changed, 217 insertions(+), 13 deletions(-) create mode 100644 DataView/MshQualitySelection.ui create mode 100644 DataView/MshQualitySelectionDialog.cpp create mode 100644 DataView/MshQualitySelectionDialog.h diff --git a/DataView/CMakeLists.txt b/DataView/CMakeLists.txt index cb0ffa78e1a..bfbd2b2eb7b 100644 --- a/DataView/CMakeLists.txt +++ b/DataView/CMakeLists.txt @@ -21,6 +21,7 @@ set( SOURCES MshItem.cpp MshLayerMapper.cpp MshModel.cpp + MshQualitySelectionDialog.cpp MshTabWidget.cpp OGSRaster.cpp QueryResultsDialog.cpp @@ -52,6 +53,7 @@ set( MOC_HEADERS ListPropertiesDialog.h MshEditDialog.h MshModel.h + MshQualitySelectionDialog.h MshTabWidget.h QueryResultsDialog.h SHPImportDialog.h @@ -83,6 +85,7 @@ set( UIS GMSHPrefs.ui LineEdit.ui MshEdit.ui + MshQualitySelection.ui MshTabWidgetBase.ui StationTabWidgetBase.ui VisPrefs.ui diff --git a/DataView/MshModel.cpp b/DataView/MshModel.cpp index 933caec0dbc..0fa6009e98f 100644 --- a/DataView/MshModel.cpp +++ b/DataView/MshModel.cpp @@ -193,17 +193,17 @@ Mesh_Group::CFEMesh* MshModel::loadMeshFromFile(std::string fileName) QTime constructTimer; constructTimer.start(); #endif -/* + msh->ConstructGrid(); -*/ + std::cout << "Nr. Nodes: " << msh->nod_vector.size() << endl; std::cout << "Nr. Elements: " << msh->ele_vector.size() << endl; -/* + #ifndef NDEBUG std::cout << "constructGrid time: " << constructTimer.elapsed() << " ms" << std::endl; #endif msh->FillTransformMatrix(); -*/ + #ifndef NDEBUG std::cout << "Loading time: " << myTimer.elapsed() << " ms" << std::endl; #endif diff --git a/DataView/MshQualitySelection.ui b/DataView/MshQualitySelection.ui new file mode 100644 index 00000000000..d082f66f6f3 --- /dev/null +++ b/DataView/MshQualitySelection.ui @@ -0,0 +1,101 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MshQualitySelection</class> + <widget class="QDialog" name="MshQualitySelection"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>247</width> + <height>257</height> + </rect> + </property> + <property name="windowTitle"> + <string>Mesh Quality Selection</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QGroupBox" name="groupBox"> + <property name="title"> + <string>Select Quality Measure</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QRadioButton" name="choiceEdges"> + <property name="text"> + <string>Aspect Ratio of Edge Length</string> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="choiceArea"> + <property name="text"> + <string>Area of 2D Elements</string> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="choiceVolume"> + <property name="text"> + <string>Volume of 3D Elements</string> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="choiceAngles"> + <property name="text"> + <string>Angles between Adjacent Edges</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>MshQualitySelection</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>MshQualitySelection</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui> diff --git a/DataView/MshQualitySelectionDialog.cpp b/DataView/MshQualitySelectionDialog.cpp new file mode 100644 index 00000000000..01f91e1978a --- /dev/null +++ b/DataView/MshQualitySelectionDialog.cpp @@ -0,0 +1,39 @@ +/** + * \file MshQualitySelectionDialog.cpp + * 2011/03/16 KR Initial implementation + */ + +#include "MshQualitySelectionDialog.h" +#include "VtkMeshSource.h" + +/// Constructor +MshQualitySelectionDialog::MshQualitySelectionDialog(VtkMeshSource* msh, QDialog* parent) +: _msh(msh), QDialog(parent) +{ + setupUi(this); + this->choiceEdges->toggle(); +} + +MshQualitySelectionDialog::~MshQualitySelectionDialog() +{ +} + +/// Instructions if the OK-Button has been pressed. +void MshQualitySelectionDialog::accept() +{ + MshQualityType::type t; + if (this->choiceEdges->isChecked()) t = MshQualityType::EDGERATIO; + else if (this->choiceArea->isChecked()) t = MshQualityType::AREA; + else if (this->choiceVolume->isChecked()) t = MshQualityType::VOLUME; + else if (this->choiceAngles->isChecked()) t = MshQualityType::EQUIANGLESKEW; + else t = MshQualityType::INVALID; + + emit measureSelected(_msh, t); + this->done(QDialog::Accepted); +} + +/// Instructions if the Cancel-Button has been pressed. +void MshQualitySelectionDialog::reject() +{ + this->done(QDialog::Rejected); +} diff --git a/DataView/MshQualitySelectionDialog.h b/DataView/MshQualitySelectionDialog.h new file mode 100644 index 00000000000..4f12fb02fe1 --- /dev/null +++ b/DataView/MshQualitySelectionDialog.h @@ -0,0 +1,38 @@ +/** + * \file MshQualitySelectionDialog.h + * 2011/03/16 KR Initial implementation + */ + +#ifndef MSHQUALITYSELECTIONDIALOG_H +#define MSHQUALITYSELECTIONDIALOG_H + + +#include "ui_MshQualitySelection.h" +#include "MshEnums.h" + +class VtkMeshSource; + +/** + * \brief A dialog window for settung up a database connection + */ +class MshQualitySelectionDialog : public QDialog, private Ui_MshQualitySelection +{ + Q_OBJECT + +public: + MshQualitySelectionDialog(VtkMeshSource* msh, QDialog* parent = 0); + ~MshQualitySelectionDialog(void); + +private: + VtkMeshSource* _msh; + +private slots: + void accept(); + void reject(); + +signals: + void measureSelected(VtkMeshSource*, MshQualityType::type); + +}; + +#endif //MSHQUALITYSELECTIONDIALOG_H diff --git a/Gui/mainwindow.cpp b/Gui/mainwindow.cpp index b539976d5e8..98f7ed43d7e 100644 --- a/Gui/mainwindow.cpp +++ b/Gui/mainwindow.cpp @@ -19,6 +19,7 @@ #include "GMSHPrefsDialog.h" #include "LineEditDialog.h" #include "ListPropertiesDialog.h" +#include "MshQualitySelectionDialog.h" #include "SHPImportDialog.h" #include "VtkAddFilterDialog.h" #include "VisPrefsDialog.h" @@ -149,7 +150,8 @@ MainWindow::MainWindow(QWidget *parent /* = 0*/) connect(mshTabWidget, SIGNAL(requestMeshRemoval(const QModelIndex&)), _meshModels, SLOT(removeMesh(const QModelIndex&))); connect(mshTabWidget, SIGNAL(qualityCheckRequested(VtkMeshSource*)), - _vtkVisPipeline, SLOT(checkMeshQuality(VtkMeshSource*))); + this, SLOT(showMshQualitySelectionDialog(VtkMeshSource*))); + // Setup connections for condition model to GUI conditionTabWidget->treeView->setModel(_conditionModel); @@ -988,6 +990,14 @@ void MainWindow::showGMSHPrefsDialog() dlg.exec(); } +void MainWindow::showMshQualitySelectionDialog(VtkMeshSource* mshSource) +{ + MshQualitySelectionDialog dlg(mshSource); + connect(&dlg, SIGNAL(measureSelected(VtkMeshSource*, MshQualityType::type)), + _vtkVisPipeline, SLOT(checkMeshQuality(VtkMeshSource*, MshQualityType::type))); + dlg.exec(); +} + void MainWindow::showVisalizationPrefsDialog() { VisPrefsDialog dlg(_vtkVisPipeline); diff --git a/Gui/mainwindow.h b/Gui/mainwindow.h index e2356d93717..f60aa821e60 100644 --- a/Gui/mainwindow.h +++ b/Gui/mainwindow.h @@ -73,6 +73,7 @@ protected slots: void showDiagramPrefsDialog(QModelIndex &index); void showLineEditDialog(const std::string &geoName); void showGMSHPrefsDialog(); + void showMshQualitySelectionDialog(VtkMeshSource* mshSource); void showPropertiesDialog(std::string name); void showVisalizationPrefsDialog(); void showTrackingSettingsDialog(); diff --git a/VtkVis/VtkVisPipeline.cpp b/VtkVis/VtkVisPipeline.cpp index 66de9281150..de0b171a6f0 100644 --- a/VtkVis/VtkVisPipeline.cpp +++ b/VtkVis/VtkVisPipeline.cpp @@ -402,15 +402,24 @@ void VtkVisPipeline::listArrays(vtkDataSet* dataSet) std::cout << "Error loading vtk file: not a valid vtkDataSet." << std::endl; } -void VtkVisPipeline::checkMeshQuality(VtkMeshSource* source) +void VtkVisPipeline::checkMeshQuality(VtkMeshSource* source, MshQualityType::type t) { if (source) { const Mesh_Group::CFEMesh* mesh = source->GetGrid()->getCFEMesh(); -// Mesh_Group::MeshQualityShortestLongestRatio checker (mesh); - Mesh_Group::MeshQualityNormalisedVolumes checker (mesh); - checker.check (); + Mesh_Group::MeshQualityChecker* checker (NULL); + if (t == MshQualityType::EDGERATIO) checker = new Mesh_Group::MeshQualityShortestLongestRatio(mesh); + else if (t == MshQualityType::AREA) checker = new Mesh_Group::MeshQualityNormalisedVolumes(mesh); + else if (t == MshQualityType::VOLUME) checker = new Mesh_Group::MeshQualityNormalisedVolumes(mesh); //HACK replace by correct measurement! + else if (t == MshQualityType::EQUIANGLESKEW) checker = new Mesh_Group::MeshQualityShortestLongestRatio(mesh); //HACK replace by correct measurement! + else + { + std::cout << "Error in VtkVisPipeline::checkMeshQuality() - Unknown MshQualityType..." << std::endl; + delete checker; + return; + } + checker->check (); - std::vector<double> quality = checker.getMeshQuality(); + std::vector<double> quality = checker->getMeshQuality(); int nSources = this->_rootItem->childCount(); for (int i=0; i<nSources; i++) @@ -428,7 +437,7 @@ void VtkVisPipeline::checkMeshQuality(VtkMeshSource* source) } } - /* *** write histogram *** */ + /* *** write histogram *** * // simple suggestion: number of classes with Sturges criterion // size_t nclasses (static_cast<size_t>(1 + 3.3 * log (static_cast<float>((mesh->getElementVector()).size())))); // bool ok; @@ -436,12 +445,14 @@ void VtkVisPipeline::checkMeshQuality(VtkMeshSource* source) // if (ok) ... size_t size (1000); std::vector<size_t> histogramm (size,0); - checker.getHistogramm(histogramm); + checker->getHistogramm(histogramm); std::ofstream out ("mesh_histogramm.txt"); const size_t histogramm_size (histogramm.size()); for (size_t k(0); k<histogramm_size; k++) { out << k/static_cast<double>(histogramm_size) << " " << histogramm[k] << std::endl; } out.close (); + */ + delete checker; } } diff --git a/VtkVis/VtkVisPipeline.h b/VtkVis/VtkVisPipeline.h index 37ee3384cd6..49a42a673b8 100644 --- a/VtkVis/VtkVisPipeline.h +++ b/VtkVis/VtkVisPipeline.h @@ -14,6 +14,7 @@ #include "Color.h" #include "Point.h" #include "GeoType.h" +#include "MshEnums.h" #include <QVector> #include <QMap> @@ -103,7 +104,7 @@ public slots: void removePipelineItem(QModelIndex index); /// Checks the quality of a mesh and cal a filter to highlight deformed elements. - void checkMeshQuality(VtkMeshSource* mesh); + void checkMeshQuality(VtkMeshSource* mesh, MshQualityType::type t); private: void listArrays(vtkDataSet* dataSet); -- GitLab