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