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

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