OGS
VtkVisImageItem Class Reference

Detailed Description

An item in the VtkVisPipeline containing an image to be visualized.

Any vtkImageAlgorithm object is represented by a VtkVisImageItem to be assigned a mapper, an actor and its visualization properties.

See also
VtkVisPipelineItem

Definition at line 25 of file VtkVisImageItem.h.

#include <VtkVisImageItem.h>

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

Public Member Functions

 VtkVisImageItem (vtkAlgorithm *algorithm, TreeItem *parentItem, const QList< QVariant > data=QList< QVariant >())
 Constructor for a source/filter object.
 VtkVisImageItem (VtkCompositeFilter *compositeFilter, TreeItem *parentItem, const QList< QVariant > data=QList< QVariant >())
 Constructor for composite filter.
 ~VtkVisImageItem () override
void Initialize (vtkRenderer *renderer) override
 Initializes vtkMapper and vtkActor necessary for visualization of the item and sets the item's properties.
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 derived classes.
vtkAlgorithm * transformFilter () const override
bool writeAsRaster ()
 Allows writing this item's source object as an ASCII raster file.
Public Member Functions inherited from VtkVisPipelineItem
 VtkVisPipelineItem (vtkAlgorithm *algorithm, TreeItem *parentItem, const QList< QVariant > data=QList< QVariant >())
 Constructor for a source/filter object.
 VtkVisPipelineItem (VtkCompositeFilter *compositeFilter, TreeItem *parentItem, const QList< QVariant > data=QList< QVariant >())
 Constructor for composite filter.
 ~VtkVisPipelineItem () override
VtkVisPipelineItemchild (int row) const
 Returns a VtkVisPipelineItem.
QVariant data (int column) const override
bool setData (int column, const QVariant &value) override
vtkAlgorithm * algorithm () const
 Returns the algorithm object.
vtkProp3D * actor () const
 Returns the actor as vtkProp3D.
virtual QString GetActiveAttribute () const
virtual void SetActiveAttribute (const QString &str)
VtkCompositeFiltercompositeFilter () const
 Returns the composite filter.
bool isVisible () const
 Returns if the VTK object is visible in the visualization.
void setVisible (bool visible)
 Sets the visibility of the VTK object in the visualization.
int writeToFile (const std::string &filename) const
 Writes this algorithm's vtkDataSet (i.e. vtkPolyData or vtkUnstructuredGrid) to a vtk-file.
virtual void setScale (double x, double y, double z) const
 Scales the data in visualisation-space. This function is empty and needs to be implemented by derived classes.
void setScaleOnChildren (double x, double y, double z) const
 Sets the geometry and date scaling recursively on all children of this item.
virtual void setBackfaceCulling (bool enable) const
 Enables / disables backface culling.
void setBackfaceCullingOnChildren (bool enable) const
 Enables / disables backface culling on all children.
QStringList getScalarArrayNames () const
 Returns a list of array names prefixed with P- or C- for point and cell data.
VtkAlgorithmPropertiesgetVtkProperties () const
 Returns the VtkAlgorithmProperties.
Public Member Functions inherited from TreeItem
 TreeItem (QList< QVariant > data, TreeItem *parent)
virtual ~TreeItem ()
void appendChild (TreeItem *item)
TreeItemchild (int row) const
virtual int childCount () const
virtual int columnCount () const
int row () const
TreeItemparentItem () const
bool removeChildren (int position, int count)

Protected Member Functions

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.
void setVtkProperties (VtkAlgorithmProperties *vtkProps)

Private Attributes

vtkImageChangeInformation * _transformFilter

Additional Inherited Members

Protected Attributes inherited from VtkVisPipelineItem
vtkProp3D * _actor
vtkAlgorithm * _algorithm
vtkRenderer * _renderer
VtkCompositeFilter_compositeFilter
VtkAlgorithmProperties_vtkProps
 The active VtkAlgorithmProperties. From algorithm, compositeFilter, or copied from parent.

Constructor & Destructor Documentation

◆ VtkVisImageItem() [1/2]

VtkVisImageItem::VtkVisImageItem ( vtkAlgorithm * algorithm,
TreeItem * parentItem,
const QList< QVariant > data = QList<QVariant>() )

Constructor for a source/filter object.

Definition at line 33 of file VtkVisImageItem.cpp.

37{
38}
TreeItem * parentItem() const
Definition TreeItem.cpp:104
virtual QVariant data(int column) const
Definition TreeItem.cpp:83
vtkImageChangeInformation * _transformFilter
vtkAlgorithm * algorithm() const
Returns the algorithm object.
VtkVisPipelineItem(vtkAlgorithm *algorithm, TreeItem *parentItem, const QList< QVariant > data=QList< QVariant >())
Constructor for a source/filter object.

References TreeItem::TreeItem(), VtkVisPipelineItem::VtkVisPipelineItem(), _transformFilter, VtkVisPipelineItem::algorithm(), VtkVisPipelineItem::data(), and TreeItem::parentItem().

◆ VtkVisImageItem() [2/2]

VtkVisImageItem::VtkVisImageItem ( VtkCompositeFilter * compositeFilter,
TreeItem * parentItem,
const QList< QVariant > data = QList<QVariant>() )

Constructor for composite filter.

Definition at line 40 of file VtkVisImageItem.cpp.

44 _transformFilter(nullptr)
45{
46}
VtkCompositeFilter * compositeFilter() const
Returns the composite filter.

References TreeItem::TreeItem(), VtkVisPipelineItem::VtkVisPipelineItem(), _transformFilter, VtkVisPipelineItem::compositeFilter(), VtkVisPipelineItem::data(), and TreeItem::parentItem().

◆ ~VtkVisImageItem()

VtkVisImageItem::~VtkVisImageItem ( )
override

Definition at line 48 of file VtkVisImageItem.cpp.

49{
50 _transformFilter->Delete();
51}

References _transformFilter.

Member Function Documentation

◆ callVTKWriter()

int VtkVisImageItem::callVTKWriter ( vtkAlgorithm * algorithm,
const std::string & filename ) const
overrideprotectedvirtual

Selects the appropriate VTK-Writer object and writes the object to a file with the given name.

Reimplemented from VtkVisPipelineItem.

Definition at line 164 of file VtkVisImageItem.cpp.

166{
167 std::string file_name_cpy(filename);
168 auto* algID = dynamic_cast<vtkImageAlgorithm*>(algorithm);
169 if (algID)
170 {
171 vtkSmartPointer<vtkXMLImageDataWriter> iWriter =
172 vtkSmartPointer<vtkXMLImageDataWriter>::New();
173 iWriter->SetInputData(algID->GetOutputDataObject(0));
174 if (BaseLib::getFileExtension(filename) != ".vti")
175 {
176 file_name_cpy.append(".vti");
177 }
178 iWriter->SetFileName(file_name_cpy.c_str());
179 return iWriter->Write();
180 }
181 ERR("VtkVisPipelineItem::writeToFile() - Unknown data type.");
182 return 0;
183}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
std::string getFileExtension(const std::string &path)

References VtkVisPipelineItem::algorithm(), ERR(), and BaseLib::getFileExtension().

◆ Initialize()

void VtkVisImageItem::Initialize ( vtkRenderer * renderer)
overridevirtual

Initializes vtkMapper and vtkActor necessary for visualization of the item and sets the item's properties.

Implements VtkVisPipelineItem.

Definition at line 53 of file VtkVisImageItem.cpp.

54{
55 auto* image = dynamic_cast<vtkImageAlgorithm*>(_algorithm);
56 if (!image)
57 {
58 OGSError::box("Cast to image failed.");
59 return;
60 }
61 image->Update();
62
63 double origin[3];
64 double spacing[3];
65 double range[2];
66 vtkImageData* image_data = image->GetOutput();
67 if (!image_data)
68 {
69 OGSError::box("GetOutput() - Image could not be initialized.");
70 return;
71 }
72 image_data->GetOrigin(origin);
73 image_data->GetSpacing(spacing);
74 vtkPointData* point_data = image_data->GetPointData();
75 if (point_data)
76 {
77 auto* scalars = point_data->GetScalars();
78 if (scalars)
79 {
80 scalars->GetRange(range);
81 }
82 }
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]));
88
89 _transformFilter = vtkImageChangeInformation::New();
90 _transformFilter->SetInputConnection(scale->GetOutputPort());
91 // double origin[3];
92 // img->getOrigin(origin);
93 // double spacing = img->getSpacing();
94 //_transformFilter->SetOutputOrigin(origin2);
95 //_transformFilter->SetOutputSpacing(spacing2);
96 _transformFilter->Update();
97
98 _renderer = renderer;
99
100 // Use a special vtkImageActor instead of vtkActor
101 vtkImageActor* imageActor = vtkImageActor::New();
102 imageActor->SetInputData(_transformFilter->GetOutput());
103 _actor = imageActor;
104 _renderer->AddActor(_actor);
105
106 // Set pre-set properties
107 auto* vtkProps = dynamic_cast<VtkAlgorithmProperties*>(_algorithm);
108 if (vtkProps)
109 {
110 setVtkProperties(vtkProps);
111 }
112
113 auto* parentItem = dynamic_cast<VtkVisPipelineItem*>(this->parentItem());
114 while (parentItem)
115 {
116 auto* parentProps =
117 dynamic_cast<VtkAlgorithmProperties*>(parentItem->algorithm());
118 if (parentProps)
119 {
120 auto* newProps = new VtkAlgorithmProperties();
121 newProps->SetScalarVisibility(parentProps->GetScalarVisibility());
122 newProps->SetTexture(parentProps->GetTexture());
123 setVtkProperties(newProps);
124 vtkProps = newProps;
125 parentItem = nullptr;
126 }
127 else
128 {
129 parentItem =
130 dynamic_cast<VtkVisPipelineItem*>(parentItem->parentItem());
131 }
132 }
133
134 // Set active scalar to the desired one from VtkAlgorithmProperties
135 // or to match those of the parent.
136 if (vtkProps)
137 {
138 if (vtkProps->GetActiveAttribute().length() > 0)
139 {
140 this->SetActiveAttribute(vtkProps->GetActiveAttribute());
141 }
142 else
143 {
144 auto* visParentItem =
145 dynamic_cast<VtkVisPipelineItem*>(this->parentItem());
146 if (visParentItem)
147 {
148 this->SetActiveAttribute(visParentItem->GetActiveAttribute());
149 }
150 if (vtkProps->GetTexture() != nullptr)
151 {
152 this->SetActiveAttribute("Solid Color");
153 }
154 }
155 }
156}
static void box(const QString &e)
Definition OGSError.cpp:13
void setVtkProperties(VtkAlgorithmProperties *vtkProps)
vtkAlgorithm * _algorithm
virtual void SetActiveAttribute(const QString &str)
void scale(PETScVector &x, PetscScalar const a)
Definition LinAlg.cpp:37

References VtkVisPipelineItem::VtkVisPipelineItem(), VtkVisPipelineItem::_actor, VtkVisPipelineItem::_algorithm, VtkVisPipelineItem::_renderer, _transformFilter, OGSError::box(), TreeItem::parentItem(), VtkVisPipelineItem::SetActiveAttribute(), and setVtkProperties().

◆ setTranslation()

void VtkVisImageItem::setTranslation ( double x,
double y,
double z ) const
overridevirtual

Translates the item in visualisation-space. This function is empty and needs to be implemented by derived classes.

Reimplemented from VtkVisPipelineItem.

Definition at line 185 of file VtkVisImageItem.cpp.

186{
187 _transformFilter->SetOriginTranslation(x, y, z);
188}

References _transformFilter.

◆ setVtkProperties()

void VtkVisImageItem::setVtkProperties ( VtkAlgorithmProperties * vtkProps)
protected

Definition at line 158 of file VtkVisImageItem.cpp.

159{
160 // todo implementation
161 (void)vtkProps;
162}

Referenced by Initialize().

◆ transformFilter()

vtkAlgorithm * VtkVisImageItem::transformFilter ( ) const
overridevirtual

Returns the transform filter for the object. This function needs to be implemented by derived classes.

Implements VtkVisPipelineItem.

Definition at line 190 of file VtkVisImageItem.cpp.

191{
192 return _transformFilter;
193}

References _transformFilter.

Referenced by VtkVisTabWidget::setActiveItem().

◆ writeAsRaster()

bool VtkVisImageItem::writeAsRaster ( )

Allows writing this item's source object as an ASCII raster file.

Definition at line 195 of file VtkVisImageItem.cpp.

196{
197 vtkSmartPointer<VtkGeoImageSource> imageSource =
198 VtkGeoImageSource::SafeDownCast(_algorithm);
199
200 auto const raster = VtkGeoImageSource::convertToRaster(imageSource);
201
202 if (!raster)
203 {
204 OGSError::box("Image could not be converted to a raster.");
205 return false;
206 }
207
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",
213 LastSavedFileDirectory::getDir() + rastername, filetype);
216 filename.toStdString());
217 return true;
218}
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 std::optional< GeoLib::Raster > convertToRaster(VtkGeoImageSource *const source)
QVariant data(int column) const override
const char * toString(mgis::behaviour::Behaviour::Kinematic kin)

References VtkVisPipelineItem::_algorithm, OGSError::box(), VtkGeoImageSource::convertToRaster(), VtkVisPipelineItem::data(), LastSavedFileDirectory::getDir(), LastSavedFileDirectory::setDir(), and FileIO::AsciiRasterInterface::writeRasterAsASC().

Referenced by VtkVisPipelineView::writeRaster().

Member Data Documentation

◆ _transformFilter

vtkImageChangeInformation* VtkVisImageItem::_transformFilter
private

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