FreeFOAM The Cross-Platform CFD Toolkit
writeTRI.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 \*---------------------------------------------------------------------------*/
25 
26 #include <triSurface/triSurface.H>
27 #include <OpenFOAM/IOmanip.H>
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 
34 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
35 
36 void triSurface::writeTRI(const bool writeSorted, Ostream& os) const
37 {
38  const pointField& ps = points();
39 
40  // Write as cloud of triangles
41 
42  labelList faceMap;
43 
44  surfacePatchList myPatches(calcPatches(faceMap));
45 
46  if (writeSorted)
47  {
48  label faceIndex = 0;
49 
50  forAll(myPatches, patchI)
51  {
52  for
53  (
54  label patchFaceI = 0;
55  patchFaceI < myPatches[patchI].size();
56  patchFaceI++
57  )
58  {
59  const label faceI = faceMap[faceIndex++];
60 
61  const point& p1 = ps[operator[](faceI)[0]];
62  const point& p2 = ps[operator[](faceI)[1]];
63  const point& p3 = ps[operator[](faceI)[2]];
64 
65  os << p1.x() << token::SPACE
66  << p1.y() << token::SPACE
67  << p1.z() << token::SPACE
68 
69  << p2.x() << token::SPACE
70  << p2.y() << token::SPACE
71  << p2.z() << token::SPACE
72 
73  << p3.x() << token::SPACE
74  << p3.y() << token::SPACE
75  << p3.z() << token::SPACE
76 
77  << "0x" << hex << operator[](faceI).region() << dec
78  << endl;
79  }
80  }
81  }
82  else
83  {
84  forAll(*this, faceI)
85  {
86  const point& p1 = ps[operator[](faceI)[0]];
87  const point& p2 = ps[operator[](faceI)[1]];
88  const point& p3 = ps[operator[](faceI)[2]];
89 
90  os << p1.x() << token::SPACE
91  << p1.y() << token::SPACE
92  << p1.z() << token::SPACE
93 
94  << p2.x() << token::SPACE
95  << p2.y() << token::SPACE
96  << p2.z() << token::SPACE
97 
98  << p3.x() << token::SPACE
99  << p3.y() << token::SPACE
100  << p3.z() << token::SPACE
101 
102  << "0x" << hex << operator[](faceI).region() << dec
103  << endl;
104  }
105  }
106 }
107 
108 
109 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
110 
111 } // End namespace Foam
112 
113 // ************************ vim: set sw=4 sts=4 et: ************************ //