FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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