OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

writeVTK.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "triSurface.H"
00028 
00029 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033 
00034 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00035 
00036 void triSurface::writeVTK(const bool writeSorted, Ostream& os) const
00037 {
00038     // Write header
00039     os  << "# vtk DataFile Version 2.0" << nl
00040         << "triSurface" << nl
00041         << "ASCII" << nl
00042         << "DATASET POLYDATA"
00043         << nl;
00044 
00045     const pointField& ps = points();
00046 
00047     os  << "POINTS " << ps.size() << " float" << nl;
00048 
00049     // Write vertex coords
00050     forAll(ps, pointi)
00051     {
00052         if (pointi > 0 && (pointi % 10) == 0)
00053         {
00054             os  << nl;
00055         }
00056         else
00057         {
00058             os  << ' ';
00059         }
00060         os  << ps[pointi].x() << ' '
00061             << ps[pointi].y() << ' '
00062             << ps[pointi].z();
00063     }
00064     os  << nl;
00065 
00066     os  << "POLYGONS " << size() << ' ' << 4*size() << nl;
00067 
00068     labelList faceMap;
00069     surfacePatchList myPatches(calcPatches(faceMap));
00070 
00071     if (writeSorted)
00072     {
00073         label faceIndex = 0;
00074 
00075         forAll(myPatches, patchI)
00076         {
00077             // Print all faces belonging to this patch
00078 
00079             for
00080             (
00081                 label patchFaceI = 0;
00082                 patchFaceI < myPatches[patchI].size();
00083                 patchFaceI++
00084             )
00085             {
00086                 if (faceIndex > 0 && (faceIndex % 10) == 0)
00087                 {
00088                     os  << nl;
00089                 }
00090                 else
00091                 {
00092                     os  << ' ';
00093                 }
00094 
00095                 const label faceI = faceMap[faceIndex++];
00096 
00097                 os  << "3 "
00098                     << operator[](faceI)[0] << ' '
00099                     << operator[](faceI)[1] << ' '
00100                     << operator[](faceI)[2];
00101             }
00102         }
00103         os  << nl;
00104 
00105 
00106         // Print region numbers
00107 
00108         os  << "CELL_DATA " << size() << nl;
00109         os  << "FIELD attributes 1" << nl;
00110         os  << "region 1 " << size() << " float" << nl;
00111 
00112         faceIndex = 0;
00113 
00114         forAll(myPatches, patchI)
00115         {
00116             for
00117             (
00118                 label patchFaceI = 0;
00119                 patchFaceI < myPatches[patchI].size();
00120                 patchFaceI++
00121             )
00122             {
00123                 if (faceIndex > 0 && (faceIndex % 10) == 0)
00124                 {
00125                     os  << nl;
00126                 }
00127                 else
00128                 {
00129                     os  << ' ';
00130                 }
00131 
00132                 const label faceI = faceMap[faceIndex++];
00133 
00134                 os  << operator[](faceI).region();
00135             }
00136         }
00137         os  << nl;
00138     }
00139     else
00140     {
00141         forAll(*this, faceI)
00142         {
00143             if (faceI > 0 && (faceI % 10) == 0)
00144             {
00145                 os  << nl;
00146             }
00147             else
00148             {
00149                 os  << ' ';
00150             }
00151             os  << "3 "
00152                 << operator[](faceI)[0] << ' '
00153                 << operator[](faceI)[1] << ' '
00154                 << operator[](faceI)[2];
00155         }
00156         os  << nl;
00157 
00158         os  << "CELL_DATA " << size() << nl;
00159         os  << "FIELD attributes 1" << nl;
00160         os  << "region 1 " << size() << " float" << nl;
00161 
00162         forAll(*this, faceI)
00163         {
00164             if (faceI > 0 && (faceI % 10) == 0)
00165             {
00166                 os  << nl;
00167             }
00168             else
00169             {
00170                 os  << ' ';
00171             }
00172             os  << operator[](faceI).region();
00173         }
00174         os  << nl;
00175     }
00176 }
00177 
00178 
00179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00180 
00181 } // End namespace Foam
00182 
00183 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd