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