FreeFOAM The Cross-Platform CFD Toolkit
writeAC.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include <triSurface/triSurface.H>
29 #include <OpenFOAM/IOmanip.H>
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 
36 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
37 
38 void triSurface::writeAC(Ostream& os) const
39 {
40  // Write with patches as separate objects under "world" object.
41  // Header is taken over from sample file.
42  // Defines separate materials for all patches. Recycle colours.
43 
44  // Define 8 standard colours as r,g,b components
45  static scalar colourMap[] =
46  {
47  1, 1, 1,
48  1, 0, 0,
49  0, 1, 0,
50  0, 0, 1,
51  1, 1, 0,
52  0, 1, 1,
53  1, 0, 1,
54  0.5, 0.5, 1
55  };
56 
57  // Calculate patch face indexing
58 
59  labelList faceMap;
60 
61  surfacePatchList myPatches(calcPatches(faceMap));
62 
63 
64  // Write header. Define materials.
65 
66  os << "AC3Db" << endl;
67 
68  forAll(myPatches, patchI)
69  {
70  const word& pName = myPatches[patchI].name();
71 
72  label colourI = patchI % 8;
73  label colourCompI = 3 * colourI;
74 
75  os << "MATERIAL \"" << pName << "Mat\" rgb "
76  << colourMap[colourCompI] << ' ' << colourMap[colourCompI+1]
77  << ' ' << colourMap[colourCompI+2]
78  << " amb 0.2 0.2 0.2 emis 0 0 0 spec 0.5 0.5 0.5 shi 10"
79  << " trans 0"
80  << endl;
81  }
82 
83  os << "OBJECT world" << endl
84  << "kids " << myPatches.size() << endl;
85 
86 
87  // Write patch points & faces.
88 
89  label faceIndex = 0;
90 
91  forAll(myPatches, patchI)
92  {
93  const surfacePatch& sp = myPatches[patchI];
94 
95  os << "OBJECT poly" << endl
96  << "name \"" << sp.name() << '"' << endl;
97 
98  // Create patch with only patch faces included for ease of addressing
99 
100  boolList include(size(), false);
101 
102  forAll(sp, patchFaceI)
103  {
104  const label faceI = faceMap[faceIndex++];
105 
106  include[faceI] = true;
107  }
108 
109  labelList pointMap;
110  labelList faceMap;
111 
112  triSurface patch = subsetMesh(include, pointMap, faceMap);
113 
114  // Now we have triSurface for this patch alone. Write it.
115 
116  os << "numvert " << patch.nPoints() << endl;
117 
118  forAll(patch.localPoints(), ptI)
119  {
120  const point& pt = patch.localPoints()[ptI];
121 
122  os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl;
123  }
124 
125  os << "numsurf " << patch.localFaces().size() << endl;
126 
127  forAll(patch.localFaces(), faceI)
128  {
129  const labelledTri& f = patch.localFaces()[faceI];
130 
131  os << "SURF 0x20" << endl // polygon
132  << "mat " << patchI << endl
133  << "refs " << f.size() << endl;
134 
135  os << f[0] << " 0 0" << endl;
136  os << f[1] << " 0 0" << endl;
137  os << f[2] << " 0 0" << endl;
138  }
139 
140  os << "kids 0" << endl;
141  }
142 }
143 
144 
145 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
146 
147 } // End namespace Foam
148 
149 // ************************ vim: set sw=4 sts=4 et: ************************ //