Loading...
Searching...
No Matches
surfacePointMerge.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2013 OpenFOAM Foundation
9 Copyright (C) 2020-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Application
28 surfacePointMerge
29
30Group
31 grpSurfaceUtilities
32
33Description
34 Merges points on surface if they are within absolute distance.
35 Since absolute distance use with care!
36
37\*---------------------------------------------------------------------------*/
38
39#include "triSurface.H"
40#include "triSurfaceTools.H"
41#include "argList.H"
42#include "OFstream.H"
43#include "boundBox.H"
44
45using namespace Foam;
46
47
48// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49
50int main(int argc, char *argv[])
51{
53 (
54 "Merge points on surface if they are within absolute distance [m]."
55 );
57 argList::addArgument("input", "The input surface file");
58 argList::addArgument("distance", "The merge distance");
59 argList::addArgument("output", "The output surface file");
60
62 (
63 "scale",
64 "factor",
65 "Input geometry scaling factor"
66 );
67
68 argList args(argc, argv);
69
70 const auto surfFileName = args.get<fileName>(1);
71 const auto mergeTol = args.get<scalar>(2);
72 const auto outFileName = args.get<fileName>(3);
73
74 const scalar scaling = args.getOrDefault<scalar>("scale", -1);
75
76 Info<< "Reading surface from " << surfFileName << " ..." << nl
77 << "Merging points within " << mergeTol << " metre." << nl;
78 if (scaling > 0)
79 {
80 Info<< "input scaling " << scaling << nl;
81 }
82
83 const triSurface surf1(surfFileName, scaling);
84
85 Info<< "Original surface:" << nl;
86 surf1.writeStats(Info);
87
88 triSurface cleanSurf(surf1);
89
90 while (true)
91 {
92 const label nOldVert = cleanSurf.nPoints();
93
94 cleanSurf = triSurfaceTools::mergePoints(cleanSurf, mergeTol);
95
96 Info<< "After merging points:" << endl;
97
98 cleanSurf.writeStats(Info);
99
100 if (nOldVert == cleanSurf.nPoints())
101 {
102 break;
103 }
104 }
105
106 cleanSurf.write(outFileName);
107
108 Info<< "End\n" << endl;
109
110 return 0;
111}
112
113
114// ************************************************************************* //
Extract command arguments and options from the supplied argc and argv parameters.
Definition argList.H:119
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition argList.C:366
static void noParallel()
Remove the parallel options.
Definition argList.C:599
static void addOption(const word &optName, const string &param="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
Definition argList.C:400
static void addNote(const string &note)
Add extra notes for the usage information.
Definition argList.C:477
A class for handling file names.
Definition fileName.H:75
static triSurface mergePoints(const triSurface &surf, const scalar mergeTol)
Merge points within distance.
Triangulated surface description with patch information.
Definition triSurface.H:74
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
Foam::argList args(argc, argv)