Beispiel #1
0
void VolumeRaycasterCL::volumeRaycast(const Volume* volume, const Layer* entryPoints,
                                      const Layer* exitPoints, const Layer* transferFunction,
                                      Layer* outImage,
                                      const VECTOR_CLASS<cl::Event>* waitForEvents /*= nullptr*/,
                                      cl::Event* event /*= nullptr*/) {
    size2_t localWorkGroupSize(workGroupSize_);
    size2_t globalWorkGroupSize(getGlobalWorkGroupSize(outputSize_.x, localWorkGroupSize.x),
                                getGlobalWorkGroupSize(outputSize_.y, localWorkGroupSize.y));

    if (useGLSharing_) {
        // SyncCLGL will synchronize with OpenGL upon creation and destruction
        SyncCLGL glSync;
        const LayerCLGL* entryCL = entryPoints->getRepresentation<LayerCLGL>();
        const LayerCLGL* exitCL = exitPoints->getRepresentation<LayerCLGL>();
        LayerCLGL* outImageCL = outImage->getEditableRepresentation<LayerCLGL>();
        const VolumeCLGL* volumeCL = volume->getRepresentation<VolumeCLGL>();
        const LayerCLGL* transferFunctionCL = transferFunction->getRepresentation<LayerCLGL>();
        const LayerCLBase* background;
        if (background_) {
            background = background_->getRepresentation<LayerCLGL>();
            glSync.addToAquireGLObjectList(static_cast<const LayerCLGL*>(background));
        } else {
            background = defaultBackground_.getRepresentation<LayerCL>();
        }
        // Shared objects must be acquired before use.
        glSync.addToAquireGLObjectList(entryCL);
        glSync.addToAquireGLObjectList(exitCL);
        glSync.addToAquireGLObjectList(outImageCL);
        glSync.addToAquireGLObjectList(volumeCL);
        glSync.addToAquireGLObjectList(transferFunctionCL);

        // Acquire all of the objects at once
        glSync.aquireAllObjects();

        volumeRaycast(volume, volumeCL, background, entryCL, exitCL, transferFunctionCL, outImageCL,
                      globalWorkGroupSize, localWorkGroupSize, waitForEvents, event);
    } else {
        const LayerCL* entryCL = entryPoints->getRepresentation<LayerCL>();
        const LayerCL* exitCL = exitPoints->getRepresentation<LayerCL>();
        LayerCL* outImageCL = outImage->getEditableRepresentation<LayerCL>();
        const VolumeCL* volumeCL = volume->getRepresentation<VolumeCL>();
        const LayerCL* transferFunctionCL = transferFunction->getRepresentation<LayerCL>();
        // const LayerCL* background = background_->getRepresentation<LayerCL>();
        const LayerCL* background;
        if (background_) {
            background = background_->getRepresentation<LayerCL>();
        } else {
            background = defaultBackground_.getRepresentation<LayerCL>();
        }
        volumeRaycast(volume, volumeCL, background, entryCL, exitCL, transferFunctionCL, outImageCL,
                      globalWorkGroupSize, localWorkGroupSize, waitForEvents, event);
    }
}
void VolumeMaxCLProcessor::process() {
    if (!kernel_) return;
    auto volume = inport_.getData();

    const size3_t dim{volume->getDimensions()};
    const size3_t outDim{glm::ceil(vec3(dim) / static_cast<float>(volumeRegionSize_.get()))};
    // const DataFormatBase* volFormat = inport_.getData()->getDataFormat(); // Not used

    if (!volumeOut_ || volumeOut_->getDimensions() != outDim) {
        volumeOut_ = std::make_shared<Volume>(outDim, DataUInt8::get());
        // volumeOut_ = std::unique_ptr<Volume>( new Volume(outDim, DataUInt32::get()) );
        // volumeOut_ = std::unique_ptr<Volume>( new Volume(outDim, DataFloat32::get()) );
        // Use same transformation to make sure that they are render at the same location
        volumeOut_->setModelMatrix(volume->getModelMatrix());
        volumeOut_->setWorldMatrix(volume->getWorldMatrix());
        outport_.setData(volumeOut_);
    }

    size3_t localWorkGroupSize(workGroupSize_.get());
    size3_t globalWorkGroupSize(getGlobalWorkGroupSize(outDim.x, localWorkGroupSize.x),
                                getGlobalWorkGroupSize(outDim.y, localWorkGroupSize.y),
                                getGlobalWorkGroupSize(outDim.z, localWorkGroupSize.z));

    if (useGLSharing_.get()) {
        SyncCLGL glSync;
        const VolumeCLGL* volumeCL = volume->getRepresentation<VolumeCLGL>();
        VolumeCLGL* volumeOutCL = volumeOut_->getEditableRepresentation<VolumeCLGL>();

        glSync.addToAquireGLObjectList(volumeCL);
        glSync.addToAquireGLObjectList(volumeOutCL);
        glSync.aquireAllObjects();

        executeVolumeOperation(volume.get(), volumeCL, volumeOutCL, outDim, globalWorkGroupSize,
                               localWorkGroupSize);
    } else {
        const VolumeCL* volumeCL = volume->getRepresentation<VolumeCL>();
        VolumeCL* volumeOutCL = volumeOut_->getEditableRepresentation<VolumeCL>();
        executeVolumeOperation(volume.get(), volumeCL, volumeOutCL, outDim, globalWorkGroupSize,
                               localWorkGroupSize);
    }
}
void MeshEntryExitPointsCL::computeEntryExitPoints(
    const mat4& NDCToTextureMat, const mat4& worldToTextureMat, const BufferCLBase* vertices,
    const BufferCLBase* indices, int nIndices, const LayerCLBase* entryPointsCL,
    const LayerCLBase* exitPointsCL, const uvec2& outportDim,
    const VECTOR_CLASS<cl::Event>* waitForEvents /*= nullptr*/, cl::Event* event /*= nullptr*/) {
    size2_t localWorkGroupSize(workGroupSize_);
    size2_t globalWorkGroupSize(getGlobalWorkGroupSize(outportDim.x, localWorkGroupSize.x),
                                getGlobalWorkGroupSize(outportDim.y, localWorkGroupSize.y));

    try {
        cl_uint arg = 0;
        kernel_->setArg(arg++, NDCToTextureMat);
        kernel_->setArg(arg++, worldToTextureMat);
        kernel_->setArg(arg++, *vertices);
        kernel_->setArg(arg++, *indices);
        kernel_->setArg(arg++, nIndices);
        kernel_->setArg(arg++, *entryPointsCL);
        kernel_->setArg(arg++, *exitPointsCL);
        OpenCL::getPtr()->getQueue().enqueueNDRangeKernel(
            *kernel_, cl::NullRange, globalWorkGroupSize, localWorkGroupSize, waitForEvents, event);
    } catch (cl::Error& err) {
        LogError(getCLErrorString(err));
    }
}