35 const UList<Type>& points,
36 const scalar mergeTol,
42 Type compareOrigin = origin;
48 compareOrigin =
sum(points)/points.size();
53 pointMap.setSize(points.size());
70 const scalar mergeTolSqr =
Foam::sqr(scalar(mergeTol));
73 const Field<Type> d(points - compareOrigin);
75 List<scalar> magSqrD(d.size());
78 magSqrD[pointi] =
magSqr(d[pointi]);
84 Field<scalar> sortedTol(points.size());
87 label pointi = order[sortI];
92 scalar(d[pointi].
x()),
93 scalar(d[pointi].
y()),
96 sortedTol[sortI] = 2*mergeTol*(
mag(pt.x())+
mag(pt.y())+
mag(pt.z()));
103 label pointi = order[0];
104 pointMap[pointi] = newPointi++;
107 for (
label sortI = 1; sortI < order.size(); sortI++)
110 label pointi = order[sortI];
111 const scalar mag2 = magSqrD[order[sortI]];
115 scalar(points[pointi].
x()),
116 scalar(points[pointi].
y()),
117 scalar(points[pointi].z())
122 label equalPointi = -1;
126 label prevSortI = sortI - 1;
128 && (
mag(magSqrD[order[prevSortI]] - mag2) <= sortedTol[sortI]);
132 label prevPointi = order[prevSortI];
135 scalar(points[prevPointi].
x()),
136 scalar(points[prevPointi].
y()),
137 scalar(points[prevPointi].z())
140 if (
magSqr(pt - prevPt) <= mergeTolSqr)
143 equalPointi = prevPointi;
150 if (equalPointi != -1)
153 pointMap[pointi] = pointMap[equalPointi];
157 Pout<<
"Foam::mergePoints : Merging points " 158 << pointi <<
" and " << equalPointi
159 <<
" with coordinates:" << points[pointi]
160 <<
" and " << points[equalPointi]
167 pointMap[pointi] = newPointi++;
179 const scalar mergeTol,
198 newPoints[pointMap[pointi]] = points[pointi];
201 return (nUnique != points.
size());
#define forAll(list, i)
Loop across all elements in list.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
void sortedOrder(const UList< T > &, labelList &order)
Generate the (stable) sort order for the list.
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Ostream & endl(Ostream &os)
Add newline and flush stream.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
Various functions to operate on Lists.
List< label > labelList
A List of labels.
dimensioned< scalar > magSqr(const dimensioned< Type > &)
void setSize(const label)
Reset size of List.
vector point
Point is a vector.
prefixOSstream Pout(cout, "Pout")
label mergePoints(const UList< Type > &points, const scalar mergeTol, const bool verbose, labelList &pointMap, const Type &origin=Type::zero)
Sorts and merges points. All points closer than/equal mergeTol get merged.
dimensioned< scalar > mag(const dimensioned< Type > &)
label size() const
Return the number of elements in the UList.