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