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 #include <triSurface/triSurface.H>
00030
00031
00032
00033 namespace Foam
00034 {
00035
00036
00037
00038
00039
00040 void triSurface::writeDXGeometry
00041 (
00042 const bool writeSorted,
00043 Ostream& os
00044 ) const
00045 {
00046 labelList faceMap;
00047 surfacePatchList myPatches(calcPatches(faceMap));
00048
00049
00050 os << "# Patches:" << endl;
00051 forAll(myPatches, patchI)
00052 {
00053 os << "# " << patchI << " "
00054 << myPatches[patchI].name() << endl;
00055 }
00056 os << endl << endl;
00057
00058
00059
00060 os << "# The irregular positions" << endl
00061 << "object 1 class array type float rank 1 shape 3 items "
00062 << nPoints() << " data follows" << endl;
00063 forAll(localPoints(), pointI)
00064 {
00065 const point& pt = localPoints()[pointI];
00066 os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl;
00067 }
00068 os << endl;
00069
00070 os << "# The irregular connections (triangles)" << endl
00071 << "object 2 class array type int rank 1 shape 3 items "
00072 << size() << " data follows" << endl;
00073
00074 if (writeSorted)
00075 {
00076 label faceIndex = 0;
00077
00078 forAll(myPatches, patchI)
00079 {
00080
00081
00082 for
00083 (
00084 label patchFaceI = 0;
00085 patchFaceI < myPatches[patchI].size();
00086 patchFaceI++
00087 )
00088 {
00089 const label faceI = faceMap[faceIndex++];
00090
00091 const labelledTri& f = localFaces()[faceI];
00092
00093 os << f[0] << ' ' << f[1] << ' ' << f[2] << endl;
00094 }
00095 }
00096 }
00097 else
00098 {
00099 forAll(*this, faceI)
00100 {
00101 const labelledTri& f = localFaces()[faceI];
00102
00103 os << f[0] << ' ' << f[1] << ' ' << f[2] << endl;
00104 }
00105 }
00106 os << "attribute \"element type\" string \"triangles\"" << endl
00107 << "attribute \"ref\" string \"positions\"" << endl << endl;
00108 }
00109
00110
00111
00112 void triSurface::writeDXTrailer(Ostream& os) const
00113 {
00114 os << "# the field, with three components: \"positions\", \"connections\""
00115 << ", and \"data\"" << endl
00116 << "object \"irregular positions irregular connections\" class field"
00117 << endl
00118 << "component \"positions\" value 1" << endl
00119 << "component \"connections\" value 2" << endl
00120 << "component \"data\" value 3" << endl;
00121 }
00122
00123
00124
00125 void triSurface::writeDX(const bool writeSorted, Ostream& os) const
00126 {
00127 writeDXGeometry(writeSorted, os);
00128
00129 os << "object 3 class array type float rank 0 items " << size()
00130 << " data follows" << endl;
00131 if (writeSorted)
00132 {
00133
00134
00135 labelList faceMap;
00136 surfacePatchList myPatches(calcPatches(faceMap));
00137
00138 forAll(myPatches, patchI)
00139 {
00140 forAll(myPatches[patchI], patchFaceI)
00141 {
00142 os << patchI << endl;
00143 }
00144 }
00145 }
00146 else
00147 {
00148
00149
00150 forAll(*this, faceI)
00151 {
00152 os << faceI << endl;
00153 }
00154 }
00155
00156 os << endl << "attribute \"dep\" string \"connections\"" << endl << endl;
00157
00158 writeDXTrailer(os);
00159
00160 os << "end" << endl;
00161 }
00162
00163
00164
00165 void triSurface::writeDX(const scalarField& field, Ostream& os) const
00166 {
00167 writeDXGeometry(false, os);
00168
00169 if (field.size() == size())
00170 {
00171
00172 os << "object 3 class array type float rank 0 items " << field.size()
00173 << " data follows" << endl;
00174 forAll(field, faceI)
00175 {
00176 os << field[faceI] << endl;
00177 }
00178 os << endl
00179 << "attribute \"dep\" string \"connections\"" << endl << endl;
00180 }
00181 else if (field.size() == nPoints())
00182 {
00183
00184 os << "object 3 class array type float rank 0 items " << field.size()
00185 << " data follows" << endl;
00186 forAll(field, pointI)
00187 {
00188 os << field[pointI] << endl;
00189 }
00190 os << endl
00191 << "attribute \"dep\" string \"positions\"" << endl << endl;
00192 }
00193 else
00194 {
00195 FatalErrorIn
00196 (
00197 "writeDX(const scalarField&, Ostream&)"
00198 ) << "Illegal field size " << field.size() << " is not equal "
00199 << " to number of faces " << size() << " or to number "
00200 << " of points " << nPoints() << exit(FatalError);
00201 }
00202
00203 writeDXTrailer(os);
00204
00205 os << "end" << endl;
00206 }
00207
00208
00209
00210 void triSurface::writeDX(const vectorField& field, Ostream& os) const
00211 {
00212 writeDXGeometry(false, os);
00213
00214 if (field.size() == size())
00215 {
00216
00217 os << "object 3 class array type float rank 1 shape 3 items "
00218 << field.size() << " data follows" << endl;
00219 forAll(field, faceI)
00220 {
00221 os << field[faceI].x() << ' '
00222 << field[faceI].y() << ' '
00223 << field[faceI].z() << endl;
00224 }
00225 os << endl
00226 << "attribute \"dep\" string \"connections\"" << endl << endl;
00227 }
00228 else if (field.size() == nPoints())
00229 {
00230
00231 os << "object 3 class array type float rank 1 shape 3 items "
00232 << field.size() << " data follows" << endl;
00233 forAll(field, pointI)
00234 {
00235 os << field[pointI].x() << ' '
00236 << field[pointI].y() << ' '
00237 << field[pointI].z() << endl;
00238 }
00239 os << endl
00240 << "attribute \"dep\" string \"positions\"" << endl << endl;
00241 }
00242 else
00243 {
00244 FatalErrorIn
00245 (
00246 "writeDX(const vectorField&, Ostream&)"
00247 ) << "Illegal field size " << field.size() << " is not equal "
00248 << " to number of faces " << size() << " or to number "
00249 << " of points " << nPoints() << exit(FatalError);
00250 }
00251
00252 writeDXTrailer(os);
00253
00254 os << "end" << endl;
00255 }
00256
00257
00258
00259
00260 }
00261
00262