8#include <vtkDataArray.h>
9#include <vtkDataSetMapper.h>
10#include <vtkImageAlgorithm.h>
11#include <vtkImageChangeInformation.h>
12#include <vtkImageData.h>
13#include <vtkImageShiftScale.h>
14#include <vtkPointData.h>
15#include <vtkRenderer.h>
16#include <vtkSmartPointer.h>
30#include <vtkImageActor.h>
31#include <vtkXMLImageDataWriter.h>
35 const QList<QVariant>
data )
42 const QList<QVariant>
data )
55 auto* image =
dynamic_cast<vtkImageAlgorithm*
>(
_algorithm);
66 vtkImageData* image_data = image->GetOutput();
69 OGSError::box(
"GetOutput() - Image could not be initialized.");
72 image_data->GetOrigin(origin);
73 image_data->GetSpacing(spacing);
74 vtkPointData* point_data = image_data->GetPointData();
77 auto* scalars = point_data->GetScalars();
80 scalars->GetRange(range);
83 vtkImageShiftScale* scale = vtkImageShiftScale::New();
84 scale->SetOutputScalarTypeToUnsignedChar();
85 scale->SetInputConnection(image->GetOutputPort());
86 scale->SetShift(-range[0]);
87 scale->SetScale(255.0 / (range[1] - range[0]));
101 vtkImageActor* imageActor = vtkImageActor::New();
121 newProps->SetScalarVisibility(parentProps->GetScalarVisibility());
122 newProps->SetTexture(parentProps->GetTexture());
138 if (vtkProps->GetActiveAttribute().length() > 0)
144 auto* visParentItem =
150 if (vtkProps->GetTexture() !=
nullptr)
165 const std::string& filename)
const
167 std::string file_name_cpy(filename);
168 auto* algID =
dynamic_cast<vtkImageAlgorithm*
>(
algorithm);
171 vtkSmartPointer<vtkXMLImageDataWriter> iWriter =
172 vtkSmartPointer<vtkXMLImageDataWriter>::New();
173 iWriter->SetInputData(algID->GetOutputDataObject(0));
176 file_name_cpy.append(
".vti");
178 iWriter->SetFileName(file_name_cpy.c_str());
179 return iWriter->Write();
181 ERR(
"VtkVisPipelineItem::writeToFile() - Unknown data type.");
197 vtkSmartPointer<VtkGeoImageSource> imageSource =
208 QFileInfo
const info(this->
data(0).toString());
209 QString
const rastername = info.completeBaseName() +
".asc";
210 QString
const filetype(
"ESRI ASCII raster file (*.asc)");
211 QString
const filename = QFileDialog::getSaveFileName(
212 nullptr,
"Save raster as",
216 filename.toStdString());
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
static void writeRasterAsASC(GeoLib::Raster const &raster, std::string const &file_name)
Writes an Esri asc-file.
static void setDir(const QString &path)
Sets the directory last used for saving a file.
static const QString getDir()
Returns the directory last used for saving a file.
static void box(const QString &e)
TreeItem * parentItem() const
TreeItem(QList< QVariant > data, TreeItem *parent)
Contains properties for the visualization of objects as VtkVisPipelineItems.
Is used to combine several filter in one VtkVisPipelineItem. You can use vtk filter and custom filter...
static std::optional< GeoLib::Raster > convertToRaster(VtkGeoImageSource *const source)
vtkImageChangeInformation * _transformFilter
VtkVisImageItem(vtkAlgorithm *algorithm, TreeItem *parentItem, const QList< QVariant > data=QList< QVariant >())
Constructor for a source/filter object.
bool writeAsRaster()
Allows writing this item's source object as an ASCII raster file.
void Initialize(vtkRenderer *renderer) override
Initializes vtkMapper and vtkActor necessary for visualization of the item and sets the item's proper...
vtkAlgorithm * transformFilter() const override
int callVTKWriter(vtkAlgorithm *algorithm, const std::string &filename) const override
Selects the appropriate VTK-Writer object and writes the object to a file with the given name.
~VtkVisImageItem() override
void setVtkProperties(VtkAlgorithmProperties *vtkProps)
void setTranslation(double x, double y, double z) const override
Translates the item in visualisation-space. This function is empty and needs to be implemented by der...
vtkAlgorithm * algorithm() const
Returns the algorithm object.
VtkVisPipelineItem(vtkAlgorithm *algorithm, TreeItem *parentItem, const QList< QVariant > data=QList< QVariant >())
Constructor for a source/filter object.
vtkAlgorithm * _algorithm
QVariant data(int column) const override
VtkCompositeFilter * compositeFilter() const
Returns the composite filter.
virtual void SetActiveAttribute(const QString &str)
std::string getFileExtension(const std::string &path)