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