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

writeOFF.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 "triSurface.H"
00028 
00029 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033 
00034 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00035 
00036 void triSurface::writeOFF(const bool writeSorted, Ostream& os) const
00037 {
00038     // Write header
00039     os  << "OFF" << endl
00040         << "# Geomview OFF file" << endl
00041         << "# Regions:" << endl;
00042 
00043     labelList faceMap;
00044     surfacePatchList myPatches(calcPatches(faceMap));
00045 
00046     // Print patch names as comment
00047     forAll(myPatches, patchI)
00048     {
00049         os  << "#     " << patchI << "    "
00050             << myPatches[patchI].name() << endl;
00051     }
00052     os << endl << endl;
00053 
00054     const pointField& ps = points();
00055 
00056     os  << "# nPoints  nTriangles  nEdges" << endl
00057         << ps.size()
00058         << ' ' << size()
00059         << ' ' << nEdges()
00060         << endl << endl;
00061 
00062     // Write vertex coords
00063     forAll(ps, pointi)
00064     {
00065         os  << ps[pointi].x() << ' '
00066             << ps[pointi].y() << ' '
00067             << ps[pointi].z() << " #" << pointi << endl;
00068     }
00069 
00070     os << endl;
00071 
00072     if (writeSorted)
00073     {
00074         label faceIndex = 0;
00075 
00076         forAll(myPatches, patchI)
00077         {
00078             // Print all faces belonging to this patch
00079 
00080             for
00081             (
00082                 label patchFaceI = 0;
00083                 patchFaceI < myPatches[patchI].size();
00084                 patchFaceI++
00085             )
00086             {
00087                 const label faceI = faceMap[faceIndex++];
00088 
00089                 os  << "3 "
00090                     << operator[](faceI)[0] << ' '
00091                     << operator[](faceI)[1] << ' '
00092                     << operator[](faceI)[2] << ' '
00093                     << operator[](faceI).region()
00094                     << endl;
00095             }
00096         }
00097     }
00098     else
00099     {
00100         forAll(*this, faceI)
00101         {
00102             os  << "3 "
00103                 << operator[](faceI)[0] << ' '
00104                 << operator[](faceI)[1] << ' '
00105                 << operator[](faceI)[2] << ' '
00106                 << operator[](faceI).region()
00107                 << endl;
00108         }
00109     }
00110 }
00111 
00112 
00113 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00114 
00115 } // End namespace Foam
00116 
00117 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd