7#include <vtkAlgorithm.h>
9#include <vtkCellData.h>
10#include <vtkFieldData.h>
11#include <vtkGenericDataObjectReader.h>
12#include <vtkImageActor.h>
13#include <vtkImageReader2.h>
15#include <vtkPointData.h>
16#include <vtkPointSet.h>
18#include <vtkRenderer.h>
19#include <vtkSmartPointer.h>
20#include <vtkTransformFilter.h>
21#include <vtkXMLImageDataReader.h>
22#include <vtkXMLPolyDataReader.h>
23#include <vtkXMLRectilinearGridReader.h>
24#include <vtkXMLStructuredGridReader.h>
25#include <vtkXMLUnstructuredGridReader.h>
29#include <QElapsedTimer>
56 QList<QVariant> rootData;
57 rootData <<
"Object name"
63 QVariant backgroundColorVariant = settings.value(
"VtkBackgroundColor");
64 if (backgroundColorVariant != QVariant())
66 this->
setBGColor(backgroundColorVariant.value<QColor>());
70 settings.value(
"resetViewOnLoad",
true).toBool();
86 light->GetPosition(lightPos);
87 if (pos[0] == lightPos[0] && pos[1] == lightPos[1] &&
88 pos[2] == lightPos[2])
93 vtkLight* l = vtkLight::New();
94 l->SetPosition(pos[0], pos[1], pos[2]);
104 light->GetPosition(lightPos);
105 if (pos[0] == lightPos[0] && pos[1] == lightPos[1] &&
106 pos[2] == lightPos[2])
119 (*it)->GetPosition(lightPos);
120 if (pos[0] == lightPos[0] && pos[1] == lightPos[1] &&
121 pos[2] == lightPos[2])
133 double* color =
_renderer->GetBackground();
134 QColor c(
static_cast<int>(color[0] * 255),
135 static_cast<int>(color[1] * 255),
136 static_cast<int>(color[2] * 255));
143 settings.setValue(
"VtkBackgroundColor", color);
144 _renderer->SetBackground(color.redF(), color.greenF(), color.blueF());
149 return _actorMap.value(actor, QModelIndex());
154 Qt::ItemFlags defaultFlags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
156 if (!
index.isValid())
158 return Qt::ItemIsEnabled;
170 QElapsedTimer myTimer;
172 INFO(
"VTK Read: {:s}.", filename.toStdString());
175 if (filename.size() > 0)
177 vtkSmartPointer<vtkXMLDataReader> reader;
178 if (filename.endsWith(
"vti"))
180 reader = vtkSmartPointer<vtkXMLImageDataReader>::New();
182 else if (filename.endsWith(
"vtr"))
184 reader = vtkSmartPointer<vtkXMLRectilinearGridReader>::New();
186 else if (filename.endsWith(
"vts"))
188 reader = vtkSmartPointer<vtkXMLStructuredGridReader>::New();
190 else if (filename.endsWith(
"vtp"))
192 reader = vtkSmartPointer<vtkXMLPolyDataReader>::New();
194 else if (filename.endsWith(
"vtu"))
196 reader = vtkSmartPointer<vtkXMLUnstructuredGridReader>::New();
198 else if (filename.endsWith(
"vtk"))
200 vtkGenericDataObjectReader* oldStyleReader =
201 vtkGenericDataObjectReader::New();
202 oldStyleReader->SetFileName(filename.toStdString().c_str());
203 oldStyleReader->ReadAllFieldsOn();
204 oldStyleReader->ReadAllScalarsOn();
205 oldStyleReader->Update();
206 vtkDataSet* dataSet =
207 vtkDataSet::SafeDownCast(oldStyleReader->GetOutput());
214 ERR(
"VtkVisPipeline::loadFromFile(): not a valid vtkDataSet.");
222 reader->SetFileName(filename.toStdString().c_str());
230 vtkSmartPointer<vtkDataSet> dataSet = reader->GetOutputAsDataSet();
237 ERR(
"VtkVisPipeline::loadFromFile(): not a valid vtkDataSet.");
241 INFO(
"{:d} ms", myTimer.elapsed());
248 for (
int i = 0; i <
_rootItem->childCount(); ++i)
254 item->setScaleOnChildren(1.0, 1.0, 1.0);
263 for (
int i = 0; i <
_rootItem->childCount(); ++i)
269 item->setBackfaceCullingOnChildren(enable);
276 const std::string& name,
283 const std::string& name)
294 const QModelIndex&
parent)
305 if (
dynamic_cast<vtkImageAlgorithm*
>(item->
algorithm()) ==
nullptr)
309 settings.value(
"globalSuperelevation", 1.0).toDouble());
313 int parentChildCount = parentItem->
childCount();
314 QModelIndex newIndex =
index(parentChildCount - 1, 0,
parent);
323 if (
dynamic_cast<vtkImageAlgorithm*
>(item->
algorithm()))
325 static_cast<vtkImageActor*
>(item->
actor())->InterpolateOff();
336 vtkAlgorithm* source, QModelIndex
parent )
338 std::string itemName;
342 auto* old_reader =
dynamic_cast<vtkGenericDataObjectReader*
>(source);
343 auto* new_reader =
dynamic_cast<vtkXMLReader*
>(source);
344 auto* image_reader =
dynamic_cast<vtkImageReader2*
>(source);
349 itemName = old_reader->GetFileName();
353 itemName = new_reader->GetFileName();
355 else if (image_reader)
357 itemName = image_reader->GetFileName();
361 itemName = props->GetName().toStdString();
365 itemName = meshSource->GetMesh()->getName();
369 if (itemName.length() == 0)
371 itemName = source->GetClassName();
374 QList<QVariant> itemData;
375 itemData << QString::fromStdString(itemName) <<
true;
378 if (
dynamic_cast<vtkImageAlgorithm*
>(source))
390 const std::string& name,
393 for (
int i = 0; i <
_rootItem->childCount(); i++)
406 const std::string& name)
408 for (
int i = 0; i <
_rootItem->childCount(); i++)
424 for (
int i = 0; i <
_rootItem->childCount(); i++)
428 if (item->
algorithm() == sItem->vtkSource())
438 if (!
index.isValid())
443 QMap<vtkProp3D*, QModelIndex>::iterator it =
_actorMap.begin();
446 QModelIndex itIndex = it.value();
447 if (itIndex ==
index)
469 vtkPointData* pointData = dataSet->GetPointData();
470 INFO(
" #point data arrays: {:d}", pointData->GetNumberOfArrays());
471 for (
int i = 0; i < pointData->GetNumberOfArrays(); i++)
472 INFO(
" Name: {:s}", pointData->GetArrayName(i));
474 vtkCellData* cellData = dataSet->GetCellData();
475 INFO(
" #cell data arrays: {:d}", cellData->GetNumberOfArrays());
476 for (
int i = 0; i < cellData->GetNumberOfArrays(); i++)
477 INFO(
" Name: {:s}", cellData->GetArrayName(i));
480 ERR(
"VtkVisPipeline::listArrays(): not a valid vtkDataSet.");
485 std::vector<double>
const& quality)
487 if (!source || quality.empty())
492 int const nSources = this->
_rootItem->childCount();
493 for (
int i = 0; i < nSources; i++)
497 if (parentItem->algorithm() != source)
502 QList<QVariant> itemData;
503 itemData <<
"MeshQuality: " +
504 QString::fromStdString(MeshQualityType2String(t))
508 "VtkCompositeElementSelectionFilter",
509 parentItem->transformFilter());
513 std::minmax_element(quality.cbegin(), quality.cend()));
515 *range.first, *range.second);
518 ->setSelectionArray(
"Selection", quality);
530 int nSources = this->
_rootItem->childCount();
531 for (
int i = 0; i < nSources; i++)
535 if (parentItem->algorithm() == source)
537 QList<QVariant> itemData;
538 itemData <<
"Selected GeoObject" <<
true;
542 "VtkCompositeGeoObjectFilter",
543 parentItem->transformFilter());
547 QModelIndex parent_index =
565 vtkUnstructuredGridAlgorithm
const*
const source,
unsigned index,
568 int nSources = this->
_rootItem->childCount();
569 for (
int i = 0; i < nSources; i++)
573 if (parentItem->algorithm() == source)
575 QList<QVariant> itemData;
576 itemData <<
"Selected Mesh Component" <<
true;
577 QList<QVariant> selected_index;
584 "VtkCompositeElementSelectionFilter",
585 parentItem->transformFilter());
587 ->setSelectionArray(
"vtkIdFilter_Ids");
589 ->SetUserVectorProperty(
"Threshold Between",
595 "VtkCompositeNodeSelectionFilter",
596 parentItem->transformFilter());
597 std::vector<unsigned> indices(1);
600 ->setSelectionArray(indices);
604 QModelIndex parent_index =
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
A model for the GeoTreeView implementing a tree as a double-linked list.
vtkPolyDataAlgorithm * vtkSource(const std::string &name, GeoLib::GEOTYPE type) const
Returns the vtk-object indicated by type of the geometry indicated by name.
A TreeItem containing a mesh and the associated vtk object used in the Mesh Model.
MeshLib::VtkMappedMeshSource * vtkSource() const
Returns the VTK object.
VtkMappedMeshSource is a source class to transform OGS meshes into complete vtkUnstructuredGrids....
A model for the StationTreeView implementing a tree as a double-linked list.
vtkPolyDataAlgorithm * vtkSource(const std::string &name) const
Objects nodes for the TreeModel.
virtual int childCount() const
void appendChild(TreeItem *item)
TreeItem * parentItem() const
bool removeRows(int position, int count, const QModelIndex &parent) override
TreeItem * getItem(const QModelIndex &index) const
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
QModelIndex parent(const QModelIndex &index) const override
TreeModel(QObject *parent=nullptr)
bool setData(const QModelIndex &index, const QVariant &value, int role) override
Contains properties for the visualization of objects as VtkVisPipelineItems.
This filter selects/thresholds elements based on the selected array.
Is used to combine several filter in one VtkVisPipelineItem. You can use vtk filter and custom filter...
Highlights a single GeoObject.
This filter displays the points/nodes given in the index field as spheres.
static VtkCompositeFilter * CreateCompositeFilter(QString type, vtkAlgorithm *inputAlgorithm)
Creates a composite filter by name.
An item in the VtkVisPipeline containing an image to be visualized.
An item in the VtkVisPipeline containing a graphic object to be visualized.
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...
vtkProp3D * actor() const
Returns the actor as vtkProp3D.
vtkAlgorithm * algorithm() const
Returns the algorithm object.
virtual void setBackfaceCulling(bool enable) const
Enables / disables backface culling.
virtual void Initialize(vtkRenderer *renderer)=0
Initializes vtkMapper and vtkActor necessary for visualization of the item and sets the item's proper...
void setGlobalBackfaceCulling(bool enable) const
Enables / disables backface culling on all actors.
QModelIndex _highlighted_mesh_component
void itemSelected(const QModelIndex &) const
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Emits vtkVisPipelineChanged() and calls base class method.
std::list< vtkLight * > _lights
void addLight(const GeoLib::Point &pos)
Adds a light to the scene at the given coordinates.
void removeLight(const GeoLib::Point &pos)
Removes a light at the given coordinates (if possible).
void vtkVisPipelineChanged() const
Is emitted when a pipeline item was added or removed.
void addPipelineItem(MeshModel *model, const QModelIndex &idx)
Adds the given Model to the pipeline.
void removePipelineItem(QModelIndex index)
Removes the vtkAlgorithm at the given QModelIndex (and all attached vtkAlgorithms) from the pipeline.
VtkVisPipeline(vtkRenderer *renderer, QObject *parent=nullptr)
void removeHighlightedGeoObject()
Removes the currently highlighted geometry-object.
void setBGColor(const QColor &color)
Sets the background-colour of the scene.
void setGlobalSuperelevation(double factor) const
Sets a global superelevation factor on all source items and resets the factor on other items to 1.
void removeHighlightedMeshComponent()
Removes the currently highlighted mesh component.
Qt::ItemFlags flags(const QModelIndex &index) const override
vtkLight * getLight(const GeoLib::Point &pos) const
Returns a light (or nullptr) for the given coordinates.
void loadFromFile(QString filename)
Loads a vtk object from the given file and adds it to the pipeline.
void highlightGeoObject(const vtkPolyDataAlgorithm *source, int index)
Applies a VtkCompositeGeoObjectFilter to add a specific index of the given geometry-source to the pip...
void highlightMeshComponent(vtkUnstructuredGridAlgorithm const *const source, unsigned index, bool is_element)
Applies a VtkCompositeSelectionFilter to add a specific component of the given mesh-source to the pip...
void showMeshElementQuality(MeshLib::VtkMappedMeshSource *source, MeshLib::MeshQualityType t, std::vector< double > const &quality)
Checks the quality of mesh elements and adds a filter to highlight deformed elements.
void removeSourceItem(MeshModel *model, const QModelIndex &idx)
Removes the given Model (and all attached vtkAlgorithms) from the pipeline.
QModelIndex getIndex(vtkProp3D *actor)
Returns the QModelIndex of VtkVisPipelineItem which actor is the given one.
bool _resetCameraOnAddOrRemove
QMap< vtkProp3D *, QModelIndex > _actorMap
QModelIndex _highlighted_geo_index
QColor getBGColor() const
Returns the background-colour of the scene.
void listArrays(vtkDataSet *dataSet)
An item in the VtkVisPipeline containing a point set object to be visualized.
MeshQualityType
Describes a mesh quality metric.