コード例 #1
0
ファイル: KDTree3.cpp プロジェクト: ghsoftco/basecode14
void KDTree3::BuildTree(const PointSet &Points)
{
    FreeMemory();
    UINT PointCount = Points.Points().Length();
    Console::WriteString(String("Building KD tree, ") + String(PointCount) + String(" points..."));
    queryPt = annAllocPt(3); // allocate query point
    dataPts = annAllocPts(PointCount, 3); // allocate data points
    nnIdx = new ANNidx[KDTree3MaxK];  // allocate near neigh indices
    dists = new ANNdist[KDTree3MaxK]; // allocate near neighbor dists
    for(UINT i = 0; i < PointCount; i++)
    {
        for(UINT ElementIndex = 0; ElementIndex < 3; ElementIndex++)
        {
            dataPts[i][ElementIndex] = Points.Points()[i].Position[ElementIndex];
        }
    }

    kdTree = new ANNkd_tree( // build search structure
        dataPts,    // the data points
        PointCount, // number of points
        3);            // dimension of space
    Console::WriteString(String("done.\n"));
}