1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
25 Example of simple laplacian smoother
27 \*---------------------------------------------------------------------------*/
29 #include "triSurface.H"
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 int main(int argc, char *argv[])
42 argList::noParallel();
43 argList::validOptions.clear();
44 argList::validArgs.clear();
45 argList::validArgs.append("surface file");
46 argList::validArgs.append("underrelax factor (0..1)");
47 argList::validArgs.append("iterations");
48 argList::validArgs.append("output file");
49 argList args(argc, argv);
51 fileName surfFileName(args.additionalArgs()[0]);
52 scalar relax(readScalar(IStringStream(args.additionalArgs()[1])()));
53 if ((relax <= 0) || (relax > 1))
55 FatalErrorIn(args.executable()) << "Illegal relaxation factor "
57 << "0: no change 1: move vertices to average of neighbours"
60 label iters(readLabel(IStringStream(args.additionalArgs()[2])()));
61 fileName outFileName(args.additionalArgs()[3]);
63 Info<< "Relax:" << relax << endl;
64 Info<< "Iters:" << iters << endl;
67 Info<< "Reading surface from " << surfFileName << " ..." << endl;
69 triSurface surf1(surfFileName);
71 Info<< "Triangles : " << surf1.size() << endl;
72 Info<< "Vertices : " << surf1.nPoints() << endl;
73 Info<< "Bounding Box : " << boundBox(surf1.localPoints()) << endl;
75 pointField newPoints(surf1.localPoints());
77 const labelListList& pointEdges = surf1.pointEdges();
80 for (label iter = 0; iter < iters; iter++)
82 forAll(pointEdges, vertI)
84 vector avgPos(vector::zero);
86 const labelList& myEdges = pointEdges[vertI];
88 forAll(myEdges, myEdgeI)
90 const edge& e = surf1.edges()[myEdges[myEdgeI]];
92 label otherVertI = e.otherVertex(vertI);
94 avgPos += surf1.localPoints()[otherVertI];
96 avgPos /= myEdges.size();
98 newPoints[vertI] = (1-relax)*newPoints[vertI] + relax*avgPos;
109 Info<< "Writing surface to " << outFileName << " ..." << endl;
111 surf2.write(outFileName);
113 Info << "End\n" << endl;
119 // ************************************************************************* //