Coder Social home page Coder Social logo

jaybro / pico_tree Goto Github PK

View Code? Open in Web Editor NEW
36.0 36.0 7.0 1.78 MB

A C++ header only library for fast nearest neighbor and range searches using a KdTree. It supports interfacing with Eigen, OpenCV, and custom data types and provides optional Python bindings.

License: MIT License

CMake 6.42% C++ 87.91% Python 5.67%
approximate-nearest-neighbor-searching cpp eigen header-only kd-tree kdtree nearest-neighbor-searching opencv pico-tree python-bindings range-searching

pico_tree's Issues

trying to use with pcl::PointXYZI

Hi, I am trying to use pico_tree with pcl::pointXYZI

looks like I should use both custom spacetraits and custom point. My custom SpaceTraits are as follows:

template <>
struct PointTraits<pcl::PointXYZI> {
  using PointType = pcl::PointXYZI;
  using ScalarType = float;
  // Spatial dimension. Set to pico_tree::kDynamicSize when the dimension is
  // only known at run-time.
  static std::size_t constexpr Dim = 3;

  // Returns a pointer to the coordinates of the input point.
  inline static float const* data(pcl::PointXYZI const& point) { return point.data; }

  // Returns the number of coordinates or spatial dimension of each point.
  inline static constexpr std::size_t size(pcl::PointXYZI const&) { return Dim; }
};

// Provides an interface for an std::deque<std::array>.
template <typename Scalar_, std::size_t Dim_>
struct SpaceTraits<std::deque<pcl::PointXYZI>> {
  using SpaceType = std::deque<pcl::PointXYZI>;
  using PointType = pcl::PointXYZI;
  using ScalarType = Scalar_;
  // Spatial dimension. Set to pico_tree::kDynamicSize when the dimension is
  // only known at run-time.
  static std::size_t constexpr Dim = Dim_;

  // Returns a point from the input space at the specified index.
  template <typename Index_>
  inline static PointType const& PointAt(
      SpaceType const& space, Index_ const index) {
    return space[static_cast<std::size_t>(index)];
  }

  // Returns number of points contained by the space.
  inline static std::size_t size(SpaceType const& space) {
    return space.size();
  }

  // Returns the number of coordinates or spatial dimension of each point.
  inline static constexpr std::size_t sdim(SpaceType const&) { return Dim; }
};

But it reports

 error: template parameters not deducible in partial specialization:
 struct SpaceTraits<std::deque<pcl::PointXYZI>>

Is it possible to use pico_tree this way? How can I use it with pcl library?

Python bindings do not respect non-contiguous NumPy arrays

When the Python pico_tree.KdTree constructor is passed a non-contiguous NumPy array, such as the result of a swapaxes operation, the KdTree is constructed with sdim and npts swapped compared to the expected values. It seems that KdTree is not respecting the array strides, but instead is assuming that the array contains a simple block of memory in C-order.

Repro follows:

import pico_tree as pt
import numpy as np

B, N = 2, 1024
knn = 16

xyz = np.random.randn(B, 3, N)
idx = np.broadcast_to(np.arange(knn, dtype=np.int64).reshape(1, 1, knn), (B, N, knn))
points = np.random.randn(B, 8, N)
xyz_p = np.swapaxes(xyz, 2, 1)
xyz_p_contiguous = np.ascontiguousarray(xyz_p)

assert xyz_p.shape == xyz_p_contiguous.shape

contiguous_tree = pt.KdTree(xyz_p_contiguous[0], pt.Metric.L2Squared, 10)
assert contiguous_tree.sdim == 3
assert contiguous_tree.npts == N

noncontiguous_tree = pt.KdTree(xyz_p[0], pt.Metric.L2Squared, 10)
assert noncontiguous_tree.sdim == 3  # Fails, sdim and npts are swapped
assert noncontiguous_tree.npts == N

xyz_p and xyz_p_contiguous contain the same data and act the same using NumPy operations, but the strides are different as xyz_p is non-contiguous. The KdTree built with the non-contiguous array has npts == 3 and sdim == 1024, the opposite to what is expected, whereas the tree built with the contiguous array works as expected.

A workaround is to ensure that arrays are contiguous before passing to pico_tree.KdTree.

can not compile on Ubuntu18.04 gcc7.5

get Error while compiling examples

pico_tree/kd_tree.hpp:362:13: error: ‘pico_tree::KdTree<Space_, Metric_, SplittingRule_, Index_>::space_’ has incomplete type
   SpaceType space_

on ubuntu18.04, gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
using cxx standard 17

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.