Loading [MathJax]/extensions/tex2jax.js
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 36 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 44 of file VtkVisImageItem.cpp.

48{
49}
TreeItem * parentItem() const
Definition TreeItem.cpp:115
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.
QVariant data(int column) const override

◆ VtkVisImageItem() [2/2]

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

Constructor for composite filter.

Definition at line 51 of file VtkVisImageItem.cpp.

55 _transformFilter(nullptr)
56{
57}
VtkCompositeFilter * compositeFilter() const
Returns the composite filter.

◆ ~VtkVisImageItem()

VtkVisImageItem::~VtkVisImageItem ( )
override

Definition at line 59 of file VtkVisImageItem.cpp.

60{
61 _transformFilter->Delete();
62}

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 175 of file VtkVisImageItem.cpp.

177{
178 std::string file_name_cpy(filename);
179 auto* algID = dynamic_cast<vtkImageAlgorithm*>(algorithm);
180 if (algID)
181 {
182 vtkSmartPointer<vtkXMLImageDataWriter> iWriter =
183 vtkSmartPointer<vtkXMLImageDataWriter>::New();
184 iWriter->SetInputData(algID->GetOutputDataObject(0));
185 if (BaseLib::getFileExtension(filename) != ".vti")
186 {
187 file_name_cpy.append(".vti");
188 }
189 iWriter->SetFileName(file_name_cpy.c_str());
190 return iWriter->Write();
191 }
192 ERR("VtkVisPipelineItem::writeToFile() - Unknown data type.");
193 return 0;
194}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
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 64 of file VtkVisImageItem.cpp.

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

References 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 196 of file VtkVisImageItem.cpp.

197{
198 _transformFilter->SetOriginTranslation(x, y, z);
199}

References _transformFilter.

◆ setVtkProperties()

void VtkVisImageItem::setVtkProperties ( VtkAlgorithmProperties * vtkProps)
protected

Definition at line 169 of file VtkVisImageItem.cpp.

170{
171 // todo implementation
172 (void)vtkProps;
173}

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 201 of file VtkVisImageItem.cpp.

202{
203 return _transformFilter;
204}

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 206 of file VtkVisImageItem.cpp.

207{
208 vtkSmartPointer<VtkGeoImageSource> imageSource =
209 VtkGeoImageSource::SafeDownCast(_algorithm);
210
211 auto const raster = VtkGeoImageSource::convertToRaster(imageSource);
212
213 if (!raster)
214 {
215 OGSError::box("Image could not be converted to a raster.");
216 return false;
217 }
218
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",
224 LastSavedFileDirectory::getDir() + rastername, filetype);
227 filename.toStdString());
228 return true;
229}
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)
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().

Member Data Documentation

◆ _transformFilter

vtkImageChangeInformation* VtkVisImageItem::_transformFilter
private

Definition at line 68 of file VtkVisImageItem.h.

Referenced by ~VtkVisImageItem(), Initialize(), setTranslation(), and transformFilter().


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