MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ query_grid()

template<typename PointT >
void MayaFlux::Kinesis::SpatialIndex< PointT >::query_grid ( const SpatialSnapshot< PointT > &  snap,
const PointT &  center,
float  radius_sq,
std::vector< QueryResult > &  out 
) const
private

Definition at line 397 of file SpatialIndex.cpp.

402{
403 auto extent = static_cast<int32_t>(std::ceil(std::sqrt(radius_sq) * m_inv_cell));
404
405 auto check_cell = [&](uint64_t h) {
406 auto it = snap.cells.find(h);
407 if (it == snap.cells.end()) {
408 return;
409 }
410 for (uint32_t slot : it->second) {
411 float d_sq = m_distance_fn(center, snap.positions[slot]);
412 if (d_sq <= radius_sq) {
413 out.push_back({ snap.slot_to_id[slot], d_sq });
414 }
415 }
416 };
417
418 if constexpr (std::is_same_v<PointT, glm::vec3>) {
419 auto [cx, cy, cz] = detail::cell_coords_3d(center, m_inv_cell);
420 for (int32_t dx = -extent; dx <= extent; ++dx) {
421 for (int32_t dy = -extent; dy <= extent; ++dy) {
422 for (int32_t dz = -extent; dz <= extent; ++dz) {
423 check_cell(detail::hash_cell_3d(cx + dx, cy + dy, cz + dz));
424 }
425 }
426 }
427 } else {
428 uint32_t dims = snap.dimensions;
429 std::vector<int32_t> base_cell(dims);
430 for (uint32_t d = 0; d < dims; ++d) {
431 base_cell[d] = static_cast<int32_t>(std::floor(center(d) * m_inv_cell));
432 }
433
434 std::vector<int32_t> offsets(dims, -extent);
435
436 auto advance = [&]() -> bool {
437 for (uint32_t d = 0; d < dims; ++d) {
438 if (++offsets[d] <= extent) {
439 return true;
440 }
441 offsets[d] = -extent;
442 }
443 return false;
444 };
445
446 do {
447 Eigen::VectorXd probe(dims);
448 for (uint32_t d = 0; d < dims; ++d) {
449 probe(d) = static_cast<double>(base_cell[d] + offsets[d]) + 0.5;
450 }
451 check_cell(detail::hash_cell_nd(probe, m_inv_cell));
452 } while (advance());
453 }
454}
uint32_t h
Definition InkPress.cpp:25
uint64_t hash_cell_3d(int32_t cx, int32_t cy, int32_t cz)
uint64_t hash_cell_nd(const Eigen::VectorXd &p, float inv_cell)
std::array< int32_t, 3 > cell_coords_3d(const glm::vec3 &p, float inv_cell)

References MayaFlux::Kinesis::detail::cell_coords_3d(), MayaFlux::Kinesis::SpatialSnapshot< PointT >::cells, MayaFlux::Kinesis::SpatialSnapshot< PointT >::dimensions, h, MayaFlux::Kinesis::detail::hash_cell_3d(), MayaFlux::Kinesis::detail::hash_cell_nd(), MayaFlux::Kinesis::SpatialSnapshot< PointT >::positions, and MayaFlux::Kinesis::SpatialSnapshot< PointT >::slot_to_id.

+ Here is the call graph for this function: