OGS
VtkCompositeTextureOnSurfaceFilter.cpp
Go to the documentation of this file.
1 
15 // ** INCLUDES **
17 
18 #include <vtkDataSetSurfaceFilter.h>
19 #include <vtkSmartPointer.h>
20 #include <vtkUnstructuredGrid.h>
21 
22 #include "BaseLib/Logging.h"
23 #include "VtkGeoImageSource.h"
24 #include "VtkRaster.h"
26 #ifdef OGS_USE_NETCDF
27 #include "NetCdfConfigureDialog.h"
28 #endif // OGS_USE_NETCDF
29 
30 #include <QFileDialog>
31 #include <QFileInfo>
32 #include <QSettings>
33 
34 //#include "VtkCompositeColormapToImageFilter.h"
35 
37  vtkAlgorithm* inputAlgorithm)
38  : VtkCompositeFilter(inputAlgorithm)
39 {
40  this->init();
41 }
42 
44  default;
45 
47 {
48  this->_inputDataObjectType = VTK_DATA_SET;
49  this->_outputDataObjectType = VTK_POLY_DATA;
50 
51  vtkSmartPointer<vtkDataSetSurfaceFilter> surfaceFilter;
53 
54  if (dynamic_cast<vtkUnstructuredGrid*>(
55  _inputAlgorithm->GetOutputDataObject(0)))
56  {
57  surfaceFilter = vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
58  surfaceFilter->SetInputConnection(_inputAlgorithm->GetOutputPort());
59  surface->SetInputConnection(surfaceFilter->GetOutputPort());
60  }
61  else
62  {
63  surface->SetInputConnection(_inputAlgorithm->GetOutputPort());
64  }
65 
66  QWidget* parent = nullptr;
67  QSettings settings;
68  QString fileName = QFileDialog::getOpenFileName(
69  parent, "Select raster file to apply as texture",
70  settings.value("lastOpenedTextureFileDirectory").toString(),
71  "Raster files (*.asc *.grd *.bmp *.jpg *.png *.tif);;"
72 #ifdef OGS_USE_NETCDF
73  "NetCDF files (*.nc);;"
74 #endif // OGS_USE_NETCDF
75  );
76  QFileInfo fi(fileName);
77 
78  if ((fi.suffix().toLower() == "asc") || (fi.suffix().toLower() == "tif") ||
79  (fi.suffix().toLower() == "png") || (fi.suffix().toLower() == "grd") ||
80  (fi.suffix().toLower() == "jpg") || (fi.suffix().toLower() == "bmp"))
81  {
82  std::string name = fileName.toStdString();
83  vtkImageAlgorithm* image = VtkRaster::loadImage(name);
84  surface->SetRaster(image);
85  surface->Update();
86 
87  QDir dir = QDir(fileName);
88  settings.setValue("lastOpenedTextureFileDirectory", dir.absolutePath());
89  }
90 #ifdef OGS_USE_NETCDF
91  else if (fi.suffix().toLower() == "nc")
92  {
93  NetCdfConfigureDialog dlg(fileName.toStdString().c_str());
94  dlg.exec();
95  if (dlg.getRaster() != nullptr)
96  {
97  VtkGeoImageSource* image = dlg.getRaster();
98  surface->SetRaster(image);
99  surface->Update();
100  }
101  }
102 #endif // OGS_USE_NETCDF
103  else
104  ERR("VtkCompositeTextureOnSurfaceFilter::init(): Error reading texture "
105  "file.");
106 
107  _outputAlgorithm = surface;
108 }
109 
111  QVariant value)
112 {
114 }
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
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.