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

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