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