initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / triSurface / triSurface / interfaces / VTK / writeVTK.C
blob94529f605ea8c8c6ebd3e1f4c2269b68c320c98d
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 "triSurface.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 namespace Foam
34 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
36 void triSurface::writeVTK(const bool writeSorted, Ostream& os) const
38     // Write header
39     os  << "# vtk DataFile Version 2.0" << nl
40         << "triSurface" << nl
41         << "ASCII" << nl
42         << "DATASET POLYDATA"
43         << nl;
45     const pointField& ps = points();
47     os  << "POINTS " << ps.size() << " float" << nl;
49     // Write vertex coords
50     forAll(ps, pointi)
51     {
52         if (pointi > 0 && (pointi % 10) == 0)
53         {
54             os  << nl;
55         }
56         else
57         {
58             os  << ' ';
59         }
60         os  << ps[pointi].x() << ' '
61             << ps[pointi].y() << ' '
62             << ps[pointi].z();
63     }
64     os  << nl;
66     os  << "POLYGONS " << size() << ' ' << 4*size() << nl;
68     labelList faceMap;
69     surfacePatchList myPatches(calcPatches(faceMap));
71     if (writeSorted)
72     {
73         label faceIndex = 0;
75         forAll(myPatches, patchI)
76         {
77             // Print all faces belonging to this patch
79             for
80             (
81                 label patchFaceI = 0;
82                 patchFaceI < myPatches[patchI].size();
83                 patchFaceI++
84             )
85             {
86                 if (faceIndex > 0 && (faceIndex % 10) == 0)
87                 {
88                     os  << nl;
89                 }
90                 else
91                 {
92                     os  << ' ';
93                 }
95                 const label faceI = faceMap[faceIndex++];
97                 os  << "3 "
98                     << operator[](faceI)[0] << ' '
99                     << operator[](faceI)[1] << ' '
100                     << operator[](faceI)[2];
101             }
102         }
103         os  << nl;
106         // Print region numbers
108         os  << "CELL_DATA " << size() << nl;
109         os  << "FIELD attributes 1" << nl;
110         os  << "region 1 " << size() << " float" << nl;
112         faceIndex = 0;
114         forAll(myPatches, patchI)
115         {
116             for
117             (
118                 label patchFaceI = 0;
119                 patchFaceI < myPatches[patchI].size();
120                 patchFaceI++
121             )
122             {
123                 if (faceIndex > 0 && (faceIndex % 10) == 0)
124                 {
125                     os  << nl;
126                 }
127                 else
128                 {
129                     os  << ' ';
130                 }
132                 const label faceI = faceMap[faceIndex++];
134                 os  << operator[](faceI).region();
135             }
136         }
137         os  << nl;
138     }
139     else
140     {
141         forAll(*this, faceI)
142         {
143             if (faceI > 0 && (faceI % 10) == 0)
144             {
145                 os  << nl;
146             }
147             else
148             {
149                 os  << ' ';
150             }
151             os  << "3 "
152                 << operator[](faceI)[0] << ' '
153                 << operator[](faceI)[1] << ' '
154                 << operator[](faceI)[2];
155         }
156         os  << nl;
158         os  << "CELL_DATA " << size() << nl;
159         os  << "FIELD attributes 1" << nl;
160         os  << "region 1 " << size() << " float" << nl;
162         forAll(*this, faceI)
163         {
164             if (faceI > 0 && (faceI % 10) == 0)
165             {
166                 os  << nl;
167             }
168             else
169             {
170                 os  << ' ';
171             }
172             os  << operator[](faceI).region();
173         }
174         os  << nl;
175     }
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 } // End namespace Foam
183 // ************************************************************************* //