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

WRLsurfaceFormat.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 "WRLsurfaceFormat.H"
00027 
00028 #include <OpenFOAM/Ostream.H>
00029 #include <OpenFOAM/OFstream.H>
00030 #include <OpenFOAM/ListOps.H>
00031 
00032 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00033 
00034 template<class Face>
00035 Foam::fileFormats::WRLsurfaceFormat<Face>::WRLsurfaceFormat()
00036 {}
00037 
00038 
00039 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00040 
00041 template<class Face>
00042 void Foam::fileFormats::WRLsurfaceFormat<Face>::write
00043 (
00044     const fileName& filename,
00045     const MeshedSurfaceProxy<Face>& surf
00046 )
00047 {
00048     const pointField& pointLst = surf.points();
00049     const List<Face>&  faceLst = surf.faces();
00050     const List<label>& faceMap = surf.faceMap();
00051 
00052     // for no zones, suppress the group name
00053     const List<surfZone>& zones =
00054     (
00055         surf.surfZones().size() > 1
00056       ? surf.surfZones()
00057       : WRLsurfaceFormat::oneZone(faceLst, "")
00058     );
00059 
00060     const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
00061 
00062     OFstream os(filename);
00063     if (!os.good())
00064     {
00065         FatalErrorIn
00066         (
00067             "fileFormats::WRLsurfaceFormat::write"
00068             "(const fileName&, const MeshedSurfaceProxy<Face>&)"
00069         )
00070             << "Cannot open file for writing " << filename
00071             << exit(FatalError);
00072     }
00073 
00074     writeHeader(os, pointLst, faceLst.size(), zones);
00075 
00076     os  << "\n"
00077         "Group {\n"
00078         " children [\n"
00079         "  Shape {\n";
00080 
00081    writeAppearance(os);
00082 
00083    os  <<
00084         "   geometry IndexedFaceSet {\n"
00085         "    coord Coordinate {\n"
00086         "     point [\n";
00087 
00088     // Write vertex coords
00089     forAll(pointLst, ptI)
00090     {
00091         const point& pt = pointLst[ptI];
00092 
00093         os  << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
00094     }
00095 
00096     os  <<
00097         "     ]\n"                     // end point
00098         "    }\n"                      // end coord Coordinate
00099         "    coordIndex [\n";
00100 
00101     label faceIndex = 0;
00102     forAll(zones, zoneI)
00103     {
00104         const surfZone& zone = zones[zoneI];
00105 
00106         if (useFaceMap)
00107         {
00108             forAll(zone, localFaceI)
00109             {
00110                 const Face& f = faceLst[faceMap[faceIndex++]];
00111 
00112                 forAll(f, fp)
00113                 {
00114                     os << f[fp] << ' ';
00115                 }
00116                 os << "-1,\n";
00117             }
00118         }
00119         else
00120         {
00121             forAll(zone, localFaceI)
00122             {
00123                 const Face& f = faceLst[faceIndex++];
00124 
00125                 forAll(f, fp)
00126                 {
00127                     os << ' ' << f[fp];
00128                 }
00129                 os << " -1,\n";
00130             }
00131         }
00132     }
00133 
00134     os  <<
00135         "    ]\n"                      // end coordIndex
00136         "   }\n"                       // end geometry IndexedFaceSet
00137         "  }\n"                        // end Shape
00138         " ]\n"                         // end children
00139         "}\n";                         // end Group
00140 }
00141 
00142 
00143 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines