OGS
VtkCompositeTextureOnSurfaceFilter.cpp
Go to the documentation of this file.
1
16
17#include <vtkDataSetSurfaceFilter.h>
18#include <vtkSmartPointer.h>
19#include <vtkUnstructuredGrid.h>
20
21#include "BaseLib/Logging.h"
22#include "VtkGeoImageSource.h"
23#include "VtkRaster.h"
25#ifdef OGS_USE_NETCDF
27#endif // OGS_USE_NETCDF
28
29#include <QFileDialog>
30#include <QFileInfo>
31#include <QSettings>
32
34 vtkAlgorithm* inputAlgorithm)
35 : VtkCompositeFilter(inputAlgorithm)
36{
37 this->init();
38}
39
41 default;
42
44{
45 this->_inputDataObjectType = VTK_DATA_SET;
46 this->_outputDataObjectType = VTK_POLY_DATA;
47
48 vtkSmartPointer<vtkDataSetSurfaceFilter> surfaceFilter;
50
51 if (dynamic_cast<vtkUnstructuredGrid*>(
52 _inputAlgorithm->GetOutputDataObject(0)))
53 {
54 surfaceFilter = vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
55 surfaceFilter->SetInputConnection(_inputAlgorithm->GetOutputPort());
56 surface->SetInputConnection(surfaceFilter->GetOutputPort());
57 }
58 else
59 {
60 surface->SetInputConnection(_inputAlgorithm->GetOutputPort());
61 }
62
63 QWidget* parent = nullptr;
64 QSettings settings;
65 QString fileName = QFileDialog::getOpenFileName(
66 parent, "Select raster file to apply as texture",
67 settings.value("lastOpenedTextureFileDirectory").toString(),
68 "Raster files (*.asc *.grd *.bmp *.jpg *.png *.tif);;"
69#ifdef OGS_USE_NETCDF
70 "NetCDF files (*.nc);;"
71#endif // OGS_USE_NETCDF
72 );
73 QFileInfo fi(fileName);
74
75 if ((fi.suffix().toLower() == "asc") || (fi.suffix().toLower() == "tif") ||
76 (fi.suffix().toLower() == "png") || (fi.suffix().toLower() == "grd") ||
77 (fi.suffix().toLower() == "jpg") || (fi.suffix().toLower() == "bmp"))
78 {
79 std::string name = fileName.toStdString();
80 vtkImageAlgorithm* image = VtkRaster::loadImage(name);
81 surface->SetRaster(image);
82 surface->Update();
83
84 QDir dir = QDir(fileName);
85 settings.setValue("lastOpenedTextureFileDirectory", dir.absolutePath());
86 }
87#ifdef OGS_USE_NETCDF
88 else if (fi.suffix().toLower() == "nc")
89 {
90 NetCdfConfigureDialog dlg(fileName.toStdString().c_str());
91 dlg.exec();
92 if (dlg.getRaster() != nullptr)
93 {
94 VtkGeoImageSource* image = dlg.getRaster();
95 surface->SetRaster(image);
96 surface->Update();
97 }
98 }
99#endif // OGS_USE_NETCDF
100 else
101 ERR("VtkCompositeTextureOnSurfaceFilter::init(): Error reading texture "
102 "file.");
103
104 _outputAlgorithm = surface;
105}
106
108 QVariant value)
109{
111}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
Definition of the VtkCompositeTextureOnSurfaceFilter class.
Definition of the VtkGeoImageSource class.
Definition of the VtkRaster class.
Definition of the VtkTextureOnSurfaceFilter class.
The dialog for converting data from NetCDF-files into OGS data structures. While NetCDF files can inc...
VtkGeoImageSource * getRaster()
virtual void SetUserProperty(QString name, QVariant value)
Sets a user property. This should be implemented by subclasses.
Is used to combine several filter in one VtkVisPipelineItem. You can use vtk filter and custom filter...
vtkAlgorithm * _outputAlgorithm
vtkAlgorithm * _inputAlgorithm
VtkCompositeTextureOnSurfaceFilter(vtkAlgorithm *inputAlgorithm)
void SetUserProperty(QString name, QVariant value) override
Sets a user property. This should be implemented by subclasses.
The VtkVisPipeline source object of a geo-referenced image (file).
static vtkImageAlgorithm * loadImage(const std::string &fileName)
Loads an image- or raster-file into an vtkImageAlgorithm-Object.
Definition VtkRaster.cpp:43
Filter class for assigning a texture to a surface.
static VtkTextureOnSurfaceFilter * New()
Create new objects with New() because of VTKs object reference counting.
void SetRaster(vtkImageAlgorithm *img)
Sets the raster/image to be used as a texture map.