Home
Downloads
Documentation
Installation
User Guide
man-pages
API Documentation
README
Release Notes
Changes
License
Support
SourceForge Project
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
surfMesh
surfaceFormats
wrl
WRLsurfaceFormat.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 "
WRLsurfaceFormat.H
"
27
28
#include <
OpenFOAM/Ostream.H
>
29
#include <
OpenFOAM/OFstream.H
>
30
#include <
OpenFOAM/ListOps.H
>
31
32
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33
34
template
<
class
Face>
35
Foam::fileFormats::WRLsurfaceFormat<Face>::WRLsurfaceFormat
()
36
{}
37
38
39
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
40
41
template
<
class
Face>
42
void
Foam::fileFormats::WRLsurfaceFormat<Face>::write
43
(
44
const
fileName
& filename,
45
const
MeshedSurfaceProxy<Face>
& surf
46
)
47
{
48
const
pointField
& pointLst = surf.
points
();
49
const
List<Face>
& faceLst = surf.
faces
();
50
const
List<label>
& faceMap = surf.
faceMap
();
51
52
// for no zones, suppress the group name
53
const
List<surfZone>
& zones =
54
(
55
surf.
surfZones
().size() > 1
56
? surf.
surfZones
()
57
: oneZone(faceLst,
""
)
58
);
59
60
const
bool
useFaceMap = (surf.
useFaceMap
() && zones.
size
() > 1);
61
62
OFstream
os(filename);
63
if
(!os.
good
())
64
{
65
FatalErrorIn
66
(
67
"fileFormats::WRLsurfaceFormat::write"
68
"(const fileName&, const MeshedSurfaceProxy<Face>&)"
69
)
70
<<
"Cannot open file for writing "
<< filename
71
<<
exit
(
FatalError
);
72
}
73
74
writeHeader(os, pointLst, faceLst.
size
(), zones);
75
76
os <<
"\n"
77
"Group {\n"
78
" children [\n"
79
" Shape {\n"
;
80
81
writeAppearance(os);
82
83
os <<
84
" geometry IndexedFaceSet {\n"
85
" coord Coordinate {\n"
86
" point [\n"
;
87
88
// Write vertex coords
89
forAll
(pointLst, ptI)
90
{
91
const
point
& pt = pointLst[ptI];
92
93
os << pt.
x
() <<
' '
<< pt.
y
() <<
' '
<< pt.
z
() <<
nl
;
94
}
95
96
os <<
97
" ]\n"
// end point
98
" }\n"
// end coord Coordinate
99
" coordIndex [\n"
;
100
101
label faceIndex = 0;
102
forAll
(zones, zoneI)
103
{
104
const
surfZone
& zone = zones[zoneI];
105
106
if
(useFaceMap)
107
{
108
forAll
(zone, localFaceI)
109
{
110
const
Face&
f
= faceLst[faceMap[faceIndex++]];
111
112
forAll
(f, fp)
113
{
114
os << f[fp] <<
' '
;
115
}
116
os <<
"-1,\n"
;
117
}
118
}
119
else
120
{
121
forAll
(zone, localFaceI)
122
{
123
const
Face&
f
= faceLst[faceIndex++];
124
125
forAll
(f, fp)
126
{
127
os <<
' '
<< f[fp];
128
}
129
os <<
" -1,\n"
;
130
}
131
}
132
}
133
134
os <<
135
" ]\n"
// end coordIndex
136
" }\n"
// end geometry IndexedFaceSet
137
" }\n"
// end Shape
138
" ]\n"
// end children
139
"}\n"
;
// end Group
140
}
141
142
143
// ************************ vim: set sw=4 sts=4 et: ************************ //