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 -------------------------------------------------------------------------------
11 License
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 
27 Application
28  surfaceClean
29 
30 Group
31  grpSurfaceUtilities
32 
33 Description
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 
51 using namespace Foam;
52 
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 
55 
56 int main(int argc, char *argv[])
57 {
59  (
60  "Clean surface by removing baffles, sliver faces,"
61  " collapsing small edges, etc."
62  );
63 
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 
71  (
72  "no-clean",
73  "Suppress surface checking/cleanup on the input surface"
74  );
75  argList::addOptionCompat("no-clean", {"noClean", -2006});
76 
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 // ************************************************************************* //
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:453
label collapseBase(triSurface &surf, const scalar minLen, const scalar minQuality)
Keep collapsing all triangles whose height is < minLen or quality < minQ.
A class for handling file names.
Definition: fileName.H:71
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
label collapseEdge(triSurface &surf, const scalar minLen)
Keep collapsing all edges < minLen.
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Definition: argList.C:365
static void noParallel()
Remove the parallel options.
Definition: argList.C:551
static void addOptionCompat(const word &optName, std::pair< const char *, int > compat)
Specify an alias for the option name.
Definition: argList.C:409
Routines collapse sliver triangles by splitting the base edge.
T getOrDefault(const word &optName, const T &deflt) const
Get a value from the named option if present, or return default.
Definition: argListI.H:300
Extract command arguments and options from the supplied argc and argv parameters. ...
Definition: argList.H:118
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:376
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:271
Routines to collapse small edges.
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition: argList.C:342
messageStream Info
Information stream (stdout output on master, null elsewhere)
Triangulated surface description with patch information.
Definition: triSurface.H:72
Foam::argList args(argc, argv)
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:171
Namespace for OpenFOAM.