Skip to content

Commit

Permalink
Removed requirement of function kdtree_distance()
Browse files Browse the repository at this point in the history
  • Loading branch information
pranjal-rai committed Aug 17, 2017
1 parent 44f0b54 commit b83c291
Show file tree
Hide file tree
Showing 13 changed files with 8 additions and 116 deletions.
9 changes: 0 additions & 9 deletions benchmarkTool/randomTests/nanoflann_testRandom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ struct PointCloud
// Must return the number of data points
inline size_t kdtree_get_point_count() const { return pts.size(); }

// Returns the distance between the vector "p1[0:size-1]" and the data point with index "idx_p2" stored in the class:
inline T kdtree_distance(const T *p1, const size_t idx_p2,size_t /*size*/) const
{
const T d0=p1[0]-pts[idx_p2].x;
const T d1=p1[1]-pts[idx_p2].y;
const T d2=p1[2]-pts[idx_p2].z;
return d0*d0+d1*d1+d2*d2;
}

// Returns the dim'th component of the idx'th point in the class:
// Since this is inlined and the "dim" argument is typically an immediate value, the
// "if/else's" are actually solved at compile time.
Expand Down
9 changes: 0 additions & 9 deletions benchmarkTool/realTests/nanoflann_testReal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,6 @@ struct PointCloud
// Must return the number of data points
inline size_t kdtree_get_point_count() const { return pts.size(); }

// Returns the distance between the vector "p1[0:size-1]" and the data point with index "idx_p2" stored in the class:
inline T kdtree_distance(const T *p1, const size_t idx_p2,size_t /*size*/) const
{
const T d0=p1[0]-pts[idx_p2].x;
const T d1=p1[1]-pts[idx_p2].y;
const T d2=p1[2]-pts[idx_p2].z;
return d0*d0+d1*d1+d2*d2;
}

// Returns the dim'th component of the idx'th point in the class:
// Since this is inlined and the "dim" argument is typically an immediate value, the
// "if/else's" are actually solved at compile time.
Expand Down
11 changes: 0 additions & 11 deletions examples/KDTreeVectorOfVectorsAdaptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,6 @@ struct KDTreeVectorOfVectorsAdaptor
return m_data.size();
}

// Returns the distance between the vector "p1[0:size-1]" and the data point with index "idx_p2" stored in the class:
inline num_t kdtree_distance(const num_t *p1, const size_t idx_p2,size_t size) const
{
num_t s=0;
for (size_t i=0; i<size; i++) {
const num_t d= p1[i]-m_data[idx_p2][i];
s+=d*d;
}
return s;
}

