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

VTKsurfaceFormat.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 "VTKsurfaceFormat.H"
00028 
00029 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00030 
00031 template<class Face>
00032 void Foam::fileFormats::VTKsurfaceFormat<Face>::writeHeaderPolygons
00033 (
00034     Ostream& os,
00035     const UList<Face>& faceLst
00036 )
00037 {
00038     label nNodes = 0;
00039 
00040     forAll(faceLst, faceI)
00041     {
00042         nNodes += faceLst[faceI].size();
00043     }
00044 
00045     os  << nl
00046         << "POLYGONS " << faceLst.size() << ' '
00047         << faceLst.size() + nNodes << nl;
00048 }
00049 
00050 
00051 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00052 
00053 template<class Face>
00054 Foam::fileFormats::VTKsurfaceFormat<Face>::VTKsurfaceFormat()
00055 {}
00056 
00057 
00058 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00059 
00060 template<class Face>
00061 void Foam::fileFormats::VTKsurfaceFormat<Face>::write
00062 (
00063     const fileName& filename,
00064     const MeshedSurfaceProxy<Face>& surf
00065 )
00066 {
00067     const pointField& pointLst = surf.points();
00068     const List<Face>&  faceLst = surf.faces();
00069     const List<label>& faceMap = surf.faceMap();
00070 
00071     const List<surfZone>& zones =
00072     (
00073         surf.surfZones().size() > 1
00074       ? surf.surfZones()
00075       : oneZone(faceLst)
00076     );
00077 
00078     const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
00079 
00080     OFstream os(filename);
00081     if (!os.good())
00082     {
00083         FatalErrorIn
00084         (
00085             "fileFormats::VTKsurfaceFormat::write"
00086             "(const fileName&, const MeshedSurfaceProxy<Face>&)"
00087         )
00088             << "Cannot open file for writing " << filename
00089             << exit(FatalError);
00090     }
00091 
00092 
00093     writeHeader(os, pointLst);
00094     writeHeaderPolygons(os, faceLst);
00095 
00096     label faceIndex = 0;
00097     forAll(zones, zoneI)
00098     {
00099         const surfZone& zone = zones[zoneI];
00100 
00101         if (useFaceMap)
00102         {
00103             forAll(zone, localFaceI)
00104             {
00105                 const Face& f = faceLst[faceMap[faceIndex++]];
00106 
00107                 os << f.size();
00108                 forAll(f, fp)
00109                 {
00110                     os << ' ' << f[fp];
00111                 }
00112                 os << ' ' << nl;
00113             }
00114         }
00115         else
00116         {
00117             forAll(zone, localFaceI)
00118             {
00119                 const Face& f = faceLst[faceIndex++];
00120 
00121                 os << f.size();
00122                 forAll(f, fp)
00123                 {
00124                     os << ' ' << f[fp];
00125                 }
00126                 os << ' ' << nl;
00127             }
00128         }
00129     }
00130 
00131     writeTail(os, zones);
00132 }
00133 
00134 
00135 template<class Face>
00136 void Foam::fileFormats::VTKsurfaceFormat<Face>::write
00137 (
00138     const fileName& filename,
00139     const UnsortedMeshedSurface<Face>& surf
00140 )
00141 {
00142     OFstream os(filename);
00143     if (!os.good())
00144     {
00145         FatalErrorIn
00146         (
00147             "fileFormats::VTKsurfaceFormat::write"
00148             "(const fileName&, const UnsortedMeshedSurface<Face>&)"
00149         )
00150             << "Cannot open file for writing " << filename
00151             << exit(FatalError);
00152     }
00153 
00154 
00155     const List<Face>& faceLst = surf.faces();
00156 
00157     writeHeader(os, surf.points());
00158     writeHeaderPolygons(os, faceLst);
00159 
00160     forAll(faceLst, faceI)
00161     {
00162         const Face& f = faceLst[faceI];
00163 
00164         os << f.size();
00165         forAll(f, fp)
00166         {
00167             os << ' ' << f[fp];
00168         }
00169         os << ' ' << nl;
00170     }
00171 
00172     writeTail(os, surf.zoneIds());
00173 }
00174 
00175 
00176 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd