OGS
VtkGeoImageSource Class Reference

Detailed Description

The VtkVisPipeline source object of a geo-referenced image (file).

Definition at line 28 of file VtkGeoImageSource.h.

#include <VtkGeoImageSource.h>

Inheritance diagram for VtkGeoImageSource:
[legend]
Collaboration diagram for VtkGeoImageSource:
[legend]

Public Member Functions

 vtkTypeMacro (VtkGeoImageSource, vtkSimpleImageToImageFilter)
void PrintSelf (ostream &os, vtkIndent indent) override
 Prints information about itself.
 VtkGeoImageSource (const VtkGeoImageSource &)=delete
void operator= (const VtkGeoImageSource &)=delete
vtkImageData * getImageData ()
 Returns the ImageData object.
bool readImage (const QString &filename)
 Reads an image from file.
void setImage (vtkImageAlgorithm *image, const QString &name)
 Imports an existing image object.
void SetUserProperty (QString name, QVariant value) override
 Sets a user property. This should be implemented by subclasses.
Public Member Functions inherited from VtkAlgorithmProperties
 VtkAlgorithmProperties (QObject *parent=nullptr)
 Constructor (sets default values)
 ~VtkAlgorithmProperties () override
vtkProperty * GetProperties () const
 Returns the vtk properties.
vtkTexture * GetTexture ()
 Returns a texture (if one has been assigned).
void SetTexture (vtkTexture *t)
 Sets a texture for the VtkVisPipelineItem.
vtkLookupTable * GetLookupTable (const QString &array_name)
 Returns the colour lookup table (if one has been assigned).
void RemoveLookupTable (const QString &array_name)
 Removes the lookup table for the given scalar.
void SetLookUpTable (const QString &array_name, vtkLookupTable *lut)
 Sets a colour lookup table for the given scalar array of the VtkVisPipelineItem.
void SetLookUpTable (const QString &array_name, const QString &filename)
 Loads a predefined color lookup table from a file for the specified scalar array.
bool GetScalarVisibility () const
 Returns the scalar visibility.
void SetScalarVisibility (bool on)
 Sets the scalar visibility.
QString GetName () const
 Returns the name. This is set to the file path if it is a source algorithm.
void SetName (QString name)
 Sets the name.
bool IsRemovable () const
 Is this algorithm removable from the pipeline (view).
QMap< QString, QVariant > * GetAlgorithmUserProperties () const
 Returns a map of user properties.
QMap< QString, QList< QVariant > > * GetAlgorithmUserVectorProperties () const
 Returns a map of vector user properties.
QVariant GetUserProperty (QString name) const
 Returns the value of a user property.
virtual void SetUserVectorProperty (QString name, QList< QVariant > values)
 Sets a vector user property. This should be implemented by subclasses.
QList< QVariant > GetUserVectorProperty (QString name) const
 Returns a list of values of a vector user property.
void SetActiveAttribute (QString name)
 Set the active attribute.
QString GetActiveAttribute () const
 Returns the desired active attribute.

Static Public Member Functions

static VtkGeoImageSourceNew ()
 Create new objects with New() because of VTKs reference counting.
static std::optional< GeoLib::RasterconvertToRaster (VtkGeoImageSource *const source)

Protected Member Functions

 VtkGeoImageSource ()
 Constructor.
 ~VtkGeoImageSource () override
 Destructor.
void SimpleExecute (vtkImageData *input, vtkImageData *output) override
 Filter execution.

Private Attributes

vtkImageAlgorithm * _imageSource {nullptr}

Additional Inherited Members

Signals inherited from VtkAlgorithmProperties
void ScalarVisibilityChanged (bool on)
Protected Attributes inherited from VtkAlgorithmProperties
vtkProperty * _property
vtkTexture * _texture
bool _scalarVisibility
std::map< QString, vtkLookupTable * > _lut
QString _name
QString _activeAttributeName
bool _removable
QMap< QString, QVariant > * _algorithmUserProperties
QMap< QString, QList< QVariant > > * _algorithmUserVectorProperties

Constructor & Destructor Documentation

◆ VtkGeoImageSource() [1/2]

VtkGeoImageSource::VtkGeoImageSource ( const VtkGeoImageSource & )
delete

◆ VtkGeoImageSource() [2/2]

VtkGeoImageSource::VtkGeoImageSource ( )
protecteddefault

Constructor.

◆ ~VtkGeoImageSource()

VtkGeoImageSource::~VtkGeoImageSource ( )
overrideprotected

Destructor.

Definition at line 52 of file VtkGeoImageSource.cpp.

53{
54 if (_imageSource)
55 {
56 _imageSource->Delete();
57 }
58}
vtkImageAlgorithm * _imageSource

References _imageSource.

Member Function Documentation

◆ convertToRaster()

std::optional< GeoLib::Raster > VtkGeoImageSource::convertToRaster ( VtkGeoImageSource *const source)
static

Definition at line 111 of file VtkGeoImageSource.cpp.

