// 说明 ///
It is easy, however, to determine whether any points were missed. The procedure returns a
count of the total number of points that lie within the radius bound. (This feature is always
enabled, even if k = 0.) In order to produce a true fi xed-radius search, first set k = 0 and run
the procedure in order to obtain the number k0 of points that lie within the radius bound.
Then, allocate index and distance arrays of size k0 each, and repeat the xed-radius search
by setting k = k0 and passing in these two arrays.
int nVerSize = G_pScene->m_nVertices;
int nPtDim = 3;///建立邻域///
int ptDim = 3;
ANNpointArray org_mesh_point_array = annAllocPts(nVerSize, nPtDim); ///<原始网格顶点位置
/*CAUTION: only search in inner Facets(with no border vertex) of Warpmesh.*/
for (unsigned i = 0; i < nVerSize; ++i)
{
org_mesh_point_array[i][0] = G_pScene->m_pVertices[i].m_vPosition.x;
org_mesh_point_array[i][1] = G_pScene->m_pVertices[i].m_vPosition.y;
org_mesh_point_array[i][2] = G_pScene->m_pVertices[i].m_vPosition.z;
}
ANNkd_tree *pAnn_SearchTree = new ANNkd_tree(org_mesh_point_array, nVerSize, nPtDim);
ANNpoint queryPt = annAllocPt(nPtDim);
ANNdist sqRad = fRadius;
ANNidxArray nnIdx;
ANNdistArray dists;
int nVerInSphere = 0;
for (unsigned i = 0; i < nVerSize; ++i)
{
queryPt[0] = G_pScene->m_pVertices[i].m_vPosition.x;
queryPt[1] = G_pScene->m_pVertices[i].m_vPosition.y;
queryPt[2] = G_pScene->m_pVertices[i].m_vPosition.z;
nVerInSphere = pAnn_SearchTree->annkFRSearch(queryPt, sqRad, 0, nnIdx, dists);
if(nVerInSphere < 1) {std::cout<<"ANN Have No Neighbor "<<std::endl;}
ANNidxArray tmp_nnIdx = new ANNidx[nVerInSphere + 1]; // near neighbor indices
ANNdistArray tmp_dists = new ANNdist[nVerInSphere + 1];; // near neighbor distances
std::set<int> ngbVerSet;
pAnn_SearchTree->annkFRSearch(queryPt, sqRad, 0, nnIdx, dists);
for (unsigned j = 0; j < nVerInSphere; ++j)
{
ngbVerSet.insert(nnIdx[j]);
}
mVertexNgbSetlist_2.push_back(ngbVerSet);
delete[](tmp_nnIdx);
delete[](tmp_dists);
}
delete (pAnn_SearchTree);
annDeallocPt(queryPt);
annDeallocPts(org_mesh_point_array);