Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] Exact closest neighbor not working correctly

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] Exact closest neighbor not working correctly


Chronological Thread 
  • From: "Sebastien Loriot (GeometryFactory)" <>
  • To:
  • Subject: Re: [cgal-discuss] Exact closest neighbor not working correctly
  • Date: Fri, 17 Apr 2020 18:40:31 +0200
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None ; spf=Pass ; spf=None
  • Ironport-phdr: 9a23:Ubj0gB/LnQF9a/9uRHKM819IXTAuvvDOBiVQ1KB20u4cTK2v8tzYMVDF4r011RmVBNidsK0P0rKP++C4ACpcuMrH6ChDOLV3FDY7yuwu1zQ6B8CEDUCpZNXLVAcdWPp4aVl+4nugOlJUEsutL3fbo3m18CJAUk6nbVk9Kev6AJPdgNqq3O6u5ZLTfx9IhD2gar9uMRm6twrcutQWjId4JKs8yBTFrmZUd+hL2GhkIU6fkwvm6sq/4ZJu/D5ct+49+8JFTK73Y7k2QbtEATspNGw4+NflvgTZQwuV4XscXGQWkh5WDAXA8Rr3QJT/vDbku+RkwCWVMtH4Qr4yWTS58qdkUwTohzsdNz44627YlMp9h79GrR27phx/x4nUYJyJNPd7Y6jQc88WSXZHU81MUSFKH4GyYJYVD+cZIOhWsYf9qVsNoxWwCwajC+HgxSNHiHLtwa030f4sHR3a0AEuHd8DtmnfotXvNKcVVOC41KfEwyjdYPxNwzj985TIchE/rvGKQLl+d83RyVMuFwPCklWbtIjpMTKL2eQKtmiU8fZgVfivimAnsQ5+viSvxsA2iojJg44ZxE3P+CJiwIYxIt24Uk97Ydm4EJdKsiGaM5B7QswnQ25yuSY6zqcKtoK8fCgP0ZkqwQPUZf+fc4WQ/B7vSOKcLS17iX9lYr6zmQi+/VW6xuDzS8W4yEhGoTBZntXRs30CyQDf5dKCR/dj4kutxDOC2g7J5e1aPUw5kKXWJ4I8zbErk5cetVjPEjPol0jzgq+bdFsr9+yt5unlf7npu52ROolpgQ/kKKsugNawAeEgPwgOQWeb/eO82aXm/ULjQbVKiuQ6k6fDsJzHPMgbqKG0DxJP3oYs7Ba/CDim0NAGknUdMF1FfxeHg5DoO1HIPv/4Ee+yj0qwnDpv3fzLPb3sDo/TInTdjbvtZ7lw51NExAo2199f5pZUCr8bIPL0X0/8rMfYDhs+MwyuwubnD8l92pkbWWKLGaKZP6bSvkWJ5uIrOeWDeIgVuDPlJ/g/+/HulWM5mUMafaSxwZQXZ2q3HvB/L0qEYHrsmcsOEXoRvgolV+Hqk12DUTtLZ3moRa485zc7CJinDYjZXIytjqaBj2+HGchdaWlCT1yNCnz1bJ6sWvEWaSvULNUyvCYDUO3rcIIr3AqytQL8g55gNOvT5mVYmp/k0dVp/fz9nBou8iZlTo7Vh3qJSHt1mX9OQjse06V2oEg7wVCGh/sry8dEHMBesqsaGjwxMoTRmrQjWoLCHznZd9LMc26IB9CvADU/VNU0moZcbEN0GtHkhRfGjXPzX+0l0oeTDZlxyZrymmDrLp8kmXnD3aglyVIhR5kXbDD0tutE7wHWQrXxvQCZmqKtL/lO2SfM8CKc1zPLsh0BFgF3VqrBUDYUYU6E9dk=

Could you please provide a minimal example that we could compile, run and that would be showing the error?

At first sight, I don't see anything suspicious.

Thanks,

Sebastien.

