diff --git a/Applications/DataExplorer/DataView/NetCdfConfigureDialog.cpp b/Applications/DataExplorer/DataView/NetCdfConfigureDialog.cpp index b23b0c01a2c605bc38a4fd326bb12736a4d10cd1..8478ac346fff02ba2ea27c0ae1cfcb826b63cccc 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 ef0b98b0b86c20b4cb09b341037eee543a1c9108..8553c052f485d975d6ed8e4b9966357343e952d7 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 5e968c2938c4dda87cd05579324c537d3fa15329..0432cda1dd14489672b76c541b4629cd4e588cd3 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 de87a33f3d6bf0e54689d885bf883b7bd51a9c11..cc1847807490f63b73db3fee52e19f5edc17c90a 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 3118da26ccc65560e1a3f66e65194c5a2cf44d92..c7847299083b0fec34b72913edff3f19550a3eac 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 dbfa2a1b7ad8bae42552aa7553d7833e3a5ebe32..a1f9618de7f01a26b0fb54ac275b92e35037ab09 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 4a71dbeae4b1132a9016498168a3d681d33cd864..1a64695b7bea4e174bf064272c6772308f549b0e 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 91ec860a32e23364b71a73a10d48a088b51d8884..a867aa90832419128a376b28529d4a8a79aeea0f 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 8dc79d771d6dc33b9923817467373070d14493fe..652d8da8dbaf43d13190b93c3d1f55ded585382c 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 14e77997e2b8b4d36d99648ce309af359e0418f8..72e9a4b8f87c1d5c9a912bddc939957e0a24ad6a 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 1c1fe607d082b37e9277afb4188b1955c089b35c..c398d1ec773ac9f7cf49f8cd21fa79b5f838fe8c 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)