Exemple #1
0
size2_t Layer::getDimensions() const {
    if (hasRepresentations() && lastValidRepresentation_) {
        size2_t dim = lastValidRepresentation_->getDimensions();
        if (dim != size2_t(0)) return dim;
    }
    return StructuredGridEntity<2>::getDimensions();
}
void RunningImageMeanAndStandardDeviationCL::computeMeanAndStandardDeviation(const uvec2& nSamples, const LayerCLBase* samples, int iteration, const LayerCLBase* prevMean, LayerCLBase* nextMean, const LayerCLBase* prevStandardDeviation, LayerCLBase* nextStandardDeviation, const size2_t& workGroupSize, const VECTOR_CLASS<cl::Event> *waitForEvents, cl::Event *event) {
    
    
    size_t workGroupSizeX = static_cast<size_t>(workGroupSize.x); size_t workGroupSizeY = static_cast<size_t>(workGroupSize.y);
    size_t globalWorkSizeX = getGlobalWorkGroupSize(nSamples.x, workGroupSizeX);
    size_t globalWorkSizeY = getGlobalWorkGroupSize(nSamples.y, workGroupSizeY);

    int argIndex = 0;
    kernel_->setArg(argIndex++, nSamples);
    kernel_->setArg(argIndex++, *samples);
    kernel_->setArg(argIndex++, static_cast<float>(iteration+1));
    kernel_->setArg(argIndex++, *prevMean);
    kernel_->setArg(argIndex++, *nextMean);
    kernel_->setArg(argIndex++, *prevStandardDeviation);
    kernel_->setArg(argIndex++, *nextStandardDeviation);
    OpenCL::getPtr()->getQueue().enqueueNDRangeKernel(*kernel_, cl::NullRange, size2_t(globalWorkSizeX, globalWorkSizeY) , size2_t(workGroupSizeX, workGroupSizeY), waitForEvents, event);
}
Exemple #3
0
void LayerCLGL::notifyAfterTextureInitialization() {
    const auto it = LayerCLGL::clImageSharingMap_.find(texture_);

    if (it != LayerCLGL::clImageSharingMap_.end()) {
        clImage_ = std::static_pointer_cast<cl::Image2DGL>(it->second);
    } else {
        if (glm::all(glm::greaterThan(texture_->getDimensions(), size2_t(0)))) {
            try {
                clImage_ = std::make_shared<cl::Image2DGL>(OpenCL::getPtr()->getContext(),
                                                           CL_MEM_READ_WRITE, GL_TEXTURE_2D, 0,
                                                           texture_->getID());
                LayerCLGL::clImageSharingMap_.insert(TextureCLImageSharingPair(texture_, clImage_));
            } catch (cl::Error& err) {
                LogOpenCLError(err.err());
                throw err;
            }
        }
    }
}
Exemple #4
0
VolumeRaycasterCL::VolumeRaycasterCL()
    : KernelOwner()
    , workGroupSize_(size2_t(8, 8))
    , useGLSharing_(true)
    , outputOffset_(0)
    , outputSize_(1)
    , camera_(nullptr)
    , samplingRate_(2.f)
    , background_(nullptr)
    , defaultBackground_(uvec2(1), DataVec4UInt8::get())
    , lightStruct_(sizeof(utilcl::LightParameters), DataUInt8::get(), BufferUsage::STATIC, nullptr,
                   CL_MEM_READ_ONLY)
    , kernel_(nullptr) {
    light_.ambientColor = vec4(1.f);
    light_.diffuseColor = vec4(1.f);
    light_.specularColor = vec4(1.f);
    light_.specularExponent = 110.f;
    light_.position = vec4(0.7f);
    light_.shadingMode = ShadingMode::Phong;

    compileKernel();
}
Exemple #5
0
size2_t getGlobalWorkGroupSize(size2_t nItems, glm::size2_t localWorkGroupSize)
{
    return localWorkGroupSize*size2_t(glm::ceil(vec2(nItems) / vec2(localWorkGroupSize)));
}
Exemple #6
0
/* 
Algorithm as describe by: 
http://devmag.org.za/2009/05/03/poisson-disk-sampling/
*/
void NoiseProcessor::poissonDisk(Image *img) {
    
    float minDist = size_.get().x;
    minDist /= poissonDotsAlongX_; //min pixel distance between samples
    auto minDist2 = minDist*minDist;
    size2_t gridSize = size2_t(1)+ size2_t(vec2(size_.get()) * (1.0f / minDist));

    auto gridImg = util::make_unique<Image>(gridSize, DataVec2INT32::get());
    auto grid = gridImg->getColorLayer()->getEditableRepresentation<LayerRAM>();

    auto imgData = static_cast<float*>(img->getColorLayer()->getEditableRepresentation<LayerRAM>()->getData());
    auto gridData = static_cast<glm::i32vec2*>(grid->getData());
    util::IndexMapper2D imgIndex(size_.get());
    util::IndexMapper2D gridIndex(gridSize);


    for (size_t i = 0; i < gridSize.x*gridSize.y; i++) {
        gridData[i] = glm::i32vec2(-2 * minDist);
    }

    std::uniform_int_distribution<int> rx(0, size_.get().x);
    std::uniform_int_distribution<int> ry(0, size_.get().y);
    std::uniform_real_distribution<float> rand(0, 1);

    std::vector<glm::i32vec2>  processList;
    std::vector<glm::i32vec2>  samplePoints;

    auto firstPoint = glm::i32vec2(rx(mt_), ry(mt_));
    processList.push_back(firstPoint);
    samplePoints.push_back(firstPoint);

    auto toGrid = [minDist](glm::i32vec2 p)->glm::i32vec2 { return glm::i32vec2(vec2(p)/minDist); };

    gridData[gridIndex(toGrid(firstPoint))] = firstPoint;

    int  someNumber = 30;

    while (processList.size() != 0 && samplePoints.size()  < static_cast<size_t>(poissonMaxPoints_)) {
        std::uniform_int_distribution<size_t> ri(0, processList.size()-1);
        auto i = ri(mt_);
        auto p = processList[i];
        processList.erase(processList.begin() + i);


        for (int j = 0; j < someNumber; j++) {
            auto newPoint = generateRandomPointAround(p, minDist, rand, mt_);
            if (newPoint.x < 0) continue;
            if (newPoint.y < 0) continue;
            if (newPoint.x >= size_.get().x) continue;
            if (newPoint.y >= size_.get().y) continue;

            auto newGridPoint = toGrid(newPoint);
            bool neighbourhood = false;

            int startX = std::max(0, newGridPoint.x - 2);
            int startY = std::max(0, newGridPoint.y - 2);
            int endX = std::min(static_cast<int>(gridSize.x) - 1, newGridPoint.x + 2);
            int endY = std::min(static_cast<int>(gridSize.y) - 1, newGridPoint.y + 2);

            for (int x = startX; x <= endX && !neighbourhood; x++) {
                for (int y = startY; y <= endY && !neighbourhood; y++) {
                    auto p2 = gridData[gridIndex(glm::i32vec2(x, y))];
                    auto dist = glm::distance2(vec2(newPoint), vec2(p2));
                    if (dist < minDist2) {
                        neighbourhood = true;
                    }
                }
            }//*/
            if (!neighbourhood) {
                processList.push_back(newPoint);
                samplePoints.push_back(newPoint);
                auto idx = gridIndex(newGridPoint);
                gridData[idx] = newPoint;
                imgData[imgIndex(newPoint)] = 1;
            }
        }

    }

}