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 "mergePoints.H"
00027 #include <OpenFOAM/SortableList.H>
00028 #include <OpenFOAM/ListOps.H>
00029
00030
00031
00032 bool Foam::mergePoints
00033 (
00034 const UList<point>& points,
00035 const scalar mergeTol,
00036 const bool verbose,
00037 labelList& pointMap,
00038 List<point>& newPoints,
00039 const point& origin
00040 )
00041 {
00042 point compareOrigin = origin;
00043
00044 if (origin == point(VGREAT, VGREAT, VGREAT))
00045 {
00046 if (points.size())
00047 {
00048 compareOrigin = sum(points)/points.size();
00049 }
00050 }
00051
00052
00053 pointMap.setSize(points.size());
00054 pointMap = -1;
00055
00056
00057 newPoints.setSize(points.size());
00058
00059 if (points.empty())
00060 {
00061 return false;
00062 }
00063
00064
00065 const scalar mergeTolSqr = sqr(mergeTol);
00066
00067
00068 SortableList<scalar> sortedMagSqr(magSqr(points - compareOrigin));
00069
00070 bool hasMerged = false;
00071
00072 label newPointI = 0;
00073
00074
00075
00076 label pointI = sortedMagSqr.indices()[0];
00077 pointMap[pointI] = newPointI;
00078 newPoints[newPointI++] = points[pointI];
00079
00080
00081 for (label sortI = 1; sortI < sortedMagSqr.size(); sortI++)
00082 {
00083
00084 label pointI = sortedMagSqr.indices()[sortI];
00085
00086
00087 label equalPointI = -1;
00088
00089 for
00090 (
00091 label prevSortI = sortI - 1;
00092 prevSortI >= 0
00093 && mag
00094 (
00095 sortedMagSqr[prevSortI]
00096 - sortedMagSqr[sortI]
00097 ) <= mergeTolSqr;
00098 prevSortI--
00099 )
00100 {
00101 label prevPointI = sortedMagSqr.indices()[prevSortI];
00102
00103 if (magSqr(points[pointI] - points[prevPointI]) <= mergeTolSqr)
00104 {
00105
00106 equalPointI = prevPointI;
00107
00108 break;
00109 }
00110 }
00111
00112
00113 if (equalPointI != -1)
00114 {
00115
00116 pointMap[pointI] = pointMap[equalPointI];
00117
00118 hasMerged = true;
00119
00120 if (verbose)
00121 {
00122 Pout<< "Foam::mergePoints : Merging points "
00123 << pointI << " and " << equalPointI
00124 << " with coordinates:" << points[pointI]
00125 << " and " << points[equalPointI]
00126 << endl;
00127 }
00128 }
00129 else
00130 {
00131
00132 pointMap[pointI] = newPointI;
00133 newPoints[newPointI++] = points[pointI];
00134 }
00135 }
00136
00137 newPoints.setSize(newPointI);
00138
00139 return hasMerged;
00140 }
00141
00142
00143