当前位置: 首页>>代码示例>>C++>>正文


C++ KDTree::addItem方法代码示例

本文整理汇总了C++中KDTree::addItem方法的典型用法代码示例。如果您正苦于以下问题:C++ KDTree::addItem方法的具体用法?C++ KDTree::addItem怎么用?C++ KDTree::addItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在KDTree的用法示例。


在下文中一共展示了KDTree::addItem方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: kNearestItems

//=======================================================================//
void stitch::Vec3::relaxEquidistantVectorsII(std::vector<stitch::Vec3> &vectors, uint32_t numIterations)
{
    const uint32_t numVectors = vectors.size();
    
    for (uint32_t iterationsDone=0; iterationsDone<numIterations; ++iterationsDone)
    {
        float minResult=0.0f;
        float maxResult=0.0f;
        float sumResult=0.0f;
        
        KDTree kdTree;
        
        for (uint32_t acteeVectorNum=0; acteeVectorNum<numVectors; ++acteeVectorNum)
        {
            kdTree.addItem(new BoundingVolume(vectors[acteeVectorNum], 0.0f, acteeVectorNum));
        }
        
        std::vector<stitch::Vec3> splitAxisVec;
        splitAxisVec.push_back(Vec3(1.0f, 0.0f, 0.0f));
        splitAxisVec.push_back(Vec3(0.0f, 1.0f, 0.0f));
        splitAxisVec.push_back(Vec3(0.0f, 0.0f, 1.0f));
        
        kdTree.build(KDTREE_DEFAULT_CHUNK_SIZE, 0, 1000, splitAxisVec);
        
        
        for (uint32_t acteeVectorNum=0; acteeVectorNum<numVectors; ++acteeVectorNum)
        {
            stitch::Vec3 relaxDelta;//Initialised to zero in the constructor.
            float minActDistance=10.0;//Some large initial distance.
            
            KNearestItems kNearestItems(vectors[acteeVectorNum], 1.0f, numVectors/100);
            kdTree.getNearestK(&kNearestItems);
            
            const uint32_t numNearestItems=kNearestItems.numItems_;
            for (uint32_t i=0; i<numNearestItems; ++i)
            {
                uint32_t actingVectorNum=kNearestItems.heapArray_[i].second->userIndex_;
                
                if (actingVectorNum!=acteeVectorNum)
                {
                    const float actDistance=(kNearestItems.heapArray_[i].second->centre_-vectors[acteeVectorNum]).lengthSq() / kNearestItems.searchRadiusSq_;
                    const float actWeight=1.0f - actDistance;
                    stitch::Vec3 actNormal=(vectors[acteeVectorNum] - vectors[actingVectorNum]);
                    actNormal.normalise();
                    
                    relaxDelta+=actNormal * (actWeight);
                    
                    if (actDistance < minActDistance) minActDistance=actDistance;
                }
            }
            
            vectors[acteeVectorNum] += relaxDelta*sqrtf(minActDistance*kNearestItems.searchRadiusSq_)*0.1;//+Vec3::randNorm()*0.005*minActDistance;
            vectors[acteeVectorNum].normalise();
            
            if (acteeVectorNum>0)
            {
                sumResult+=minActDistance;
                if (minActDistance<minResult) minResult=minActDistance;
                if (minActDistance>maxResult) maxResult=minActDistance;
            } else
            {
                sumResult=minResult=maxResult=minActDistance;
            }
        }
        
        //std::cout << "relaxActingDistance = ["  << minResult << "|" << (sumResult/numVectors) << "|" << maxResult << "]\n";
        //std::cout.flush();
    }
}
开发者ID:bduvenhage,项目名称:stitch-engine,代码行数:70,代码来源:Vec3.cpp


注:本文中的KDTree::addItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。