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