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 "TRIsurfaceFormat.H"
00027 #include <OpenFOAM/ListOps.H>
00028
00029
00030
00031 template<class Face>
00032 inline void Foam::fileFormats::TRIsurfaceFormat<Face>::writeShell
00033 (
00034 Ostream& os,
00035 const pointField& pointLst,
00036 const Face& f,
00037 const label zoneI
00038 )
00039 {
00040
00041
00042 const point& p0 = pointLst[f[0]];
00043 for (label fp1 = 1; fp1 < f.size() - 1; ++fp1)
00044 {
00045 label fp2 = f.fcIndex(fp1);
00046
00047 const point& p1 = pointLst[f[fp1]];
00048 const point& p2 = pointLst[f[fp2]];
00049
00050 os << p0.x() << ' ' << p0.y() << ' ' << p0.z() << ' '
00051 << p1.x() << ' ' << p1.y() << ' ' << p1.z() << ' '
00052 << p2.x() << ' ' << p2.y() << ' ' << p2.z() << ' '
00053
00054 << "0x" << hex << zoneI << dec << endl;
00055 }
00056 }
00057
00058
00059
00060
00061 template<class Face>
00062 Foam::fileFormats::TRIsurfaceFormat<Face>::TRIsurfaceFormat
00063 (
00064 const fileName& filename
00065 )
00066 {
00067 read(filename);
00068 }
00069
00070
00071
00072
00073 template<class Face>
00074 bool Foam::fileFormats::TRIsurfaceFormat<Face>::read
00075 (
00076 const fileName& filename
00077 )
00078 {
00079 this->clear();
00080
00081
00082 TRIsurfaceFormatCore reader(filename);
00083
00084
00085 this->storedPoints().transfer(reader.points());
00086
00087
00088 List<label> sizes(reader.sizes().xfer());
00089 List<label> zoneIds(reader.zoneIds().xfer());
00090
00091
00092 List<Face> faceLst(zoneIds.size());
00093
00094 if (reader.sorted())
00095 {
00096
00097 forAll(faceLst, faceI)
00098 {
00099 const label startPt = 3*faceI;
00100 faceLst[faceI] = triFace(startPt, startPt+1, startPt+2);
00101 }
00102 }
00103 else
00104 {
00105
00106
00107 List<label> faceMap;
00108 sortedOrder(zoneIds, faceMap);
00109
00110
00111 forAll(faceMap, faceI)
00112 {
00113 const label startPt = 3*faceMap[faceI];
00114 faceLst[faceI] = triFace(startPt, startPt+1, startPt+2);
00115 }
00116 }
00117 zoneIds.clear();
00118
00119
00120 this->storedFaces().transfer(faceLst);
00121
00122 this->addZones(sizes);
00123 this->stitchFaces(SMALL);
00124 return true;
00125 }
00126
00127
00128 template<class Face>
00129 void Foam::fileFormats::TRIsurfaceFormat<Face>::write
00130 (
00131 const fileName& filename,
00132 const MeshedSurfaceProxy<Face>& surf
00133 )
00134 {
00135 const pointField& pointLst = surf.points();
00136 const List<Face>& faceLst = surf.faces();
00137 const List<label>& faceMap = surf.faceMap();
00138
00139 const List<surfZone>& zones =
00140 (
00141 surf.surfZones().size() > 1
00142 ? surf.surfZones()
00143 : TRIsurfaceFormat::oneZone(faceLst)
00144 );
00145
00146 const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
00147
00148 OFstream os(filename);
00149 if (!os.good())
00150 {
00151 FatalErrorIn
00152 (
00153 "fileFormats::TRIsurfaceFormat::write"
00154 "(const fileName&, const MeshedSurfaceProxy<Face>&)"
00155 )
00156 << "Cannot open file for writing " << filename
00157 << exit(FatalError);
00158 }
00159
00160 label faceIndex = 0;
00161 forAll(zones, zoneI)
00162 {
00163 const surfZone& zone = zones[zoneI];
00164
00165 if (useFaceMap)
00166 {
00167 forAll(zone, localFaceI)
00168 {
00169 const Face& f = faceLst[faceMap[faceIndex++]];
00170 writeShell(os, pointLst, f, zoneI);
00171 }
00172 }
00173 else
00174 {
00175 forAll(zone, localFaceI)
00176 {
00177 const Face& f = faceLst[faceIndex++];
00178 writeShell(os, pointLst, f, zoneI);
00179 }
00180 }
00181 }
00182 }
00183
00184
00185 template<class Face>
00186 void Foam::fileFormats::TRIsurfaceFormat<Face>::write
00187 (
00188 const fileName& filename,
00189 const UnsortedMeshedSurface<Face>& surf
00190 )
00191 {
00192 const pointField& pointLst = surf.points();
00193 const List<Face>& faceLst = surf.faces();
00194
00195 OFstream os(filename);
00196 if (!os.good())
00197 {
00198 FatalErrorIn
00199 (
00200 "fileFormats::TRIsurfaceFormat::write"
00201 "(const fileName&, const UnsortedMeshedSurface<Face>&)"
00202 )
00203 << "Cannot open file for writing " << filename
00204 << exit(FatalError);
00205 }
00206
00207
00208
00209 if (surf.zoneToc().size() == 1)
00210 {
00211 const List<label>& zoneIds = surf.zoneIds();
00212
00213 forAll(faceLst, faceI)
00214 {
00215 writeShell(os, pointLst, faceLst[faceI], zoneIds[faceI]);
00216 }
00217 }
00218 else
00219 {
00220 labelList faceMap;
00221 List<surfZone> zoneLst = surf.sortedZones(faceMap);
00222
00223 label faceIndex = 0;
00224 forAll(zoneLst, zoneI)
00225 {
00226 forAll(zoneLst[zoneI], localFaceI)
00227 {
00228 const Face& f = faceLst[faceMap[faceIndex++]];
00229 writeShell(os, pointLst, f, zoneI);
00230 }
00231 }
00232 }
00233 }
00234
00235
00236