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-------------------------------------------------------------------------------
11License
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
29template<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
65template<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// ************************************************************************* //
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
Definition: HashTableI.H:180
A HashTable to objects of type <T> with a label key.
Definition: Map.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
OBJstream os(runTime.globalPath()/outputName)
const pointField & points
void writeOBJ(Ostream &os, const point &pt)
Write obj representation of a point.
Definition: meshTools.C:203
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
labelList f(nPoints)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333