ENH: add vtk::Tools::Patch faceCentres() method

This commit is contained in:
Mark Olesen 2019-02-01 10:37:15 +01:00
parent 8473fd0b2a
commit 932666c408
2 changed files with 39 additions and 2 deletions

View File

@ -195,7 +195,7 @@ namespace Tools
//- Convert OpenFOAM patch to vtkPolyData
struct Patch
{
//- Convert local patch points to vtkPoints
//- Return local patch points as vtkPoints
template<class PatchType>
static vtkSmartPointer<vtkPoints> points(const PatchType& p);
@ -210,6 +210,10 @@ namespace Tools
//- Convert patch face normals to vtkFloatArray
template<class PatchType>
static vtkSmartPointer<vtkFloatArray> faceNormals(const PatchType& p);
//- Return patch face centres as vtkPoints
template<class PatchType>
static vtkSmartPointer<vtkPoints> faceCentres(const PatchType& p);
};

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -139,6 +139,39 @@ Foam::vtk::Tools::Patch::faceNormals(const PatchType& p)
}
template<class PatchType>
vtkSmartPointer<vtkPoints>
Foam::vtk::Tools::Patch::faceCentres(const PatchType& p)
{
auto vtkpoints = vtkSmartPointer<vtkPoints>::New();
vtkpoints->SetNumberOfPoints(p.size());
// Use cached values if available or loop over faces
// (avoid triggering cache)
vtkIdType pointId = 0;
if (p.hasFaceCentres())
{
for (const point& pt : p.faceCentres())
{
vtkpoints->SetPoint(pointId++, pt.v_);
}
}
else
{
for (const auto& f : p)
{
const point pt(f.centre(p.points()));
vtkpoints->SetPoint(pointId++, pt.v_);
}
}
return vtkpoints;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//
// Low-Level conversions