23#ifndef VCL_SPACE_COMPLEX_GRID_STATIC_GRID_H
24#define VCL_SPACE_COMPLEX_GRID_STATIC_GRID_H
26#include "abstract_grid.h"
27#include "iterators/static_grid_iterator.h"
28#include "regular_grid.h"
30#include <vclib/mesh.h>
37template<
typename Gr
idType,
typename ValueType>
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);
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; };
232template<
typename ValueType,
typename ScalarType =
double>
235template<
typename ValueType,
typename ScalarType =
double>
240template<Po
intIteratorConcept It>
244 typename It::value_type::ScalarType>;
246template<Po
intIteratorConcept It,
typename F>
250 typename It::value_type::ScalarType>;
252template<VertexPo
interRangeConcept Rng>
257 typename RemovePtr<
typename std::ranges::iterator_t<
258 Rng>::value_type>::PositionType::ScalarType,
262 typename std::ranges::iterator_t<Rng>::value_type>;
The AbstractGrid class describes a generic Spatial Data Structure organized on a regular grid,...
Definition abstract_grid.h:106
bool insert(const ValueType &v)
Inserts the given element in the AbstractGrid.
Definition abstract_grid.h:181
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:117
A class representing a box in N-dimensional space.
Definition box.h:46
PointT size() const
Computes the size of the box.
Definition box.h:267
Definition regular_grid.h:35
Definition static_grid.h:43
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