jlblancoc/nanoflann

What't the the meaning of function accum_dist?

Opened this issue · 0 comments

I am build a KD tree with some constraint. For object it has timestamp t and a 3D position p, only the delta time less than some threshold, the distance could be valid, otherwise return the inf value. I modify the code based on example, the result index is found correct, but the return dist_sqr is not right. I found it's maybe the method of accum_dist(), but I don't know what's the parameters and affect of this function, could you be give some explain?

template <class DataSource>
class MyCustomMetric
{
   public:
    using ElementType  = double;
    using DistanceType = double;
    MyCustomMetric(
        const DataSource& dataList, const double& param, bool with_t = false)
        : data_(dataList), param_(param), with_t_(with_t)
    {
    }

   public:
    inline const DataSource& dataList() const { return data_; }

    inline double evalMetric(
        const double* a, const size_t b_idx, size_t dim_size) const
    {
        double result{0};
        if (with_t_)
        {
            if (abs(a[3] - data_.kdtree_get_pt(b_idx, 3)) > 4)
            {
                result = std::numeric_limits<double>::max();
            }
            else
            {
                for (size_t i = 0; i < dim_size - 1; ++i)
                {
                    double diff = a[i] - data_.kdtree_get_pt(b_idx, i);
                    result += std::pow(diff, param_);
                }
            }
        }
        else
        {
            for (size_t i = 0; i < dim_size; ++i)
            {
                double diff = a[i] - data_.kdtree_get_pt(b_idx, i);
                result += std::pow(diff, param_);
            }
        }
        return result;
    }

    template <typename U, typename V>
    inline double accum_dist(const U a, const V b, const size_t idx) const
    {
        return pow(a-b,param_);
    }

   private:
    const DataSource& data_;
    double            param_ = 2.0;
    bool              with_t_{false};
};