VTKsurfaceFormat.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 "VTKsurfaceFormat.H"
00028
00029
00030
00031 template<class Face>
00032 void Foam::fileFormats::VTKsurfaceFormat<Face>::writeHeaderPolygons
00033 (
00034 Ostream& os,
00035 const UList<Face>& faceLst
00036 )
00037 {
00038 label nNodes = 0;
00039
00040 forAll(faceLst, faceI)
00041 {
00042 nNodes += faceLst[faceI].size();
00043 }
00044
00045 os << nl
00046 << "POLYGONS " << faceLst.size() << ' '
00047 << faceLst.size() + nNodes << nl;
00048 }
00049
00050
00051
00052
00053 template<class Face>
00054 Foam::fileFormats::VTKsurfaceFormat<Face>::VTKsurfaceFormat()
00055 {}
00056
00057
00058
00059
00060 template<class Face>
00061 void Foam::fileFormats::VTKsurfaceFormat<Face>::write
00062 (
00063 const fileName& filename,
00064 const MeshedSurfaceProxy<Face>& surf
00065 )
00066 {
00067 const pointField& pointLst = surf.points();
00068 const List<Face>& faceLst = surf.faces();
00069 const List<label>& faceMap = surf.faceMap();
00070
00071 const List<surfZone>& zones =
00072 (
00073 surf.surfZones().size() > 1
00074 ? surf.surfZones()
00075 : oneZone(faceLst)
00076 );
00077
00078 const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
00079
00080 OFstream os(filename);
00081 if (!os.good())
00082 {
00083 FatalErrorIn
00084 (
00085 "fileFormats::VTKsurfaceFormat::write"
00086 "(const fileName&, const MeshedSurfaceProxy<Face>&)"
00087 )
00088 << "Cannot open file for writing " << filename
00089 << exit(FatalError);
00090 }
00091
00092
00093 writeHeader(os, pointLst);
00094 writeHeaderPolygons(os, faceLst);
00095
00096 label faceIndex = 0;
00097 forAll(zones, zoneI)
00098 {
00099 const surfZone& zone = zones[zoneI];
00100
00101 if (useFaceMap)
00102 {
00103 forAll(zone, localFaceI)
00104 {
00105 const Face& f = faceLst[faceMap[faceIndex++]];
00106
00107 os << f.size();
00108 forAll(f, fp)
00109 {
00110 os << ' ' << f[fp];
00111 }
00112 os << ' ' << nl;
00113 }
00114 }
00115 else
00116 {
00117 forAll(zone, localFaceI)
00118 {
00119 const Face& f = faceLst[faceIndex++];
00120
00121 os << f.size();
00122 forAll(f, fp)
00123 {
00124 os << ' ' << f[fp];
00125 }
00126 os << ' ' << nl;
00127 }
00128 }
00129 }
00130
00131 writeTail(os, zones);
00132 }
00133
00134
00135 template<class Face>
00136 void Foam::fileFormats::VTKsurfaceFormat<Face>::write
00137 (
00138 const fileName& filename,
00139 const UnsortedMeshedSurface<Face>& surf
00140 )
00141 {
00142 OFstream os(filename);
00143 if (!os.good())
00144 {
00145 FatalErrorIn
00146 (
00147 "fileFormats::VTKsurfaceFormat::write"
00148 "(const fileName&, const UnsortedMeshedSurface<Face>&)"
00149 )
00150 << "Cannot open file for writing " << filename
00151 << exit(FatalError);
00152 }
00153
00154
00155 const List<Face>& faceLst = surf.faces();
00156
00157 writeHeader(os, surf.points());
00158 writeHeaderPolygons(os, faceLst);
00159
00160 forAll(faceLst, faceI)
00161 {
00162 const Face& f = faceLst[faceI];
00163
00164 os << f.size();
00165 forAll(f, fp)
00166 {
00167 os << ' ' << f[fp];
00168 }
00169 os << ' ' << nl;
00170 }
00171
00172 writeTail(os, surf.zoneIds());
00173 }
00174
00175
00176
Copyright © 2000-2009 OpenCFD Ltd