2010-05-12 13:27:55 +00:00
|
|
|
/*---------------------------------------------------------------------------*\
|
|
|
|
========= |
|
2013-12-11 16:09:41 +00:00
|
|
|
\\ / F ield | foam-extend: Open Source CFD
|
2015-05-17 13:32:07 +00:00
|
|
|
\\ / O peration | Version: 3.2
|
|
|
|
\\ / A nd | Web: http://www.foam-extend.org
|
|
|
|
\\/ M anipulation | For copyright notice see file Copyright
|
2010-05-12 13:27:55 +00:00
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
License
|
2013-12-11 16:09:41 +00:00
|
|
|
This file is part of foam-extend.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2013-12-11 16:09:41 +00:00
|
|
|
foam-extend is free software: you can redistribute it and/or modify it
|
2010-05-12 13:27:55 +00:00
|
|
|
under the terms of the GNU General Public License as published by the
|
2013-12-11 16:09:41 +00:00
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
2010-05-12 13:27:55 +00:00
|
|
|
option) any later version.
|
|
|
|
|
2013-12-11 16:09:41 +00:00
|
|
|
foam-extend is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2013-12-11 16:09:41 +00:00
|
|
|
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
Description
|
|
|
|
Example of simple laplacian smoother
|
|
|
|
|
|
|
|
\*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#include "triSurface.H"
|
|
|
|
#include "argList.H"
|
|
|
|
#include "OFstream.H"
|
|
|
|
#include "boundBox.H"
|
|
|
|
|
|
|
|
using namespace Foam;
|
|
|
|
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
|
|
// Main program:
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
argList::noParallel();
|
|
|
|
argList::validOptions.clear();
|
|
|
|
argList::validArgs.clear();
|
|
|
|
argList::validArgs.append("surface file");
|
|
|
|
argList::validArgs.append("underrelax factor (0..1)");
|
|
|
|
argList::validArgs.append("iterations");
|
|
|
|
argList::validArgs.append("output file");
|
|
|
|
argList args(argc, argv);
|
|
|
|
|
|
|
|
fileName surfFileName(args.additionalArgs()[0]);
|
|
|
|
scalar relax(readScalar(IStringStream(args.additionalArgs()[1])()));
|
|
|
|
if ((relax <= 0) || (relax > 1))
|
|
|
|
{
|
|
|
|
FatalErrorIn(args.executable()) << "Illegal relaxation factor "
|
|
|
|
<< relax << endl
|
|
|
|
<< "0: no change 1: move vertices to average of neighbours"
|
|
|
|
<< exit(FatalError);
|
|
|
|
}
|
|
|
|
label iters(readLabel(IStringStream(args.additionalArgs()[2])()));
|
|
|
|
fileName outFileName(args.additionalArgs()[3]);
|
|
|
|
|
|
|
|
Info<< "Relax:" << relax << endl;
|
|
|
|
Info<< "Iters:" << iters << endl;
|
|
|
|
|
|
|
|
|
|
|
|
Info<< "Reading surface from " << surfFileName << " ..." << endl;
|
|
|
|
|
|
|
|
triSurface surf1(surfFileName);
|
|
|
|
|
|
|
|
Info<< "Triangles : " << surf1.size() << endl;
|
|
|
|
Info<< "Vertices : " << surf1.nPoints() << endl;
|
|
|
|
Info<< "Bounding Box : " << boundBox(surf1.localPoints()) << endl;
|
|
|
|
|
|
|
|
pointField newPoints(surf1.localPoints());
|
|
|
|
|
|
|
|
const labelListList& pointEdges = surf1.pointEdges();
|
|
|
|
|
|
|
|
|
2013-04-15 11:57:08 +00:00
|
|
|
for (label iter = 0; iter < iters; iter++)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
forAll(pointEdges, vertI)
|
|
|
|
{
|
|
|
|
vector avgPos(vector::zero);
|
|
|
|
|
|
|
|
const labelList& myEdges = pointEdges[vertI];
|
|
|
|
|
|
|
|
forAll(myEdges, myEdgeI)
|
|
|
|
{
|
|
|
|
const edge& e = surf1.edges()[myEdges[myEdgeI]];
|
|
|
|
|
|
|
|
label otherVertI = e.otherVertex(vertI);
|
|
|
|
|
|
|
|
avgPos += surf1.localPoints()[otherVertI];
|
|
|
|
}
|
|
|
|
avgPos /= myEdges.size();
|
|
|
|
|
|
|
|
newPoints[vertI] = (1-relax)*newPoints[vertI] + relax*avgPos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
triSurface surf2
|
|
|
|
(
|
|
|
|
surf1.localFaces(),
|
|
|
|
surf1.patches(),
|
|
|
|
newPoints
|
|
|
|
);
|
|
|
|
|
|
|
|
Info<< "Writing surface to " << outFileName << " ..." << endl;
|
|
|
|
|
|
|
|
surf2.write(outFileName);
|
|
|
|
|
|
|
|
Info << "End\n" << endl;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ************************************************************************* //
|