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
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 #include <OpenFOAM/argList.H>
00067 #include <OpenFOAM/fileName.H>
00068 #include <triSurface/triSurface.H>
00069 #include <OpenFOAM/OFstream.H>
00070 #include <OpenFOAM/IFstream.H>
00071 #include <OpenFOAM/triFace.H>
00072 #include <OpenFOAM/triFaceList.H>
00073
00074 using namespace Foam;
00075
00076
00077
00078
00079
00080 int main(int argc, char *argv[])
00081 {
00082 argList::noParallel();
00083 argList::validArgs.clear();
00084 argList::validArgs.append("Foam surface file");
00085 argList::validArgs.append("Foam surface file");
00086 argList::validArgs.append("Foam output file");
00087 argList::validOptions.insert("points", "pointsFile");
00088 argList::validOptions.insert("mergeRegions", "");
00089 argList args(argc, argv);
00090
00091 fileName inFileName1(args.additionalArgs()[0]);
00092 fileName inFileName2(args.additionalArgs()[1]);
00093 fileName outFileName(args.additionalArgs()[2]);
00094
00095 bool addPoint = args.optionFound("points");
00096 bool mergeRegions = args.optionFound("mergeRegions");
00097
00098 if (addPoint)
00099 {
00100 Info<< "Reading a surface and adding points from a file"
00101 << "; merging the points and writing the surface to another file"
00102 << nl << endl;
00103
00104 Info<< "Surface : " << inFileName1<< nl
00105 << "Points : " << args.option("points") << nl
00106 << "Writing : " << outFileName << nl << endl;
00107 }
00108 else
00109 {
00110 Info<< "Reading two surfaces"
00111 << "; merging points and writing the surface to another file"
00112 << nl << endl;
00113
00114 if (mergeRegions)
00115 {
00116 Info<< "Regions from the two files will get merged" << nl
00117 << "Do not use this option if you want to keep the regions"
00118 << " separate" << nl << endl;
00119 }
00120 else
00121 {
00122 Info<< "Regions from the two files will not get merged" << nl
00123 << "Regions from " << inFileName2 << " will get offset so"
00124 << " as not to overlap with the regions in " << inFileName1
00125 << nl << endl;
00126 }
00127
00128
00129 Info<< "Surface1 : " << inFileName1<< nl
00130 << "Surface2 : " << inFileName2<< nl
00131 << "Writing : " << outFileName << nl << endl;
00132 }
00133
00134 const triSurface surface1(inFileName1);
00135
00136 Info<< "Surface1:" << endl;
00137 surface1.writeStats(Info);
00138 Info<< endl;
00139
00140 const pointField& points1 = surface1.points();
00141
00142
00143 triSurface combinedSurf;
00144
00145 if (addPoint)
00146 {
00147 IFstream pointsFile(args.option("points"));
00148 pointField extraPoints(pointsFile);
00149
00150 Info<< "Additional Points:" << extraPoints.size() << endl;
00151
00152 vectorField pointsAll(points1);
00153 label pointI = pointsAll.size();
00154 pointsAll.setSize(pointsAll.size() + extraPoints.size());
00155
00156 forAll(extraPoints, i)
00157 {
00158 pointsAll[pointI++] = extraPoints[i];
00159 }
00160
00161 combinedSurf = triSurface(surface1, surface1.patches(), pointsAll);
00162 }
00163 else
00164 {
00165 const triSurface surface2(inFileName2);
00166
00167 Info<< "Surface2:" << endl;
00168 surface2.writeStats(Info);
00169 Info<< endl;
00170
00171
00172
00173 List<labelledTri> facesAll(surface1.size() + surface2.size());
00174
00175 const pointField& points2 = surface2.points();
00176
00177 vectorField pointsAll(points1.size() + points2.size());
00178
00179
00180 label pointi = 0;
00181
00182 forAll(points1, point1i)
00183 {
00184 pointsAll[pointi++] = points1[point1i];
00185 }
00186
00187 forAll(points2, point2i)
00188 {
00189 pointsAll[pointi++] = points2[point2i];
00190 }
00191
00192
00193 label trianglei = 0;
00194
00195
00196 forAll(surface1, faceI)
00197 {
00198 facesAll[trianglei++] = surface1[faceI];
00199 }
00200 label nRegions1 = surface1.patches().size();
00201
00202
00203 if (!mergeRegions)
00204 {
00205 Info<< "Surface " << inFileName1 << " has " << nRegions1
00206 << " regions"
00207 << nl
00208 << "All region numbers in " << inFileName2 << " will be offset"
00209 << " by this amount" << nl << endl;
00210 }
00211
00212
00213 forAll(surface2, faceI)
00214 {
00215 const labelledTri& tri = surface2[faceI];
00216
00217 labelledTri& destTri = facesAll[trianglei++];
00218 destTri[0] = tri[0] + points1.size();
00219 destTri[1] = tri[1] + points1.size();
00220 destTri[2] = tri[2] + points1.size();
00221 if (mergeRegions)
00222 {
00223 destTri.region() = tri.region();
00224 }
00225 else
00226 {
00227 destTri.region() = tri.region() + nRegions1;
00228 }
00229 }
00230
00231 label nRegions2 = surface2.patches().size();
00232
00233 geometricSurfacePatchList newPatches;
00234
00235 if (mergeRegions)
00236 {
00237
00238 newPatches.setSize(max(nRegions1, nRegions2));
00239
00240 forAll(surface1.patches(), patchI)
00241 {
00242 newPatches[patchI] = surface1.patches()[patchI];
00243 }
00244 forAll(surface2.patches(), patchI)
00245 {
00246 newPatches[patchI] = surface2.patches()[patchI];
00247 }
00248 }
00249 else
00250 {
00251 Info<< "Regions from " << inFileName2 << " have been renumbered:"
00252 << nl
00253 << " old\tnew" << nl;
00254
00255 for (label regionI = 0; regionI < nRegions2; regionI++)
00256 {
00257 Info<< " " << regionI << '\t' << regionI+nRegions1
00258 << nl;
00259 }
00260 Info<< nl;
00261
00262 newPatches.setSize(nRegions1 + nRegions2);
00263
00264 label newPatchI = 0;
00265
00266 forAll(surface1.patches(), patchI)
00267 {
00268 newPatches[newPatchI++] = surface1.patches()[patchI];
00269 }
00270
00271 forAll(surface2.patches(), patchI)
00272 {
00273 newPatches[newPatchI++] = surface2.patches()[patchI];
00274 }
00275 }
00276
00277
00278 Info<< "New patches:" << nl;
00279 forAll(newPatches, patchI)
00280 {
00281 Info<< " " << patchI << '\t' << newPatches[patchI].name() << nl;
00282 }
00283 Info<< endl;
00284
00285
00286
00287 combinedSurf = triSurface(facesAll, newPatches, pointsAll);
00288 }
00289
00290
00291 combinedSurf.cleanup(true);
00292
00293 Info<< "Merged surface:" << endl;
00294
00295 combinedSurf.writeStats(Info);
00296
00297 Info<< endl;
00298
00299 Info << "Writing : " << outFileName << endl;
00300
00301
00302 combinedSurf.write(outFileName);
00303
00304 Info << "End\n" << endl;
00305
00306 return 0;
00307 }
00308
00309
00310