readPoints.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 #include "starMesh.H"
00031 #include "IFstream.H"
00032
00033
00034
00035 label starMesh::readVtxLabel(IFstream& is)
00036 {
00037 char lcs[16];
00038
00039 for (int i=0; i<15; i++)
00040 {
00041 is.get(lcs[i]);
00042 }
00043
00044 lcs[15] = '\0';
00045
00046 return atoi(lcs);
00047 }
00048
00049
00050 scalar starMesh::readVtxCmpt(IFstream& is)
00051 {
00052 char lcs[17];
00053
00054 for (int i=0; i<16; i++)
00055 {
00056 is.get(lcs[i]);
00057 }
00058
00059 lcs[16] = '\0';
00060
00061 return scalar(atof(lcs));
00062 }
00063
00064
00065 void starMesh::readToNl(IFstream& is)
00066 {
00067 char c;
00068 do
00069 {
00070 is.get(c);
00071 } while (is && c != '\n');
00072 }
00073
00074
00075 void starMesh::readPoints(const scalar scaleFactor)
00076 {
00077 label nPoints = 0;
00078 label maxLabel = -1;
00079
00080 fileName pointsFileName(casePrefix_ + ".vrt");
00081
00082 {
00083 IFstream pointsFile(pointsFileName);
00084
00085
00086
00087 if (pointsFile.good())
00088 {
00089 label pointLabel;
00090 scalar x, y, z;
00091
00092 maxLabel = -1;
00093 while (pointsFile)
00094 {
00095 pointLabel = readVtxLabel(pointsFile);
00096
00097 if (!pointsFile) break;
00098
00099 maxLabel = max(maxLabel, pointLabel);
00100
00101 x = readVtxCmpt(pointsFile);
00102 y = readVtxCmpt(pointsFile);
00103 z = readVtxCmpt(pointsFile);
00104
00105 readToNl(pointsFile);
00106
00107 nPoints++;
00108 }
00109 }
00110 else
00111 {
00112 FatalErrorIn("starMesh::readPoints()")
00113 << "Cannot read file " << pointsFileName
00114 << abort(FatalError);
00115 }
00116 }
00117
00118 Info<< "Number of points = " << nPoints << endl << endl;
00119
00120 points_.setSize(nPoints);
00121
00122 # ifdef starMesh_H
00123 starPointID_.setSize(nPoints);
00124
00125
00126 starPointID_ = -1;
00127 # endif
00128
00129 starPointLabelLookup_.setSize(maxLabel+1);
00130
00131
00132 starPointLabelLookup_ = -1;
00133
00134 if (nPoints > 0)
00135 {
00136
00137
00138
00139 IFstream pointsFile(pointsFileName);
00140 label pointLabel;
00141
00142 forAll(points_, p)
00143 {
00144 pointLabel = readVtxLabel(pointsFile);
00145 points_[p].x() = readVtxCmpt(pointsFile);
00146 points_[p].y() = readVtxCmpt(pointsFile);
00147 points_[p].z() = readVtxCmpt(pointsFile);
00148
00149 readToNl(pointsFile);
00150
00151 # ifdef starMesh_H
00152 starPointID_[p] = pointLabel;
00153 # endif
00154
00155 starPointLabelLookup_[pointLabel] = p;
00156 }
00157
00158 if (scaleFactor > 1.0 + SMALL || scaleFactor < 1.0 - SMALL)
00159 {
00160 points_ *= scaleFactor;
00161 }
00162 }
00163 else
00164 {
00165 FatalError
00166 << "void starMesh::readPoints() : "
00167 << "no points in file "
00168 << pointsFileName
00169 << abort(FatalError);
00170 }
00171 }
00172
00173
00174
Copyright © 2000-2009 OpenCFD Ltd