matchPoints.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 #include "matchPoints.H"
00028 #include "SortableList.H"
00029 #include "ListOps.H"
00030
00031
00032
00033 bool Foam::matchPoints
00034 (
00035 const UList<point>& pts0,
00036 const UList<point>& pts1,
00037 const UList<scalar>& matchDistances,
00038 const bool verbose,
00039 labelList& from0To1,
00040 const point& origin
00041 )
00042 {
00043 from0To1.setSize(pts0.size());
00044 from0To1 = -1;
00045
00046 bool fullMatch = true;
00047
00048 point compareOrigin = origin;
00049
00050 if (origin == point(VGREAT, VGREAT, VGREAT))
00051 {
00052 if (pts1.size())
00053 {
00054 compareOrigin = sum(pts1)/pts1.size();
00055 }
00056 }
00057
00058 SortableList<scalar> pts0MagSqr(magSqr(pts0 - compareOrigin));
00059
00060 SortableList<scalar> pts1MagSqr(magSqr(pts1 - compareOrigin));
00061
00062 forAll(pts0MagSqr, i)
00063 {
00064 scalar dist0 = pts0MagSqr[i];
00065
00066 label face0I = pts0MagSqr.indices()[i];
00067
00068 scalar matchDist = matchDistances[face0I];
00069
00070 label startI = findLower(pts1MagSqr, 0.99999*dist0 - matchDist);
00071
00072 if (startI == -1)
00073 {
00074 startI = 0;
00075 }
00076
00077
00078
00079 scalar minDistSqr = VGREAT;
00080 label minFaceI = -1;
00081
00082 for
00083 (
00084 label j = startI;
00085 (
00086 (j < pts1MagSqr.size())
00087 && (pts1MagSqr[j] < 1.00001*dist0 + matchDist)
00088 );
00089 j++
00090 )
00091 {
00092 label faceI = pts1MagSqr.indices()[j];
00093
00094 scalar distSqr = magSqr(pts0[face0I] - pts1[faceI]);
00095
00096 if (distSqr <= sqr(matchDist) && distSqr < minDistSqr)
00097 {
00098 minDistSqr = distSqr;
00099 minFaceI = faceI;
00100 }
00101 }
00102
00103 if (minFaceI == -1)
00104 {
00105 fullMatch = false;
00106
00107 if (verbose)
00108 {
00109 Pout<< "Cannot find point in pts1 matching point " << face0I
00110 << " coord:" << pts0[face0I]
00111 << " in pts0 when using tolerance " << matchDist << endl;
00112
00113
00114 Pout<< "Searching started from:" << startI << " in pts1"
00115 << endl;
00116 for
00117 (
00118 label j = startI;
00119 (
00120 (j < pts1MagSqr.size())
00121 && (pts1MagSqr[j] < 1.00001*dist0 + matchDist)
00122 );
00123 j++
00124 )
00125 {
00126 label faceI = pts1MagSqr.indices()[j];
00127
00128 Pout<< "Compared coord:" << pts1[faceI]
00129 << " with difference to point "
00130 << mag(pts1[faceI] - pts0[face0I]) << endl;
00131 }
00132 }
00133 }
00134
00135 from0To1[face0I] = minFaceI;
00136 }
00137
00138 return fullMatch;
00139 }
00140
00141
Copyright © 2000-2009 OpenCFD Ltd