8 #ifndef META_OCEAN_GEOMETRY_SPATIAL_DISTRIBUTION_H
9 #define META_OCEAN_GEOMETRY_SPATIAL_DISTRIBUTION_H
36 class OCEAN_GEOMETRY_EXPORT
Array
44 inline Scalar left()
const;
56 inline Scalar width()
const;
62 inline Scalar height()
const;
68 inline unsigned int horizontalBins()
const;
74 inline unsigned int verticalBins()
const;
80 inline unsigned int bins()
const;
89 inline unsigned int index(
const Scalar x,
const Scalar y)
const;
98 inline int horizontalBin(
const Scalar x)
const;
107 inline int verticalBin(
const Scalar y)
const;
116 inline int clampedHorizontalBin(
const Scalar x)
const;
125 inline int clampedVerticalBin(
const Scalar y)
const;
131 inline bool isValid()
const;
138 inline bool operator==(
const Array& right)
const;
145 inline bool operator!=(
const Array& right)
const;
151 explicit inline operator bool()
const;
181 inline Array(
const Scalar left,
const Scalar top,
const Scalar width,
const Scalar height,
const unsigned int horizontalBins,
const unsigned int verticalBins);
195 inline Array& operator=(
Array&&
object) noexcept;
212 unsigned int horizontalBins_ = 0u;
215 unsigned int verticalBins_ = 0u;
291 inline bool hasCopiedNeighborhood8()
const;
304 inline const Indices32& operator()(
const unsigned int horizontal,
const unsigned int vertical)
const;
312 inline Indices32& operator()(
const unsigned int horizontal,
const unsigned int vertical);
320 inline const Indices32& operator[](
const unsigned int index)
const;
328 inline Indices32& operator[](
const unsigned int index);
363 bool hasCopiedNeighborhood8_ =
false;
397 inline OccupancyArray(
const Box2& boundingBox,
const unsigned int horizontalBins,
const unsigned int verticalBins,
const bool allFree =
true);
409 inline OccupancyArray(
const Scalar left,
const Scalar top,
const Scalar width,
const Scalar height,
const unsigned int horizontalBins,
const unsigned int verticalBins,
const bool allFree =
true);
417 inline bool isOccupiedNeighborhood9(
const unsigned int horizontal,
const unsigned int vertical)
const;
424 inline bool isOccupiedNeighborhood9(
const Vector2& point)
const;
432 inline bool isNotOccupiedNeighborhood9(
const unsigned int horizontal,
const unsigned int vertical)
const;
439 inline bool isNotOccupiedNeighborhood9(
const Vector2& point)
const;
447 inline unsigned int countOccupiedNeighborhood9(
const unsigned int horizontal,
const unsigned int vertical)
const;
453 inline unsigned int occupiedBins()
const;
459 inline unsigned int freeBins()
const;
468 inline bool addPoint(
const Vector2& point);
479 inline bool addPointWithCounter(
const Vector2& point,
const unsigned int maximalOccupancyCounter);
488 inline bool removePoint(
const Vector2& point);
516 inline bool operator()(
const unsigned int horizontal,
const unsigned int vertical)
const;
523 inline bool operator()(
const Vector2& point)
const;
531 inline unsigned int& operator()(
const unsigned int horizontal,
const unsigned int vertical);
538 inline bool operator[](
const unsigned int index)
const;
545 inline unsigned int& operator[](
const unsigned int index);
566 inline bool operator==(
const OccupancyArray& occupancyArray)
const;
573 inline bool operator!=(
const OccupancyArray& occupancyArray)
const;
594 inline DistanceElement(
const unsigned int index,
const unsigned int candidateIndex,
const Scalar distance);
600 inline unsigned int index()
const;
606 inline unsigned int candidateIndex()
const;
612 inline Scalar distance()
const;
639 unsigned int index_ = 0u;
642 unsigned int candidateIndex_ = 0u;
666 static void idealBins(
const unsigned int width,
const unsigned int height,
const size_t numberBins,
unsigned int& horizontalBins,
unsigned int& verticalBins,
const unsigned int minimalHorizontalBins = 2u,
const unsigned int minimalVerticalBins = 2u);
681 static void idealBinsNeighborhood9(
const unsigned int width,
const unsigned int height,
const Scalar distance,
unsigned int& horizontalBins,
unsigned int& verticalBins,
const unsigned int minimalHorizontalBins = 2u,
const unsigned int minimalVerticalBins = 2u,
const unsigned int maximalHorizontalBins = 20u,
const unsigned int maximalVerticalBins = 20u);
701 static inline DistributionArray distributeToArray(
const ImagePoint* imagePoints,
const size_t number,
const Scalar left,
const Scalar top,
const Scalar width,
const Scalar height,
const unsigned int averagePointsPerBin,
const unsigned int maxHorizontalBins,
const unsigned int maxVerticalBins,
unsigned int& horizontalBins,
unsigned int& verticalBins);
733 template <
typename T, const Vector2& (*tFunction)(const T&)>
734 static DistributionArray distributeToArray(
const T* elements,
const size_t number,
const Scalar left,
const Scalar top,
const Scalar width,
const Scalar height,
const unsigned int horizontalBins,
const unsigned int verticalBins);
750 template <
unsigned int tMaximalBins>
793 static void filterCandidatePoint(
const ImagePoint* imagePoints,
const size_t numberImagePoints,
const ImagePoint* candidatePoints,
const size_t numberCandidatePoints,
const unsigned int width,
const unsigned int height,
const Scalar filterDistance,
const unsigned int filterSize,
Indices32* filteredIndices =
nullptr,
ImagePoints* filteredCandidates =
nullptr);
885 static void determineMinimalSqrDistances(
const ImagePoint* imagePoints,
const size_t numberImagePoints,
const unsigned int* interestIndices,
const size_t numberInterestIndices,
const unsigned int width,
const unsigned int height,
const unsigned int bins,
Scalar* sqrDistances);
922 static inline ImagePoints distributeAndFilter(
const ImagePoint* imagePoints,
const size_t numberImagePoints,
const Scalar left,
const Scalar top,
const Scalar width,
const Scalar height,
const unsigned int horizontalBins,
const unsigned int verticalBins);
953 template <
typename TIndex>
954 static inline std::vector<TIndex> distributeAndFilterIndices(
const ImagePoint* imagePoints,
const size_t numberImagePoints,
const Scalar left,
const Scalar top,
const Scalar width,
const Scalar height,
const unsigned int horizontalBins,
const unsigned int verticalBins);
970 template <
typename T, Vector2 (*tFunction)(const T&)>
971 static std::vector<T> distributeAndFilter(
const T* elements,
const size_t numberElements,
const Scalar left,
const Scalar top,
const Scalar width,
const Scalar height,
const unsigned int horizontalBins,
const unsigned int verticalBins);
992 template <
typename T, Vector2 (*tFunction)(const T&)>
993 static std::vector<T> distributeAndFilter(
const T* elements,
const size_t numberElements,
const Scalar left,
const Scalar top,
const Scalar width,
const Scalar height,
const unsigned int horizontalBins,
const unsigned int verticalBins,
const size_t numberDesiredFilteredElements,
Indices32 *indices =
nullptr);
1011 template <
typename T,
typename TIndex, Vector2 (*tFunction)(const T&)>
1012 static std::vector<TIndex> distributeAndFilterIndices(
const T* elements,
const size_t numberElements,
const Scalar left,
const Scalar top,
const Scalar width,
const Scalar height,
const unsigned int horizontalBins,
const unsigned int verticalBins);
1022 template <
typename T>
1023 static inline T identity(
const T& value);
1027 areaLeft_(
object.areaLeft_),
1028 areaTop_(
object.areaTop_),
1029 areaWidth_(
object.areaWidth_),
1030 areaHeight_(
object.areaHeight_),
1031 horizontalBins_(
object.horizontalBins_),
1032 verticalBins_(
object.verticalBins_),
1033 horizontalPoint2Bin_(
object.horizontalPoint2Bin_),
1034 verticalPoint2Bin_(
object.verticalPoint2Bin_)
1036 object.areaLeft_ =
Scalar(0);
1037 object.areaTop_ =
Scalar(0);
1038 object.areaWidth_ =
Scalar(0);
1039 object.areaHeight_ =
Scalar(0);
1040 object.horizontalBins_ = 0u;
1041 object.verticalBins_ = 0u;
1042 object.horizontalPoint2Bin_ =
Scalar(0);
1043 object.verticalPoint2Bin_ =
Scalar(0);
1050 areaHeight_(height),
1051 horizontalBins_(horizontalBins),
1052 verticalBins_(verticalBins),
1081 return horizontalBins_;
1086 return verticalBins_;
1091 return horizontalBins_ * verticalBins_;
1096 const int xBin = horizontalBin(x);
1097 const int yBin = verticalBin(y);
1099 ocean_assert(xBin >= 0 && xBin <
int(horizontalBins_));
1100 ocean_assert(yBin >= 0 && yBin <
int(verticalBins_));
1102 return yBin * horizontalBins_ + xBin;
1108 return int(
Numeric::floor((x - areaLeft_) * horizontalPoint2Bin_));
1119 ocean_assert(isValid());
1120 return minmax<int>(0, horizontalBin(x), horizontalBins_ - 1);
1125 ocean_assert(isValid());
1126 return minmax<int>(0, verticalBin(y), verticalBins_ - 1);
1131 return horizontalBins_ != 0u && verticalBins_ != 0u;
1148 return !(*
this == right);
1151 inline SpatialDistribution::Array::operator bool()
const
1158 if (
this != &
object)
1161 areaTop_ =
object.areaTop_;
1162 areaWidth_ =
object.areaWidth_;
1163 areaHeight_ =
object.areaHeight_;
1164 horizontalBins_ =
object.horizontalBins_;
1165 verticalBins_ =
object.verticalBins_;
1166 horizontalPoint2Bin_ =
object.horizontalPoint2Bin_;
1167 verticalPoint2Bin_ =
object.verticalPoint2Bin_;
1175 if (
this != &
object)
1178 areaTop_ =
object.areaTop_;
1179 areaWidth_ =
object.areaWidth_;
1180 areaHeight_ =
object.areaHeight_;
1181 horizontalBins_ =
object.horizontalBins_;
1182 verticalBins_ =
object.verticalBins_;
1183 horizontalPoint2Bin_ =
object.horizontalPoint2Bin_;
1184 verticalPoint2Bin_ =
object.verticalPoint2Bin_;
1186 object.areaLeft_ =
Scalar(0);
1187 object.areaTop_ =
Scalar(0);
1188 object.areaWidth_ =
Scalar(0);
1189 object.areaHeight_ =
Scalar(0);
1190 object.horizontalBins_ = 0u;
1191 object.verticalBins_ = 0u;
1192 object.horizontalPoint2Bin_ =
Scalar(0);
1193 object.verticalPoint2Bin_ =
Scalar(0);
1201 indexGroups_(std::move(
object.indexGroups_)),
1202 hasCopiedNeighborhood8_(
object.hasCopiedNeighborhood8_)
1208 Array(left, top, width, height, horizontalBins, verticalBins),
1209 indexGroups_(horizontalBins * verticalBins),
1210 hasCopiedNeighborhood8_(false)
1217 return hasCopiedNeighborhood8_;
1222 ocean_assert(horizontal < horizontalBins_);
1223 ocean_assert(vertical < verticalBins_);
1225 return indexGroups_[vertical * horizontalBins_ + horizontal];
1230 ocean_assert(horizontal < horizontalBins_);
1231 ocean_assert(vertical < verticalBins_);
1233 return indexGroups_[vertical * horizontalBins_ + horizontal];
1238 ocean_assert(index < horizontalBins_ * verticalBins_);
1239 return indexGroups_[index];
1244 ocean_assert(index < horizontalBins_ * verticalBins_);
1245 return indexGroups_[index];
1251 indexGroups_ =
object.indexGroups_;
1252 hasCopiedNeighborhood8_ =
object.hasCopiedNeighborhood8_;
1259 if (
this != &
object)
1262 indexGroups_ = std::move(
object.indexGroups_);
1263 hasCopiedNeighborhood8_ =
object.hasCopiedNeighborhood8_;
1265 object.hasCopiedNeighborhood8_ =
false;
1273 if (!Array::operator==(distributionArray))
1283 return !(*
this == distributionArray);
1288 occupancy_(std::move(
object.occupancy_))
1294 Array(boundingBox.left(), boundingBox.top(), boundingBox.width(), boundingBox.height(), horizontalBins, verticalBins),
1295 occupancy_(horizontalBins * verticalBins, allFree ? 0u : 1u)
1301 Array(left, top, width, height, horizontalBins, verticalBins),
1302 occupancy_(horizontalBins * verticalBins, allFree ? 0u : 1u)
1309 ocean_assert(horizontal < horizontalBins_);
1310 ocean_assert(vertical < verticalBins_);
1312 unsigned int number = 0u;
1314 for (
unsigned int y = max(0,
int(vertical) - 1); y < min(vertical + 2u, verticalBins_); ++y)
1316 for (
unsigned int x = max(0,
int(horizontal) - 1); x < min(horizontal + 2u, horizontalBins_); ++x)
1330 ocean_assert(horizontal < horizontalBins_);
1331 ocean_assert(vertical < verticalBins_);
1333 for (
unsigned int y = max(0,
int(vertical) - 1); y < min(vertical + 2u, verticalBins_); ++y)
1335 for (
unsigned int x = max(0,
int(horizontal) - 1); x < min(horizontal + 2u, horizontalBins_); ++x)
1349 const unsigned int horizontal = horizontalBin(point.
x());
1350 const unsigned int vertical = verticalBin(point.
y());
1352 if (horizontal < horizontalBins_ && vertical < verticalBins_)
1354 for (
unsigned int y = max(0,
int(vertical) - 1); y < min(vertical + 2u, verticalBins_); ++y)
1356 for (
unsigned int x = max(0,
int(horizontal) - 1); x < min(horizontal + 2u, horizontalBins_); ++x)
1371 ocean_assert(horizontal < horizontalBins_);
1372 ocean_assert(vertical < verticalBins_);
1374 for (
unsigned int y = max(0,
int(vertical) - 1); y < min(vertical + 2u, verticalBins_); ++y)
1376 for (
unsigned int x = max(0,
int(horizontal) - 1); x < min(horizontal + 2u, horizontalBins_); ++x)
1390 const unsigned int horizontal = horizontalBin(point.
x());
1391 const unsigned int vertical = verticalBin(point.
y());
1393 if (horizontal < horizontalBins_ && vertical < verticalBins_)
1395 for (
unsigned int y = max(0,
int(vertical) - 1); y < min(vertical + 2u, verticalBins_); ++y)
1397 for (
unsigned int x = max(0,
int(horizontal) - 1); x < min(horizontal + 2u, horizontalBins_); ++x)
1412 unsigned int count = 0u;
1414 for (
const Index32& bin : occupancy_)
1427 unsigned int count = 0u;
1429 for (
const Index32& bin : occupancy_)
1442 const unsigned int horizontal = (
unsigned int)(horizontalBin(point.
x()));
1443 const unsigned int vertical = (
unsigned int)(verticalBin(point.
y()));
1445 if (horizontal < horizontalBins_ && vertical < verticalBins_)
1447 const unsigned int index = vertical * horizontalBins_ + horizontal;
1449 if (!occupancy_[index])
1451 occupancy_[index] = 1u;
1461 const unsigned int horizontal = (
unsigned int)(horizontalBin(point.
x()));
1462 const unsigned int vertical = (
unsigned int)(verticalBin(point.
y()));
1464 if (horizontal < horizontalBins_ && vertical < verticalBins_)
1466 const unsigned int index = vertical * horizontalBins_ + horizontal;
1468 if (occupancy_[index] <= maximalOccupancyCounter)
1470 occupancy_[index]++;
1480 const unsigned int horizontal = (
unsigned int)(horizontalBin(point.
x()));
1481 const unsigned int vertical = (
unsigned int)(verticalBin(point.
y()));
1483 if (horizontal < horizontalBins_ && vertical < verticalBins_)
1485 const unsigned int index = vertical * horizontalBins_ + horizontal;
1487 if (occupancy_[index])
1489 occupancy_[index] = 0u;
1499 for (
size_t n = 0; n < occupancy_.size(); ++n)
1507 const unsigned int horizontal = (
unsigned int)(horizontalBin(point.
x()));
1508 const unsigned int vertical = (
unsigned int)(verticalBin(point.
y()));
1510 if (horizontal < horizontalBins_ && vertical < verticalBins_)
1512 occupancy_[vertical * horizontalBins_ + horizontal] = 1u;
1520 const unsigned int horizontal = (
unsigned int)(horizontalBin(point.
x()));
1521 const unsigned int vertical = (
unsigned int)(verticalBin(point.
y()));
1523 if (horizontal < horizontalBins_ && vertical < verticalBins_)
1525 occupancy_[vertical * horizontalBins_ + horizontal] = 0u;
1533 ocean_assert(horizontal < horizontalBins_);
1534 ocean_assert(vertical < verticalBins_);
1536 return occupancy_[vertical * horizontalBins_ + horizontal] != 0u;
1541 ocean_assert(horizontal < horizontalBins_);
1542 ocean_assert(vertical < verticalBins_);
1544 return occupancy_[vertical * horizontalBins_ + horizontal];
1549 const unsigned int xBin = horizontalBin(point.
x());
1550 const unsigned int yBin = verticalBin(point.
y());
1552 return xBin < horizontalBins_ && yBin < horizontalBins_ && occupancy_[yBin * horizontalBins_ + xBin] != 0u;
1557 ocean_assert(index < horizontalBins_ * verticalBins_);
1558 return occupancy_[index] != 0u;
1563 ocean_assert(index < horizontalBins_ * verticalBins_);
1564 return occupancy_[index];
1570 occupancy_ =
object.occupancy_;
1577 if (
this != &
object)
1580 occupancy_ = std::move(
object.occupancy_);
1588 if (!Array::operator==(occupancyArray))
1593 return occupancy_ == occupancyArray.
occupancy_;
1598 return !(*
this == occupancyArray);
1603 candidateIndex_(candidateIndex),
1616 return candidateIndex_;
1641 template <
unsigned int tMaximalBins>
1644 static_assert(tMaximalBins > 0u,
"Invalid maximal bin parameter!");
1646 const unsigned int horizontalBins = min(tMaximalBins, (
unsigned int)
Numeric::ceil(width / max(searchDistance,
Scalar(2))));
1647 const unsigned int verticalBins = min(tMaximalBins, (
unsigned int)
Numeric::ceil(height / max(searchDistance,
Scalar(2))));
1649 return distributeToArray(imagePoints, number, left, top, width, height, horizontalBins, verticalBins);
1652 template <
typename T, const Vector2& (*tFunction)(const T&)>
1655 ocean_assert(elements);
1656 ocean_assert(width > 0 && height > 0);
1658 ocean_assert(horizontalBins > 0);
1659 ocean_assert(verticalBins > 0);
1661 ocean_assert(
Scalar(horizontalBins) <= width);
1662 ocean_assert(
Scalar(verticalBins) <= width);
1665 DistributionArray indexArray(left, top, width, height, horizontalBins, verticalBins);
1667 for (
size_t n = 0; n < number; ++n)
1669 const Vector2& point = tFunction(*elements);
1671 const unsigned int horizontal = (
unsigned int)(indexArray.
horizontalBin(point.
x()));
1672 const unsigned int vertical = (
unsigned int)(indexArray.
verticalBin(point.
y()));
1677 indexArray(horizontal, vertical).push_back((
unsigned int)n);
1686 inline SpatialDistribution::DistributionArray SpatialDistribution::distributeToArray(
const ImagePoint* imagePoints,
const size_t number,
const Scalar left,
const Scalar top,
const Scalar width,
const Scalar height,
const unsigned int averagePointsPerBin,
const unsigned int maxHorizontalBins,
const unsigned int maxVerticalBins,
unsigned int& horizontalBins,
unsigned int& verticalBins)
1688 ocean_assert(imagePoints || number == 0);
1690 ocean_assert(width > 0 && height > 0);
1691 ocean_assert(averagePointsPerBin > 0);
1693 ocean_assert(maxHorizontalBins >= 1u);
1694 ocean_assert(maxVerticalBins >= 1u);
1698 return DistributionArray(left, top, width, height, horizontalBins, verticalBins);
1708 horizontalBins = min(maxHorizontalBins, max(1u, (
unsigned int)(
Numeric::sqrt(
sqr))));
1709 verticalBins = min(maxVerticalBins, max(1u, (
unsigned int)(
Scalar(horizontalBins) * height / width)));
1711 return distributeToArray(imagePoints, number, left, top, width, height, horizontalBins, verticalBins);
1716 return distributeAndFilter<ImagePoint, &SpatialDistribution::identity>(imagePoints, numberImagePoints, left, top, width, height, horizontalBins, verticalBins);
1719 template <
typename TIndex>
1722 return distributeAndFilterIndices<ImagePoint, TIndex, &SpatialDistribution::identity>(imagePoints, numberImagePoints, left, top, width, height, horizontalBins, verticalBins);
1725 template <
typename T, Vector2 (*tFunction)(const T&)>
1728 ocean_assert(elements || numberElements == 0);
1729 ocean_assert(width >= 0 && height >= 0);
1730 ocean_assert(horizontalBins >= 1u && verticalBins >= 1u);
1732 if (numberElements == 0)
1734 return std::vector<T>();
1737 OccupancyArray occupancyArray(left, top, width, height, horizontalBins, verticalBins);
1739 const size_t bins = occupancyArray.
bins();
1741 std::vector<T> result;
1742 result.reserve(bins);
1744 for (
size_t n = 0; n < numberElements && result.size() < bins; ++n)
1746 if (occupancyArray.
addPoint(tFunction(elements[n])))
1748 result.push_back(elements[n]);
1755 template <
typename T, Vector2 (*tFunction)(const T&)>
1758 ocean_assert(elements !=
nullptr || numberElements == 0);
1759 ocean_assert(width >= 0 && height >= 0);
1760 ocean_assert(horizontalBins >= 1u && verticalBins >= 1u);
1761 ocean_assert(numberDesiredFilteredElements <= numberElements);
1763 if (numberElements == 0 || numberDesiredFilteredElements == 0)
1765 return std::vector<T>();
1768 OccupancyArray occupancyArray(left, top, width, height, horizontalBins, verticalBins);
1770 std::vector<unsigned char> usedElements(numberElements, 0u);
1772 const size_t bins = occupancyArray.
bins();
1774 std::vector<T> result;
1775 result.reserve(bins);
1777 unsigned int filterIteration = 0u;
1779 while (result.size() < numberDesiredFilteredElements && filterIteration < (
unsigned int)numberDesiredFilteredElements)
1781 for (
size_t n = 0; n < numberElements && result.size() < numberDesiredFilteredElements; ++n)
1783 if (usedElements[n] == 0u && occupancyArray.
addPointWithCounter(tFunction(elements[n]), filterIteration))
1785 result.push_back(elements[n]);
1786 usedElements[n] = 1u;
1795 for (
size_t n = 0; n < numberElements; ++n)
1799 indices->push_back(
Index32(n));
1807 template <
typename T,
typename TIndex, Vector2 (*tFunction)(const T&)>
1810 ocean_assert(elements || numberElements == 0);
1811 ocean_assert(width >= 0 && height >= 0);
1812 ocean_assert(horizontalBins >= 1u && verticalBins >= 1u);
1814 if (numberElements == 0)
1816 return std::vector<TIndex>();
1821 OccupancyArray occupancyArray(left, top, width, height, horizontalBins, verticalBins);
1823 const size_t bins = occupancyArray.
bins();
1825 std::vector<TIndex> result;
1826 result.reserve(bins);
1828 for (
size_t n = 0; n < numberElements && result.size() < bins; ++n)
1830 if (occupancyArray.
addPoint(tFunction(elements[n])))
1832 result.push_back(TIndex(n));
1839 template <
typename T>
This class implements a base class for data arrays.
Definition: SpatialDistribution.h:37
unsigned int horizontalBins() const
Returns the number of horizontal distribution bins.
Definition: SpatialDistribution.h:1079
Scalar width() const
Returns the width of the distribution area.
Definition: SpatialDistribution.h:1069
int horizontalBin(const Scalar x) const
Returns the horizontal bin of a given horizontal position.
Definition: SpatialDistribution.h:1105
int verticalBin(const Scalar y) const
Returns the vertical bin of a given vertical position.
Definition: SpatialDistribution.h:1111
Scalar horizontalPoint2Bin_
Horizontal position to bin factor.
Definition: SpatialDistribution.h:218
Array & operator=(const Array &object)
Assign operator.
Definition: SpatialDistribution.h:1156
Scalar areaTop_
Top position of the distribution area.
Definition: SpatialDistribution.h:203
Scalar top() const
Returns the top position of the distribution area.
Definition: SpatialDistribution.h:1064
unsigned int verticalBins() const
Returns the number of vertical distribution bins.
Definition: SpatialDistribution.h:1084
int clampedVerticalBin(const Scalar y) const
Returns the vertical bin of a given vertical position.
Definition: SpatialDistribution.h:1123
Scalar areaLeft_
Left position of the distribution area.
Definition: SpatialDistribution.h:200
Scalar areaHeight_
Height of the distribution area.
Definition: SpatialDistribution.h:209
Array()=default
Creates an empty array object.
int clampedHorizontalBin(const Scalar x) const
Returns the horizontal bin of a given horizontal position.
Definition: SpatialDistribution.h:1117
bool isValid() const
Returns whether this object holds a valid distribution.
Definition: SpatialDistribution.h:1129
Scalar height() const
Returns the height of the distribution area.
Definition: SpatialDistribution.h:1074
Scalar verticalPoint2Bin_
Vertical position to bin factor.
Definition: SpatialDistribution.h:221
bool operator==(const Array &right) const
Returns whether two Array objects are identical.
Definition: SpatialDistribution.h:1134
bool operator!=(const Array &right) const
Returns whether two Array objects are not identical.
Definition: SpatialDistribution.h:1146
Scalar areaWidth_
Width of the distribution area.
Definition: SpatialDistribution.h:206
unsigned int verticalBins_
Number of vertical distribution bins.
Definition: SpatialDistribution.h:215
Array(const Array &object)=default
Copy constructor.
unsigned int horizontalBins_
Number of horizontal distribution bins.
Definition: SpatialDistribution.h:212
Scalar left() const
Returns the left position of the distribution area.
Definition: SpatialDistribution.h:1059
unsigned int index(const Scalar x, const Scalar y) const
Returns the bin index for a given position.
Definition: SpatialDistribution.h:1094
unsigned int bins() const
Returns the number of bins this distribution holds.
Definition: SpatialDistribution.h:1089
Definition of a class holding an index and a distance.
Definition: SpatialDistribution.h:585
Scalar distance_
Distance value.
Definition: SpatialDistribution.h:645
unsigned int candidateIndex() const
Returns the candidate index of this element.
Definition: SpatialDistribution.h:1614
static bool compareLeftSmaller(const DistanceElement &left, const DistanceElement &right)
Compares two distance elements.
Definition: SpatialDistribution.h:1624
unsigned int index() const
Returns the interest index of this element.
Definition: SpatialDistribution.h:1609
static bool compareLeftHigher(const DistanceElement &left, const DistanceElement &right)
Compares two distance elements.
Definition: SpatialDistribution.h:1629
DistanceElement(const unsigned int index, const unsigned int candidateIndex, const Scalar distance)
Creates a new distance element.
Definition: SpatialDistribution.h:1601
bool operator<(const DistanceElement &element) const
Returns whether the left element holds a higher distance than the right one.
Definition: SpatialDistribution.h:1634
Scalar distance() const
Returns the distance of this element.
Definition: SpatialDistribution.h:1619
This class implements a distribution array.
Definition: SpatialDistribution.h:228
DistributionArray()=default
Creates an empty distribution array object.
bool hasCopiedNeighborhood8() const
Returns whether this distribution array contains copies of indices within the 8-neighborhood of each ...
Definition: SpatialDistribution.h:1215
DistributionArray & operator=(const DistributionArray &object)
Assign operator.
Definition: SpatialDistribution.h:1248
bool hasCopiedNeighborhood8_
True, if the array contains copies of indices within the 8-neighborhood of each individual bin; False...
Definition: SpatialDistribution.h:363
void clear()
Removes all elements form this array.
DistributionArray(const DistributionArray &object)=default
Copy constructor.
const Indices32 & operator()(const unsigned int horizontal, const unsigned int vertical) const
Returns the distribution indices of a specified bin.
Definition: SpatialDistribution.h:1220
IndexGroups32 indexGroups_
Distribution array with point indices.
Definition: SpatialDistribution.h:360
const Indices32 & operator[](const unsigned int index) const
Returns the distribution indices of a specified bin.
Definition: SpatialDistribution.h:1236
DistributionArray(const DistributionArray &distributionArray, const bool copyNeighborhood8)
Copies a given distribution array and optional copies the indices from the 8-neighborhood of each ind...
bool operator!=(const DistributionArray &distributionArray) const
Returns whether two DistributionArray objects are not identical.
Definition: SpatialDistribution.h:1281
bool operator==(const DistributionArray &distributionArray) const
Returns whether two DistributionArray objects are identical.
Definition: SpatialDistribution.h:1271
void indicesNeighborhood9(const unsigned int horizontal, const unsigned int vertical, Indices32 &indices) const
Returns the indices of the 8-neighborhood and the specified bin itself.
Indices32 indicesNeighborhood9(const unsigned int horizontal, const unsigned int vertical) const
Returns the indices of the 8-neighborhood and the specified bin itself.
This class implements an occupancy array.
Definition: SpatialDistribution.h:370
OccupancyArray & operator+=(const Vector2 &point)
Adds an image point to this occupancy array.
Definition: SpatialDistribution.h:1505
bool operator!=(const OccupancyArray &occupancyArray) const
Returns whether two OccupancyArray objects are not identical.
Definition: SpatialDistribution.h:1596
unsigned int freeBins() const
Returns the number of free bins.
Definition: SpatialDistribution.h:1425
bool isNotOccupiedNeighborhood9(const unsigned int horizontal, const unsigned int vertical) const
Returns whether at least one bin in the 8-neighborhood or the specified bin itself is not occupied.
Definition: SpatialDistribution.h:1369
OccupancyArray & operator-=(const Vector2 &point)
Removes an image point from this occupancy array.
Definition: SpatialDistribution.h:1518
unsigned int occupiedBins() const
Returns the number of occupied bins.
Definition: SpatialDistribution.h:1410
unsigned int countOccupiedNeighborhood9(const unsigned int horizontal, const unsigned int vertical) const
Returns the number of occupied bins in the 9-neighborhood (so the specified bin is included).
Definition: SpatialDistribution.h:1307
OccupancyArray()=default
Creates an empty distribution array object.
OccupancyArray & operator=(const OccupancyArray &object)
Assign operator.
Definition: SpatialDistribution.h:1567
bool isOccupiedNeighborhood9(const unsigned int horizontal, const unsigned int vertical) const
Returns whether at least one bin in the 8-neighborhood or the specified bin itself is occupied.
Definition: SpatialDistribution.h:1328
void reset()
Resets all occupied bins so that all bins a free afterwards.
Definition: SpatialDistribution.h:1497
bool removePoint(const Vector2 &point)
Removes an image point and returns whether the corresponding bin was occupied before.
Definition: SpatialDistribution.h:1478
bool addPointWithCounter(const Vector2 &point, const unsigned int maximalOccupancyCounter)
Adds an image point and returns whether the occupancy counter of the corresponding bin was equal or b...
Definition: SpatialDistribution.h:1459
bool addPoint(const Vector2 &point)
Adds an image point and returns whether the corresponding bin was not occupied before (was free befor...
Definition: SpatialDistribution.h:1440
OccupancyArray(const OccupancyArray &object)=default
Copy constructor.
bool operator()(const unsigned int horizontal, const unsigned int vertical) const
Returns whether a specified bin is occupied.
Definition: SpatialDistribution.h:1531
bool operator==(const OccupancyArray &occupancyArray) const
Returns whether two OccupancyArray objects are identical.
Definition: SpatialDistribution.h:1586
Indices32 occupancy_
Occupancy array.
Definition: SpatialDistribution.h:578
bool operator[](const unsigned int index) const
Returns whether a specified bin is occupied.
Definition: SpatialDistribution.h:1555
This class implements spatial distribution function for 2D geometric data.
Definition: SpatialDistribution.h:30
static void determineMinimalSqrDistances(const ImagePoint *imagePoints, const size_t numberImagePoints, const unsigned int width, const unsigned int height, const unsigned int bins, Scalar *sqrDistances)
Determines the minimal square distances for each given 2D image point to all other points in the same...
static Index32 determineNearestNeighbor(const ImagePoint &interestPoint, const ImagePoint *imagePoints, const size_t numberImagePoints, const Scalar radius, const DistributionArray &distributionImagePoints, Scalar *sqrDistance=nullptr)
Determines the nearest image point between an interest point and a set of given image point lying ins...
static DistributionArray distributeToArray(const ImagePoint *imagePoints, const size_t number, const Scalar left, const Scalar top, const Scalar width, const Scalar height, const unsigned int averagePointsPerBin, const unsigned int maxHorizontalBins, const unsigned int maxVerticalBins, unsigned int &horizontalBins, unsigned int &verticalBins)
Distributes the given 2D image points into a spatial array.
Definition: SpatialDistribution.h:1686
static ImagePoints distributeAndFilter(const ImagePoint *imagePoints, const size_t numberImagePoints, const Scalar left, const Scalar top, const Scalar width, const Scalar height, const unsigned int horizontalBins, const unsigned int verticalBins, const size_t size)
Distributes the given image points into an array of specified size and returns as much points as requ...
static OccupancyArray createOccupancyArray(const ImagePoint *imagePoints, const size_t number, const Scalar left, const Scalar top, const Scalar width, const Scalar height, const unsigned int horizontalBins, const unsigned int verticalBins)
Distributes the given 2D image points into a spatial array.
static void idealBins(const unsigned int width, const unsigned int height, const size_t numberBins, unsigned int &horizontalBins, unsigned int &verticalBins, const unsigned int minimalHorizontalBins=2u, const unsigned int minimalVerticalBins=2u)
Calculates the ideal number of horizontal and vertical bins for an array if the overall number of bin...
static DistributionArray distributeToArray(const ImagePoint *imagePoints, const size_t number, const Scalar left, const Scalar top, const Scalar width, const Scalar height, const unsigned int horizontalBins, const unsigned int verticalBins)
Distributes a set of given 2D image points into a spatial array.
static Indices32 filterAccordingDistance(const ImagePoint *imagePoints, const size_t number, const unsigned int width, const unsigned int height, const Scalar distance)
Filters the given 2D image points according to their distance to neighboring image points.
std::vector< DistanceElement > DistanceElements
Definition of a vector holding distance elements.
Definition: SpatialDistribution.h:651
static void determineMinimalSqrDistances(const ImagePoint *imagePoints, const size_t numberImagePoints, const ImagePoint *candidates, const size_t numberCandidates, const unsigned int width, const unsigned int height, const unsigned int bins, Scalar *sqrDistances)
Determines the minimal square distances for each given 2D image point to another given set of 2D imag...
static DistanceElements sortAccordingDistance(const ImagePoint *imagePoints, const size_t number, const unsigned int width, const unsigned int height, const unsigned int bins, const bool minimalDistanceFirst)
Sorts the given 2D image points according to their minimal distance to neighboring image points.
static std::vector< TIndex > distributeAndFilterIndices(const ImagePoint *imagePoints, const size_t numberImagePoints, const Scalar left, const Scalar top, const Scalar width, const Scalar height, const unsigned int horizontalBins, const unsigned int verticalBins)
Distributes the given image points into an array of specified size and returns (at most) one point in...
Definition: SpatialDistribution.h:1720
static void determineMinimalSqrDistances(const ImagePoint *imagePoints, const size_t numberImagePoints, const ImagePoint *candidates, const size_t numberCandidates, const DistributionArray &distributionCandidates, Scalar *sqrDistances, unsigned int *candidateIndices=nullptr)
Determines the minimal square distances for each given image point to another given set of image poin...
static Scalar determineMinimalSqrDistance(const ImagePoint *imagePoints, const size_t numberImagePoints, const unsigned int index, const DistributionArray &distributionImagePoints)
Determines the minimal square distance for one given 2D image point to all other points in the same s...
static DistanceElements sortAccordingDistance(const ImagePoint *imagePoints, const size_t number, const bool minimalDistanceFirst)
Sorts the given 2D image points according to their minimal distance to neighboring image points.
static Indices32 determineNeighbors(const ImagePoint &imagePoint, const ImagePoint *candidatePoints, const size_t numberCandidatePoints, const Scalar radius, const DistributionArray &distributionCandidatePoints)
Determines all candidate points for a given image point (interest point) lying inside a specified cir...
static void idealBinsNeighborhood9(const unsigned int width, const unsigned int height, const Scalar distance, unsigned int &horizontalBins, unsigned int &verticalBins, const unsigned int minimalHorizontalBins=2u, const unsigned int minimalVerticalBins=2u, const unsigned int maximalHorizontalBins=20u, const unsigned int maximalVerticalBins=20u)
Calculates the ideal number of horizontal and vertical bins for an array if bin elements within a cer...
static T identity(const T &value)
This function simply returns the given object (actually a copy of the object).
Definition: SpatialDistribution.h:1840
static ImagePoints distributeAndFilter(const ImagePoint *imagePoints, const size_t numberImagePoints, const Scalar left, const Scalar top, const Scalar width, const Scalar height, const unsigned int horizontalBins, const unsigned int verticalBins)
Distributes the given image points into an array of specified size and returns (at most) one point fr...
Definition: SpatialDistribution.h:1714
static void filterCandidatePoint(const ImagePoint *imagePoints, const size_t numberImagePoints, const ImagePoint *candidatePoints, const size_t numberCandidatePoints, const unsigned int width, const unsigned int height, const Scalar filterDistance, const unsigned int filterSize, Indices32 *filteredIndices=nullptr, ImagePoints *filteredCandidates=nullptr)
Filters the given 2D candidate points according to the distance to the given image points.
static void determineMinimalSqrDistances(const ImagePoint *imagePoints, const size_t numberImagePoints, const unsigned int *interestIndices, const size_t numberInterestIndices, const unsigned int width, const unsigned int height, const unsigned int bins, Scalar *sqrDistances)
Determines the minimal square distances for each specified image point inside their neighborhood.
This class provides basic numeric functionalities.
Definition: Numeric.h:57
static T sqrt(const T value)
Returns the square root of a given value.
Definition: Numeric.h:1533
static constexpr T eps()
Returns a small epsilon.
static T floor(const T value)
Returns the largest integer value that is not greater than the given value.
Definition: Numeric.h:2026
static T ceil(const T value)
Returns the smallest integer value that is not less than the given value.
Definition: Numeric.h:1988
const T & x() const noexcept
Returns the x value.
Definition: Vector2.h:698
const T & y() const noexcept
Returns the y value.
Definition: Vector2.h:710
unsigned int sqrDistance(const char first, const char second)
Returns the square distance between two values.
Definition: base/Utilities.h:1089
std::vector< Indices32 > IndexGroups32
Definition of a vector holding 32 bit indices, so we have groups of indices.
Definition: Base.h:102
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition: Base.h:96
unsigned int sqr(const char value)
Returns the square value of a given value.
Definition: base/Utilities.h:1029
uint32_t Index32
Definition of a 32 bit index value.
Definition: Base.h:84
std::vector< ImagePoint > ImagePoints
Definition of a vector holding 2D image points.
Definition: geometry/Geometry.h:123
float Scalar
Definition of a scalar type.
Definition: Math.h:128
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15