vtkSurfaceWriter.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "vtkSurfaceWriter.H"
00028
00029 #include "OFstream.H"
00030 #include "OSspecific.H"
00031
00032
00033
00034 template<class Type>
00035 void Foam::vtkSurfaceWriter<Type>::writeGeometry
00036 (
00037 Ostream& os,
00038 const pointField& points,
00039 const faceList& faces
00040 )
00041 {
00042
00043 os
00044 << "# vtk DataFile Version 2.0" << nl
00045 << "sampleSurface" << nl
00046 << "ASCII" << nl
00047 << "DATASET POLYDATA" << nl;
00048
00049
00050 os << "POINTS " << points.size() << " float" << nl;
00051 forAll(points, pointI)
00052 {
00053 const point& pt = points[pointI];
00054 os << float(pt.x()) << ' '
00055 << float(pt.y()) << ' '
00056 << float(pt.z()) << nl;
00057 }
00058 os << nl;
00059
00060
00061
00062 label nNodes = 0;
00063 forAll(faces, faceI)
00064 {
00065 nNodes += faces[faceI].size();
00066 }
00067
00068 os << "POLYGONS " << faces.size() << ' '
00069 << faces.size() + nNodes << nl;
00070
00071 forAll(faces, faceI)
00072 {
00073 const face& f = faces[faceI];
00074
00075 os << f.size();
00076 forAll(f, fp)
00077 {
00078 os << ' ' << f[fp];
00079 }
00080 os << nl;
00081 }
00082 }
00083
00084
00085 namespace Foam
00086 {
00087
00088
00089 template<>
00090 void Foam::vtkSurfaceWriter<Foam::scalar>::writeData
00091 (
00092 Ostream& os,
00093 const Field<Foam::scalar>& values
00094 )
00095 {
00096 os << "1 " << values.size() << " float" << nl;
00097
00098 forAll(values, elemI)
00099 {
00100 if (elemI)
00101 {
00102 if (elemI % 10)
00103 {
00104 os << ' ';
00105 }
00106 else
00107 {
00108 os << nl;
00109 }
00110 }
00111
00112 const scalar& v = values[elemI];
00113 os << float(v);
00114 }
00115 os << nl;
00116 }
00117
00118
00119 template<>
00120 void Foam::vtkSurfaceWriter<Foam::vector>::writeData
00121 (
00122 Ostream& os,
00123 const Field<Foam::vector>& values
00124 )
00125 {
00126 os << "3 " << values.size() << " float" << nl;
00127
00128 forAll(values, elemI)
00129 {
00130 const vector& v = values[elemI];
00131 os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2])
00132 << nl;
00133 }
00134 }
00135
00136
00137
00138 template<>
00139 void Foam::vtkSurfaceWriter<Foam::sphericalTensor>::writeData
00140 (
00141 Ostream& os,
00142 const Field<sphericalTensor>& values
00143 )
00144 {
00145 os << "1 " << values.size() << " float" << nl;
00146
00147 forAll(values, elemI)
00148 {
00149 const sphericalTensor& v = values[elemI];
00150 os << float(v[0]) << nl;
00151 }
00152 }
00153
00154
00155
00156 template<>
00157 void Foam::vtkSurfaceWriter<Foam::symmTensor>::writeData
00158 (
00159 Ostream& os,
00160 const Field<symmTensor>& values
00161 )
00162 {
00163 os << "6 " << values.size() << " float" << nl;
00164
00165 forAll(values, elemI)
00166 {
00167 const symmTensor& v = values[elemI];
00168 os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2])
00169 << float(v[3]) << ' ' << float(v[4]) << ' ' << float(v[5])
00170 << nl;
00171
00172 }
00173 }
00174
00175
00176
00177 template<>
00178 void Foam::vtkSurfaceWriter<Foam::tensor>::writeData
00179 (
00180 Ostream& os,
00181 const Field<tensor>& values
00182 )
00183 {
00184 os << "9 " << values.size() << " float" << nl;
00185
00186 forAll(values, elemI)
00187 {
00188 const tensor& v = values[elemI];
00189 os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2])
00190 << float(v[3]) << ' ' << float(v[4]) << ' ' << float(v[5])
00191 << float(v[6]) << ' ' << float(v[7]) << ' ' << float(v[8])
00192 << nl;
00193 }
00194 }
00195
00196 }
00197
00198
00199
00200 template<class Type>
00201 void Foam::vtkSurfaceWriter<Type>::writeData
00202 (
00203 Ostream& os,
00204 const Field<Type>& values
00205 )
00206 {
00207 os << "1 " << values.size() << " float" << nl;
00208
00209 forAll(values, elemI)
00210 {
00211 os << float(0) << nl;
00212 }
00213 }
00214
00215
00216
00217
00218
00219 template<class Type>
00220 Foam::vtkSurfaceWriter<Type>::vtkSurfaceWriter()
00221 :
00222 surfaceWriter<Type>()
00223 {}
00224
00225
00226
00227
00228 template<class Type>
00229 Foam::vtkSurfaceWriter<Type>::~vtkSurfaceWriter()
00230 {}
00231
00232
00233
00234
00235 template<class Type>
00236 void Foam::vtkSurfaceWriter<Type>::write
00237 (
00238 const fileName& outputDir,
00239 const fileName& surfaceName,
00240 const pointField& points,
00241 const faceList& faces,
00242 const bool verbose
00243 ) const
00244 {
00245 if (!isDir(outputDir))
00246 {
00247 mkDir(outputDir);
00248 }
00249
00250 fileName fName(outputDir/surfaceName + ".vtk");
00251
00252 if (verbose)
00253 {
00254 Info<< "Writing geometry to " << fName << endl;
00255 }
00256
00257 OFstream os(fName);
00258 writeGeometry(os, points, faces);
00259 }
00260
00261
00262 template<class Type>
00263 void Foam::vtkSurfaceWriter<Type>::write
00264 (
00265 const fileName& outputDir,
00266 const fileName& surfaceName,
00267 const pointField& points,
00268 const faceList& faces,
00269 const fileName& fieldName,
00270 const Field<Type>& values,
00271 const bool verbose
00272 ) const
00273 {
00274 if (!isDir(outputDir))
00275 {
00276 mkDir(outputDir);
00277 }
00278
00279 OFstream os
00280 (
00281 outputDir/fieldName + '_' + surfaceName + ".vtk"
00282 );
00283
00284 if (verbose)
00285 {
00286 Info<< "Writing field " << fieldName << " to " << os.name() << endl;
00287 }
00288
00289 writeGeometry(os, points, faces);
00290
00291
00292 if (values.size() == points.size())
00293 {
00294 os << "POINT_DATA ";
00295 }
00296 else
00297 {
00298 os << "CELL_DATA ";
00299 }
00300
00301 os << values.size() << nl
00302 << "FIELD attributes 1" << nl
00303 << fieldName << " ";
00304
00305
00306 writeData(os, values);
00307
00308 }
00309
00310
00311
Copyright © 2000-2009 OpenCFD Ltd