src/mcrt/photon_map.cc
// We are going to sort in each step. Yes it's bloody expensive but fuck it :)
We are going to sort in each step. Yes it's bloody expensive but fuck it :)
We are going to sort in each step . Yes it ' s bloody expensive but fuck it : )
void mcrt::PhotonMap::KdNode::construct(std::vector<const Photon*>& photons) {
    if (photons.size() == 1) {
        photon = photons[0];
        return;
    }
    sort(photons); 
    std::size_t medianPhoton = median(photons);
    photon = photons[medianPhoton];
    processed += 2;
    double progress { getProgress() };
    if (progress - cachedProgress >= 0.01) {
        if (progress < 1.0)
            printProgress("Balance k-d: ",
                          progress);
        cachedProgress = progress;
    }
    std::size_t leftSize { medianPhoton };
    std::size_t rightSize { photons.size() - leftSize  - 1 };
    if (leftSize != 0) {
        std::vector<const Photon*> leftPhotons(leftSize);
        std::copy(photons.cbegin(), photons.cbegin() + medianPhoton, leftPhotons.begin());
        left = new KdNode { getNextAxis() };
        left->construct(leftPhotons);
    }
    if (rightSize != 0) {
        std::vector<const Photon*> rightPhotons(rightSize);
        std::copy(photons.cbegin() + medianPhoton + 1, photons.cend(), rightPhotons.begin());
        right = new KdNode { getNextAxis() };
        right->construct(rightPhotons);
    }
}
void mcrt :: PhotonMap :: KdNode :: construct ( std :: vector < const Photon * > & photons ) { if ( photons . size ( ) == 1 ) { photon = photons [ 0 ] ; return ; } sort ( photons ) ; std :: size_t medianPhoton = median ( photons ) ; photon = photons [ medianPhoton ] ; processed += 2 ; double progress { getProgress ( ) } ; if ( progress - cachedProgress >= 0.01 ) { if ( progress < 1.0 ) printProgress ( " " , progress ) ; cachedProgress = progress ; } std :: size_t leftSize { medianPhoton } ; std :: size_t rightSize { photons . size ( ) - leftSize - 1 } ; if ( leftSize != 0 ) { std :: vector < const Photon * > leftPhotons ( leftSize ) ; std :: copy ( photons . cbegin ( ) , photons . cbegin ( ) + medianPhoton , leftPhotons . begin ( ) ) ; left = new KdNode { getNextAxis ( ) } ; left -> construct ( leftPhotons ) ; } if ( rightSize != 0 ) { std :: vector < const Photon * > rightPhotons ( rightSize ) ; std :: copy ( photons . cbegin ( ) + medianPhoton + 1 , photons . cend ( ) , rightPhotons . begin ( ) ) ; right = new KdNode { getNextAxis ( ) } ; right -> construct ( rightPhotons ) ; } }
We are going to sort in each step.
We are going to sort in each step .
// Sort along an split axis.