BioDynaMo  v1.05.159-3be850bb
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_
AgentHandle GetAgentHandle(uint64_t idx) const
Contains code required by all agents.
Definition: agent.h:79
virtual const Real3 & GetPosition() const =0
std::array< int32_t, 2 > threshold_dimensions_
void RoundOffGridDimensions(const std::array< real_t, 6 > &grid_dimensions)
std::array< int32_t, 2 > GetDimensionThresholds() const override
std::unique_ptr< NanoflannImpl > impl_
NanoFlannAdapter * nf_adapter_
void ForEachNeighbor(Functor< void, Agent *, real_t > &lambda, const Agent &query, real_t squared_radius) override
std::array< int32_t, 6 > grid_dimensions_
NeighborMutexBuilder * GetNeighborMutexBuilder() override
LoadBalanceInfo * GetLoadBalanceInfo() override
void UpdateImplementation() override
std::array< int32_t, 6 > GetDimensions() const override
Agent * GetAgent(const AgentUid &uid)
size_t GetNumAgents(int numa_node=-1) const
ResourceManager * GetResourceManager()
Returns the ResourceManager instance.
Definition: simulation.cc:244
static Simulation * GetActive()
This function returns the currently active Simulation simulation.
Definition: simulation.cc:68
Definition: agent.cc:39
double real_t
Definition: real_t.h:21
MathArray< real_t, 3 > Real3
Aliases for a size 3 MathArray.
Definition: math_array.h:434
real_t kdtree_distance(const coord_t &p1, const idx_t idx_p2, size_t) const
AgentFlatIdxMap flat_idx_map_
size_t kdtree_get_point_count() const
Must return the number of data points.
bool kdtree_get_bbox(BBOX &) const
real_t kdtree_get_pt(const idx_t idx, int dim) const