// Returns the dim'th component of the idx'th point in the class:
inline num_t kdtree_get_pt(const size_t idx, int dim) const {
return m_data[idx][dim];
Expand Down
9 changes: 0 additions & 9 deletions examples/dynamic_pointcloud_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,6 @@ struct PointCloud
// Must return the number of data points
inline size_t kdtree_get_point_count() const { return pts.size(); }

// Returns the distance between the vector "p1[0:size-1]" and the data point with index "idx_p2" stored in the class:
inline T kdtree_distance(const T *p1, const size_t idx_p2,size_t /*size*/) const
{
const T d0=p1[0]-pts[idx_p2].x;
const T d1=p1[1]-pts[idx_p2].y;
const T d2=p1[2]-pts[idx_p2].z;
return d0*d0+d1*d1+d2*d2;
}

// Returns the dim'th component of the idx'th point in the class:
// Since this is inlined and the "dim" argument is typically an immediate value, the
// "if/else's" are actually solved at compile time.
Expand Down
9 changes: 0 additions & 9 deletions examples/example_with_pkgconfig/pointcloud_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ struct PointCloud
// Must return the number of data points
inline size_t kdtree_get_point_count() const { return pts.size(); }

// Returns the distance between the vector "p1[0:size-1]" and the data point with index "idx_p2" stored in the class:
inline float kdtree_distance(const float *p1, const size_t idx_p2,size_t size) const
{
float d0=p1[0]-pts[idx_p2].x;
float d1=p1[1]-pts[idx_p2].y;
float d2=p1[2]-pts[idx_p2].z;
return d0*d0+d1*d1+d2*d2;
}

// Returns the dim'th component of the idx'th point in the class:
// Since this is inlined and the "dim" argument is typically an immediate value, the
// "if/else's" are actually solved at compile time.
Expand Down
9 changes: 0 additions & 9 deletions examples/pointcloud_adaptor_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,6 @@ struct PointCloudAdaptor
// Must return the number of data points
inline size_t kdtree_get_point_count() const { return derived().pts.size(); }

// Returns the distance between the vector "p1[0:size-1]" and the data point with index "idx_p2" stored in the class:
inline coord_t kdtree_distance(const coord_t *p1, const size_t idx_p2,size_t /*size*/) const
{
const coord_t d0=p1[0]-derived().pts[idx_p2].x;
const coord_t d1=p1[1]-derived().pts[idx_p2].y;
const coord_t d2=p1[2]-derived().pts[idx_p2].z;
return d0*d0+d1*d1+d2*d2;
}

// Returns the dim'th component of the idx'th point in the class:
// Since this is inlined and the "dim" argument is typically an immediate value, the
// "if/else's" are actually solved at compile time.
Expand Down
9 changes: 0 additions & 9 deletions examples/pointcloud_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,6 @@ struct PointCloud
// Must return the number of data points
inline size_t kdtree_get_point_count() const { return pts.size(); }

// Returns the distance between the vector "p1[0:size-1]" and the data point with index "idx_p2" stored in the class:
inline T kdtree_distance(const T *p1, const size_t idx_p2,size_t /*size*/) const
{
const T d0=p1[0]-pts[idx_p2].x;
const T d1=p1[1]-pts[idx_p2].y;
const T d2=p1[2]-pts[idx_p2].z;
return d0*d0+d1*d1+d2*d2;
}

// Returns the dim'th component of the idx'th point in the class:
// Since this is inlined and the "dim" argument is typically an immediate value, the
// "if/else's" are actually solved at compile time.
Expand Down
9 changes: 0 additions & 9 deletions examples/pointcloud_kdd_radius.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,6 @@ struct PointCloud
// Must return the number of data points
inline size_t kdtree_get_point_count() const { return pts.size(); }

// Returns the distance between the vector "p1[0:size-1]" and the data point with index "idx_p2" stored in the class:
inline T kdtree_distance(const T *p1, const size_t idx_p2,size_t /*size*/) const
{
const T d0=p1[0]-pts[idx_p2].x;
const T d1=p1[1]-pts[idx_p2].y;
const T d2=p1[2]-pts[idx_p2].z;
return d0*d0+d1*d1+d2*d2;
}

// Returns the dim'th component of the idx'th point in the class:
// Since this is inlined and the "dim" argument is typically an immediate value, the
// "if/else's" are actually solved at compile time.
Expand Down
9 changes: 0 additions & 9 deletions examples/saveload_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,6 @@ struct PointCloud
// Must return the number of data points
inline size_t kdtree_get_point_count() const { return pts.size(); }

// Returns the distance between the vector "p1[0:size-1]" and the data point with index "idx_p2" stored in the class:
inline T kdtree_distance(const T *p1, const size_t idx_p2,size_t /*size */) const
{
const T d0=p1[0]-pts[idx_p2].x;
const T d1=p1[1]-pts[idx_p2].y;
const T d2=p1[2]-pts[idx_p2].z;
return d0*d0+d1*d1+d2*d2;
}

// Returns the dim'th component of the idx'th point in the class:
// Since this is inlined and the "dim" argument is typically an immediate value, the
// "if/else's" are actually solved at compile time.
Expand Down
14 changes: 8 additions & 6 deletions include/nanoflann.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,12 @@ namespace nanoflann
L2_Simple_Adaptor(const DataSource &_data_source) : data_source(_data_source) { }

inline DistanceType operator()(const T* a, const size_t b_idx, size_t size) const {
return data_source.kdtree_distance(a,b_idx,size);
DistanceType result = DistanceType();
for (int i=0; i<size; ++i) {
const DistanceType diff = a[i] - data_source.kdtree_get_pt(b_idx, i);
result += diff * diff;
}
return result;
}

template <typename U, typename V>
Expand All @@ -389,6 +394,7 @@ namespace nanoflann
InnerProdQuat_Adaptor(const DataSource &_data_source) : data_source(_data_source) { }

inline DistanceType operator()(const T* a, const size_t b_idx, size_t size) const {
// Update this
return data_source.kdtree_distance(a,b_idx,size);
}

Expand All @@ -410,6 +416,7 @@ namespace nanoflann
acosInnerProdQuat_Adaptor(const DataSource &_data_source) : data_source(_data_source) { }

inline DistanceType operator()(const T* a, const size_t b_idx, size_t size) const {
// Update this
return data_source.kdtree_distance(a,b_idx,size);
}

Expand Down Expand Up @@ -1018,8 +1025,6 @@ namespace nanoflann
* // Must return the number of data poins
* inline size_t kdtree_get_point_count() const { ... }
*
* // [Only if using the metric_L2_Simple type] Must return the Euclidean (L2) distance between the vector "p1[0:size-1]" and the data point with index "idx_p2" stored in the class:
* inline DistanceType kdtree_distance(const T *p1, const size_t idx_p2,size_t size) const { ... }
*
* // Must return the dim'th component of the idx'th point in the class:
* inline T kdtree_get_pt(const size_t idx, int dim) const { ... }
Expand Down Expand Up @@ -1396,9 +1401,6 @@ namespace nanoflann
* // Must return the number of data poins
* inline size_t kdtree_get_point_count() const { ... }
*
* // [Only if using the metric_L2_Simple type] Must return the Euclidean (L2) distance between the vector "p1[0:size-1]" and the data point with index "idx_p2" stored in the class:
* inline DistanceType kdtree_distance(const T *p1, const size_t idx_p2,size_t size) const { ... }
*
* // Must return the dim'th component of the idx'th point in the class:
* inline T kdtree_get_pt(const size_t idx, int dim) const { ... }
*
Expand Down
9 changes: 0 additions & 9 deletions perf-tests/nanoflann/test_leaf_max_size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,6 @@ struct PointCloud
// Must return the number of data points
inline size_t kdtree_get_point_count() const { return pts.size(); }

// Returns the distance between the vector "p1[0:size-1]" and the data point with index "idx_p2" stored in the class:
inline T kdtree_distance(const T *p1, const size_t idx_p2,size_t size) const
{
T d0=p1[0]-pts[idx_p2].x;
T d1=p1[1]-pts[idx_p2].y;
T d2=p1[2]-pts[idx_p2].z;
return d0*d0+d1*d1+d2*d2;
}

// Returns the dim'th component of the idx'th point in the class:
// Since this is inlined and the "dim" argument is typically an immediate value, the
// "if/else's" are actually solved at compile time.
Expand Down
9 changes: 0 additions & 9 deletions perf-tests/nanoflann/test_nanoflann.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,6 @@ struct PointCloud
// Must return the number of data points
inline size_t kdtree_get_point_count() const { return pts.size(); }

// Returns the distance between the vector "p1[0:size-1]" and the data point with index "idx_p2" stored in the class:
inline float kdtree_distance(const float *p1, const size_t idx_p2,size_t size) const
{
float d0=p1[0]-pts[idx_p2].x;
float d1=p1[1]-pts[idx_p2].y;
float d2=p1[2]-pts[idx_p2].z;
return d0*d0+d1*d1+d2*d2;
}

// Returns the dim'th component of the idx'th point in the class:
// Since this is inlined and the "dim" argument is typically an immediate value, the
// "if/else's" are actually solved at compile time.
Expand Down
9 changes: 0 additions & 9 deletions tests/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,6 @@ struct PointCloud
// Must return the number of data points
inline size_t kdtree_get_point_count() const { return pts.size(); }

// Returns the distance between the vector "p1[0:size-1]" and the data point with index "idx_p2" stored in the class:
inline T kdtree_distance(const T *p1, const size_t idx_p2,size_t /* size*/) const
{
const T d0=p1[0]-pts[idx_p2].x;
const T d1=p1[1]-pts[idx_p2].y;
const T d2=p1[2]-pts[idx_p2].z;
return d0*d0+d1*d1+d2*d2;
}

// Returns the dim'th component of the idx'th point in the class:
// Since this is inlined and the "dim" argument is typically an immediate value, the
// "if/else's" are actually solved at compile time.
Expand Down

0 comments on commit b83c291

Please sign in to comment.