53int main(
int argc,
char *argv[])
57 "Add two surfaces via a geometric merge on points."
58 " Does not check for overlapping/intersecting triangles."
61 argList::noParallel();
62 argList::addArgument(
"surface1",
"The input surface file 1");
63 argList::addArgument(
"surface2",
"The input surface file 2");
64 argList::addArgument(
"output",
"The output surface file");
70 "Provide additional points"
72 argList::addBoolOption
75 "Combine regions from both surfaces"
81 "Geometry scaling factor on input surfaces"
90 const bool addPoint =
args.
found(
"points");
91 const bool mergeRegions =
args.
found(
"mergeRegions");
97 Info<<
"Reading a surface and adding points from a file"
98 <<
"; merging the points and writing the surface to another file"
101 Info<<
"Surface : " << inFileName1<<
nl
103 <<
"Writing : " << outFileName << nl << endl;
107 Info<<
"Reading two surfaces"
108 <<
"; merging points and writing the surface to another file"
113 Info<<
"Regions from the two files will get merged" <<
nl
114 <<
"Do not use this option if you want to keep the regions"
115 <<
" separate" <<
nl <<
endl;
119 Info<<
"Regions from the two files will not get merged" <<
nl
120 <<
"Regions from " << inFileName2 <<
" will get offset so"
121 <<
" as not to overlap with the regions in " << inFileName1
126 Info<<
"Surface1 : " << inFileName1<<
nl
127 <<
"Surface2 : " << inFileName2<<
nl
128 <<
"Writing : " << outFileName <<
nl <<
endl;
133 Info<<
"Scaling : " << scaleFactor <<
nl;
136 const triSurface surface1(inFileName1, scaleFactor);
138 surface1.writeStats(Info);
141 const pointField& points1 = surface1.points();
151 Info<<
"Additional Points:" << extraPoints.size() <<
endl;
154 label pointi = pointsAll.size();
155 pointsAll.setSize(pointsAll.size() + extraPoints.size());
157 for (
const auto& pt : extraPoints)
159 pointsAll[pointi++] = pt;
162 combinedSurf =
triSurface(surface1, surface1.patches(), pointsAll);
166 const triSurface surface2(inFileName2, scaleFactor);
168 surface2.writeStats(Info);
175 const pointField& points2 = surface2.points();
182 for (
const auto& pt : points1)
184 pointsAll[pointi++] = pt;
187 for (
const auto& pt : points2)
189 pointsAll[pointi++] = pt;
196 label nNewPatches = 0;
197 labelList patch1Map(surface1.patches().size());
198 labelList patch2Map(surface2.patches().size());
204 forAll(surface1.patches(), i)
206 const word&
name = surface1.patches()[i].name();
209 const label combinedi = nameToPatch(name, nameToPatch.
size());
211 patch1Map[i] = combinedi;
216 forAll(surface2.patches(), i)
218 const word&
name = surface2.patches()[i].name();
221 const label combinedi = nameToPatch(name, nameToPatch.
size());
223 patch2Map[i] = combinedi;
226 nNewPatches = nameToPatch.
size();
230 Info<<
"Surface " << inFileName1
231 <<
" has " << surface1.patches().size()
234 <<
"All region numbers in " << inFileName2 <<
" will be offset"
235 <<
" by this amount" <<
nl <<
endl;
237 patch1Map =
identity(surface1.patches().size());
238 patch2Map =
identity(surface2.patches().size(), patch1Map.size());
240 nNewPatches = surface1.patches().size()+surface2.patches().size();
249 destTri.triFace::operator=(tri);
250 destTri.
region() = patch1Map[tri.region()];
257 destTri[0] = tri[0] + points1.
size();
258 destTri[1] = tri[1] + points1.
size();
259 destTri[2] = tri[2] + points1.
size();
260 destTri.
region() = patch2Map[tri.region()];
265 forAll(surface1.patches(), patchi)
267 newPatches[patch1Map[patchi]] = surface1.patches()[patchi];
269 forAll(surface2.patches(), patchi)
271 newPatches[patch2Map[patchi]] = surface2.patches()[patchi];
274 Info<<
"New patches:" <<
nl;
275 forAll(newPatches, patchi)
277 Info<<
" " << patchi <<
'\t' << newPatches[patchi].name() <<
nl;
283 combinedSurf =
triSurface(facesAll, newPatches, pointsAll);
295 Info<<
"Writing : " << outFileName <<
endl;
298 combinedSurf.
write(outFileName, mergeRegions);
static constexpr label size() noexcept
Return the number of elements in the FixedList.
A HashTable similar to std::unordered_map.
label size() const noexcept
The number of elements in table.
Input from file stream, using an ISstream.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void size(const label n)
Older name for setAddressableSize.
Extract command arguments and options from the supplied argc and argv parameters.
T get(const label index) const
Get a value from the argument at index.
bool found(const word &optName) const
Return true if the named option is found.
T getOrDefault(const word &optName, const T &deflt) const
Get a value from the named option if present, or return default.
A class for handling file names.
A triFace with additional (region) index.
label region() const noexcept
Return the region index.
Triangulated surface description with patch information.
void cleanup(const bool verbose)
Remove non-valid triangles.
void write(Ostream &os) const
Write to Ostream in simple OpenFOAM format.
void writeStats(Ostream &os) const
Write some statistics.
A class for handling words, derived from Foam::string.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
constexpr char nl
The newline '\n' character (0x0a)
Foam::argList args(argc, argv)
#define forAll(list, i)
Loop across all elements in list.