结构体"/>
flann L2结构体
/*** Squared Euclidean distance functor, optimized version欧式距离平方优化后的版本*/
template<class T>
struct L2
{typedef bool is_kdtree_distance;typedef T ElementType;typedef typename Accumulator<T>::Type ResultType;/*** Compute the squared Euclidean distance between two vectors.计算两个向量的欧式距离** This is highly optimised, with loop unrolling, as it is one* of the most expensive inner loops.这是高度优化,以循环展开,并且它是最昂贵的内部循环之一** The computation of squared root at the end is omitted for* efficiency.最后为了效率省略了平方根*/template <typename Iterator1, typename Iterator2>ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType worst_dist = -1) const{ResultType result = ResultType();ResultType diff0, diff1, diff2, diff3;Iterator1 last = a + size;Iterator1 lastgroup = last - 3;/* Process 4 items with each loop for efficiency. */while (a < lastgroup) {diff0 = (ResultType)(a[0] - b[0]);diff1 = (ResultType)(a[1] - b[1]);diff2 = (ResultType)(a[2] - b[2]);diff3 = (ResultType)(a[3] - b[3]);result += diff0 * diff0 + diff1 * diff1 + diff2 * diff2 + diff3 * diff3;a += 4;b += 4;if ((worst_dist>0)&&(result>worst_dist)){return result;}}/* Process last 0-3 pixels. Not needed for standard vector lengths.不需要标准向量长度 */while (a < last) {diff0 = (ResultType)(*a++ - *b++);result += diff0 * diff0;}return result;}/*** Partial euclidean distance, using just one dimension只用一维的偏欧式距离. This is used by the* kd-tree when computing partial distances while traversing the tree.** Squared root is omitted for efficiency.*/template <typename U, typename V>inline ResultType accum_dist(const U& a, const V& b, int) const{return (a-b)*(a-b);}
};
更多推荐
flann L2结构体
发布评论