FreeFOAM The Cross-Platform CFD Toolkit
writeOFF.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 
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32 
33 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
34 
35 void triSurface::writeOFF(const bool writeSorted, Ostream& os) const
36 {
37  // Write header
38  os << "OFF" << endl
39  << "# Geomview OFF file" << endl
40  << "# Regions:" << endl;
41 
42  labelList faceMap;
43  surfacePatchList myPatches(calcPatches(faceMap));
44 
45  // Print patch names as comment
46  forAll(myPatches, patchI)
47  {
48  os << "# " << patchI << " "
49  << myPatches[patchI].name() << endl;
50  }
51  os << endl << endl;
52 
53  const pointField& ps = points();
54 
55  os << "# nPoints nTriangles nEdges" << endl
56  << ps.size()
57  << ' ' << size()
58  << ' ' << nEdges()
59  << endl << endl;
60 
61  // Write vertex coords
62  forAll(ps, pointi)
63  {
64  os << ps[pointi].x() << ' '
65  << ps[pointi].y() << ' '
66  << ps[pointi].z() << " #" << pointi << endl;
67  }
68 
69  os << endl;
70 
71  if (writeSorted)
72  {
73  label faceIndex = 0;
74 
75  forAll(myPatches, patchI)
76  {
77  // Print all faces belonging to this patch
78 
79  for
80  (
81  label patchFaceI = 0;
82  patchFaceI < myPatches[patchI].size();
83  patchFaceI++
84  )
85  {
86  const label faceI = faceMap[faceIndex++];
87 
88  os << "3 "
89  << operator[](faceI)[0] << ' '
90  << operator[](faceI)[1] << ' '
91  << operator[](faceI)[2] << ' '
92  << operator[](faceI).region()
93  << endl;
94  }
95  }
96  }
97  else
98  {
99  forAll(*this, faceI)
100  {
101  os << "3 "
102  << operator[](faceI)[0] << ' '
103  << operator[](faceI)[1] << ' '
104  << operator[](faceI)[2] << ' '
105  << operator[](faceI).region()
106  << endl;
107  }
108  }
109 }
110 
111 
112 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
113 
114 } // End namespace Foam
115 
116 // ************************ vim: set sw=4 sts=4 et: ************************ //