18#include <vtkAlgorithm.h>
20#include <vtkCellData.h>
21#include <vtkFieldData.h>
22#include <vtkGenericDataObjectReader.h>
23#include <vtkImageActor.h>
24#include <vtkImageReader2.h>
26#include <vtkPointData.h>
27#include <vtkPointSet.h>
29#include <vtkRenderer.h>
30#include <vtkSmartPointer.h>
31#include <vtkTransformFilter.h>
32#include <vtkXMLImageDataReader.h>
33#include <vtkXMLPolyDataReader.h>
34#include <vtkXMLRectilinearGridReader.h>
35#include <vtkXMLStructuredGridReader.h>
36#include <vtkXMLUnstructuredGridReader.h>
40#include <QElapsedTimer>
67 QList<QVariant> rootData;
68 rootData <<
"Object name"
74 QVariant backgroundColorVariant = settings.value(
"VtkBackgroundColor");
75 if (backgroundColorVariant != QVariant())
77 this->
setBGColor(backgroundColorVariant.value<QColor>());
81 settings.value(
"resetViewOnLoad",
true).toBool();
97 light->GetPosition(lightPos);
98 if (pos[0] == lightPos[0] && pos[1] == lightPos[1] &&
99 pos[2] == lightPos[2])
104 vtkLight* l = vtkLight::New();
105 l->SetPosition(pos[0], pos[1], pos[2]);
115 light->GetPosition(lightPos);
116 if (pos[0] == lightPos[0] && pos[1] == lightPos[1] &&
117 pos[2] == lightPos[2])
130 (*it)->GetPosition(lightPos);
131 if (pos[0] == lightPos[0] && pos[1] == lightPos[1] &&
132 pos[2] == lightPos[2])
144 double* color =
_renderer->GetBackground();
145 QColor c(
static_cast<int>(color[0] * 255),
146 static_cast<int>(color[1] * 255),
147 static_cast<int>(color[2] * 255));
154 settings.setValue(
"VtkBackgroundColor", color);
155 _renderer->SetBackground(color.redF(), color.greenF(), color.blueF());
160 return _actorMap.value(actor, QModelIndex());
165 Qt::ItemFlags defaultFlags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
167 if (!
index.isValid())
169 return Qt::ItemIsEnabled;
181 QElapsedTimer myTimer;
183 INFO(
"VTK Read: {:s}.", filename.toStdString());
186 if (filename.size() > 0)
188 vtkSmartPointer<vtkXMLDataReader> reader;
189 if (filename.endsWith(
"vti"))
191 reader = vtkSmartPointer<vtkXMLImageDataReader>::New();
193 else if (filename.endsWith(
"vtr"))
195 reader = vtkSmartPointer<vtkXMLRectilinearGridReader>::New();
197 else if (filename.endsWith(
"vts"))
199 reader = vtkSmartPointer<vtkXMLStructuredGridReader>::New();
201 else if (filename.endsWith(
"vtp"))
203 reader = vtkSmartPointer<vtkXMLPolyDataReader>::New();
205 else if (filename.endsWith(
"vtu"))
207 reader = vtkSmartPointer<vtkXMLUnstructuredGridReader>::New();
209 else if (filename.endsWith(
"vtk"))
211 vtkGenericDataObjectReader* oldStyleReader =
212 vtkGenericDataObjectReader::New();
213 oldStyleReader->SetFileName(filename.toStdString().c_str());
214 oldStyleReader->ReadAllFieldsOn();
215 oldStyleReader->ReadAllScalarsOn();
216 oldStyleReader->Update();
217 vtkDataSet* dataSet =
218 vtkDataSet::SafeDownCast(oldStyleReader->GetOutput());
225 ERR(
"VtkVisPipeline::loadFromFile(): not a valid vtkDataSet.");
233 reader->SetFileName(filename.toStdString().c_str());
241 vtkSmartPointer<vtkDataSet> dataSet = reader->GetOutputAsDataSet();
248 ERR(
"VtkVisPipeline::loadFromFile(): not a valid vtkDataSet.");
252 INFO(
"{:d} ms", myTimer.elapsed());
265 item->setScaleOnChildren(1.0, 1.0, 1.0);
280 item->setBackfaceCullingOnChildren(enable);
287 const std::string& name,
294 const std::string& name)
305 const QModelIndex& parent)
316 if (
dynamic_cast<vtkImageAlgorithm*
>(item->
algorithm()) ==
nullptr)
320 settings.value(
"globalSuperelevation", 1.0).toDouble());
324 int parentChildCount = parentItem->
childCount();
325 QModelIndex newIndex =
index(parentChildCount - 1, 0,
parent);
334 if (
dynamic_cast<vtkImageAlgorithm*
>(item->
algorithm()))
336 static_cast<vtkImageActor*
>(item->
actor())->InterpolateOff();
347 vtkAlgorithm* source, QModelIndex parent )
349 std::string itemName;
353 auto* old_reader =
dynamic_cast<vtkGenericDataObjectReader*
>(source);
354 auto* new_reader =
dynamic_cast<vtkXMLReader*
>(source);
355 auto* image_reader =
dynamic_cast<vtkImageReader2*
>(source);
360 itemName = old_reader->GetFileName();
364 itemName = new_reader->GetFileName();
366 else if (image_reader)
368 itemName = image_reader->GetFileName();
372 itemName = props->GetName().toStdString();
380 if (itemName.length() == 0)
382 itemName = source->GetClassName();
385 QList<QVariant> itemData;
386 itemData << QString::fromStdString(itemName) <<
true;
389 if (
dynamic_cast<vtkImageAlgorithm*
>(source))
401 const std::string& name,
417 const std::string& name)
439 if (item->
algorithm() == sItem->vtkSource())
449 if (!
index.isValid())
454 QMap<vtkProp3D*, QModelIndex>::iterator it =
_actorMap.begin();
457 QModelIndex itIndex = it.value();
458 if (itIndex ==
index)
480 vtkPointData* pointData = dataSet->GetPointData();
481 INFO(
" #point data arrays: {:d}", pointData->GetNumberOfArrays());
482 for (
int i = 0; i < pointData->GetNumberOfArrays(); i++)
483 INFO(
" Name: {:s}", pointData->GetArrayName(i));
485 vtkCellData* cellData = dataSet->GetCellData();
486 INFO(
" #cell data arrays: {:d}", cellData->GetNumberOfArrays());
487 for (
int i = 0; i < cellData->GetNumberOfArrays(); i++)
488 INFO(
" Name: {:s}", cellData->GetArrayName(i));
491 ERR(
"VtkVisPipeline::listArrays(): not a valid vtkDataSet.");
496 std::vector<double>
const& quality)
498 if (!source || quality.empty())
504 for (
int i = 0; i < nSources; i++)
508 if (parentItem->algorithm() != source)
513 QList<QVariant> itemData;
514 itemData <<
"MeshQuality: " +
515 QString::fromStdString(MeshQualityType2String(t))
519 "VtkCompositeElementSelectionFilter",
520 parentItem->transformFilter());
524 std::minmax_element(quality.cbegin(), quality.cend()));
526 *range.first, *range.second);
529 ->setSelectionArray(
"Selection", quality);
542 for (
int i = 0; i < nSources; i++)
546 if (parentItem->algorithm() == source)
548 QList<QVariant> itemData;
549 itemData <<
"Selected GeoObject" <<
true;
553 "VtkCompositeGeoObjectFilter",
554 parentItem->transformFilter());
558 QModelIndex parent_index =
576 vtkUnstructuredGridAlgorithm
const*
const source,
unsigned index,
580 for (
int i = 0; i < nSources; i++)
584 if (parentItem->algorithm() == source)
586 QList<QVariant> itemData;
587 itemData <<
"Selected Mesh Component" <<
true;
588 QList<QVariant> selected_index;
595 "VtkCompositeElementSelectionFilter",
596 parentItem->transformFilter());
598 ->setSelectionArray(
"vtkIdFilter_Ids");
600 ->SetUserVectorProperty(
"Threshold Between",
606 "VtkCompositeNodeSelectionFilter",
607 parentItem->transformFilter());
608 std::vector<unsigned> indices(1);
611 ->setSelectionArray(indices);
615 QModelIndex parent_index =
Definition of the GeoTreeModel class.
Definition of the LinearIntervalInterpolation class.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition of the MeshItem class.
Definition of the MeshModel class.
Definition of the Mesh class.
Definition of the StationTreeModel class.
Definition of the TreeModel class.
Definition of the VtkAlgorithmProperties class.
Definition of the VtkCompositeSelectionFilter class.
Definition of the VtkCompositeGeoObjectFilter class.
Definition of the VtkCompositeNodeSelectionFilter class.
Definition of the VtkFilterFactory class.
VtkMappedMeshSource is a source class to transform OGS meshes into complete vtkUnstructuredGrids....
Definition of the VtkVisImageItem class.
Definition of the VtkVisPipelineItem class.
Definition of the VtkVisPipeline class.
Definition of the VtkVisPointSetItem class.
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.
const std::string getName() const
Get name of the mesh.
const MeshLib::Mesh * GetMesh() const
Returns the mesh.
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
TreeItem * child(int row) const
A hierarchical model for a tree implemented as a double-linked list.
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
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.