Giter Site home page Giter Site logo

Comments (3)

DingFeng9313 avatar DingFeng9313 commented on May 20, 2024 1

Thanks a lot. That solved my problem. I copied code from example files "kd_tree_custom_space_type.cpp", that is why it is std::deque. Initially I want to use std::vector.

Thanks again.

from pico_tree.

Jaybro avatar Jaybro commented on May 20, 2024

You can definitely use pico_tree with PCL. At first glance your custom PointTraits are fine, except that I don't see a namespace:

namespace pico_tree {

template <>
struct PointTraits<pcl::PointXYZI> {
  ...
};

}  // namespace pico_tree

However, your custom SpaceTraits needs a few changes:

namespace pico_tree {

// pcl::PointXYZI doesn't require template arguments, so we leave the template
// parameters for SpaceTraits empty. This results in a full template
// specialization for std::deque<pcl::PointXYZI>.
template <>
struct SpaceTraits<std::deque<pcl::PointXYZI>> {
  ...
  using ScalarType = float;
  static std::size_t constexpr Dim = 3;
  ...
};

}  // namespace pico_tree

from pico_tree.

Jaybro avatar Jaybro commented on May 20, 2024

Note that I would recommend using an std::vector over an std::deque because it would be faster. All you have to do is #include <pico_tree/vector_traits.hpp> and add your custom PointTraits<pcl::PointXYZI>.

If you really want to work with std::deque then here is a generic SpaceTraits<std::deque<Point_>> that will work for any point type Point_ supported by a PointTraits<Point_>:

namespace pico_tree {

// Provides an interface for an std::deque<Point_>.
template <typename Point_>
struct SpaceTraits<std::deque<Point_>> {
  using SpaceType = std::deque<Point_>;
  using PointType = Point_;
  using ScalarType = typename PointTraits<Point_>::ScalarType;
  static std::size_t constexpr Dim = PointTraits<Point_>::Dim;

  // It is not reliably possible to get the spatial dimension of an std::deque.
  // I.e., when the point set is empty.
  static_assert(
      Dim != kDynamicSize, "DEQUE_OF_POINT_DOES_NOT_SUPPORT_DYNAMIC_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; }
};

}  // namespace pico_tree

from pico_tree.

Related Issues (7)

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.