foamVtkWritePointSet.C 2.48 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6
     \\/     M anipulation  | Copyright (C) 2017 OpenCFD Ltd.
7
8
9
10
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

11
12
13
14
    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
15
16
17
18
19
20
21

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
22
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
23
24
25

\*---------------------------------------------------------------------------*/

26
27
28
#include "foamVtkWritePointSet.H"
#include "foamVtkOutputOptions.H"
#include "OFstream.H"
29
30
31
#include "primitiveMesh.H"
#include "pointSet.H"

32
// * * * * * * * * * * * * * * * Global Functions  * * * * * * * * * * * * * //
33

34
void Foam::vtk::writePointSet
35
36
(
    const primitiveMesh& mesh,
37
    const pointSet& set,
38
    const fileName& baseName,
39
    const vtk::outputOptions outOpts
40
41
)
{
42
    outputOptions opts(outOpts);
43
    opts.legacy(true);  // Legacy only, no xml, no append
44

45
46
47
    const bool legacy_(opts.legacy());

    std::ofstream os((baseName + (legacy_ ? ".vtk" : ".vtp")).c_str());
48

49
    autoPtr<vtk::formatter> format = opts.newFormatter(os);
50

51
    if (legacy_)
52
    {
53
        legacy::fileHeader(format(), set.name(), vtk::fileTag::POLY_DATA);
54
    }
55
56
57
58
59
60

    //-------------------------------------------------------------------------

    const labelList pointLabels(set.sortedToc());

    // Write points
61
    legacy::beginPoints(os, pointLabels.size());
62

63
    vtk::writeList(format(), mesh.points(), pointLabels);
64
65
66
    format().flush();

    // Write data - pointID
67
    legacy::dataHeader(os, vtk::fileTag::POINT_DATA, pointLabels.size(), 1);
68

69
    os << "pointID 1 " << pointLabels.size() << " int" << nl;
70

71
    vtk::writeList(format(), pointLabels);
72
73
    format().flush();
}
74
75
76


// ************************************************************************* //