surfaceClean.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Application
25  surfaceClean
26 
27 Description
28  - removes baffles
29  - collapses small edges, removing triangles.
30  - converts sliver triangles into split edges by projecting point onto
31  base of triangle.
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #include "triSurface.H"
36 #include "argList.H"
37 #include "OFstream.H"
38 
39 #include "collapseBase.H"
40 #include "collapseEdge.H"
41 
42 using namespace Foam;
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 
47 int main(int argc, char *argv[])
48 {
49  #include "removeCaseOptions.H"
50 
51  argList::validArgs.append("surface file");
52  argList::validArgs.append("output surface file");
53  argList::validArgs.append("min length");
54  argList::validArgs.append("min quality");
56  (
57  "noClean",
58  "perform some surface checking/cleanup on the input surface"
59  );
60  argList args(argc, argv);
61 
62  const fileName inFileName = args[1];
63  const fileName outFileName = args[2];
64  const scalar minLen = args.argRead<scalar>(3);
65  const scalar minQuality = args.argRead<scalar>(4);
66 
67  Info<< "Reading surface " << inFileName << nl
68  << "Collapsing all triangles with" << nl
69  << " edges or heights < " << minLen << nl
70  << " quality < " << minQuality << nl
71  << "Writing result to " << outFileName << nl << endl;
72 
73 
74  Info<< "Reading surface from " << inFileName << " ..." << nl << endl;
75  triSurface surf(inFileName);
76  surf.writeStats(Info);
77 
78  if (!args.optionFound("noClean"))
79  {
80  Info<< "Removing duplicate and illegal triangles ..." << nl << endl;
81  surf.cleanup(true);
82  }
83 
84  Info<< "Collapsing triangles to edges ..." << nl << endl;
85 
86  while (true)
87  {
88  label nEdgeCollapse = collapseEdge(surf, minLen);
89 
90  if (nEdgeCollapse == 0)
91  {
92  break;
93  }
94  }
95  while (true)
96  {
97  label nSplitEdge = collapseBase(surf, minLen, minQuality);
98 
99  if (nSplitEdge == 0)
100  {
101  break;
102  }
103  }
104 
105  Info<< nl
106  << "Resulting surface:" << endl;
107  surf.writeStats(Info);
108 
109  Info<< nl
110  << "Writing refined surface to " << outFileName << " ..." << endl;
111  surf.write(outFileName);
112 
113  Info<< "\nEnd\n" << endl;
114 
115  return 0;
116 }
117 
118 
119 // ************************************************************************* //
virtual Ostream & write(const char)=0
Write character.
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:103
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:118
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:114
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:153
T argRead(const label index) const
Read a value from the argument at index.
Definition: argListI.H:183
A class for handling file names.
Definition: fileName.H:82
Triangulated surface description with patch information.
Definition: triSurface.H:69
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.
int main(int argc, char *argv[])
Definition: financialFoam.C:44
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
messageStream Info
static const char nl
Definition: Ostream.H:266
Foam::argList args(argc, argv)