On 4/17/20 6:25 PM, Juan Jose Casafranca wrote:
I am trying to find the closest neighbor in a point cloud to a given point. I have followed the documentation example in which the points are stored in a user vector and the Tree only contains indices. Since the results were not what I was expecting, I am also computing the closest neighbor by brute force. Ill explain my code:

I have a vector of points (coarsePoints) and I have a vector of indices (xC_vertices). The indices are the points in coarsePoints that can be marked as closest neighbor.

This is how I compute the closest point using a brute force algorithm
```

for (int i = 0; i < d_vertices.size(); ++i) {

Real minDistance = std::numeric_limits<Real>::infinity();

int vertexId = -1;

const auto &dPoint = highResPoints[d_vertices[i]];

const CPF::Point_3 pD{dPoint[0], dPoint[1], dPoint[2]};

for (int j = 0; j < xC_vertices.size(); ++j) {

const auto &xPoint = coarsePoints[xC_vertices[j]];

const CPF::Point_3 pC{xPoint[0], xPoint[1], xPoint[2]};


if (CGAL::squared_distance(pC, pD) < minDistance) {

vertexId = j;

minDistance = CGAL::squared_distance(pC, pD);

}

}

```


When using CGAL, I have the following (based on the documentation example):


```

class My_point_property_map

{

const sofa::helper::vector<CPF::SofaTypes::Point> &points;

const std::vector<CPF::SofaTypes::Tetra::value_type> &xC_vertices;

public:

typedef CPF::Point_3 value_type;

typedef value_type &reference;

typedef std::size_t key_type;

typedef boost::lvalue_property_map_tag category;

My_point_property_map(const sofa::helper::vector<CPF::SofaTypes::Point> &pts,

const std::vector<CPF::SofaTypes::Tetra::value_type> &xC_vertices_)

: points(pts)

, xC_vertices(xC_vertices_)

{

}

value_type operator[](key_type k) const

{

const CPF::SofaTypes::Point &sPoint = points[xC_vertices[k]];

return CPF::Point_3{sPoint[0], sPoint[1], sPoint[2]};

}

friend value_type get(const My_point_property_map &ppmap, key_type i) { return ppmap[i]; }

};


using SearchTraitsBase = CGAL::Search_traits_3<CPF::K>;

using SearchTraits = CGAL::Search_traits_adapter<std::size_t, My_point_property_map, SearchTraitsBase>;

using NeighborSearch = CGAL::Orthogonal_k_neighbor_search<SearchTraits>;

using Tree = NeighborSearch::Tree;

using Splitter = typename Tree::Splitter;

using SearchDistance = typename NeighborSearch::Distance;


int searchNeighbor() {

My_point_property_map ppmap(coarsePoints, xC_vertices);

Tree searchTree(boost::counting_iterator<int>(0),

boost::counting_iterator<int>(xC_vertices.size()),

Splitter(),

SearchTraits(ppmap));

SearchDistance trDistance(ppmap);


for (int i = 0; i < d_vertices.size(); ++i) {

NeighborSearch search(searchTree, CPF::Point_3{dPoint[0], dPoint[1], dPoint[2]}, 1, 0, true, trDistance);

for (const auto &searchResult : search) {

if (searchResult.first != vertexId) {

spdlog::get("cpf")->info("Brute force id = {}", vertexId);

spdlog::get("cpf")->info("CGAL id = {}", searchResult.first);

spdlog::get("cpf")->info("Brute force distance = {}", minDistance);

spdlog::get("cpf")->info("CGAL distance = {}", searchResult.second);

}

}

} }

```


This return a los of vertices that are actually different:


[2020-04-17 18:10:31.988] [cpf] [info] Brute force id = 386

[2020-04-17 18:10:31.988] [cpf] [info] CGAL id = 84

[2020-04-17 18:10:31.988] [cpf] [info] Brute force distance = 0.0

[2020-04-17 18:10:31.988] [cpf] [info] CGAL distance = 0.041339367896971506


I am not sure if I am using incorrectly the NeighborSearch or what is happening. Any ideas what might be wrong?







Archive powered by MHonArc 2.6.18.

Top of Page