1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "vtkSurfaceWriter.H"
30 #include "OSspecific.H"
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
35 void Foam::vtkSurfaceWriter<Type>::writeGeometry
38 const pointField& points,
44 << "# vtk DataFile Version 2.0" << nl
45 << "sampleSurface" << nl
47 << "DATASET POLYDATA" << nl;
49 // Write vertex coords
50 os << "POINTS " << points.size() << " float" << nl;
51 forAll(points, pointI)
53 const point& pt = points[pointI];
54 os << float(pt.x()) << ' '
55 << float(pt.y()) << ' '
56 << float(pt.z()) << nl;
65 nNodes += faces[faceI].size();
68 os << "POLYGONS " << faces.size() << ' '
69 << faces.size() + nNodes << nl;
73 const face& f = faces[faceI];
88 // Write scalarField in vtk format
90 void Foam::vtkSurfaceWriter<Foam::scalar>::writeData
93 const Field<Foam::scalar>& values
96 os << "1 " << values.size() << " float" << nl;
112 const scalar& v = values[elemI];
118 // Write vectorField in vtk format
120 void Foam::vtkSurfaceWriter<Foam::vector>::writeData
123 const Field<Foam::vector>& values
126 os << "3 " << values.size() << " float" << nl;
128 forAll(values, elemI)
130 const vector& v = values[elemI];
131 os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2])
137 // Write sphericalTensorField in vtk format
139 void Foam::vtkSurfaceWriter<Foam::sphericalTensor>::writeData
142 const Field<sphericalTensor>& values
145 os << "1 " << values.size() << " float" << nl;
147 forAll(values, elemI)
149 const sphericalTensor& v = values[elemI];
150 os << float(v[0]) << nl;
155 // Write symmTensorField in vtk format
157 void Foam::vtkSurfaceWriter<Foam::symmTensor>::writeData
160 const Field<symmTensor>& values
163 os << "6 " << values.size() << " float" << nl;
165 forAll(values, elemI)
167 const symmTensor& v = values[elemI];
168 os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2])
169 << float(v[3]) << ' ' << float(v[4]) << ' ' << float(v[5])
176 // Write tensorField in vtk format
178 void Foam::vtkSurfaceWriter<Foam::tensor>::writeData
181 const Field<tensor>& values
184 os << "9 " << values.size() << " float" << nl;
186 forAll(values, elemI)
188 const tensor& v = values[elemI];
189 os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2])
190 << float(v[3]) << ' ' << float(v[4]) << ' ' << float(v[5])
191 << float(v[6]) << ' ' << float(v[7]) << ' ' << float(v[8])
199 // Write generic field in vtk format
201 void Foam::vtkSurfaceWriter<Type>::writeData
204 const Field<Type>& values
207 os << "1 " << values.size() << " float" << nl;
209 forAll(values, elemI)
211 os << float(0) << nl;
216 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
218 // Construct from components
220 Foam::vtkSurfaceWriter<Type>::vtkSurfaceWriter()
222 surfaceWriter<Type>()
226 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
229 Foam::vtkSurfaceWriter<Type>::~vtkSurfaceWriter()
233 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
236 void Foam::vtkSurfaceWriter<Type>::write
238 const fileName& outputDir,
239 const fileName& surfaceName,
240 const pointField& points,
241 const faceList& faces,
245 if (!isDir(outputDir))
250 fileName fName(outputDir/surfaceName + ".vtk");
254 Info<< "Writing geometry to " << fName << endl;
258 writeGeometry(os, points, faces);
263 void Foam::vtkSurfaceWriter<Type>::write
265 const fileName& outputDir,
266 const fileName& surfaceName,
267 const pointField& points,
268 const faceList& faces,
269 const fileName& fieldName,
270 const Field<Type>& values,
274 if (!isDir(outputDir))
281 outputDir/fieldName + '_' + surfaceName + ".vtk"
286 Info<< "Writing field " << fieldName << " to " << os.name() << endl;
289 writeGeometry(os, points, faces);
291 // start writing data
292 if (values.size() == points.size())
301 os << values.size() << nl
302 << "FIELD attributes 1" << nl
303 << fieldName.c_str() << " ";
306 writeData(os, values);
311 // ************************************************************************* //