surfaceFind.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
00034 #ifndef namespaceFoam
00035 #define namespaceFoam
00036 using namespace Foam;
00037 #endif
00038
00039
00040
00041
00042
00043 int main(int argc, char *argv[])
00044 {
00045 argList::noParallel();
00046 argList::validArgs.clear();
00047 argList::validOptions.insert("x", "X");
00048 argList::validOptions.insert("y", "Y");
00049 argList::validOptions.insert("z", "Z");
00050
00051 argList::validArgs.append("surface file");
00052
00053 argList args(argc, argv);
00054
00055 point samplePt
00056 (
00057 args.optionRead<scalar>("x"),
00058 args.optionRead<scalar>("y"),
00059 args.optionRead<scalar>("z")
00060 );
00061 Info<< "Looking for nearest face/vertex to " << samplePt << endl;
00062
00063
00064 Info<< "Reading surf1 ..." << endl;
00065 triSurface surf1(args.additionalArgs()[0]);
00066
00067
00068
00069
00070
00071 const pointField& localPoints = surf1.localPoints();
00072
00073 label minIndex = -1;
00074 scalar minDist = GREAT;
00075
00076 forAll(localPoints, pointI)
00077 {
00078 const scalar dist = mag(localPoints[pointI] - samplePt);
00079 if (dist < minDist)
00080 {
00081 minDist = dist;
00082 minIndex = pointI;
00083 }
00084 }
00085
00086 Info<< "Nearest vertex:" << endl
00087 << " index :" << minIndex << " (in localPoints)" << endl
00088 << " index :" << surf1.meshPoints()[minIndex]
00089 << " (in points)" << endl
00090 << " coordinates:" << localPoints[minIndex] << endl
00091 << endl;
00092
00093
00094
00095
00096
00097 const pointField& points = surf1.points();
00098
00099 minIndex = -1;
00100 minDist = GREAT;
00101
00102 forAll(surf1, faceI)
00103 {
00104 const labelledTri& f = surf1[faceI];
00105 const point centre = f.centre(points);
00106
00107 const scalar dist = mag(centre - samplePt);
00108 if (dist < minDist)
00109 {
00110 minDist = dist;
00111 minIndex = faceI;
00112 }
00113 }
00114
00115 const labelledTri& f = surf1[minIndex];
00116
00117 Info<< "Face with nearest centre:" << endl
00118 << " index :" << minIndex << endl
00119 << " centre :" << f.centre(points) << endl
00120 << " face :" << f << endl
00121 << " vertex coords:" << points[f[0]] << " "
00122 << points[f[1]] << " " << points[f[2]] << endl
00123 << endl;
00124
00125
00126 Info << "End\n" << endl;
00127
00128 return 0;
00129 }
00130
00131
00132
Copyright © 2000-2009 OpenCFD Ltd