Newer
Older
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
Add two surfaces. Does geometric merge on points. Does not check for
overlapping/intersecting triangles.
Keeps patches separate by renumbering.
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "fileName.H"
#include "triSurface.H"
#include "OFstream.H"
#include "IFstream.H"
#include "triFace.H"
#include "triFaceList.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
argList::noParallel();
argList::validArgs.clear();
argList::validArgs.append("Foam surface file");
argList::validArgs.append("Foam surface file");
argList::validArgs.append("Foam output file");
argList::validOptions.insert("points", "pointsFile");
argList::validOptions.insert("mergeRegions", "");
argList args(argc, argv);
fileName inFileName1(args.additionalArgs()[0]);
fileName inFileName2(args.additionalArgs()[1]);
fileName outFileName(args.additionalArgs()[2]);
bool addPoint = args.optionFound("points");
bool mergeRegions = args.optionFound("mergeRegions");
if (addPoint)
{
Info<< "Reading a surface and adding points from a file"
<< "; merging the points and writing the surface to another file"
<< nl << endl;
Info<< "Surface : " << inFileName1<< nl
<< "Points : " << args.option("points") << nl
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<< "Writing : " << outFileName << nl << endl;
}
else
{
Info<< "Reading two surfaces"
<< "; merging points and writing the surface to another file"
<< nl << endl;
if (mergeRegions)
{
Info<< "Regions from the two files will get merged" << nl
<< "Do not use this option if you want to keep the regions"
<< " separate" << nl << endl;
}
else
{
Info<< "Regions from the two files will not get merged" << nl
<< "Regions from " << inFileName2 << " will get offset so"
<< " as not to overlap with the regions in " << inFileName1
<< nl << endl;
}
Info<< "Surface1 : " << inFileName1<< nl
<< "Surface2 : " << inFileName2<< nl
<< "Writing : " << outFileName << nl << endl;
}
const triSurface surface1(inFileName1);
Info<< "Surface1:" << endl;
surface1.writeStats(Info);
Info<< endl;
const pointField& points1 = surface1.points();
// Final surface
triSurface combinedSurf;
if (addPoint)
{
IFstream pointsFile(args.option("points"));
pointField extraPoints(pointsFile);
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
Info<< "Additional Points:" << extraPoints.size() << endl;
vectorField pointsAll(points1);
label pointI = pointsAll.size();
pointsAll.setSize(pointsAll.size() + extraPoints.size());
forAll(extraPoints, i)
{
pointsAll[pointI++] = extraPoints[i];
}
combinedSurf = triSurface(surface1, surface1.patches(), pointsAll);
}
else
{
const triSurface surface2(inFileName2);
Info<< "Surface2:" << endl;
surface2.writeStats(Info);
Info<< endl;
// Make new storage
List<labelledTri> facesAll(surface1.size() + surface2.size());
const pointField& points2 = surface2.points();
vectorField pointsAll(points1.size() + points2.size());
label pointi = 0;
// Copy points1 into pointsAll
forAll(points1, point1i)
{
pointsAll[pointi++] = points1[point1i];
}
// Add surface2 points
forAll(points2, point2i)
{
pointsAll[pointi++] = points2[point2i];
}
label trianglei = 0;
// Copy triangles1 into trianglesAll
forAll(surface1, faceI)
{
label nRegions1 = surface1.patches().size();
if (!mergeRegions)
{
Info<< "Surface " << inFileName1 << " has " << nRegions1
<< " regions"
<< nl
<< "All region numbers in " << inFileName2 << " will be offset"
<< " by this amount" << nl << endl;
}
// Add (renumbered) surface2 triangles
forAll(surface2, faceI)
{
const labelledTri& tri = surface2[faceI];
labelledTri& destTri = facesAll[trianglei++];
destTri[0] = tri[0] + points1.size();
destTri[1] = tri[1] + points1.size();
destTri[2] = tri[2] + points1.size();
if (mergeRegions)
{
destTri.region() = tri.region();
}
else
{
destTri.region() = tri.region() + nRegions1;
}
}
label nRegions2 = surface2.patches().size();
geometricSurfacePatchList newPatches;
if (mergeRegions)
{
// Overwrite
newPatches.setSize(max(nRegions1, nRegions2));
forAll(surface1.patches(), patchI)
{
newPatches[patchI] = surface1.patches()[patchI];
}
forAll(surface2.patches(), patchI)
{
newPatches[patchI] = surface2.patches()[patchI];
}
}
else
{
Info<< "Regions from " << inFileName2 << " have been renumbered:"
<< nl
<< " old\tnew" << nl;
for (label regionI = 0; regionI < nRegions2; regionI++)
{
Info<< " " << regionI << '\t' << regionI+nRegions1
<< nl;
}
Info<< nl;
newPatches.setSize(nRegions1 + nRegions2);
label newPatchI = 0;
forAll(surface1.patches(), patchI)
{
newPatches[newPatchI++] = surface1.patches()[patchI];
}
forAll(surface2.patches(), patchI)
{
newPatches[newPatchI++] = surface2.patches()[patchI];
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
Info<< "New patches:" << nl;
forAll(newPatches, patchI)
{
Info<< " " << patchI << '\t' << newPatches[patchI].name() << nl;
}
Info<< endl;
// Construct new surface mesh
combinedSurf = triSurface(facesAll, newPatches, pointsAll);
}
// Merge all common points and do some checks
combinedSurf.cleanup(true);
Info<< "Merged surface:" << endl;
combinedSurf.writeStats(Info);
Info<< endl;
Info << "Writing : " << outFileName << endl;
// No need to 'group' while writing since all in correct order anyway.
combinedSurf.write(outFileName);
Info << "End\n" << endl;
return 0;
}
// ************************************************************************* //