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 #include "WRLsurfaceFormat.H"
00027
00028 #include <OpenFOAM/Ostream.H>
00029 #include <OpenFOAM/OFstream.H>
00030 #include <OpenFOAM/ListOps.H>
00031
00032
00033
00034 template<class Face>
00035 Foam::fileFormats::WRLsurfaceFormat<Face>::WRLsurfaceFormat()
00036 {}
00037
00038
00039
00040
00041 template<class Face>
00042 void Foam::fileFormats::WRLsurfaceFormat<Face>::write
00043 (
00044 const fileName& filename,
00045 const MeshedSurfaceProxy<Face>& surf
00046 )
00047 {
00048 const pointField& pointLst = surf.points();
00049 const List<Face>& faceLst = surf.faces();
00050 const List<label>& faceMap = surf.faceMap();
00051
00052
00053 const List<surfZone>& zones =
00054 (
00055 surf.surfZones().size() > 1
00056 ? surf.surfZones()
00057 : WRLsurfaceFormat::oneZone(faceLst, "")
00058 );
00059
00060 const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
00061
00062 OFstream os(filename);
00063 if (!os.good())
00064 {
00065 FatalErrorIn
00066 (
00067 "fileFormats::WRLsurfaceFormat::write"
00068 "(const fileName&, const MeshedSurfaceProxy<Face>&)"
00069 )
00070 << "Cannot open file for writing " << filename
00071 << exit(FatalError);
00072 }
00073
00074 writeHeader(os, pointLst, faceLst.size(), zones);
00075
00076 os << "\n"
00077 "Group {\n"
00078 " children [\n"
00079 " Shape {\n";
00080
00081 writeAppearance(os);
00082
00083 os <<
00084 " geometry IndexedFaceSet {\n"
00085 " coord Coordinate {\n"
00086 " point [\n";
00087
00088
00089 forAll(pointLst, ptI)
00090 {
00091 const point& pt = pointLst[ptI];
00092
00093 os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
00094 }
00095
00096 os <<
00097 " ]\n"
00098 " }\n"
00099 " coordIndex [\n";
00100
00101 label faceIndex = 0;
00102 forAll(zones, zoneI)
00103 {
00104 const surfZone& zone = zones[zoneI];
00105
00106 if (useFaceMap)
00107 {
00108 forAll(zone, localFaceI)
00109 {
00110 const Face& f = faceLst[faceMap[faceIndex++]];
00111
00112 forAll(f, fp)
00113 {
00114 os << f[fp] << ' ';
00115 }
00116 os << "-1,\n";
00117 }
00118 }
00119 else
00120 {
00121 forAll(zone, localFaceI)
00122 {
00123 const Face& f = faceLst[faceIndex++];
00124
00125 forAll(f, fp)
00126 {
00127 os << ' ' << f[fp];
00128 }
00129 os << " -1,\n";
00130 }
00131 }
00132 }
00133
00134 os <<
00135 " ]\n"
00136 " }\n"
00137 " }\n"
00138 " ]\n"
00139 "}\n";
00140 }
00141
00142
00143