Fem: Add method to rename pipeline VTK data arrays
This commit is contained in:
committed by
Benjamin Nauck
parent
f1258e36b2
commit
6d376dc77a
@@ -27,6 +27,7 @@
|
||||
#include <vtkAppendFilter.h>
|
||||
#include <vtkDataSetReader.h>
|
||||
#include <vtkImageData.h>
|
||||
#include <vtkPointData.h>
|
||||
#include <vtkRectilinearGrid.h>
|
||||
#include <vtkStructuredGrid.h>
|
||||
#include <vtkUnstructuredGrid.h>
|
||||
@@ -46,8 +47,6 @@
|
||||
#endif
|
||||
|
||||
#include <Base/Console.h>
|
||||
#include <cmath>
|
||||
#include <QString>
|
||||
|
||||
#include "FemMesh.h"
|
||||
#include "FemMeshObject.h"
|
||||
@@ -737,6 +736,38 @@ void FemPostPipeline::onDocumentRestored()
|
||||
}
|
||||
}
|
||||
|
||||
void FemPostPipeline::renameArrays(const std::map<std::string, std::string>& names)
|
||||
{
|
||||
std::vector<vtkSmartPointer<vtkDataSet>> fields;
|
||||
auto data = Data.getValue();
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (auto dataSet = vtkDataSet::SafeDownCast(data)) {
|
||||
fields.emplace_back(dataSet);
|
||||
}
|
||||
else if (auto blocks = vtkMultiBlockDataSet::SafeDownCast(data)) {
|
||||
for (unsigned int i = 0; i < blocks->GetNumberOfBlocks(); ++i) {
|
||||
if (auto dataSet = vtkDataSet::SafeDownCast(blocks->GetBlock(i))) {
|
||||
fields.emplace_back(dataSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto f : fields) {
|
||||
auto pointData = f->GetPointData();
|
||||
for (const auto& name : names) {
|
||||
auto array = pointData->GetAbstractArray(name.first.c_str());
|
||||
if (array) {
|
||||
array->SetName(name.second.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Data.touch();
|
||||
}
|
||||
|
||||
PyObject* FemPostPipeline::getPyObject()
|
||||
{
|
||||
if (PythonObject.is(Py::_None())) {
|
||||
|
||||
@@ -98,6 +98,7 @@ public:
|
||||
Base::Unit unit,
|
||||
std::string& frame_type);
|
||||
void scale(double s);
|
||||
void renameArrays(const std::map<std::string, std::string>& names);
|
||||
|
||||
// load from results
|
||||
void load(FemResultObject* res);
|
||||
|
||||
@@ -66,5 +66,10 @@ Load a single result object or create a multiframe result by loading multiple re
|
||||
<UserDocu>Check if this pipeline holds a given post-processing object</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="renameArrays">
|
||||
<Documentation>
|
||||
<UserDocu>Change name of data arrays</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
</PythonExport>
|
||||
</GenerateModel>
|
||||
|
||||
@@ -285,6 +285,28 @@ PyObject* FemPostPipelinePy::holdsPostObject(PyObject* args)
|
||||
return Py_BuildValue("O", (ok ? Py_True : Py_False));
|
||||
}
|
||||
|
||||
PyObject* FemPostPipelinePy::renameArrays(PyObject* args)
|
||||
{
|
||||
PyObject* pyObj;
|
||||
if (!PyArg_ParseTuple(args, "O!", &(PyDict_Type), &pyObj)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Py::Dict pyNames {pyObj};
|
||||
std::map<std::string, std::string> names {};
|
||||
for (auto&& [key, value] : pyNames) {
|
||||
if (!key.isString() || !value.isString()) {
|
||||
PyErr_SetString(PyExc_TypeError, "Names must be string objects");
|
||||
return nullptr;
|
||||
}
|
||||
names.emplace(key.as_string(), static_cast<Py::Object>(value).as_string());
|
||||
}
|
||||
|
||||
getFemPostPipelinePtr()->renameArrays(names);
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* FemPostPipelinePy::getCustomAttributes(const char* /*attr*/) const
|
||||
{
|
||||
return nullptr;
|
||||
|
||||
Reference in New Issue
Block a user