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