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* image =
dynamic_cast<vtkImageAlgorithm*
>(
_algorithm);
77 vtkImageData* image_data = image->GetOutput();
80 OGSError::box(
"GetOutput() - Image could not be initialized.");
83 image_data->GetOrigin(origin);
84 image_data->GetSpacing(spacing);
85 vtkPointData* point_data = image_data->GetPointData();
88 auto* scalars = point_data->GetScalars();
91 scalars->GetRange(range);
94 vtkImageShiftScale* scale = vtkImageShiftScale::New();
95 scale->SetOutputScalarTypeToUnsignedChar();
96 scale->SetInputConnection(image->GetOutputPort());
97 scale->SetShift(-range[0]);
98 scale->SetScale(255.0 / (range[1] - range[0]));
112 vtkImageActor* imageActor = vtkImageActor::New();
132 newProps->SetScalarVisibility(parentProps->GetScalarVisibility());
133 newProps->SetTexture(parentProps->GetTexture());
149 if (vtkProps->GetActiveAttribute().length() > 0)
155 auto* visParentItem =
161 if (vtkProps->GetTexture() !=
nullptr)
176 const std::string& filename)
const
178 std::string file_name_cpy(filename);
179 auto* algID =
dynamic_cast<vtkImageAlgorithm*
>(
algorithm);
182 vtkSmartPointer<vtkXMLImageDataWriter> iWriter =
183 vtkSmartPointer<vtkXMLImageDataWriter>::New();
184 iWriter->SetInputData(algID->GetOutputDataObject(0));
187 file_name_cpy.append(
".vti");
189 iWriter->SetFileName(file_name_cpy.c_str());
190 return iWriter->Write();
192 ERR(
"VtkVisPipelineItem::writeToFile() - Unknown data type.");
208 vtkSmartPointer<VtkGeoImageSource> imageSource =
219 QFileInfo
const info(this->
data(0).toString());
220 QString
const rastername = info.completeBaseName() +
".asc";
221 QString
const filetype(
"ESRI ASCII raster file (*.asc)");
222 QString
const filename = QFileDialog::getSaveFileName(
223 nullptr,
"Save raster as",
227 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)