示例#1
0
 void pop_preview(Array2d* a)
 {
     if (a) {
         a->resize(boost::extents[pv_.size()][pv_[0].size()]);
         *a = pv_;
         print2d(std::cerr, *a);
     }
     auto p = const_mats_[::rand() % const_mats_.size()];
     int x = ::sqrt(p.second);
     pv_.resize(boost::extents[x][x]);
     pv_.assign(p.first, p.first + p.second);
     print2d(std::cerr, pv_);
 }
示例#2
0
    bool next_round()
    {
        pop_preview(&smat_);

        p_[1] = int(vmat_[0].size() - smat_[0].size()) / 2;
        p_[0] = -int(smat_.size()-1);
        while (p_[0] <= 0) {
            Point tmp = p_;
            if (is_collision(vmat_, p_, smat_)) {
                or_assign(vmat_, p_, smat_);
                over();
                return 0;
            }
            if (p_[0] == 0)
                break;
            ++p_[0];
        }
        td_ = time(0);
        return 1;
    }
RowCol searchSorted2dArray(const Array2d<T>& a, const T& target) {
    int rows = a.size();
    int cols = a[0].size();

    int top = 0;
    int bottom = rows - 1;
    int left = 0;
    int right = cols - 1;

    int row = bottom;
    int col = left;
    while (row >= top && col <= right) {
        if (a[row][col] < target) {
            ++col;
        } else if (a[row][col] > target) {
            --row;
        } else {
            return RowCol(row, col);
        }
    }
    return RowCol(-1, -1);
}
void buildDistributions(
        SkeletonVisibilityDistributions& distributions,
        const Scene& scene,
        const std::vector<GraphNodeIndex>& skeletonNodes,
        const EmissionVertex* pEmissionVertexArray,
        const Array2d<BDPTPathVertex>& surfaceLightVertexArray,
        std::size_t lightPathCount,
        bool useNodeRadianceScale,
        bool useNodeDistanceScale,
        std::size_t threadCount) {
    auto maxDepth = surfaceLightVertexArray.size(0);
    auto pathCount = lightPathCount;

    auto evalDefaultConservativeWeight = [&](std::size_t depth, std::size_t pathIdx) {
        if(!depth) {
            if(!pEmissionVertexArray[pathIdx].m_pLight ||
                    pEmissionVertexArray[pathIdx].m_fLightPdf == 0.f) {
                return 0.f;
            }
            return 1.f;
        }
        if(surfaceLightVertexArray(depth - 1u, pathIdx).m_fPathPdf == 0.f) {
            return 0.f;
        }
        return 1.f;
    };

    auto evalNodeVisibilityWeight = [&](std::size_t depth, std::size_t pathIdx, const Vec3f& nodePosition, float nodeMaxballRadius) {
        if(!depth) {
            if(!pEmissionVertexArray[pathIdx].m_pLight ||
                    pEmissionVertexArray[pathIdx].m_fLightPdf == 0.f) {
                return 0.f;
            }

            RaySample shadowRaySample;
            auto L = pEmissionVertexArray[pathIdx].m_pLight->sampleDirectIllumination(
                        scene,
                        pEmissionVertexArray[pathIdx].m_PositionSample,
                        nodePosition,
                        shadowRaySample);

            if(L == zero<Vec3f>() || shadowRaySample.pdf == 0.f) {
                return 0.f;
            }
            if(scene.occluded(shadowRaySample.value)) {
                return 0.f;
            }

            Vec3f weight(1.f);

            if(useNodeRadianceScale) {
                weight *= L;
            }

            if(useNodeDistanceScale) {
                weight /= shadowRaySample.pdf;
            }

            return luminance(weight);
        }
        auto& lightVertex = surfaceLightVertexArray(depth - 1, pathIdx);
        if(lightVertex.m_fPathPdf == 0.f) {
            return 0.f;
        }

        auto& I = lightVertex.m_Intersection;
        auto dir = nodePosition - I.P;
        auto l = BnZ::length(dir);
        dir /= l;

        if(dot(I.Ns, dir) <= 0.f || scene.occluded(Ray(I, dir, l))) {
            return 0.f;
        }

        Vec3f weight(1.f);

        if(useNodeRadianceScale) {
            weight *= lightVertex.m_Power;
        }

        if(useNodeDistanceScale) {
            weight /= sqr(l);
        }

        return luminance(weight);
    };

    auto evalNodeGeometryWeight = [&](std::size_t depth, std::size_t pathIdx, const Vec3f& nodePosition, float nodeMaxballRadius) {
        if(!depth) {
            if(!pEmissionVertexArray[pathIdx].m_pLight ||
                    pEmissionVertexArray[pathIdx].m_fLightPdf == 0.f) {
                return 0.f;
            }

            RaySample shadowRaySample;
            auto L = pEmissionVertexArray[pathIdx].m_pLight->sampleDirectIllumination(
                        scene,
                        pEmissionVertexArray[pathIdx].m_PositionSample,
                        nodePosition,
                        shadowRaySample);

            if(L == zero<Vec3f>() || shadowRaySample.pdf == 0.f) {
                return 0.f;
            }

            Vec3f weight(1.f);

            if(useNodeRadianceScale) {
                weight *= L;
            }

            if(useNodeDistanceScale) {
                weight /= shadowRaySample.pdf;
            }

            return luminance(weight);
        }
        auto& lightVertex = surfaceLightVertexArray(depth - 1, pathIdx);
        if(lightVertex.m_fPathPdf == 0.f) {
            return 0.f;
        }

        auto& I = lightVertex.m_Intersection;
        auto dir = nodePosition - I.P;
        auto l = BnZ::length(dir);
        dir /= l;

        if(dot(I.Ns, dir) <= 0.f) {
            return 0.f;
        }

        Vec3f weight(1.f);

        if(useNodeRadianceScale) {
            weight *= lightVertex.m_Power;
        }

        if(useNodeDistanceScale) {
            weight /= sqr(l);
        }

        return luminance(weight);
    };

    auto evalNodeConservativeWeight = [&](std::size_t depth, std::size_t pathIdx, const Vec3f& nodePosition, float nodeMaxballRadius) {
        if(!depth) {
            if(!pEmissionVertexArray[pathIdx].m_pLight ||
                    pEmissionVertexArray[pathIdx].m_fLightPdf == 0.f) {
                return 0.f;
            }
            return 1.f;
        }
        if(surfaceLightVertexArray(depth - 1u, pathIdx).m_fPathPdf == 0.f) {
            return 0.f;
        }
        return 1.f;
    };

    distributions.buildDistributions(*scene.getCurvSkeleton(), skeletonNodes, pathCount, maxDepth, threadCount,
                              evalDefaultConservativeWeight,
                              evalNodeVisibilityWeight,
                              evalNodeGeometryWeight,
                              evalNodeConservativeWeight);
}