当前位置:   article > 正文

ANN 查找半径为 fRadius 内所有顶点_fix radius ann

fix radius ann

    //            说明  ///

    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);

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/煮酒与君饮/article/detail/966629
推荐阅读
相关标签
  

闽ICP备14008679号