19#include <vtkDataArray.h>
20#include <vtkDataSetMapper.h>
21#include <vtkImageAlgorithm.h>
22#include <vtkImageChangeInformation.h>
23#include <vtkImageData.h>
24#include <vtkImageShiftScale.h>
25#include <vtkPointData.h>
26#include <vtkRenderer.h>
27#include <vtkSmartPointer.h>
41#include <vtkImageActor.h>
42#include <vtkXMLImageDataWriter.h>
45 vtkAlgorithm* algorithm,
TreeItem* parentItem,
46 const QList<QVariant> data )
53 const QList<QVariant> data )
55 _transformFilter(nullptr)
66 auto* img =
dynamic_cast<vtkImageAlgorithm*
>(
_algorithm);
73 img->GetOutput()->GetOrigin(origin);
74 img->GetOutput()->GetSpacing(spacing);
76 img->GetOutput()->GetPointData()->GetScalars()->GetRange(range);
77 vtkImageShiftScale* scale = vtkImageShiftScale::New();
78 scale->SetOutputScalarTypeToUnsignedChar();
79 scale->SetInputConnection(img->GetOutputPort());
80 scale->SetShift(-range[0]);
81 scale->SetScale(255.0 / (range[1] - range[0]));
95 vtkImageActor* imageActor = vtkImageActor::New();
115 newProps->SetScalarVisibility(parentProps->GetScalarVisibility());
116 newProps->SetTexture(parentProps->GetTexture());
132 if (vtkProps->GetActiveAttribute().length() > 0)
138 auto* visParentItem =
144 if (vtkProps->GetTexture() !=
nullptr)
159 const std::string& filename)
const
161 std::string file_name_cpy(filename);
162 auto* algID =
dynamic_cast<vtkImageAlgorithm*
>(
algorithm);
165 vtkSmartPointer<vtkXMLImageDataWriter> iWriter =
166 vtkSmartPointer<vtkXMLImageDataWriter>::New();
167 iWriter->SetInputData(algID->GetOutputDataObject(0));
170 file_name_cpy.append(
".vti");
172 iWriter->SetFileName(file_name_cpy.c_str());
173 return iWriter->Write();
175 ERR(
"VtkVisPipelineItem::writeToFile() - Unknown data type.");
191 vtkSmartPointer<VtkGeoImageSource> imageSource =
202 QFileInfo
const info(this->
data(0).toString());
203 QString
const rastername = info.completeBaseName() +
".asc";
204 QString
const filetype(
"ESRI ASCII raster file (*.asc)");
205 QString
const filename = QFileDialog::getSaveFileName(
206 nullptr,
"Save raster as",
210 filename.toStdString());
Definition of the AsciiRasterInterface class.
Manages the last directory used for saving a file.
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition of the OGSError class.
Definition of the GeoLib::Raster class.
Definition of the VtkAlgorithmProperties class.
Definition of the VtkGeoImageSource class.
Definition of the VtkVisImageItem class.
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)
Objects nodes for the TreeModel.
TreeItem * parentItem() const
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...
An item in the VtkVisPipeline containing a graphic object to be visualized.
vtkAlgorithm * algorithm() const
Returns the algorithm object.
vtkAlgorithm * _algorithm
QVariant data(int column) const override
virtual void SetActiveAttribute(const QString &str)
std::string getFileExtension(const std::string &path)