surfaceSmooth.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "triSurface.H"
00031 #include "argList.H"
00032 #include "OFstream.H"
00033 #include "boundBox.H"
00034
00035 using namespace Foam;
00036
00037
00038
00039
00040
00041 int main(int argc, char *argv[])
00042 {
00043 argList::noParallel();
00044 argList::validOptions.clear();
00045 argList::validArgs.clear();
00046 argList::validArgs.append("surface file");
00047 argList::validArgs.append("underrelax factor (0..1)");
00048 argList::validArgs.append("iterations");
00049 argList::validArgs.append("output file");
00050 argList args(argc, argv);
00051
00052 fileName surfFileName(args.additionalArgs()[0]);
00053 scalar relax(readScalar(IStringStream(args.additionalArgs()[1])()));
00054 if ((relax <= 0) || (relax > 1))
00055 {
00056 FatalErrorIn(args.executable()) << "Illegal relaxation factor "
00057 << relax << endl
00058 << "0: no change 1: move vertices to average of neighbours"
00059 << exit(FatalError);
00060 }
00061 label iters(readLabel(IStringStream(args.additionalArgs()[2])()));
00062 fileName outFileName(args.additionalArgs()[3]);
00063
00064 Info<< "Relax:" << relax << endl;
00065 Info<< "Iters:" << iters << endl;
00066
00067
00068 Info<< "Reading surface from " << surfFileName << " ..." << endl;
00069
00070 triSurface surf1(surfFileName);
00071
00072 Info<< "Triangles : " << surf1.size() << endl;
00073 Info<< "Vertices : " << surf1.nPoints() << endl;
00074 Info<< "Bounding Box : " << boundBox(surf1.localPoints()) << endl;
00075
00076 pointField newPoints(surf1.localPoints());
00077
00078 const labelListList& pointEdges = surf1.pointEdges();
00079
00080
00081 for(label iter = 0; iter < iters; iter++)
00082 {
00083 forAll(pointEdges, vertI)
00084 {
00085 vector avgPos(vector::zero);
00086
00087 const labelList& myEdges = pointEdges[vertI];
00088
00089 forAll(myEdges, myEdgeI)
00090 {
00091 const edge& e = surf1.edges()[myEdges[myEdgeI]];
00092
00093 label otherVertI = e.otherVertex(vertI);
00094
00095 avgPos += surf1.localPoints()[otherVertI];
00096 }
00097 avgPos /= myEdges.size();
00098
00099 newPoints[vertI] = (1-relax)*newPoints[vertI] + relax*avgPos;
00100 }
00101 }
00102
00103 triSurface surf2
00104 (
00105 surf1.localFaces(),
00106 surf1.patches(),
00107 newPoints
00108 );
00109
00110 Info<< "Writing surface to " << outFileName << " ..." << endl;
00111
00112 surf2.write(outFileName);
00113
00114 Info << "End\n" << endl;
00115
00116 return 0;
00117 }
00118
00119
00120
Copyright © 2000-2009 OpenCFD Ltd