meshToolsTemplates.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2013 OpenFOAM Foundation
9  Copyright (C) 2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 template<class FaceType>
31 (
32  Ostream& os,
33  const UList<FaceType>& faces,
34  const UList<point>& points,
35  const labelList& faceLabels
36 )
37 {
38  Map<label> foamToObj(4*faceLabels.size());
39 
40  label vertI = 0;
41 
42  for (const label facei : faceLabels)
43  {
44  const FaceType& f = faces[facei];
45 
46  forAll(f, fp)
47  {
48  if (foamToObj.insert(f[fp], vertI))
49  {
50  writeOBJ(os, points[f[fp]]);
51  vertI++;
52  }
53  }
54 
55  os << 'f';
56  forAll(f, fp)
57  {
58  os << ' ' << foamToObj[f[fp]]+1;
59  }
60  os << ' ' << foamToObj[f[0]]+1 << endl;
61  }
62 }
63 
64 
65 template<class FaceType>
67 (
68  Ostream& os,
69  const UList<FaceType>& faces,
70  const UList<point>& points
71 )
72 {
73  labelList allFaces(faces.size());
74  forAll(allFaces, i)
75  {
76  allFaces[i] = i;
77  }
78  writeOBJ(os, faces, points, allFaces);
79 }
80 
81 
82 // ************************************************************************* //
Foam::meshTools::writeOBJ
void writeOBJ(Ostream &os, const point &pt)
Write obj representation of a point.
Definition: meshTools.C:203
Foam::Map< label >
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
os
OBJstream os(runTime.globalPath()/outputName)
f
labelList f(nPoints)
Foam::List< label >
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::UList::size
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56