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