From a90d2215461582021ceee108c8b18adee9d00fde Mon Sep 17 00:00:00 2001 From: qingfengxia Date: Sun, 22 Jan 2017 13:19:24 +0000 Subject: [PATCH] Fem: add length scaling (metre to mm) option for VTK mesh import --- src/Mod/Fem/App/FemVTKTools.cpp | 41 +++++++++++++++++++++++++++++---- src/Mod/Fem/App/FemVTKTools.h | 2 +- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/Mod/Fem/App/FemVTKTools.cpp b/src/Mod/Fem/App/FemVTKTools.cpp index c5f8d337b..0f06ed00b 100644 --- a/src/Mod/Fem/App/FemVTKTools.cpp +++ b/src/Mod/Fem/App/FemVTKTools.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -109,7 +110,13 @@ template void writeVTKFile(const char* filename, vtkSmartPointer< writer->Write(); } -void FemVTKTools::importVTKMesh(vtkSmartPointer dataset, FemMesh* mesh) +/* + double scale = 1000; + p[0] = p[0]* scale; // scale back to mm + p[1] = p[1]* scale; + p[1] = p[1]* scale; + */ +void FemVTKTools::importVTKMesh(vtkSmartPointer dataset, FemMesh* mesh, float scale) { const vtkIdType nPoints = dataset->GetNumberOfPoints(); const vtkIdType nCells = dataset->GetNumberOfCells(); @@ -126,7 +133,7 @@ void FemVTKTools::importVTKMesh(vtkSmartPointer dataset, FemMesh* me for(vtkIdType i=0; iGetPoint(i); - meshds->AddNodeWithID(p[0], p[1], p[2], i+1); + meshds->AddNodeWithID(p[0]*scale, p[1]*scale, p[2]*scale, i+1); } for(vtkIdType iCell=0; iCellGetInt("UserSchema",0); + float scale = 1.0; + if(unitSchema == 0) // standard mm + { + scale = 1000.0; // convert from meter in length of CFD result file + } vtkSmartPointer ds; if(f.hasExtension("vtu")) { @@ -528,7 +542,7 @@ App::DocumentObject* FemVTKTools::readFluidicResult(const char* filename, App::D App::DocumentObject* mesh = pcDoc->addObject("Fem::FemMeshObject", "ResultMesh"); FemMesh* fmesh = new FemMesh(); // PropertyFemMesh instance is responsible to relase FemMesh ?? - importVTKMesh(dataset, fmesh); + importVTKMesh(dataset, fmesh, scale); static_cast(mesh->getPropertyByName("FemMesh"))->setValue(*fmesh); static_cast(result->getPropertyByName("Mesh"))->setValue(mesh); // PropertyLink is the property type to store DocumentObject pointer @@ -636,20 +650,37 @@ void FemVTKTools::importFluidicResult(vtkSmartPointer dataset, App:: vtkSmartPointer vel = pd->GetArray(vars["Velocity"]); if(nPoints && vel && vel->GetNumberOfComponents() == 3) { std::vector vec(nPoints); - double vmin=1.0e100, vmean=0.0, vmax=0.0; // only velocity magnitude is calc in c++ + double vmin=1.0e100, vmean=0.0, vmax=0.0; + //stat of Vx, Vy, Vz is not necessary + double vmins[3] = {0.0, 0.0, 0.0}; + double vmeans[3] = {0.0, 0.0, 0.0}; + double vmaxs[3] = {0.0, 0.0, 0.0}; for(vtkIdType i=0; iGetTuple(i); // both vtkFloatArray and vtkDoubleArray return double* for GetTuple(i) double vmag = std::sqrt(p[0]*p[0] + p[1]*p[1] + p[2]*p[2]); + for(int ii=0; ii<3; ii++) { + vmeans[ii] += p[ii]; + if(p[ii] > vmaxs[ii]) vmaxs[ii] = p[ii]; + if(p[ii] < vmins[ii]) vmins[ii] = p[ii]; + } vmean += vmag; if(vmag > vmax) vmax = vmag; if(vmag < vmin) vmin = vmag; + vec[i] = (Base::Vector3d(p[0], p[1], p[2])); nodeIds[i] = i; } + + for(int ii=0; ii<3; ii++) { + stats[ii*3] = vmins[ii]; + stats[ii*3 + 2] = vmaxs[ii]; + stats[ii*3 + 1] = vmeans[ii]/nPoints; + } int index = varids["Umag"]; stats[index*3] = vmin; stats[index*3 + 2] = vmax; stats[index*3 + 1] = vmean/nPoints; + App::PropertyVectorList* velocity = static_cast(res->getPropertyByName("Velocity")); if(velocity) { //PropertyVectorList will not show up in PropertyEditor diff --git a/src/Mod/Fem/App/FemVTKTools.h b/src/Mod/Fem/App/FemVTKTools.h index bcb14c426..5ae255640 100644 --- a/src/Mod/Fem/App/FemVTKTools.h +++ b/src/Mod/Fem/App/FemVTKTools.h @@ -46,7 +46,7 @@ namespace Fem /*! FemMesh import from vtkUnstructuredGrid instance */ - static void importVTKMesh(vtkSmartPointer grid, FemMesh* mesh); + static void importVTKMesh(vtkSmartPointer grid, FemMesh* mesh, float scale = 1.0); /*! FemMesh read from vtkUnstructuredGrid data file */