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

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