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