FreeFOAM The Cross-Platform CFD Toolkit
surfacePointMerge.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  surfacePointMerge
26 
27 Description
28  Merges points on surface if they are within absolute distance.
29 
30  Since absolute distance use with care!
31 
32 Usage
33 
34  - surfacePointMerge [OPTIONS] <Foam surface file> <(absolute) merge distance> <Foam output surface file>
35 
36  @param <Foam surface file> \n
37  @todo Detailed description of argument.
38 
39  @param <(absolute) merge distance> \n
40  @todo Detailed description of argument.
41 
42  @param <Foam output surface file> \n
43  @todo Detailed description of argument.
44 
45  @param -case <dir>\n
46  Case directory.
47 
48  @param -help \n
49  Display help message.
50 
51  @param -doc \n
52  Display Doxygen API documentation page for this application.
53 
54  @param -srcDoc \n
55  Display Doxygen source documentation page for this application.
56 
57 \*---------------------------------------------------------------------------*/
58 
59 #include <triSurface/triSurface.H>
61 #include <OpenFOAM/argList.H>
62 #include <OpenFOAM/OFstream.H>
63 #include <OpenFOAM/boundBox.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("merge distance");
77  argList::validArgs.append("output file");
78  argList args(argc, argv);
79 
80  fileName surfFileName(args.additionalArgs()[0]);
81  scalar mergeTol(readScalar(IStringStream(args.additionalArgs()[1])()));
82  fileName outFileName(args.additionalArgs()[2]);
83 
84  Info<< "Reading surface from " << surfFileName << " ..." << endl;
85  Info<< "Merging points within " << mergeTol << " meter." << endl;
86 
87  triSurface surf1(surfFileName);
88 
89  Info<< "Original surface:" << endl;
90 
91  surf1.writeStats(Info);
92 
93 
94  triSurface cleanSurf(surf1);
95 
96  while(true)
97  {
98  label nOldVert = cleanSurf.nPoints();
99 
100  cleanSurf = triSurfaceTools::mergePoints(cleanSurf, mergeTol);
101 
102  Info<< "After merging points:" << endl;
103 
104  cleanSurf.writeStats(Info);
105 
106  if (nOldVert == cleanSurf.nPoints())
107  {
108  break;
109  }
110  }
111 
112  cleanSurf.write(outFileName);
113 
114  Info << "End\n" << endl;
115 
116  return 0;
117 }
118 
119 
120 // ************************ vim: set sw=4 sts=4 et: ************************ //