OGS
VtkVisPipelineItem.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4// ** INCLUDES **
6
7#include <vtkActor.h>
8#include <vtkAlgorithm.h>
9#include <vtkCellData.h>
10#include <vtkDataSetMapper.h>
11#include <vtkGenericDataObjectWriter.h>
12#include <vtkImageActor.h>
13#include <vtkPointData.h>
14#include <vtkPointSet.h>
15#include <vtkProperty.h>
16#include <vtkRenderer.h>
17#include <vtkSmartPointer.h>
18#include <vtkTextureMapToPlane.h>
19
20#include <QMessageBox>
21
22#include "BaseLib/FileTools.h"
23#include "QVtkDataSetMapper.h"
25#include "VtkCompositeFilter.h"
26
28 vtkAlgorithm* algorithm, TreeItem* parentItem,
29 const QList<QVariant> data /*= QList<QVariant>()*/)
31 _actor(nullptr),
33 _renderer(nullptr),
34 _compositeFilter(nullptr),
35 _vtkProps(nullptr)
36{
37 auto* visParentItem = dynamic_cast<VtkVisPipelineItem*>(parentItem);
38 if (parentItem->parentItem())
39 {
40 _algorithm->SetInputConnection(
41 visParentItem->algorithm()->GetOutputPort());
42 }
43}
44
47 const QList<QVariant> data /*= QList<QVariant>()*/)
49 _actor(nullptr),
50 _renderer(nullptr),
52 _vtkProps(nullptr)
53{
54 _algorithm = _compositeFilter->GetOutputAlgorithm();
55}
56
58{
59 _renderer->RemoveActor(_actor);
60 _actor->Delete();
61 delete _compositeFilter;
62}
63
65{
66 TreeItem* treeItem = TreeItem::child(row);
67 if (treeItem)
68 {
69 return dynamic_cast<VtkVisPipelineItem*>(treeItem);
70 }
71
72 return nullptr;
73}
74
75QVariant VtkVisPipelineItem::data(int column) const
76{
77 if (column == 1)
78 {
79 return isVisible();
80 }
81
82 return TreeItem::data(column);
83}
84
85bool VtkVisPipelineItem::setData(int column, const QVariant& value)
86{
87 if (column == 1)
88 {
89 setVisible(value.toBool());
90 return true;
91 }
92
93 return TreeItem::setData(column, value);
94}
96{
97 return static_cast<bool>(_actor->GetVisibility());
98}
99
101{
102 _actor->SetVisibility(static_cast<int>(visible));
103 _actor->Modified();
104 _renderer->Render();
105}
106
107int VtkVisPipelineItem::writeToFile(const std::string& filename) const
108{
109 if (!filename.empty())
110 {
111 return callVTKWriter(this->algorithm(), filename);
112 }
113 return 0;
114}
115
117 const std::string& filename) const
118{
119 // needs to be implemented in derived classes!
120 (void)algorithm;
121 (void)filename;
122 return 0;
123}
124
126{
127 return _actor;
128}
129
130void VtkVisPipelineItem::setScale(double x, double y, double z) const
131{
132 (void)x;
133 (void)y, (void)z;
134}
135
136void VtkVisPipelineItem::setTranslation(double x, double y, double z) const
137{
138 (void)x;
139 (void)y, (void)z;
140}
141
142void VtkVisPipelineItem::setScaleOnChildren(double x, double y, double z) const
143{
144 for (int i = 0; i < this->childCount(); ++i)
145 {
146 VtkVisPipelineItem* child = this->child(i);
147 child->setScale(x, y, z);
148 }
149}
150
152{
153 // Reimplemented in subclass
154 (void)enable;
155}
156
158{
159 for (int i = 0; i < this->childCount(); ++i)
160 {
161 VtkVisPipelineItem* child = this->child(i);
162 child->setBackfaceCulling(static_cast<int>(enable));
163 child->setBackfaceCullingOnChildren(static_cast<int>(enable));
164 }
165}
166
168{
169 this->algorithm()->Update();
170 vtkDataSet* dataSet =
171 vtkDataSet::SafeDownCast(this->algorithm()->GetOutputDataObject(0));
172 QStringList dataSetAttributesList;
173 if (dataSet)
174 {
175 vtkPointData* pointData = dataSet->GetPointData();
176 // std::cout << " #point data arrays: " <<
177 // pointData->GetNumberOfArrays() << std::endl;
178 for (int i = 0; i < pointData->GetNumberOfArrays(); i++)
179 {
180 // std::cout << " Name: " << pointData->GetArrayName(i) <<
181 // std::endl;
182 dataSetAttributesList.push_back(QString("P-") +
183 pointData->GetArrayName(i));
184 }
185
186 vtkCellData* cellData = dataSet->GetCellData();
187 // std::cout << " #cell data arrays: " << cellData->GetNumberOfArrays()
188 // << std::endl;
189 for (int i = 0; i < cellData->GetNumberOfArrays(); i++)
190 {
191 // std::cout << " Name: " << cellData->GetArrayName(i) <<
192 // std::endl;
193 dataSetAttributesList.push_back(QString("C-") +
194 cellData->GetArrayName(i));
195 }
196 }
197 return dataSetAttributesList;
198}
virtual int childCount() const
Definition TreeItem.cpp:54
TreeItem * parentItem() const
Definition TreeItem.cpp:104
TreeItem * child(int row) const
Definition TreeItem.cpp:41
int row() const
Definition TreeItem.cpp:62
virtual bool setData(int column, const QVariant &value)
Definition TreeItem.cpp:91
TreeItem(QList< QVariant > data, TreeItem *parent)
Definition TreeItem.cpp:12
virtual QVariant data(int column) const
Definition TreeItem.cpp:83
Is used to combine several filter in one VtkVisPipelineItem. You can use vtk filter and custom filter...
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...
virtual void setTranslation(double x, double y, double z) const
Translates the item in visualisation-space. This function is empty and needs to be implemented by der...
vtkProp3D * actor() const
Returns the actor as vtkProp3D.
QStringList getScalarArrayNames() const
Returns a list of array names prefixed with P- or C- for point and cell data.
vtkAlgorithm * algorithm() const
Returns the algorithm object.
VtkAlgorithmProperties * _vtkProps
The active VtkAlgorithmProperties. From algorithm, compositeFilter, or copied from parent.
virtual void setBackfaceCulling(bool enable) const
Enables / disables backface culling.
bool isVisible() const
Returns if the VTK object is visible in the visualization.
bool setData(int column, const QVariant &value) override
void setBackfaceCullingOnChildren(bool enable) const
Enables / disables backface culling on all children.
VtkVisPipelineItem(vtkAlgorithm *algorithm, TreeItem *parentItem, const QList< QVariant > data=QList< QVariant >())
Constructor for a source/filter object.
void setVisible(bool visible)
Sets the visibility of the VTK object in the visualization.
vtkAlgorithm * _algorithm
VtkCompositeFilter * _compositeFilter
VtkVisPipelineItem * child(int row) const
Returns a VtkVisPipelineItem.
virtual int callVTKWriter(vtkAlgorithm *algorithm, const std::string &filename) const
int writeToFile(const std::string &filename) const
Writes this algorithm's vtkDataSet (i.e. vtkPolyData or vtkUnstructuredGrid) to a vtk-file.
QVariant data(int column) const override
VtkCompositeFilter * compositeFilter() const
Returns the composite filter.
void setScaleOnChildren(double x, double y, double z) const
Sets the geometry and date scaling recursively on all children of this item.