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

160{
161 std::string file_name_cpy(filename);
162 auto* algID = dynamic_cast<vtkImageAlgorithm*>(algorithm);
163 if (algID)
164 {
165 vtkSmartPointer<vtkXMLImageDataWriter> iWriter =
166 vtkSmartPointer<vtkXMLImageDataWriter>::New();
167 iWriter->SetInputData(algID->GetOutputDataObject(0));
168 if (BaseLib::getFileExtension(filename) != ".vti")
169 {
170 file_name_cpy.append(".vti");
171 }
172 iWriter->SetFileName(file_name_cpy.c_str());
173 return iWriter->Write();
174 }
175 ERR("VtkVisPipelineItem::writeToFile() - Unknown data type.");
176 return 0;
177}
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* img = dynamic_cast<vtkImageAlgorithm*>(_algorithm);
67 img->Update();
68 // VtkGeoImageSource* img = dynamic_cast<VtkGeoImageSource*>(_algorithm);
69
70 double origin[3];
71 double spacing[3];
72 double range[2];
73 img->GetOutput()->GetOrigin(origin);
74 img->GetOutput()->GetSpacing(spacing);
75 // img->getRange(range);
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]));
82
83 _transformFilter = vtkImageChangeInformation::New();
84 _transformFilter->SetInputConnection(scale->GetOutputPort());
85 // double origin[3];
86 // img->getOrigin(origin);
87 // double spacing = img->getSpacing();
88 //_transformFilter->SetOutputOrigin(origin2);
89 //_transformFilter->SetOutputSpacing(spacing2);
90 _transformFilter->Update();
91
92 _renderer = renderer;
93
94 // Use a special vtkImageActor instead of vtkActor
95 vtkImageActor* imageActor = vtkImageActor::New();
96 imageActor->SetInputData(_transformFilter->GetOutput());
97 _actor = imageActor;
98 _renderer->AddActor(_actor);
99
100 // Set pre-set properties
101 auto* vtkProps = dynamic_cast<VtkAlgorithmProperties*>(_algorithm);
102 if (vtkProps)
103 {
104 setVtkProperties(vtkProps);
105 }
106
107 auto* parentItem = dynamic_cast<VtkVisPipelineItem*>(this->parentItem());
108 while (parentItem)
109 {
110 auto* parentProps =
111 dynamic_cast<VtkAlgorithmProperties*>(parentItem->algorithm());
112 if (parentProps)
113 {
114 auto* newProps = new VtkAlgorithmProperties();
115 newProps->SetScalarVisibility(parentProps->GetScalarVisibility());
116 newProps->SetTexture(parentProps->GetTexture());
117 setVtkProperties(newProps);
118 vtkProps = newProps;
119 parentItem = nullptr;
120 }
121 else
122 {
123 parentItem =
124 dynamic_cast<VtkVisPipelineItem*>(parentItem->parentItem());
125 }
126 }
127
128 // Set active scalar to the desired one from VtkAlgorithmProperties
129 // or to match those of the parent.
130 if (vtkProps)
131 {
132 if (vtkProps->GetActiveAttribute().length() > 0)
133 {
134 this->SetActiveAttribute(vtkProps->GetActiveAttribute());
135 }
136 else
137 {
138 auto* visParentItem =
139 dynamic_cast<VtkVisPipelineItem*>(this->parentItem());
140 if (visParentItem)
141 {
142 this->SetActiveAttribute(visParentItem->GetActiveAttribute());
143 }
144 if (vtkProps->GetTexture() != nullptr)
145 {
146 this->SetActiveAttribute("Solid Color");
147 }
148 }
149 }
150}
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, 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 179 of file VtkVisImageItem.cpp.

180{
181 _transformFilter->SetOriginTranslation(x, y, z);
182}

References _transformFilter.

◆ setVtkProperties()

void VtkVisImageItem::setVtkProperties ( VtkAlgorithmProperties * vtkProps)
protected

Definition at line 152 of file VtkVisImageItem.cpp.

153{
154 // todo implementation
155 (void)vtkProps;
156}

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

185{
186 return _transformFilter;
187}

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

190{
191 vtkSmartPointer<VtkGeoImageSource> imageSource =
192 VtkGeoImageSource::SafeDownCast(_algorithm);
193
194 auto const raster = VtkGeoImageSource::convertToRaster(imageSource);
195
196 if (!raster)
197 {
198 OGSError::box("Image could not be converted to a raster.");
199 return false;
200 }
201
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",
207 LastSavedFileDirectory::getDir() + rastername, filetype);
210 filename.toStdString());
211 return true;
212}
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)
Definition OGSError.cpp:23
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: