surfaceClean.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 surfaceClean
29
30Group
31 grpSurfaceUtilities
32
33Description
34 Utility to clean surfaces.
35
36 Current functionality
37 - removes baffles
38 - collapses small edges, removing triangles.
39 - converts sliver triangles into split edges by projecting point onto
40 base of triangle.
41
42\*---------------------------------------------------------------------------*/
43
44#include "triSurface.H"
45#include "argList.H"
46#include "OFstream.H"
47
48#include "collapseBase.H"
49#include "collapseEdge.H"
50
51using namespace Foam;
52
53// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54
55
56int main(int argc, char *argv[])
57{
58 argList::addNote
59 (
60 "Clean surface by removing baffles, sliver faces,"
61 " collapsing small edges, etc."
62 );
63
64 argList::noParallel();
65 argList::addArgument("input", "The input surface file");
66 argList::addArgument("length", "The min length");
67 argList::addArgument("quality", "The min quality");
68 argList::addArgument("output", "The output surface file");
69
70 argList::addBoolOption
71 (
72 "no-clean",
73 "Suppress surface checking/cleanup on the input surface"
74 );
75 argList::addOptionCompat("no-clean", {"noClean", -2006});
76
77 argList::addOption
78 (
79 "scale",
80 "factor",
81 "Input geometry scaling factor"
82 );
83 argList args(argc, argv);
84
85 const auto inFileName = args.get<fileName>(1);
86 const auto minLen = args.get<scalar>(2);
87 const auto minQuality = args.get<scalar>(3);
88 const auto outFileName = args.get<fileName>(4);
89
90 Info<< "Reading surface " << inFileName << nl
91 << "Collapsing all triangles with" << nl
92 << " edges or heights < " << minLen << nl
93 << " quality < " << minQuality << nl
94 << "Writing result to " << outFileName << nl << endl;
95
96
97 Info<< "Reading surface from " << inFileName << " ..." << nl << endl;
98
99 triSurface surf
100 (
101 inFileName,
102 args.getOrDefault<scalar>("scale", -1)
103 );
104 surf.writeStats(Info);
105
106 if (!args.found("no-clean"))
107 {
108 Info<< "Removing duplicate and illegal triangles ..." << nl << endl;
109 surf.cleanup(true);
110 }
111
112 Info<< "Collapsing triangles to edges ..." << nl << endl;
113
114 while (true)
115 {
116 const label nEdgeCollapse = collapseEdge(surf, minLen);
117
118 if (nEdgeCollapse == 0)
119 {
120 break;
121 }
122 }
123 while (true)
124 {
125 const label nSplitEdge = collapseBase(surf, minLen, minQuality);
126
127 if (nSplitEdge == 0)
128 {
129 break;
130 }
131 }
132
133 Info<< nl
134 << "Resulting surface:" << endl;
135 surf.writeStats(Info);
136
137 Info<< nl
138 << "Writing refined surface to " << outFileName << " ..." << endl;
139 surf.write(outFileName);
140
141 Info<< "\nEnd\n" << endl;
142
143 return 0;
144}
145
146
147// ************************************************************************* //
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:124
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:278
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:178
T getOrDefault(const word &optName, const T &deflt) const
Get a value from the named option if present, or return default.
Definition: argListI.H:307
A class for handling file names.
Definition: fileName.H:76
Triangulated surface description with patch information.
Definition: triSurface.H:79
Routines collapse sliver triangles by splitting the base edge.
label collapseBase(triSurface &surf, const scalar minLen, const scalar minQuality)
Keep collapsing all triangles whose height is < minLen or quality < minQ.
Routines to collapse small edges.
label collapseEdge(triSurface &surf, const scalar minLen)
Keep collapsing all edges < minLen.
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:372
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
Foam::argList args(argc, argv)