30 #ifndef PLANNER_CSPACE_BLOCKMEM_GRIDMAP_H 31 #define PLANNER_CSPACE_BLOCKMEM_GRIDMAP_H 41 template <
class T,
int DIM,
int NONCYCLIC>
47 virtual void clear(
const T zero) = 0;
56 virtual std::function<void(CyclicVecInt<DIM, NONCYCLIC>,
size_t&,
size_t&)>
getAddressor()
const = 0;
59 template <
class T,
int DIM,
int NONCYCLIC,
int BLOCK_WIDTH = 0x20,
bool ENABLE_VALIDATION = false>
65 return v && ((v & (v - 1)) == 0);
67 static_assert(isPowOf2(BLOCK_WIDTH),
"BLOCK_WIDTH must be power of 2");
68 static_assert(BLOCK_WIDTH > 0,
"BLOCK_WIDTH must be >0");
70 static constexpr
size_t log2Recursive(
const size_t v,
const size_t depth = 0)
72 return v == 1 ? depth : log2Recursive(v >> 1, depth + 1);
76 constexpr
static size_t block_bit_ = log2Recursive(BLOCK_WIDTH);
77 constexpr
static size_t block_bit_mask_ = (1 << block_bit_) - 1;
79 std::unique_ptr<T[]>
c_;
92 for (
int i = 0; i < NONCYCLIC; i++)
94 addr = (addr << block_bit_) + (pos[i] & block_bit_mask_);
95 baddr *= block_size_[i];
96 baddr += pos[i] >> block_bit_;
98 for (
int i = NONCYCLIC; i < DIM; i++)
106 std::function<void(CyclicVecInt<DIM, NONCYCLIC>,
size_t&,
size_t&)>
getAddressor()
const 111 std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
123 for (
size_t i = 0; i < ser_size_; i++)
132 for (p[0] = min[0]; p[0] < max[0]; ++p[0])
134 for (p[1] = min[1]; p[1] < max[1]; ++p[1])
136 for (p[2] = min[2]; p[2] < max[2]; ++p[2])
148 for (p[0] = min[0]; p[0] < max[0]; ++p[0])
150 for (p[1] = min[1]; p[1] < max[1]; ++p[1])
152 for (p[2] = min[2]; p[2] < max[2]; ++p[2])
154 (*this)[p] = base[p];
161 for (
size_t i = 0; i < ser_size_; i++)
171 for (
int i = 0; i < NONCYCLIC; i++)
173 if (size_tmp[i] < BLOCK_WIDTH)
174 size_tmp[i] = BLOCK_WIDTH;
179 for (
int i = 0; i < DIM; i++)
185 block_size_[i] = (size_tmp[i] + width - 1) / width;
193 block_ser_size_ *= width;
194 block_num_ *= block_size_[i];
196 ser_size_ = block_ser_size_ * block_num_;
198 c_.reset(
new T[ser_size_]);
207 : dummy_(
std::numeric_limits<T>::
max())
213 block_addr(pos, baddr, addr);
214 const size_t a = baddr * block_ser_size_ + addr;
215 if (ENABLE_VALIDATION)
225 block_addr(pos, baddr, addr);
226 const size_t a = baddr * block_ser_size_ + addr;
227 if (ENABLE_VALIDATION)
230 return std::numeric_limits<T>::max();
236 for (
int i = 0; i < NONCYCLIC; i++)
238 if (pos[i] < tolerance || size_[i] - tolerance <= pos[i])
241 for (
int i = NONCYCLIC; i < DIM; i++)
243 if (pos[i] < 0 || size_[i] <= pos[i])
252 memcpy(c_.get(), gm.
c_.get(), ser_size_ *
sizeof(T));
259 #endif // PLANNER_CSPACE_BLOCKMEM_GRIDMAP_H void reset(const CyclicVecInt< DIM, NONCYCLIC > &size)
BlockMemGridmap(const CyclicVecInt< DIM, NONCYCLIC > &size_)
std::function< void(CyclicVecInt< DIM, NONCYCLIC >, size_t &, size_t &)> getAddressor() const
bool validate(const CyclicVecInt< DIM, NONCYCLIC > &pos, const int tolerance=0) const
virtual void clear_partially(const T zero, const CyclicVecInt< DIM, NONCYCLIC > &min, const CyclicVecInt< DIM, NONCYCLIC > &max)=0
virtual const CyclicVecInt< DIM, NONCYCLIC > & size() const =0
virtual std::function< void(CyclicVecInt< DIM, NONCYCLIC >, size_t &, size_t &)> getAddressor() const =0
virtual void clear(const T zero)=0
const CyclicVecInt< DIM, NONCYCLIC > & size() const
void clear_partially(const T zero, const CyclicVecInt< DIM, NONCYCLIC > &min, const CyclicVecInt< DIM, NONCYCLIC > &max)
const BlockMemGridmap< T, DIM, NONCYCLIC, BLOCK_WIDTH, ENABLE_VALIDATION > & operator=(const BlockMemGridmap< T, DIM, NONCYCLIC, BLOCK_WIDTH, ENABLE_VALIDATION > &gm)
virtual void reset(const CyclicVecInt< DIM, NONCYCLIC > &size)=0
void block_addr(const CyclicVecInt< DIM, NONCYCLIC > &pos, size_t &baddr, size_t &addr) const
static constexpr bool isPowOf2(const int v)
void copy_partially(const BlockMemGridmapBase< T, DIM, NONCYCLIC > &base, const CyclicVecInt< DIM, NONCYCLIC > &min, const CyclicVecInt< DIM, NONCYCLIC > &max)
CyclicVecInt< DIM, NONCYCLIC > size_
virtual T & operator[](const CyclicVecInt< DIM, NONCYCLIC > &pos)=0
void clear_positive(const T zero)
T & operator[](const CyclicVecInt< DIM, NONCYCLIC > &pos)
virtual void copy_partially(const BlockMemGridmapBase< T, DIM, NONCYCLIC > &base, const CyclicVecInt< DIM, NONCYCLIC > &min, const CyclicVecInt< DIM, NONCYCLIC > &max)=0
double min(double a, double b)
static constexpr size_t log2Recursive(const size_t v, const size_t depth=0)
CyclicVecInt< DIM, NONCYCLIC > block_size_
virtual size_t ser_size() const =0
double max(double a, double b)
const T operator[](const CyclicVecInt< DIM, NONCYCLIC > &pos) const