From 2f2aedd2d3e6a33b1049b49429180f755088c3e2 Mon Sep 17 00:00:00 2001 From: Lars Bilke <lars.bilke@ufz.de> Date: Fri, 26 Sep 2014 12:25:09 +0200 Subject: [PATCH] Moved VtkMeshConverter to MeshLib/MeshGenerators. Builds now both in CLI as well as GUI configuration. --- .../DataView/NetCdfConfigureDialog.cpp | 12 ++++---- .../DataExplorer/VtkVis/CMakeLists.txt | 2 -- .../VtkVis/MeshFromRasterDialog.cpp | 7 +++-- .../VtkVis/MeshFromRasterDialog.h | 9 ++++-- .../VtkVis/VtkVisPipelineView.cpp | 12 ++++---- .../DataExplorer/VtkVis/VtkVisPipelineView.h | 6 ++-- FileIO/VtkIO/VtuInterface.cpp | 29 ++++++++++++++++++- FileIO/VtkIO/VtuInterface.h | 3 ++ .../MeshGenerators}/VtkMeshConverter.cpp | 3 ++ .../MeshGenerators}/VtkMeshConverter.h | 10 ++++--- Tests/CMakeLists.txt | 2 ++ 11 files changed, 70 insertions(+), 25 deletions(-) rename {Applications/DataExplorer/VtkVis => MeshLib/MeshGenerators}/VtkMeshConverter.cpp (99%) rename {Applications/DataExplorer/VtkVis => MeshLib/MeshGenerators}/VtkMeshConverter.h (98%) diff --git a/Applications/DataExplorer/DataView/NetCdfConfigureDialog.cpp b/Applications/DataExplorer/DataView/NetCdfConfigureDialog.cpp index b23b0c01a2c..8478ac346ff 100644 --- a/Applications/DataExplorer/DataView/NetCdfConfigureDialog.cpp +++ b/Applications/DataExplorer/DataView/NetCdfConfigureDialog.cpp @@ -3,7 +3,7 @@ #include "NetCdfConfigureDialog.h" -#include "VtkMeshConverter.h" +#include "MeshGenerators/VtkMeshConverter.h" #include "VtkGeoImageSource.h" #include "VtkRaster.h" @@ -361,8 +361,8 @@ void NetCdfConfigureDialog::createDataObject() if (this->radioMesh->isChecked()) { MeshElemType meshElemType = MeshElemType::QUAD; - UseIntensityAs useIntensity = UseIntensityAs::MATERIAL; - if ((comboBoxMeshElemType->currentIndex()) == 1) + MeshLib::UseIntensityAs useIntensity = MeshLib::UseIntensityAs::MATERIAL; + if ((comboBoxMeshElemType->currentIndex()) == 1) { meshElemType = MeshElemType::TRIANGLE; }else{ @@ -370,12 +370,12 @@ void NetCdfConfigureDialog::createDataObject() } if ((comboBoxUseIntensity->currentIndex()) == 1) { - useIntensity = UseIntensityAs::ELEVATION; + useIntensity = MeshLib::UseIntensityAs::ELEVATION; }else{ - useIntensity = UseIntensityAs::MATERIAL; + useIntensity = MeshLib::UseIntensityAs::MATERIAL; } - _currentMesh = VtkMeshConverter::convertImgToMesh(data_array,originNetCdf,sizeLon,sizeLat,resolution,meshElemType,useIntensity); + _currentMesh = MeshLib::VtkMeshConverter::convertImgToMesh(data_array,originNetCdf,sizeLon,sizeLat,resolution,meshElemType,useIntensity); } else { diff --git a/Applications/DataExplorer/VtkVis/CMakeLists.txt b/Applications/DataExplorer/VtkVis/CMakeLists.txt index ef0b98b0b86..8553c052f48 100644 --- a/Applications/DataExplorer/VtkVis/CMakeLists.txt +++ b/Applications/DataExplorer/VtkVis/CMakeLists.txt @@ -27,7 +27,6 @@ SET( SOURCES VtkFilterFactory.cpp VtkGeoImageSource.cpp VtkImageDataToLinePolyDataFilter.cpp - VtkMeshConverter.cpp VtkMeshSource.cpp VtkPolylinesSource.cpp VtkPointsSource.cpp @@ -82,7 +81,6 @@ SET( HEADERS VtkFilterFactory.h VtkGeoImageSource.h VtkImageDataToLinePolyDataFilter.h - VtkMeshConverter.h VtkMeshSource.h VtkPolylinesSource.h VtkPointsSource.h diff --git a/Applications/DataExplorer/VtkVis/MeshFromRasterDialog.cpp b/Applications/DataExplorer/VtkVis/MeshFromRasterDialog.cpp index 5e968c2938c..0432cda1dd1 100644 --- a/Applications/DataExplorer/VtkVis/MeshFromRasterDialog.cpp +++ b/Applications/DataExplorer/VtkVis/MeshFromRasterDialog.cpp @@ -14,6 +14,7 @@ #include "MeshFromRasterDialog.h" #include "OGSError.h" +#include "MeshGenerators/VtkMeshConverter.h" MeshFromRasterDialog::MeshFromRasterDialog(QDialog* parent) : QDialog(parent) @@ -33,9 +34,9 @@ MeshFromRasterDialog::~MeshFromRasterDialog() void MeshFromRasterDialog::accept() { - UseIntensityAs i_type(UseIntensityAs::ELEVATION); - if (this->materialButton->isChecked()) i_type = UseIntensityAs::MATERIAL; - else if (this->ignoreButton->isChecked()) i_type = UseIntensityAs::NONE; + MeshLib::UseIntensityAs i_type(MeshLib::UseIntensityAs::ELEVATION); + if (this->materialButton->isChecked()) i_type = MeshLib::UseIntensityAs::MATERIAL; + else if (this->ignoreButton->isChecked()) i_type = MeshLib::UseIntensityAs::NONE; MeshElemType e_type(MeshElemType::TRIANGLE); if (this->quadButton->isChecked()) e_type = MeshElemType::QUAD; diff --git a/Applications/DataExplorer/VtkVis/MeshFromRasterDialog.h b/Applications/DataExplorer/VtkVis/MeshFromRasterDialog.h index de87a33f3d6..cc184780749 100644 --- a/Applications/DataExplorer/VtkVis/MeshFromRasterDialog.h +++ b/Applications/DataExplorer/VtkVis/MeshFromRasterDialog.h @@ -16,10 +16,15 @@ #define MSHFROMRASTERDIALOG_H #include "ui_MeshFromRaster.h" -#include "VtkMeshConverter.h" #include <QtGui/QDialog> +enum class MeshElemType; + +namespace MeshLib { + enum class UseIntensityAs; +} + /** * \brief A dialog for specifying the parameters to construct a mesh based on a raster @@ -42,7 +47,7 @@ private slots: void reject(); signals: - void setMeshParameters(QString, MeshElemType, UseIntensityAs); + void setMeshParameters(QString, MeshElemType, MeshLib::UseIntensityAs); }; diff --git a/Applications/DataExplorer/VtkVis/VtkVisPipelineView.cpp b/Applications/DataExplorer/VtkVis/VtkVisPipelineView.cpp index 3118da26ccc..c7847299083 100644 --- a/Applications/DataExplorer/VtkVis/VtkVisPipelineView.cpp +++ b/Applications/DataExplorer/VtkVis/VtkVisPipelineView.cpp @@ -15,6 +15,9 @@ // ** INCLUDES ** #include "VtkVisPipelineView.h" +#include "Mesh.h" +#include "MeshGenerators/VtkMeshConverter.h" + #include "OGSError.h" #include "CheckboxDelegate.h" @@ -34,7 +37,6 @@ #include <QMessageBox> //image to mesh conversion -#include "Mesh.h" #include "VtkGeoImageSource.h" #include <vtkImageData.h> #include "MeshFromRasterDialog.h" @@ -200,7 +202,7 @@ void VtkVisPipelineView::showImageToMeshConversionDialog() dlg->exec(); } -void VtkVisPipelineView::constructMeshFromImage(QString msh_name, MeshElemType element_type, UseIntensityAs intensity_type) +void VtkVisPipelineView::constructMeshFromImage(QString msh_name, MeshElemType element_type, MeshLib::UseIntensityAs intensity_type) { vtkSmartPointer<vtkAlgorithm> algorithm = static_cast<VtkVisPipelineItem*>(static_cast<VtkVisPipeline*>(this->model())-> @@ -212,7 +214,7 @@ void VtkVisPipelineView::constructMeshFromImage(QString msh_name, MeshElemType e double spacing[3]; imageSource->GetOutput()->GetSpacing(spacing); - MeshLib::Mesh* mesh = VtkMeshConverter::convertImgToMesh(imageSource->GetOutput(), origin, spacing[0], element_type, intensity_type); + MeshLib::Mesh* mesh = MeshLib::VtkMeshConverter::convertImgToMesh(imageSource->GetOutput(), origin, spacing[0], element_type, intensity_type); if (mesh) { mesh->setName(msh_name.toStdString()); @@ -246,7 +248,7 @@ void VtkVisPipelineView::convertVTKToOGSMesh() grid = vtkUnstructuredGrid::SafeDownCast(xmlReader->GetOutput()); } } - MeshLib::Mesh* mesh = VtkMeshConverter::convertUnstructuredGrid(grid); + MeshLib::Mesh* mesh = MeshLib::VtkMeshConverter::convertUnstructuredGrid(grid); mesh->setName(item->data(0).toString().toStdString()); emit meshAdded(mesh); } @@ -280,7 +282,7 @@ void VtkVisPipelineView::selectionChanged( const QItemSelection &selected, void VtkVisPipelineView::selectItem(vtkProp3D* actor) { - this->selectItem(static_cast<VtkVisPipeline*>(this->model())->getIndex(actor)); + this->selectItem(static_cast<VtkVisPipeline*>(this->model())->getIndex(actor)); } void VtkVisPipelineView::selectItem(const QModelIndex &index) diff --git a/Applications/DataExplorer/VtkVis/VtkVisPipelineView.h b/Applications/DataExplorer/VtkVis/VtkVisPipelineView.h index dbfa2a1b7ad..a1f9618de7f 100644 --- a/Applications/DataExplorer/VtkVis/VtkVisPipelineView.h +++ b/Applications/DataExplorer/VtkVis/VtkVisPipelineView.h @@ -17,7 +17,6 @@ // ** INCLUDES ** #include <QTreeView> -#include "VtkMeshConverter.h" class QItemSelection; class QAbstractItemModel; @@ -25,8 +24,11 @@ class VtkVisPipelineItem; class vtkProp3D; class vtkDataObject; +enum class MeshElemType; + namespace MeshLib { class Mesh; + enum class UseIntensityAs; } /** @@ -74,7 +76,7 @@ private slots: void addPipelineFilterItem(); /// Calls the conversion method for creating an OGS Mesh from a vtkImageData object. - void constructMeshFromImage(QString msh_name, MeshElemType element_type, UseIntensityAs intensity_type); + void constructMeshFromImage(QString msh_name, MeshElemType element_type, MeshLib::UseIntensityAs intensity_type); /// Calls the dialog to void showImageToMeshConversionDialog(); diff --git a/FileIO/VtkIO/VtuInterface.cpp b/FileIO/VtkIO/VtuInterface.cpp index 4a71dbeae4b..1a64695b7be 100644 --- a/FileIO/VtkIO/VtuInterface.cpp +++ b/FileIO/VtkIO/VtuInterface.cpp @@ -14,6 +14,9 @@ #include "VtuInterface.h" #include "Mesh.h" +#include "MeshGenerators/VtkMeshConverter.h" + +#include "logog/include/logog.hpp" #include <vtkXMLUnstructuredGridReader.h> #include <vtkSmartPointer.h> @@ -37,7 +40,31 @@ MeshLib::Mesh* VtuInterface::readVTUFile(const std::string &file_name) reader->SetFileName(file_name.c_str()); reader->Update(); - return nullptr; + vtkUnstructuredGrid* vtkGrid = reader->GetOutput(); + + return MeshLib::VtkMeshConverter::convertUnstructuredGrid(vtkGrid); +} + +void VtuInterface::setMesh(const MeshLib::Mesh* mesh) +{ + if (!mesh) + { + ERR("VtuInterface::write(): No mesh specified."); + return; + } + this->_mesh = const_cast<MeshLib::Mesh*>(mesh); +}; + +bool VtuInterface::write() +{ + if(!_mesh) + { + ERR("VtuInterface::write(): No mesh specified."); + return false; + } + + // TODO write with MappedMesh + return false; } } diff --git a/FileIO/VtkIO/VtuInterface.h b/FileIO/VtkIO/VtuInterface.h index 91ec860a32e..a867aa90832 100644 --- a/FileIO/VtkIO/VtuInterface.h +++ b/FileIO/VtkIO/VtuInterface.h @@ -41,6 +41,9 @@ public: /// Decide if the mesh data should be written compressed (default is false). void setCompressData(bool flag=true) { _use_compressor = flag; }; + /// Sets the mesh to write. + void setMesh(const MeshLib::Mesh* mesh); + private: bool write(); diff --git a/Applications/DataExplorer/VtkVis/VtkMeshConverter.cpp b/MeshLib/MeshGenerators/VtkMeshConverter.cpp similarity index 99% rename from Applications/DataExplorer/VtkVis/VtkMeshConverter.cpp rename to MeshLib/MeshGenerators/VtkMeshConverter.cpp index 8dc79d771d6..652d8da8dba 100644 --- a/Applications/DataExplorer/VtkVis/VtkMeshConverter.cpp +++ b/MeshLib/MeshGenerators/VtkMeshConverter.cpp @@ -39,6 +39,7 @@ #include <vtkUnstructuredGrid.h> #include <vtkFloatArray.h> +namespace MeshLib { MeshLib::Mesh* VtkMeshConverter::convertImgToMesh(vtkImageData* img, const double origin[3], @@ -368,3 +369,5 @@ double VtkMeshConverter::getExistingValue(const double* img, size_t length) } return -9999; } + +} // end namespace MeshLib diff --git a/Applications/DataExplorer/VtkVis/VtkMeshConverter.h b/MeshLib/MeshGenerators/VtkMeshConverter.h similarity index 98% rename from Applications/DataExplorer/VtkVis/VtkMeshConverter.h rename to MeshLib/MeshGenerators/VtkMeshConverter.h index 14e77997e2b..72e9a4b8f87 100644 --- a/Applications/DataExplorer/VtkVis/VtkMeshConverter.h +++ b/MeshLib/MeshGenerators/VtkMeshConverter.h @@ -16,15 +16,15 @@ #ifndef VTKMESHCONVERTER_H #define VTKMESHCONVERTER_H -namespace MeshLib { - class Mesh; -} - #include "MeshEnums.h" class vtkImageData; // For conversion from Image to QuadMesh class vtkUnstructuredGrid; // For conversion vom vtk to ogs mesh +namespace MeshLib { + +class Mesh; + /// Selection of possible interpretations for intensities enum class UseIntensityAs { @@ -82,4 +82,6 @@ private: static double getExistingValue(const double* img, std::size_t length); }; +} // end namespace MeshLib + #endif // VTKMESHCONVERTER_H diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 1c1fe607d08..c398d1ec773 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -63,6 +63,8 @@ IF(OGS_BUILD_GUI) VtkVis ${VTK_LIBRARIES} ) +ELSE() + TARGET_LINK_LIBRARIES(testrunner vtkIO) ENDIF() IF (QT4_FOUND) -- GitLab