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 | Copyright (C) 2011-2013 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 {
50  argList::validArgs.append("surfaceFile");
51  argList::validArgs.append("min length");
52  argList::validArgs.append("min quality");
53  argList::validArgs.append("output surfaceFile");
55  (
56  "noClean",
57  "perform some surface checking/cleanup on the input surface"
58  );
59  argList args(argc, argv);
60 
61  const fileName inFileName = args[1];
62  const scalar minLen = args.argRead<scalar>(2);
63  const scalar minQuality = args.argRead<scalar>(3);
64  const fileName outFileName = args[4];
65 
66  Info<< "Reading surface " << inFileName << nl
67  << "Collapsing all triangles with" << nl
68  << " edges or heights < " << minLen << nl
69  << " quality < " << minQuality << nl
70  << "Writing result to " << outFileName << nl << endl;
71 
72 
73  Info<< "Reading surface from " << inFileName << " ..." << nl << endl;
74  triSurface surf(inFileName);
75  surf.writeStats(Info);
76 
77  if (!args.optionFound("noClean"))
78  {
79  Info<< "Removing duplicate and illegal triangles ..." << nl << endl;
80  surf.cleanup(true);
81  }
82 
83  Info<< "Collapsing triangles to edges ..." << nl << endl;
84 
85  while (true)
86  {
87  label nEdgeCollapse = collapseEdge(surf, minLen);
88 
89  if (nEdgeCollapse == 0)
90  {
91  break;
92  }
93  }
94  while (true)
95  {
96  label nSplitEdge = collapseBase(surf, minLen, minQuality);
97 
98  if (nSplitEdge == 0)
99  {
100  break;
101  }
102  }
103 
104  Info<< nl
105  << "Resulting surface:" << endl;
106  surf.writeStats(Info);
107 
108  Info<< nl
109  << "Writing refined surface to " << outFileName << " ..." << endl;
110  surf.write(outFileName);
111 
112  Info<< "\nEnd\n" << endl;
113 
114  return 0;
115 }
116 
117 
118 // ************************************************************************* //
label collapseBase(triSurface &surf, const scalar minLen, const scalar minQuality)
Keep collapsing all triangles whose height is < minLen or quality < minQ.
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
A class for handling file names.
Definition: fileName.H:69
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
label collapseEdge(triSurface &surf, const scalar minLen)
Keep collapsing all edges < minLen.
static void noParallel()
Remove the parallel options.
Definition: argList.C:146
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:154
Routines collapse sliver triangles by splitting the base edge.
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
Extract command arguments and options from the supplied argc and argv parameters. ...
Definition: argList.H:102
static const char nl
Definition: Ostream.H:262
T argRead(const label index) const
Read a value from the argument at index.
Definition: argListI.H:177
Routines to collapse small edges.
messageStream Info
virtual Ostream & write(const token &)=0
Write next token to stream.
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:83
Triangulated surface description with patch information.
Definition: triSurface.H:65
Foam::argList args(argc, argv)
Namespace for OpenFOAM.