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

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