writeAC.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
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 \*---------------------------------------------------------------------------*/
25 
26 #include "triSurface.H"
27 #include "IOmanip.H"
28 
29 
30 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
31 
32 void Foam::triSurface::writeAC(Ostream& os) const
33 {
34  // Write with patches as separate objects under "world" object.
35  // Header is taken over from sample file.
36  // Defines separate materials for all patches. Recycle colours.
37 
38  // Define 8 standard colours as r,g,b components
39  static scalar colourMap[] =
40  {
41  1, 1, 1,
42  1, 0, 0,
43  0, 1, 0,
44  0, 0, 1,
45  1, 1, 0,
46  0, 1, 1,
47  1, 0, 1,
48  0.5, 0.5, 1
49  };
50 
51  // Calculate patch face indexing
52 
54 
55  surfacePatchList patches(calcPatches(faceMap));
56 
57 
58  // Write header. Define materials.
59 
60  os << "AC3Db" << endl;
61 
63  {
64  const word& pName = patches[patchi].name();
65 
66  label colourI = patchi % 8;
67  label colourCompI = 3 * colourI;
68 
69  os << "MATERIAL \"" << pName << "Mat\" rgb "
70  << colourMap[colourCompI] << ' ' << colourMap[colourCompI+1]
71  << ' ' << colourMap[colourCompI+2]
72  << " amb 0.2 0.2 0.2 emis 0 0 0 spec 0.5 0.5 0.5 shi 10"
73  << " trans 0"
74  << endl;
75  }
76 
77  os << "OBJECT world" << endl
78  << "kids " << patches.size() << endl;
79 
80 
81  // Write patch points & faces.
82 
83  label faceIndex = 0;
84 
86  {
87  const surfacePatch& sp = patches[patchi];
88 
89  os << "OBJECT poly" << endl
90  << "name \"" << sp.name() << '"' << endl;
91 
92  // Create patch with only patch faces included for ease of addressing
93 
94  boolList include(size(), false);
95 
96  forAll(sp, patchFacei)
97  {
98  const label facei = faceMap[faceIndex++];
99 
100  include[facei] = true;
101  }
102 
103  labelList pointMap;
105 
106  triSurface patch = subsetMesh(include, pointMap, faceMap);
107 
108  // Now we have triSurface for this patch alone. Write it.
109 
110  os << "numvert " << patch.nPoints() << endl;
111 
112  forAll(patch.localPoints(), ptI)
113  {
114  const point& pt = patch.localPoints()[ptI];
115 
116  os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl;
117  }
118 
119  os << "numsurf " << patch.localFaces().size() << endl;
120 
121  forAll(patch.localFaces(), facei)
122  {
123  const labelledTri& f = patch.localFaces()[facei];
124 
125  os << "SURF 0x20" << endl // polygon
126  << "mat " << patchi << endl
127  << "refs " << f.size() << endl;
128 
129  os << f[0] << " 0 0" << endl;
130  os << f[1] << " 0 0" << endl;
131  os << f[2] << " 0 0" << endl;
132  }
133 
134  os << "kids 0" << endl;
135  }
136 }
137 
138 
139 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
List< surfacePatch > surfacePatchList
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
List< bool > boolList
Bool container classes.
Definition: boolList.H:50
List< label > labelList
A List of labels.
Definition: labelList.H:56
const Cmpt & x() const
Definition: VectorI.H:75
Istream and Ostream manipulators taking arguments.
labelList f(nPoints)
const geometricSurfacePatchList & patches() const
Definition: triSurface.H:322
triSurface()
Construct null.
Definition: triSurface.C:533
label patchi
vector point
Point is a vector.
Definition: point.H:41
triSurface subsetMesh(const boolList &include, labelList &pointMap, labelList &faceMap) const
Return new surface. Returns pointMap, faceMap from.
Definition: triSurface.C:1089
label size() const
Return the number of elements in the UList.
Definition: ListI.H:170