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  Utility to clean surfaces.
29 
30  Current functionality
31  - removes baffles
32  - collapses small edges, removing triangles.
33  - converts sliver triangles into split edges by projecting point onto
34  base of triangle.
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #include "triSurface.H"
39 #include "argList.H"
40 #include "OFstream.H"
41 
42 #include "collapseBase.H"
43 #include "collapseEdge.H"
44 
45 using namespace Foam;
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 
50 int main(int argc, char *argv[])
51 {
53  argList::validArgs.append("surfaceFile");
54  argList::validArgs.append("min length");
55  argList::validArgs.append("min quality");
56  argList::validArgs.append("output surfaceFile");
58  (
59  "noClean",
60  "perform some surface checking/cleanup on the input surface"
61  );
62  argList args(argc, argv);
63 
64  const fileName inFileName = args[1];
65  const scalar minLen = args.argRead<scalar>(2);
66  const scalar minQuality = args.argRead<scalar>(3);
67  const fileName outFileName = args[4];
68 
69  Info<< "Reading surface " << inFileName << nl
70  << "Collapsing all triangles with" << nl
71  << " edges or heights < " << minLen << nl
72  << " quality < " << minQuality << nl
73  << "Writing result to " << outFileName << nl << endl;
74 
75 
76  Info<< "Reading surface from " << inFileName << " ..." << nl << endl;
77  triSurface surf(inFileName);
78  surf.writeStats(Info);
79 
80  if (!args.optionFound("noClean"))
81  {
82  Info<< "Removing duplicate and illegal triangles ..." << nl << endl;
83  surf.cleanup(true);
84  }
85 
86  Info<< "Collapsing triangles to edges ..." << nl << endl;
87 
88  while (true)
89  {
90  label nEdgeCollapse = collapseEdge(surf, minLen);
91 
92  if (nEdgeCollapse == 0)
93  {
94  break;
95  }
96  }
97  while (true)
98  {
99  label nSplitEdge = collapseBase(surf, minLen, minQuality);
100 
101  if (nSplitEdge == 0)
102  {
103  break;
104  }
105  }
106 
107  Info<< nl
108  << "Resulting surface:" << endl;
109  surf.writeStats(Info);
110 
111  Info<< nl
112  << "Writing refined surface to " << outFileName << " ..." << endl;
113  surf.write(outFileName);
114 
115  Info<< "\nEnd\n" << endl;
116 
117  return 0;
118 }
119 
120 
121 // ************************************************************************* //
Foam::argList::validArgs
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:143
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::argList::addBoolOption
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:98
Foam::argList
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:97
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
OFstream.H
Foam::label
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
Foam::triSurface
Triangulated surface description with patch information.
Definition: triSurface.H:57
Foam::Ostream::write
virtual Ostream & write(const token &)=0
Write next token to stream.
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
collapseEdge.H
Routines to collapse small edges.
argList.H
main
int main(int argc, char *argv[])
Definition: postCalc.C:54
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
collapseBase.H
Routines collapse sliver triangles by splitting the base edge.
collapseBase
label collapseBase(triSurface &surf, const scalar minLen, const scalar minQuality)
Keep collapsing all triangles whose height is < minLen or quality < minQ.
Foam::argList::optionFound
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
Foam::argList::argRead
T argRead(const label index) const
Read a value from the argument at index.
Definition: argListI.H:177
collapseEdge
label collapseEdge(triSurface &surf, const scalar minLen)
Keep collapsing all edges < minLen.
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:161
args
Foam::argList args(argc, argv)