1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2008-2011 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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "vtkSurfaceWriter.H"
29 #include "OSspecific.H"
31 #include "makeSurfaceWriterMethods.H"
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 makeSurfaceWriterType(vtkSurfaceWriter);
41 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 void Foam::vtkSurfaceWriter::writeGeometry
46 const pointField& points,
52 << "# vtk DataFile Version 2.0" << nl
53 << "sampleSurface" << nl
55 << "DATASET POLYDATA" << nl;
57 // Write vertex coords
58 os << "POINTS " << points.size() << " float" << nl;
59 forAll(points, pointI)
61 const point& pt = points[pointI];
62 os << float(pt.x()) << ' '
63 << float(pt.y()) << ' '
64 << float(pt.z()) << nl;
73 nNodes += faces[faceI].size();
76 os << "POLYGONS " << faces.size() << ' '
77 << faces.size() + nNodes << nl;
81 const face& f = faces[faceI];
97 void Foam::vtkSurfaceWriter::writeData
100 const Field<scalar>& values
103 os << "1 " << values.size() << " float" << nl;
105 forAll(values, elemI)
119 os << float(values[elemI]);
126 void Foam::vtkSurfaceWriter::writeData
129 const Field<vector>& values
132 os << "3 " << values.size() << " float" << nl;
134 forAll(values, elemI)
136 const vector& v = values[elemI];
137 os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2])
144 void Foam::vtkSurfaceWriter::writeData
147 const Field<sphericalTensor>& values
150 os << "1 " << values.size() << " float" << nl;
152 forAll(values, elemI)
154 const sphericalTensor& v = values[elemI];
155 os << float(v[0]) << nl;
161 void Foam::vtkSurfaceWriter::writeData
164 const Field<symmTensor>& values
167 os << "6 " << values.size() << " float" << nl;
169 forAll(values, elemI)
171 const symmTensor& v = values[elemI];
172 os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2])
173 << float(v[3]) << ' ' << float(v[4]) << ' ' << float(v[5])
181 void Foam::vtkSurfaceWriter::writeData
184 const Field<tensor>& values
187 os << "9 " << values.size() << " float" << nl;
189 forAll(values, elemI)
191 const tensor& v = values[elemI];
192 os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2])
193 << float(v[3]) << ' ' << float(v[4]) << ' ' << float(v[5])
194 << float(v[6]) << ' ' << float(v[7]) << ' ' << float(v[8])
202 // Write generic field in vtk format
204 void Foam::vtkSurfaceWriter::writeData
207 const Field<Type>& values
210 os << "1 " << values.size() << " float" << nl;
212 forAll(values, elemI)
214 os << float(0) << nl;
220 void Foam::vtkSurfaceWriter::writeTemplate
222 const fileName& outputDir,
223 const fileName& surfaceName,
224 const pointField& points,
225 const faceList& faces,
226 const word& fieldName,
227 const Field<Type>& values,
228 const bool isNodeValues,
232 if (!isDir(outputDir))
237 OFstream os(outputDir/fieldName + '_' + surfaceName + ".vtk");
241 Info<< "Writing field " << fieldName << " to " << os.name() << endl;
244 writeGeometry(os, points, faces);
246 // start writing data
256 os << values.size() << nl
257 << "FIELD attributes 1" << nl
261 writeData(os, values);
265 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
267 Foam::vtkSurfaceWriter::vtkSurfaceWriter()
273 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
275 Foam::vtkSurfaceWriter::~vtkSurfaceWriter()
279 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
281 void Foam::vtkSurfaceWriter::write
283 const fileName& outputDir,
284 const fileName& surfaceName,
285 const pointField& points,
286 const faceList& faces,
290 if (!isDir(outputDir))
295 OFstream os(outputDir/surfaceName + ".vtk");
299 Info<< "Writing geometry to " << os.name() << endl;
302 writeGeometry(os, points, faces);
306 // create write methods
307 defineSurfaceWriterWriteFields(Foam::vtkSurfaceWriter);
310 // ************************************************************************* //