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

writeOBJ.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 Description
00025     Lightwave OBJ format.
00026 
00027     Note: Java obj loader does not support '#' on line
00028 
00029 \*---------------------------------------------------------------------------*/
00030 
00031 #include <triSurface/triSurface.H>
00032 
00033 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00034 
00035 namespace Foam
00036 {
00037 
00038 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00039 
00040 void triSurface::writeOBJ(const bool writeSorted, Ostream& os) const
00041 {
00042     // Write header
00043     os  << "# Wavefront OBJ file" << endl
00044         << "# Regions:" << endl;
00045 
00046     labelList faceMap;
00047 
00048     surfacePatchList myPatches(calcPatches(faceMap));
00049 
00050     const pointField& ps = points();
00051 
00052     // Print patch names as comment
00053     forAll(myPatches, patchI)
00054     {
00055         os  << "#     " << patchI << "    "
00056             << myPatches[patchI].name() << endl;
00057     }
00058     os  << "#" << endl;
00059 
00060     os  << "# points    : " << ps.size() << endl
00061         << "# triangles : " << size() << endl
00062         << "#" << endl;
00063 
00064 
00065     // Write vertex coords
00066     forAll(ps, pointi)
00067     {
00068         os  << "v "
00069             << ps[pointi].x() << ' '
00070             << ps[pointi].y() << ' '
00071             << ps[pointi].z() << endl;
00072     }
00073 
00074     if (writeSorted)
00075     {
00076         label faceIndex = 0;
00077 
00078         forAll(myPatches, patchI)
00079         {
00080             // Print all faces belonging to this patch
00081 
00082             os << "g " << myPatches[patchI].name() << endl;
00083 
00084             for
00085             (
00086                 label patchFaceI = 0;
00087                 patchFaceI < myPatches[patchI].size();
00088                 patchFaceI++
00089             )
00090             {
00091                 const label faceI = faceMap[faceIndex++];
00092 
00093                 os  << "f "
00094                     << operator[](faceI)[0] + 1 << ' '
00095                     << operator[](faceI)[1] + 1 << ' '
00096                     << operator[](faceI)[2] + 1
00097                     //<< "  # " << operator[](faceI).region()
00098                     << endl;
00099             }
00100         }
00101     }
00102     else
00103     {
00104         forAll(*this, faceI)
00105         {
00106             os  << "f "
00107                 << operator[](faceI)[0] + 1 << ' '
00108                 << operator[](faceI)[1] + 1 << ' '
00109                 << operator[](faceI)[2] + 1
00110                 //<< "  # " << operator[](faceI).region()
00111                 << endl;
00112         }
00113     }
00114 }
00115 
00116 
00117 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00118 
00119 } // End namespace Foam
00120 
00121 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines