readTRI.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
00028
00029
00030
00031
00032
00033
00034 #include "triSurface.H"
00035 #include "STLpoint.H"
00036 #include "SLList.H"
00037 #include "IFstream.H"
00038 #include "readHexLabel.H"
00039 #include "stringList.H"
00040
00041
00042
00043 namespace Foam
00044 {
00045
00046
00047
00048 bool triSurface::readTRI(const fileName& TRIfileName)
00049 {
00050 IFstream TRIfile(TRIfileName);
00051
00052 if (!TRIfile.good())
00053 {
00054 FatalErrorIn("triSurface::readTRI(const fileName&)")
00055 << "Cannot read file " << TRIfileName
00056 << exit(FatalError);
00057 }
00058
00059 SLList<STLpoint> STLpoints;
00060 SLList<label> STLlabels;
00061 HashTable<label, string> STLsolidNames;
00062
00063
00064 label maxRegion = 0;
00065
00066 while(TRIfile)
00067 {
00068 string line = getLineNoComment(TRIfile);
00069
00070 if (line.empty())
00071 {
00072 break;
00073 }
00074
00075 IStringStream lineStream(line);
00076
00077 STLpoint p
00078 (
00079 readScalar(lineStream),
00080 readScalar(lineStream),
00081 readScalar(lineStream)
00082 );
00083
00084 if (!lineStream) break;
00085
00086 STLpoints.append(p);
00087 STLpoints.append
00088 (
00089 STLpoint
00090 (
00091 readScalar(lineStream),
00092 readScalar(lineStream),
00093 readScalar(lineStream)
00094 )
00095 );
00096 STLpoints.append
00097 (
00098 STLpoint
00099 (
00100 readScalar(lineStream),
00101 readScalar(lineStream),
00102 readScalar(lineStream)
00103 )
00104 );
00105
00106
00107
00108 char zero;
00109 lineStream >> zero;
00110
00111 word rawSolidName(lineStream);
00112
00113 word solidName("patch" + rawSolidName(1, rawSolidName.size()-1));
00114
00115 label region = -1;
00116
00117 HashTable<label, string>::const_iterator findName =
00118 STLsolidNames.find(solidName);
00119
00120 if (findName != STLsolidNames.end())
00121 {
00122 region = findName();
00123 }
00124 else
00125 {
00126 Pout<< "Mapping triangle colour 0" << rawSolidName
00127 << " to region " << maxRegion << " name " << solidName
00128 << endl;
00129
00130 region = maxRegion++;
00131 STLsolidNames.insert(solidName, region);
00132 }
00133 STLlabels.append(region);
00134 }
00135
00136
00137 pointField rawPoints(STLpoints.size());
00138
00139 label i = 0;
00140 for
00141 (
00142 SLList<STLpoint>::iterator iter = STLpoints.begin();
00143 iter != STLpoints.end();
00144 ++iter
00145 )
00146 {
00147 rawPoints[i++] = *iter;
00148 }
00149
00150 setSize(STLlabels.size());
00151
00152 label pointI = 0;
00153 SLList<label>::iterator iter = STLlabels.begin();
00154 forAll (*this, i)
00155 {
00156 operator[](i)[0] = pointI++;
00157 operator[](i)[1] = pointI++;
00158 operator[](i)[2] = pointI++;
00159 operator[](i).region() = *iter;
00160 ++iter;
00161 }
00162
00163 stitchTriangles(rawPoints);
00164
00165
00166 stringList names(STLsolidNames.toc());
00167
00168 patches_.setSize(names.size());
00169
00170 forAll(names, nameI)
00171 {
00172 patches_[nameI].name() = names[nameI];
00173 patches_[nameI].geometricType() = "empty";
00174 }
00175
00176 return true;
00177 }
00178
00179
00180
00181
00182 }
00183
00184
Copyright © 2000-2009 OpenCFD Ltd