FEM: Extract postprocessing data only if available. Fixes #22193 (#23127)

* FEM: Extract postprocessing data only if available. Fixes #22193

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Stefan Tröger
2025-08-25 05:16:29 +02:00
committed by GitHub
parent 134e34944b
commit 17ec624997
2 changed files with 30 additions and 0 deletions

View File

@@ -29,6 +29,7 @@
#include <vtkAlgorithm.h>
#include <vtkAlgorithmOutput.h>
#include <vtkUnstructuredGrid.h>
#include <vtkInformation.h>
#endif
#include <App/FeaturePythonPyImp.h>
@@ -218,6 +219,17 @@ DocumentObjectExecReturn* FemPostFilter::execute()
return StdReturn;
}
bool FemPostFilter::dataIsAvailable()
{
auto algo = getFilterOutput();
if (!algo) {
return false;
}
vtkInformation* info = algo->GetInputInformation(0, 0);
return bool(info->Has(vtkDataObject::DATA_OBJECT()));
}
vtkSmartPointer<vtkDataSet> FemPostFilter::getInputData()
{
auto active = m_pipelines[m_activePipeline];
@@ -233,12 +245,21 @@ vtkSmartPointer<vtkDataSet> FemPostFilter::getInputData()
if (!algo) {
return nullptr;
}
// make sure the data processing is up to date
if (Frame.getValue() > 0) {
algo->UpdateTimeStep(Frame.getValue());
}
else {
algo->Update();
}
// check if the algorithm has data available
vtkInformation* info = algo->GetInputInformation(0, 0);
if (!bool(info->Has(vtkDataObject::DATA_OBJECT()))) {
return nullptr;
}
return vtkDataSet::SafeDownCast(algo->GetOutputDataObject(0));
}
@@ -472,6 +493,10 @@ void FemPostDataAlongLineFilter::GetAxisData()
std::vector<double> coords;
std::vector<double> values;
if (!dataIsAvailable()) {
return;
}
vtkSmartPointer<vtkDataObject> data = m_probe->GetOutputDataObject(0);
vtkDataSet* dset = vtkDataSet::SafeDownCast(data);
if (!dset) {
@@ -597,6 +622,10 @@ short int FemPostDataAtPointFilter::mustExecute() const
void FemPostDataAtPointFilter::GetPointData()
{
if (!dataIsAvailable()) {
return;
}
std::vector<double> values;
vtkSmartPointer<vtkDataObject> data = m_probe->GetOutputDataObject(0);

View File

@@ -62,6 +62,7 @@ class FemExport FemPostFilter: public Fem::FemPostObject
PROPERTY_HEADER_WITH_OVERRIDE(Fem::FemPostFilter);
protected:
bool dataIsAvailable();
vtkSmartPointer<vtkDataSet> getInputData();
std::vector<std::string> getInputVectorFields();
std::vector<std::string> getInputScalarFields();