113{
114 int dims[3];
115 source->GetOutput()->GetDimensions(dims);
116 double origin[3];
117 source->GetOutput()->GetOrigin(origin);
118 double spacing[3];
119 source->GetOutput()->GetSpacing(spacing);
120 MathLib::Point3d const origin_pnt(
121 std::array<double, 3>{{origin[0] - 0.5 * spacing[0],
122 origin[1] - 0.5 * spacing[1], origin[2]}});
123 GeoLib::RasterHeader const header = {static_cast<std::size_t>(dims[0]),
124 static_cast<std::size_t>(dims[1]),
125 static_cast<std::size_t>(dims[2]),
126 origin_pnt,
127 spacing[0],
128 -9999};
129
130 vtkSmartPointer<vtkDataArray> const pixelData =
131 vtkSmartPointer<vtkDataArray>(
132 source->GetOutput()->GetPointData()->GetScalars());
133 int const nTuple = pixelData->GetNumberOfComponents();
134 if (nTuple < 1 || nTuple > 4)
135 {
136 ERR("VtkMeshConverter::convertImgToMesh(): Unsupported pixel "
137 "composition!");
138 return {};
139 }
140
141 std::vector<double> pix(header.n_cols * header.n_rows * header.n_depth, 0);
142 for (std::size_t k = 0; k < header.n_depth; k++)
143 {
144 std::size_t const layer_idx = (k * header.n_rows * header.n_cols);
145 for (std::size_t i = 0; i < header.n_rows; i++)
146 {
147 std::size_t const idx = i * header.n_cols + layer_idx;
148 for (std::size_t j = 0; j < header.n_cols; j++)
149 {
150 double const* const colour = pixelData->GetTuple(idx + j);
151 bool const visible = (nTuple == 2 || nTuple == 4)
152 ? (colour[nTuple - 1] != 0)
153 : true;
154 if (!visible)
155 {
156 pix[idx + j] = header.no_data;
157 }
158 else
159 {
160 pix[idx + j] = (nTuple < 3) ? colour[0] : // grey (+ alpha)
161 (0.3 * colour[0] + 0.6 * colour[1] +
162 0.1 * colour[2]); // rgb(a)
163 }
164 }
165 }
166 }
167
168 return std::make_optional<GeoLib::Raster>(header, pix.begin(), pix.end());
169}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40

References VtkGeoImageSource(), and ERR().

Referenced by VtkVisPipelineView::showImageToMeshConversionDialog(), and VtkVisImageItem::writeAsRaster().

◆ getImageData()

vtkImageData * VtkGeoImageSource::getImageData ( )

Returns the ImageData object.

Definition at line 83 of file VtkGeoImageSource.cpp.

84{
85 return this->_imageSource->GetImageDataInput(0);
86}

References _imageSource.

◆ New()

VtkGeoImageSource * VtkGeoImageSource::New ( )
static

Create new objects with New() because of VTKs reference counting.

References VtkGeoImageSource().

Referenced by NetCdfConfigureDialog::createDataObject(), and MainWindow::loadFile().

◆ operator=()

void VtkGeoImageSource::operator= ( const VtkGeoImageSource & )
delete

References VtkGeoImageSource().

◆ PrintSelf()

void VtkGeoImageSource::PrintSelf ( ostream & os,
vtkIndent indent )
override

Prints information about itself.

Definition at line 60 of file VtkGeoImageSource.cpp.

61{
62 this->Superclass::PrintSelf(os, indent);
63}

◆ readImage()

bool VtkGeoImageSource::readImage ( const QString & filename)

Reads an image from file.

Definition at line 65 of file VtkGeoImageSource.cpp.

66{
67 vtkImageAlgorithm* img(VtkRaster::loadImage(filename.toStdString()));
68 if (img == nullptr)
69 {
70 return false;
71 }
72 this->setImage(img, filename);
73 return true;
74}
void setImage(vtkImageAlgorithm *image, const QString &name)
Imports an existing image object.
static vtkImageAlgorithm * loadImage(const std::string &fileName)
Loads an image- or raster-file into an vtkImageAlgorithm-Object.
Definition VtkRaster.cpp:32

References VtkRaster::loadImage(), and setImage().

Referenced by MainWindow::loadFile().

◆ setImage()

void VtkGeoImageSource::setImage ( vtkImageAlgorithm * image,
const QString & name )

Imports an existing image object.

Definition at line 76 of file VtkGeoImageSource.cpp.

77{
78 this->_imageSource = image;
79 this->SetInputConnection(_imageSource->GetOutputPort());
80 this->SetName(name);
81}
void SetName(QString name)
Sets the name.

References _imageSource, and VtkAlgorithmProperties::SetName().

Referenced by readImage().

◆ SetUserProperty()

void VtkGeoImageSource::SetUserProperty ( QString name,
QVariant value )
overridevirtual

Sets a user property. This should be implemented by subclasses.

Reimplemented from VtkAlgorithmProperties.

Definition at line 105 of file VtkGeoImageSource.cpp.

106{
107 Q_UNUSED(name);
108 Q_UNUSED(value);
109}

◆ SimpleExecute()

void VtkGeoImageSource::SimpleExecute ( vtkImageData * input,
vtkImageData * output )
overrideprotected

Filter execution.

Definition at line 88 of file VtkGeoImageSource.cpp.

89{
90 vtkDebugMacro(<< "Executing VtkGeoImageSource");
91 void* inPtr = input->GetScalarPointer();
92 void* outPtr = output->GetScalarPointer();
93 switch (output->GetScalarType())
94 {
95 // This is simply a #define for a big case list.
96 // It handles all data types that VTK supports.
98 input, output, (VTK_TT*)(inPtr), (VTK_TT*)(outPtr)));
99 default:
100 vtkGenericWarningMacro("Execute: Unknown input ScalarType");
101 return;
102 }
103}
void vtkSimpleImageFilterExampleExecute(vtkImageData *input, vtkImageData *output, IT *inPtr, IT *outPtr)

References vtkSimpleImageFilterExampleExecute().

◆ vtkTypeMacro()

VtkGeoImageSource::vtkTypeMacro ( VtkGeoImageSource ,
vtkSimpleImageToImageFilter  )

References VtkGeoImageSource().

Member Data Documentation

◆ _imageSource

vtkImageAlgorithm* VtkGeoImageSource::_imageSource {nullptr}
private

Definition at line 68 of file VtkGeoImageSource.h.

68{nullptr};

Referenced by ~VtkGeoImageSource(), getImageData(), and setImage().


The documentation for this class was generated from the following files: