initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / surfMesh / surfaceFormats / vtk / VTKsurfaceFormat.C
blob2b09481030efa3d5af5af110df973b9beafe43ba
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "VTKsurfaceFormat.H"
29 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
31 template<class Face>
32 void Foam::fileFormats::VTKsurfaceFormat<Face>::writeHeaderPolygons
34     Ostream& os,
35     const UList<Face>& faceLst
38     label nNodes = 0;
40     forAll(faceLst, faceI)
41     {
42         nNodes += faceLst[faceI].size();
43     }
45     os  << nl
46         << "POLYGONS " << faceLst.size() << ' '
47         << faceLst.size() + nNodes << nl;
51 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
53 template<class Face>
54 Foam::fileFormats::VTKsurfaceFormat<Face>::VTKsurfaceFormat()
58 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
60 template<class Face>
61 void Foam::fileFormats::VTKsurfaceFormat<Face>::write
63     const fileName& filename,
64     const MeshedSurfaceProxy<Face>& surf
67     const pointField& pointLst = surf.points();
68     const List<Face>&  faceLst = surf.faces();
69     const List<label>& faceMap = surf.faceMap();
71     const List<surfZone>& zones =
72     (
73         surf.surfZones().size() > 1
74       ? surf.surfZones()
75       : oneZone(faceLst)
76     );
78     const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
80     OFstream os(filename);
81     if (!os.good())
82     {
83         FatalErrorIn
84         (
85             "fileFormats::VTKsurfaceFormat::write"
86             "(const fileName&, const MeshedSurfaceProxy<Face>&)"
87         )
88             << "Cannot open file for writing " << filename
89             << exit(FatalError);
90     }
93     writeHeader(os, pointLst);
94     writeHeaderPolygons(os, faceLst);
96     label faceIndex = 0;
97     forAll(zones, zoneI)
98     {
99         const surfZone& zone = zones[zoneI];
101         if (useFaceMap)
102         {
103             forAll(zone, localFaceI)
104             {
105                 const Face& f = faceLst[faceMap[faceIndex++]];
107                 os << f.size();
108                 forAll(f, fp)
109                 {
110                     os << ' ' << f[fp];
111                 }
112                 os << ' ' << nl;
113             }
114         }
115         else
116         {
117             forAll(zone, localFaceI)
118             {
119                 const Face& f = faceLst[faceIndex++];
121                 os << f.size();
122                 forAll(f, fp)
123                 {
124                     os << ' ' << f[fp];
125                 }
126                 os << ' ' << nl;
127             }
128         }
129     }
131     writeTail(os, zones);
135 template<class Face>
136 void Foam::fileFormats::VTKsurfaceFormat<Face>::write
138     const fileName& filename,
139     const UnsortedMeshedSurface<Face>& surf
142     OFstream os(filename);
143     if (!os.good())
144     {
145         FatalErrorIn
146         (
147             "fileFormats::VTKsurfaceFormat::write"
148             "(const fileName&, const UnsortedMeshedSurface<Face>&)"
149         )
150             << "Cannot open file for writing " << filename
151             << exit(FatalError);
152     }
155     const List<Face>& faceLst = surf.faces();
157     writeHeader(os, surf.points());
158     writeHeaderPolygons(os, faceLst);
160     forAll(faceLst, faceI)
161     {
162         const Face& f = faceLst[faceI];
164         os << f.size();
165         forAll(f, fp)
166         {
167             os << ' ' << f[fp];
168         }
169         os << ' ' << nl;
170     }
172     writeTail(os, surf.zoneIds());
176 // ************************************************************************* //