writeAC.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | foam-extend: Open Source CFD
4  \\ / O peration | Version: 3.2
5  \\ / A nd | Web: http://www.foam-extend.org
6  \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9  This file is part of foam-extend.
10 
11  foam-extend is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by the
13  Free Software Foundation, either version 3 of the License, or (at your
14  option) any later version.
15 
16  foam-extend is distributed in the hope that it will be useful, but
17  WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "triSurface.H"
29 #include "IOmanip.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 
36 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
37 
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 
60 
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;
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 // ************************************************************************* //
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeFast.C:90
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::PrimitivePatch::localPoints
const Field< PointType > & localPoints() const
Return pointField of points in patch.
Definition: PrimitivePatchTemplate.C:432
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::triSurface::subsetMesh
triSurface subsetMesh(const boolList &include, labelList &pointMap, labelList &faceMap) const
Return new surface. Returns pointMap, faceMap from.
Definition: triSurface.C:1013
Foam::label
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
Foam::triSurface
Triangulated surface description with patch information.
Definition: triSurface.H:57
Foam::triSurface::writeAC
void writeAC(Ostream &) const
Write to Ostream in AC3D format. Always sorted by patch.
Definition: writeAC.C:38
IOmanip.H
Istream and Ostream manipulators taking arguments.
Foam::PrimitivePatch::nPoints
label nPoints() const
Return number of points supporting patch faces.
Definition: PrimitivePatchTemplate.H:293
Foam::Vector::x
const Cmpt & x() const
Definition: VectorI.H:65
Foam::surfacePatch
'Patch' on surface as subset of triSurface.
Definition: surfacePatch.H:51
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::Vector::z
const Cmpt & z() const
Definition: VectorI.H:77
Foam::List< labelledTri >::size
label size() const
Return the number of elements in the UList.
Foam::triSurface::calcPatches
surfacePatchList calcPatches(labelList &faceMap) const
Sort faces according to region. Returns patch list.
Definition: triSurface.C:501
f
labelList f(nPoints)
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::labelledTri
Triangle with additional region number.
Definition: labelledTri.H:49
Foam::PrimitivePatch::localFaces
const List< Face > & localFaces() const
Return patch faces addressing into local point list.
Definition: PrimitivePatchTemplate.C:372
Foam::Vector::y
const Cmpt & y() const
Definition: VectorI.H:71
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::geometricSurfacePatch::name
const word & name() const
Return name.
Definition: geometricSurfacePatch.H:101