gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
SPoint3KDTree.h
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 
6 #ifndef SPOINT3_KDTREE_H
7 #define SPOINT3_KDTREE_H
8 
9 #include "SPoint3.h"
10 #include "nanoflann.hpp"
11 
12 struct SPoint3Cloud {
13  std::vector<SPoint3> pts;
14 };
15 
16 template <typename Derived> struct SPoint3CloudAdaptor {
17  const Derived &obj;
18  SPoint3CloudAdaptor(const Derived &obj_) : obj(obj_) {}
19  inline const Derived &derived() const { return obj; }
20  inline size_t kdtree_get_point_count() const { return derived().pts.size(); }
21  inline double kdtree_distance(const double *p1, const size_t idx_p2,
22  size_t /*size*/) const
23  {
24  const double d0 = p1[0] - derived().pts[idx_p2].x();
25  const double d1 = p1[1] - derived().pts[idx_p2].y();
26  const double d2 = p1[2] - derived().pts[idx_p2].z();
27  return d0 * d0 + d1 * d1 + d2 * d2;
28  }
29  inline double kdtree_get_pt(const size_t idx, int dim) const
30  {
31  if(dim == 0)
32  return derived().pts[idx].x();
33  else if(dim == 1)
34  return derived().pts[idx].y();
35  else
36  return derived().pts[idx].z();
37  }
38  template <class BBOX> bool kdtree_get_bbox(BBOX & /*bb*/) const
39  {
40  return false;
41  }
42 };
43 
47 
48 #endif
SPoint3CloudAdaptor::kdtree_get_bbox
bool kdtree_get_bbox(BBOX &) const
Definition: SPoint3KDTree.h:38
SPoint3CloudAdaptor::kdtree_get_point_count
size_t kdtree_get_point_count() const
Definition: SPoint3KDTree.h:20
SPoint3CloudAdaptor::kdtree_distance
double kdtree_distance(const double *p1, const size_t idx_p2, size_t) const
Definition: SPoint3KDTree.h:21
SPoint3KDTree
nanoflann::KDTreeSingleIndexAdaptor< nanoflann::L2_Simple_Adaptor< double, SPoint3CloudAdaptor< SPoint3Cloud > >, SPoint3CloudAdaptor< SPoint3Cloud >, 3 > SPoint3KDTree
Definition: SPoint3KDTree.h:46
SPoint3CloudAdaptor::obj
const Derived & obj
Definition: SPoint3KDTree.h:17
nanoflann::L2_Simple_Adaptor
Definition: nanoflann.hpp:361
SPoint3Cloud::pts
std::vector< SPoint3 > pts
Definition: SPoint3KDTree.h:13
nanoflann.hpp
SPoint3CloudAdaptor
Definition: SPoint3KDTree.h:16
SPoint3CloudAdaptor::kdtree_get_pt
double kdtree_get_pt(const size_t idx, int dim) const
Definition: SPoint3KDTree.h:29
SPoint3Cloud
Definition: SPoint3KDTree.h:12
SPoint3CloudAdaptor::derived
const Derived & derived() const
Definition: SPoint3KDTree.h:19
SPoint3CloudAdaptor::SPoint3CloudAdaptor
SPoint3CloudAdaptor(const Derived &obj_)
Definition: SPoint3KDTree.h:18
nanoflann::KDTreeSingleIndexAdaptor
Definition: nanoflann.hpp:746
SPoint3.h