42 StaticGrid<GridType, ValueType>>
47 using PairType = std::pair<uint, ValueType>;
56 std::vector<PairType> mValues;
61 std::vector<uint> mGrid;
64 using KeyType = AbsGrid::KeyType;
74 template<
typename ObjIterator>
78 const IntersectsCellFunction& intersects =
nullptr) :
86 StaticGrid(
Rng&&
r,
const IntersectsCellFunction& intersects =
nullptr) :
87 StaticGrid(std::ranges::begin(
r), std::ranges::end(
r), intersects)
94 for (uint
i = 0;
i < GridType::DIM; ++
i) {
100 std::sort(mValues.begin(), mValues.end(), mComparator);
106 for (uint
ci = 0;
ci < mGrid.size(); ++
ci) {
108 if (
vi < mValues.size() && mValues[
vi].first ==
ci)
111 mGrid[
ci] = mValues.size();
117 while (
vi < mValues.size() && mValues[
vi].first ==
ci) {
123 bool empty()
const {
return mValues.empty(); }
125 bool cellEmpty(
const KeyType&
k)
const
127 uint
ind = GridType::indexOfCell(
k);
128 return mGrid[
ind] == mValues.size();
131 std::set<KeyType> nonEmptyCells()
const
133 std::set<KeyType> keys;
135 for (uint
i = 0;
i < mValues.size(); ++
i) {
138 keys.insert(GridType::cellOfIndex(
actualInd));
144 std::size_t countInCell(
const KeyType&
k)
const
146 uint
ind = GridType::indexOfCell(
k);
150 while (
i < mValues.size() && mValues[
i].first ==
ind) {
157 std::pair<Iterator, Iterator> valuesInCell(
const KeyType&
k)
159 uint
ind = GridType::indexOfCell(
k);
161 if (
i < mValues.size()) {
162 std::pair<Iterator, Iterator>
p;
163 p.first =
Iterator(mValues.begin() +
i, (
const GridType&) *
this);
164 while (
i < mValues.size() && mValues[
i].first ==
ind) {
167 auto it =
i < mValues.size() ? mValues.begin() +
i : mValues.end();
172 return std::make_pair(end(), end());
176 std::pair<ConstIterator, ConstIterator> valuesInCell(
const KeyType&
k)
const
178 uint
ind = GridType::indexOfCell(
k);
180 if (
i < mValues.size()) {
181 std::pair<ConstIterator, ConstIterator>
p;
184 while (
i < mValues.size() && mValues[
i].first ==
ind) {
187 auto it =
i < mValues.size() ? mValues.begin() +
i : mValues.end();
192 return std::make_pair(end(), end());
198 return Iterator(mValues.begin(), (
const GridType&) *
this);
203 return ConstIterator(mValues.begin(), (
const GridType&) *
this);
210 return ConstIterator(mValues.end(), (
const GridType&) *
this);
215 using AbsGrid::erase;
216 using AbsGrid::eraseAllInCell;
217 using AbsGrid::eraseInSphere;
219 bool insertInCell(
const KeyType& cell,
const ValueType& v)
221 uint
cellIndex = GridType::indexOfCell(cell);
227 bool eraseInCell(
const KeyType&,
const ValueType&) {
return false; };
std::function< bool(const typename GridType::BBoxType &, const RemoveCVRefAndPointer< ValueType > &)> IntersectsCellFunction
The IntersectsCellFunction type is a std::function that takes as input a bounding box and a value,...
Definition abstract_grid.h:119
std::remove_pointer_t< T > RemovePtr
Utility alias to get a type without the pointer. e.g. If T is int*, the resulting type is int.
Definition pointers.h:42