Commit c5518dd9 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: additional vtk tools for faceNormals, writing file-series

parent 0ec8e3e7
......@@ -197,6 +197,10 @@ public:
//- Convert patch points/faces to vtkPolyData
template<class PatchType>
static vtkSmartPointer<vtkPolyData> mesh(const PatchType& p);
//- Convert patch face normals to vtkFloatArray
template<class PatchType>
static vtkSmartPointer<vtkFloatArray> faceNormals(const PatchType& p);
};
......
......@@ -109,6 +109,32 @@ Foam::vtk::Tools::Patch::mesh(const PatchType& p)
}
template<class PatchType>
vtkSmartPointer<vtkFloatArray>
Foam::vtk::Tools::Patch::faceNormals(const PatchType& p)
{
auto array = vtkSmartPointer<vtkFloatArray>::New();
array->SetNumberOfComponents(3);
array->SetNumberOfTuples(p.size());
// Unit normals for patch faces.
// If not already cached, could be more memory efficient to loop over
// the individual faces instead.
const vectorField& norms = p.faceNormals();
vtkIdType faceId = 0;
for (const vector& n : norms)
{
array->SetTuple(faceId, n.v_);
++faceId;
}
return array;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//
// Low-Level conversions
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -46,6 +46,7 @@ Foam::vtk::fileTagNames
{ fileTag::POINT_DATA, "PointData" },
{ fileTag::POLY_DATA, "PolyData" },
{ fileTag::UNSTRUCTURED_GRID, "UnstructuredGrid" },
{ fileTag::MULTI_BLOCK, "vtkMultiBlockDataSet" },
};
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -115,6 +115,7 @@ namespace vtk
POINT_DATA, //!< "PointData"
POLY_DATA, //!< "PolyData"
UNSTRUCTURED_GRID, //!< "UnstructuredGrid"
MULTI_BLOCK, //!< "vtkMultiBlockDataSet"
};
//- Strings corresponding to the vtk xml tags
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -33,6 +33,7 @@ License
#include "foamVtkLegacyAsciiFormatter.H"
#include "foamVtkLegacyRawFormatter.H"
#include "typeInfo.H"
#include "instant.H"
// * * * * * * * * * * * * * * * Static Data * * * * * * * * * * * * * * * * //
......@@ -101,19 +102,52 @@ Foam::vtk::newFormatter
}
void Foam::vtk::writeSeries
(
Ostream& os,
const word& prefix,
const word& suffix,
const UList<instant>& series
)
{
// Begin file-series (JSON)
os << "{\n \"file-series-version\" : \"1.0\",\n \"files\" : [\n";
// Track how many entries are remaining
// - trailing commas on all but the final entry (JSON requirement)
label nremain = series.size();
// Each entry
// { "name" : "<prefix>name<suffix>", "time" : value }
for (const instant& inst : series)
{
os << " { \"name\" : \""
<< prefix << inst.name() << suffix
<< "\", \"time\" : " << inst.value() << " }";
if (--nremain)
{
os << ',';
}
os << nl;
}
os << " ]\n}\n";
}
Foam::label Foam::vtk::writeVtmFile
(
std::ostream& os,
const UList<fileName>& files
)
{
const word& content = "vtkMultiBlockDataSet";
asciiFormatter vtmFile(os);
vtmFile
.xmlHeader()
.beginVTKFile(content, "1.0");
.beginVTKFile(fileTagNames[vtk::fileTag::MULTI_BLOCK], "1.0");
forAll(files, i)
{
......@@ -124,7 +158,7 @@ Foam::label Foam::vtk::writeVtmFile
.closeTag(true);
}
vtmFile.endTag(content).endVTKFile();
vtmFile.endTag(fileTagNames[vtk::fileTag::MULTI_BLOCK]).endVTKFile();
return files.size();
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -54,6 +54,9 @@ SourceFiles
namespace Foam
{
// Forward declarations
class instant;
namespace vtk
{
......@@ -73,6 +76,19 @@ namespace vtk
);
//- Write file series (JSON format) for specified time instances
//
// \param prefix before the \c instant.name()
// \param suffix after the \c instant.name()
// \param series the list of name/value entries
void writeSeries
(
Ostream& os,
const word& prefix,
const word& suffix,
const UList<instant>& series
);
//- Write vtm datasets for specified files
label writeVtmFile(std::ostream& os, const UList<fileName>& files);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment