BioDynaMo  v1.05.120-25dc9790
kd_tree_environment.h
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2021 CERN & University of Surrey for the benefit of the
4 // BioDynaMo collaboration. All Rights Reserved.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // See the LICENSE file distributed with this work for details.
10 // See the NOTICE file distributed with this work for additional information
11 // regarding copyright ownership.
12 //
13 // -----------------------------------------------------------------------------
14 
15 #ifndef CORE_ENVIRONMENT_KD_TREE_ENVIRONMENT_
16 #define CORE_ENVIRONMENT_KD_TREE_ENVIRONMENT_
17 
21 #include "core/simulation.h"
22 
23 namespace bdm {
24 
26  using coord_t = Real3;
27  using idx_t = uint64_t;
28 
30 
32  inline size_t kdtree_get_point_count() const {
34  }
35 
38  inline real_t kdtree_distance(const coord_t& p1, const idx_t idx_p2,
39  size_t /*size*/) const {
41  auto& p2 = rm_->GetAgent(ah)->GetPosition();
42  return p1 * p2;
43  }
44 
48  inline real_t kdtree_get_pt(const idx_t idx, int dim) const {
50  auto& pos = rm_->GetAgent(ah)->GetPosition();
51  return pos[dim];
52  }
53 
61  template <class BBOX>
62  bool kdtree_get_bbox(BBOX&) const {
63  return false;
64  }
65 
67  ResourceManager* rm_ = nullptr;
68 };
69 
71  public:
72  struct NanoflannImpl;
73 
75 
76  ~KDTreeEnvironment() override;
77 
78  std::array<int32_t, 6> GetDimensions() const override;
79 
80  std::array<int32_t, 2> GetDimensionThresholds() const override;
81 
83 
85 
86  void Clear() override;
87 
89  const Agent& query, real_t squared_radius) override;
90 
91  void ForEachNeighbor(Functor<void, Agent*>& lambda, const Agent& query,
92  void* criteria) override;
93 
95  const Real3& query_position, real_t squared_radius,
96  const Agent* query_agent = nullptr) override;
97 
98  protected:
99  void UpdateImplementation() override;
100 
101  private:
102  // Hide nanoflann-specific types from header (pimpl idiom)
103  std::unique_ptr<NanoflannImpl> impl_;
106  std::array<int32_t, 6> grid_dimensions_;
109  std::array<int32_t, 2> threshold_dimensions_;
111 
112  void RoundOffGridDimensions(const std::array<real_t, 6>& grid_dimensions);
113 
114  void CheckGridGrowth();
115 };
116 
117 } // namespace bdm
118 
119 #endif // CORE_ENVIRONMENT_KD_TREE_ENVIRONMENT_
bdm::KDTreeEnvironment::grid_dimensions_
std::array< int32_t, 6 > grid_dimensions_
Definition: kd_tree_environment.h:106
bdm::Environment::NeighborMutexBuilder
Definition: environment.h:103
bdm::AgentFlatIdxMap::GetAgentHandle
AgentHandle GetAgentHandle(uint64_t idx) const
Definition: agent_flat_idx_map.h:63
bdm::ResourceManager::GetNumAgents
size_t GetNumAgents(int numa_node=-1) const
Definition: resource_manager.h:256
bdm::KDTreeEnvironment::GetLoadBalanceInfo
LoadBalanceInfo * GetLoadBalanceInfo() override
Definition: kd_tree_environment.cc:137
bdm::ResourceManager::GetAgent
Agent * GetAgent(const AgentUid &uid)
Definition: resource_manager.h:103
bdm::KDTreeEnvironment::UpdateImplementation
void UpdateImplementation() override
Definition: kd_tree_environment.cc:49
bdm
Definition: agent.cc:39
bdm::KDTreeEnvironment::threshold_dimensions_
std::array< int32_t, 2 > threshold_dimensions_
Definition: kd_tree_environment.h:109
bdm::NanoFlannAdapter::flat_idx_map_
AgentFlatIdxMap flat_idx_map_
Definition: kd_tree_environment.h:66
bdm::KDTreeEnvironment::GetDimensionThresholds
std::array< int32_t, 2 > GetDimensionThresholds() const override
Definition: kd_tree_environment.cc:133
bdm::real_t
double real_t
Definition: real_t.h:21
bdm::LoadBalanceInfo
Definition: load_balance_info.h:24
bdm::Agent
Contains code required by all agents.
Definition: agent.h:79
bdm::NanoFlannAdapter::idx_t
uint64_t idx_t
Definition: kd_tree_environment.h:27
bdm::Functor< void, Agent *, real_t >
bdm::KDTreeEnvironment::GetDimensions
std::array< int32_t, 6 > GetDimensions() const override
Definition: kd_tree_environment.cc:129
bdm::KDTreeEnvironment::NanoflannImpl
Definition: kd_tree_environment.cc:31
bdm::Simulation::GetResourceManager
ResourceManager * GetResourceManager()
Returns the ResourceManager instance.
Definition: simulation.cc:244
bdm::ResourceManager
Definition: resource_manager.h:53
bdm::KDTreeEnvironment::impl_
std::unique_ptr< NanoflannImpl > impl_
Definition: kd_tree_environment.h:103
agent_flat_idx_map.h
bdm::KDTreeEnvironment::GetNeighborMutexBuilder
NeighborMutexBuilder * GetNeighborMutexBuilder() override
Definition: kd_tree_environment.cc:145
math_array.h
bdm::NanoFlannAdapter::kdtree_get_point_count
size_t kdtree_get_point_count() const
Must return the number of data points.
Definition: kd_tree_environment.h:32
bdm::KDTreeEnvironment
Definition: kd_tree_environment.h:70
bdm::NanoFlannAdapter::rm_
ResourceManager * rm_
Definition: kd_tree_environment.h:67
bdm::NanoFlannAdapter::kdtree_get_pt
real_t kdtree_get_pt(const idx_t idx, int dim) const
Definition: kd_tree_environment.h:48
bdm::NanoFlannAdapter::kdtree_distance
real_t kdtree_distance(const coord_t &p1, const idx_t idx_p2, size_t) const
Definition: kd_tree_environment.h:38
bdm::KDTreeEnvironment::ForEachNeighbor
void ForEachNeighbor(Functor< void, Agent *, real_t > &lambda, const Agent &query, real_t squared_radius) override
Definition: kd_tree_environment.cc:93
bdm::Real3
MathArray< real_t, 3 > Real3
Aliases for a size 3 MathArray.
Definition: math_array.h:434
bdm::KDTreeEnvironment::CheckGridGrowth
void CheckGridGrowth()
Definition: kd_tree_environment.cc:165
environment.h
simulation.h
bdm::AgentFlatIdxMap
Definition: agent_flat_idx_map.h:41
bdm::KDTreeEnvironment::KDTreeEnvironment
KDTreeEnvironment()
Definition: kd_tree_environment.cc:35
bdm::KDTreeEnvironment::~KDTreeEnvironment
~KDTreeEnvironment() override
Definition: kd_tree_environment.cc:44
bdm::MathArray< real_t, 3 >
bdm::Environment
Definition: environment.h:30
bdm::NanoFlannAdapter::kdtree_get_bbox
bool kdtree_get_bbox(BBOX &) const
Definition: kd_tree_environment.h:62
bdm::Agent::GetPosition
virtual const Real3 & GetPosition() const =0
bdm::NanoFlannAdapter
Definition: kd_tree_environment.h:25
bdm::Simulation::GetActive
static Simulation * GetActive()
This function returns the currently active Simulation simulation.
Definition: simulation.cc:68
bdm::NanoFlannAdapter::NanoFlannAdapter
NanoFlannAdapter()
Definition: kd_tree_environment.h:29
bdm::KDTreeEnvironment::RoundOffGridDimensions
void RoundOffGridDimensions(const std::array< real_t, 6 > &grid_dimensions)
Definition: kd_tree_environment.cc:155
bdm::KDTreeEnvironment::nf_adapter_
NanoFlannAdapter * nf_adapter_
Definition: kd_tree_environment.h:110
bdm::KDTreeEnvironment::Clear
void Clear() override
Definition: kd_tree_environment.cc:149
bdm::AgentHandle
Definition: agent_handle.h:29