From b05d61b391499c804f5ffe1c51135550a3ff0be2 Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Sun, 30 Sep 2018 21:42:46 +0200 Subject: [PATCH] FEM: vtk, export FC result, small code improvements --- src/Mod/Fem/App/FemVTKTools.cpp | 66 +++++++++++++++++---------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/src/Mod/Fem/App/FemVTKTools.cpp b/src/Mod/Fem/App/FemVTKTools.cpp index e7037fc83f..37808ac0b9 100644 --- a/src/Mod/Fem/App/FemVTKTools.cpp +++ b/src/Mod/Fem/App/FemVTKTools.cpp @@ -790,19 +790,19 @@ void _importResult(const vtkSmartPointer dataset, App::DocumentObjec } void _exportResult(const App::DocumentObject* result, vtkSmartPointer grid, - const std::map& vectors, const std::map scalers){ + std::vector vectors, std::vector scalars){ const Fem::FemResultObject* res = static_cast(result); const vtkIdType nPoints = grid->GetNumberOfPoints(); // vectors - for (auto const& kv: vectors) { + for (std::vector::iterator it = vectors.begin(); it != vectors.end(); ++it ) { const int dim=3; //Fixme, detect dim App::PropertyVectorList* field = nullptr; - if (res->getPropertyByName(kv.first.c_str())) - field = static_cast(res->getPropertyByName(kv.first.c_str())); + if (res->getPropertyByName(it->c_str())) + field = static_cast(res->getPropertyByName(it->c_str())); else - Base::Console().Error("PropertyVectorList %s not found \n", kv.first.c_str()); + Base::Console().Error("PropertyVectorList %s not found \n", it->c_str()); if (field && field->getSize() > 0) { if (nPoints != field->getSize()) Base::Console().Error("Size of PropertyVectorList = %d, not equal to vtk mesh node count %d \n", field->getSize(), nPoints); @@ -810,7 +810,7 @@ void _exportResult(const App::DocumentObject* result, vtkSmartPointer data = vtkSmartPointer::New(); data->SetNumberOfComponents(dim); data->SetNumberOfTuples(vel.size()); - data->SetName(kv.second.c_str()); // kv.first may be a better name, without space + data->SetName(it->c_str()); vtkIdType i=0; for (std::vector::const_iterator it=vel.begin(); it!=vel.end(); ++it) { @@ -819,35 +819,35 @@ void _exportResult(const App::DocumentObject* result, vtkSmartPointerGetPointData()->AddArray(data); - Base::Console().Message(" Info: PropertyVectorList %s exported as vtk array name '%s'\n", kv.first.c_str(), kv.second.c_str()); + Base::Console().Message(" Info: PropertyVectorList %s exported as vtk array name '%s'\n", it->c_str(), it->c_str()); } else - Base::Console().Message(" Info: PropertyVectorList %s NOT exported to vtk, because size is: %i\n", kv.first.c_str(), field->getSize()); + Base::Console().Message(" Info: PropertyVectorList %s NOT exported to vtk, because size is: %i\n", it->c_str(), field->getSize()); } // scalars - for (auto const& kv: scalers) { + for (std::vector::iterator it = scalars.begin(); it != scalars.end(); ++it ) { App::PropertyFloatList* field = nullptr; - if (res->getPropertyByName(kv.first.c_str())) - field = static_cast(res->getPropertyByName(kv.first.c_str())); + if (res->getPropertyByName(it->c_str())) + field = static_cast(res->getPropertyByName(it->c_str())); else - Base::Console().Error("PropertyFloatList %s not found \n", kv.first.c_str()); + Base::Console().Error("PropertyFloatList %s not found \n", it->c_str()); if (field && field->getSize() > 0) { if (nPoints != field->getSize()) Base::Console().Error("Size of PropertyFloatList = %d, not equal to vtk mesh node count %d \n", field->getSize(), nPoints); const std::vector& vec = field->getValues(); vtkSmartPointer data = vtkSmartPointer::New(); data->SetNumberOfValues(vec.size()); - data->SetName(kv.second.c_str()); + data->SetName(it->c_str()); for (size_t i=0; iSetValue(i, vec[i]); grid->GetPointData()->AddArray(data); - Base::Console().Message(" Info: PropertyFloatList %s exported as vtk array name '%s'\n", kv.first.c_str(), kv.second.c_str()); + Base::Console().Message(" Info: PropertyFloatList %s exported as vtk array name '%s'\n", it->c_str(), it->c_str()); } else - Base::Console().Message(" Info: PropertyFloatList %s NOT exported to vtk, because size is: %i\n", kv.first.c_str(), field->getSize()); + Base::Console().Message(" Info: PropertyFloatList %s NOT exported to vtk, because size is: %i\n", it->c_str(), field->getSize()); } } @@ -933,26 +933,28 @@ void FemVTKTools::exportFreeCADResult(const App::DocumentObject* res, vtkSmartPo // see src/Mod/Fem/femobjects/_FemResultMechanical // App::PropertyVectorList will be a list of vectors in vtk - std::map vectors; - vectors["DisplacementVectors"] = "DisplacementVectors"; - vectors["StrainVectors"] = "StrainVectors"; - vectors["StressVectors"] = "StrainVectors"; + std::vector vectors = { + "DisplacementVectors", + "StressVectors", + "StrainVectors" + }; // App::PropertyFloatList will be a list of scalars in vtk - std::map scalers; - scalers["Peeq"] = "Peeq"; - scalers["DisplacementLengths"] = "DisplacementLengths"; - scalers["StressValues"] = "StressValues"; - scalers["PrincipalMax"] = "PrincipalMax"; - scalers["PrincipalMed"] = "PrincipalMed"; - scalers["PrincipalMin"] = "PrincipalMin"; - scalers["MaxShear"] = "MaxShear"; - scalers["MassFlowRate"] = "MassFlowRate"; - scalers["NetworkPressure"] = "Network Pressure"; - scalers["UserDefined"] = "UserDefined"; - scalers["Temperature"] = "Temperature"; + std::vector scalars = { + "Peeq", + "DisplacementLengths", + "StressValues", + "PrincipalMax", + "PrincipalMed", + "PrincipalMin", + "MaxShear", + "MassFlowRate", + "NetworkPressure", + "UserDefined", + "Temperature" + }; - _exportResult(res, grid, vectors, scalers); + _exportResult(res, grid, vectors, scalars); Base::Console().Message("End: Create VTK result data from FreeCAD result data.\n");