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

writeVTK.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 <triSurface/triSurface.H>
00027 
00028 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00029 
00030 namespace Foam
00031 {
00032 
00033 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00034 
00035 void triSurface::writeVTK(const bool writeSorted, Ostream& os) const
00036 {
00037     // Write header
00038     os  << "# vtk DataFile Version 2.0" << nl
00039         << "triSurface" << nl
00040         << "ASCII" << nl
00041         << "DATASET POLYDATA"
00042         << nl;
00043 
00044     const pointField& ps = points();
00045 
00046     os  << "POINTS " << ps.size() << " float" << nl;
00047 
00048     // Write vertex coords
00049     forAll(ps, pointi)
00050     {
00051         if (pointi > 0 && (pointi % 10) == 0)
00052         {
00053             os  << nl;
00054         }
00055         else
00056         {
00057             os  << ' ';
00058         }
00059         os  << ps[pointi].x() << ' '
00060             << ps[pointi].y() << ' '
00061             << ps[pointi].z();
00062     }
00063     os  << nl;
00064 
00065     os  << "POLYGONS " << size() << ' ' << 4*size() << nl;
00066 
00067     labelList faceMap;
00068     surfacePatchList myPatches(calcPatches(faceMap));
00069 
00070     if (writeSorted)
00071     {
00072         label faceIndex = 0;
00073 
00074         forAll(myPatches, patchI)
00075         {
00076             // Print all faces belonging to this patch
00077 
00078             for
00079             (
00080                 label patchFaceI = 0;
00081                 patchFaceI < myPatches[patchI].size();
00082                 patchFaceI++
00083             )
00084             {
00085                 if (faceIndex > 0 && (faceIndex % 10) == 0)
00086                 {
00087                     os  << nl;
00088                 }
00089                 else
00090                 {
00091                     os  << ' ';
00092                 }
00093 
00094                 const label faceI = faceMap[faceIndex++];
00095 
00096                 os  << "3 "
00097                     << operator[](faceI)[0] << ' '
00098                     << operator[](faceI)[1] << ' '
00099                     << operator[](faceI)[2];
00100             }
00101         }
00102         os  << nl;
00103 
00104 
00105         // Print region numbers
00106 
00107         os  << "CELL_DATA " << size() << nl;
00108         os  << "FIELD attributes 1" << nl;
00109         os  << "region 1 " << size() << " float" << nl;
00110 
00111         faceIndex = 0;
00112 
00113         forAll(myPatches, patchI)
00114         {
00115             for
00116             (
00117                 label patchFaceI = 0;
00118                 patchFaceI < myPatches[patchI].size();
00119                 patchFaceI++
00120             )
00121             {
00122                 if (faceIndex > 0 && (faceIndex % 10) == 0)
00123                 {
00124                     os  << nl;
00125                 }
00126                 else
00127                 {
00128                     os  << ' ';
00129                 }
00130 
00131                 const label faceI = faceMap[faceIndex++];
00132 
00133                 os  << operator[](faceI).region();
00134             }
00135         }
00136         os  << nl;
00137     }
00138     else
00139     {
00140         forAll(*this, faceI)
00141         {
00142             if (faceI > 0 && (faceI % 10) == 0)
00143             {
00144                 os  << nl;
00145             }
00146             else
00147             {
00148                 os  << ' ';
00149             }
00150             os  << "3 "
00151                 << operator[](faceI)[0] << ' '
00152                 << operator[](faceI)[1] << ' '
00153                 << operator[](faceI)[2];
00154         }
00155         os  << nl;
00156 
00157         os  << "CELL_DATA " << size() << nl;
00158         os  << "FIELD attributes 1" << nl;
00159         os  << "region 1 " << size() << " float" << nl;
00160 
00161         forAll(*this, faceI)
00162         {
00163             if (faceI > 0 && (faceI % 10) == 0)
00164             {
00165                 os  << nl;
00166             }
00167             else
00168             {
00169                 os  << ' ';
00170             }
00171             os  << operator[](faceI).region();
00172         }
00173         os  << nl;
00174     }
00175 }
00176 
00177 
00178 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00179 
00180 } // End namespace Foam
00181 
00182 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines