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) 2011-2017 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  surfacePointMerge
26 
27 Description
28  Merges points on surface if they are within absolute distance.
29  Since absolute distance use with care!
30 
31 \*---------------------------------------------------------------------------*/
32 
33 #include "triSurface.H"
34 #include "triSurfaceTools.H"
35 #include "argList.H"
36 #include "OFstream.H"
37 #include "boundBox.H"
38 
39 using namespace Foam;
40 
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 int main(int argc, char *argv[])
45 {
47  argList::validArgs.append("surface file");
48  argList::validArgs.append("output surface file");
49  argList::validArgs.append("merge distance");
50  argList args(argc, argv);
51 
52  const fileName surfFileName = args[1];
53  const fileName outFileName = args[2];
54  const scalar mergeTol = args.argRead<scalar>(3);
55 
56  Info<< "Reading surface from " << surfFileName << " ..." << endl;
57  Info<< "Merging points within " << mergeTol << " metre." << endl;
58 
59  triSurface surf1(surfFileName);
60 
61  Info<< "Original surface:" << endl;
62 
63  surf1.writeStats(Info);
64 
65 
66  triSurface cleanSurf(surf1);
67 
68  while (true)
69  {
70  label nOldVert = cleanSurf.nPoints();
71 
72  cleanSurf = triSurfaceTools::mergePoints(cleanSurf, mergeTol);
73 
74  Info<< "After merging points:" << endl;
75 
76  cleanSurf.writeStats(Info);
77 
78  if (nOldVert == cleanSurf.nPoints())
79  {
80  break;
81  }
82  }
83 
84  cleanSurf.write(outFileName);
85 
86  Info<< "End\n" << endl;
87 
88  return 0;
89 }
90 
91 
92 // ************************************************************************* //
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
static void noParallel()
Remove the parallel options.
Definition: argList.C:148
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:154
static triSurface mergePoints(const triSurface &surf, const scalar mergeTol)
Merge points within distance.
Extract command arguments and options from the supplied argc and argv parameters. ...
Definition: argList.H:102
T argRead(const label index) const
Read a value from the argument at index.
Definition: argListI.H:177
messageStream Info
virtual Ostream & write(const token &)=0
Write next token to stream.
Triangulated surface description with patch information.
Definition: triSurface.H:65
Foam::argList args(argc, argv)
Namespace for OpenFOAM.