FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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  Collapses small edges, removing triangles and converts sliver triangles
29  into split edges by projecting point onto base of triangle.
30 
31 Usage
32 
33  - surfaceClean [OPTIONS] <Foam surface file> <min length> <Foam output surface file>
34 
35  @param <Foam surface file> \n
36  @todo Detailed description of argument.
37 
38  @param <min length> \n
39  @todo Detailed description of argument.
40 
41  @param <Foam output surface file> \n
42  @todo Detailed description of argument.
43 
44  @param -case <dir>\n
45  Case directory.
46 
47  @param -help \n
48  Display help message.
49 
50  @param -doc \n
51  Display Doxygen API documentation page for this application.
52 
53  @param -srcDoc \n
54  Display Doxygen source documentation page for this application.
55 
56 \*---------------------------------------------------------------------------*/
57 
58 #include <triSurface/triSurface.H>
59 #include <OpenFOAM/argList.H>
60 #include <OpenFOAM/OFstream.H>
61 
62 #include "collapseBase.H"
63 #include "collapseEdge.H"
64 
65 using namespace Foam;
66 
67 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
68 
69 // Main program:
70 
71 int main(int argc, char *argv[])
72 {
75  argList::validArgs.append("surface file");
76  argList::validArgs.append("min length");
77  argList::validArgs.append("output surface file");
78  argList args(argc, argv);
79 
80  fileName inFileName(args.additionalArgs()[0]);
81  scalar minLen(readScalar(IStringStream(args.additionalArgs()[1])()));
82  fileName outFileName(args.additionalArgs()[2]);
83 
84  Pout<< "Reading surface " << inFileName << nl
85  << "Collapsing all triangles with edges or heights < " << minLen << nl
86  << "Writing result to " << outFileName << nl << endl;
87 
88 
89  Pout<< "Reading surface from " << inFileName << " ..." << nl << endl;
90  triSurface surf(inFileName);
91  surf.writeStats(Pout);
92 
93 
94  Pout<< "Collapsing triangles to edges ..." << nl << endl;
95 
96  while (true)
97  {
98  label nEdgeCollapse = collapseEdge(surf, minLen);
99 
100  if (nEdgeCollapse == 0)
101  {
102  break;
103  }
104  }
105  while (true)
106  {
107  label nSplitEdge = collapseBase(surf, minLen);
108 
109  if (nSplitEdge == 0)
110  {
111  break;
112  }
113  }
114 
115  Pout<< nl << "Resulting surface:" << endl;
116  surf.writeStats(Pout);
117  Pout<< nl;
118 
119  Pout<< "Writing refined surface to " << outFileName << " ..." << endl;
120  surf.write(outFileName);
121  Pout<< nl;
122 
123  Pout<< "End\n" << endl;
124 
125  return 0;
126 }
127 
128 
129 // ************************ vim: set sw=4 sts=4 et: ************************ //