Skip to content

Commit

Permalink
retrieve fields from legacy vtk datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
aumuell authored and MDjur committed Mar 8, 2024
1 parent e4a7d08 commit f04d138
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions module/read/ReadVtk/ReadVtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ bool isCollectionFile(const std::string &fn)
return false;
}

template<class VO>
std::vector<std::string> getFields(VO *dsa)
{
std::vector<std::string> fields;
if (!dsa)
return fields;
int na = dsa->GetNumberOfArrays();
for (int i = 0; i < na; ++i) {
fields.push_back(dsa->GetArrayName(i));
//cerr << "field " << i << ": " << fields[i] << endl;
}
return fields;
}

template<class Reader>
VtkFile readFile(const std::string &filename, int piece = -1, bool ghost = false, bool onlyMeta = false)
{
Expand Down Expand Up @@ -123,7 +137,19 @@ VtkFile readFile(const std::string &filename, int piece = -1, bool ghost = false
if (onlyMeta) {
if (reader->GetOutput()) {
reader->GetOutput()->Register(reader);
result.dataset = reader->GetOutput();

if (result.pointfields.empty() && result.cellfields.empty()) {
reader->Update();
result.dataset = reader->GetOutput();
if (auto ds = vtkDataSet::SafeDownCast(result.dataset)) {
result.pointfields = getFields<vtkFieldData>(ds->GetPointData());
if (result.pointfields.empty())
result.pointfields = getFields<vtkFieldData>(ds->GetFieldData());
result.cellfields = getFields<vtkFieldData>(ds->GetCellData());
}
} else {
result.dataset = reader->GetOutput();
}
}
return result;
}
Expand Down Expand Up @@ -307,20 +333,6 @@ std::map<double, std::vector<VtkFile>> ReadVtk::readXmlCollection(const std::str
return timesteps;
}

template<class VO>
std::vector<std::string> getFields(VO *dsa)
{
std::vector<std::string> fields;
if (!dsa)
return fields;
int na = dsa->GetNumberOfArrays();
for (int i = 0; i < na; ++i) {
fields.push_back(dsa->GetArrayName(i));
//cerr << "field " << i << ": " << fields[i] << endl;
}
return fields;
}

void ReadVtk::setChoices(const VtkFile &fileinfo)
{
std::vector<std::string> cellFields({Invalid});
Expand Down

0 comments on commit f04d138

Please sign in to comment.