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

writeAC.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 
00026 \*---------------------------------------------------------------------------*/
00027 
00028 #include <triSurface/triSurface.H>
00029 #include <OpenFOAM/IOmanip.H>
00030 
00031 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00032 
00033 namespace Foam
00034 {
00035 
00036 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00037 
00038 void triSurface::writeAC(Ostream& os) const
00039 {
00040     // Write with patches as separate objects under "world" object.
00041     // Header is taken over from sample file.
00042     // Defines separate materials for all patches. Recycle colours.
00043 
00044     // Define 8 standard colours as r,g,b components
00045     static scalar colourMap[] =
00046     {
00047         1, 1, 1,
00048         1, 0, 0,
00049         0, 1, 0,
00050         0, 0, 1,
00051         1, 1, 0,
00052         0, 1, 1,
00053         1, 0, 1,
00054         0.5, 0.5, 1
00055     };
00056 
00057     // Calculate patch face indexing
00058 
00059     labelList faceMap;
00060 
00061     surfacePatchList myPatches(calcPatches(faceMap));
00062 
00063 
00064     // Write header. Define materials.
00065 
00066     os  << "AC3Db" << endl;
00067 
00068     forAll(myPatches, patchI)
00069     {
00070         const word& pName = myPatches[patchI].name();
00071 
00072         label colourI = patchI % 8;
00073         label colourCompI = 3 * colourI;
00074 
00075         os  << "MATERIAL \"" << pName << "Mat\" rgb "
00076             << colourMap[colourCompI] << ' ' << colourMap[colourCompI+1]
00077             << ' ' << colourMap[colourCompI+2]
00078             << "  amb 0.2 0.2 0.2  emis 0 0 0  spec 0.5 0.5 0.5  shi 10"
00079             << "  trans 0"
00080             << endl;
00081     }
00082 
00083     os  << "OBJECT world" << endl
00084         << "kids " << myPatches.size() << endl;
00085 
00086 
00087     // Write patch points & faces.
00088 
00089     label faceIndex = 0;
00090 
00091     forAll(myPatches, patchI)
00092     {
00093         const surfacePatch& sp = myPatches[patchI];
00094 
00095         os  << "OBJECT poly" << endl
00096             << "name \"" << sp.name() << '"' << endl;
00097 
00098         // Create patch with only patch faces included for ease of addressing
00099 
00100         boolList include(size(), false);
00101 
00102         forAll(sp, patchFaceI)
00103         {
00104             const label faceI = faceMap[faceIndex++];
00105 
00106             include[faceI] = true;
00107         }
00108 
00109         labelList pointMap;
00110         labelList faceMap;
00111 
00112         triSurface patch = subsetMesh(include, pointMap, faceMap);
00113 
00114         // Now we have triSurface for this patch alone. Write it.
00115 
00116         os << "numvert " << patch.nPoints() << endl;
00117 
00118         forAll(patch.localPoints(), ptI)
00119         {
00120             const point& pt = patch.localPoints()[ptI];
00121 
00122             os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl;
00123         }
00124 
00125         os << "numsurf " << patch.localFaces().size() << endl;
00126 
00127         forAll(patch.localFaces(), faceI)
00128         {
00129             const labelledTri& f = patch.localFaces()[faceI];
00130 
00131             os  << "SURF 0x20" << endl          // polygon
00132                 << "mat " << patchI << endl
00133                 << "refs " << f.size() << endl;
00134 
00135             os << f[0] << " 0 0" << endl;
00136             os << f[1] << " 0 0" << endl;
00137             os << f[2] << " 0 0" << endl;
00138         }
00139 
00140         os << "kids 0" << endl;
00141     }
00142 }
00143 
00144 
00145 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00146 
00147 } // End namespace Foam
00148 
00149 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines