From cfbc73c854a43d06ac7387e5d5437a45a177db85 Mon Sep 17 00:00:00 2001 From: Jakub Mitura <53857487+jakubMitura14@users.noreply.github.com> Date: Thu, 4 Nov 2021 19:31:57 +0100 Subject: [PATCH] fixing mask subtraction --- Project.toml | 2 +- build/display/GLFW/shadersEtc/Uniforms.jl | 12 +- docs/Project.toml | 2 +- docs/src/loadExampleData.jl | 151 +++++++++++++++++- src/display/GLFW/SegmentationDisplay.jl | 2 +- src/display/GLFW/shadersEtc/Uniforms.jl | 26 ++- .../reactToKeyboard/MaskDiffrence.jl | 7 +- 7 files changed, 180 insertions(+), 22 deletions(-) diff --git a/Project.toml b/Project.toml index a2f1cfe..2f7c070 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MedEye3d" uuid = "48a1af7b-3279-4eeb-8f2b-7ca229bb51b1" authors = ["M.D Jakub Mitura <53857487+jakubMitura14@users.noreply.github.com>"] -version = "0.2.0" +version = "0.3.0" [deps] ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" diff --git a/build/display/GLFW/shadersEtc/Uniforms.jl b/build/display/GLFW/shadersEtc/Uniforms.jl index 21df125..6bd71e6 100644 --- a/build/display/GLFW/shadersEtc/Uniforms.jl +++ b/build/display/GLFW/shadersEtc/Uniforms.jl @@ -122,19 +122,19 @@ uniform!(myuniform, rand(Cfloat, 4, 4)) """ function uniform! end -@generated function uniform!(location::GLint, values::Vararg{T, N}) where {N, T <: Real} +@generated function uniform!(location, values::Vararg{T, N}) where {N, T <: Real} suffix = _type_suffix(T) glFunc = Symbol("glUniform$(N)$suffix") return :( $(glFunc)(location, values...) ) end -@generated function uniform!(location::GLint, vector::SVector{N, T}) where {N, T <: Real} +@generated function uniform!(location, vector::SVector{N, T}) where {N, T <: Real} suffix = _type_suffix(T) glFunc = Symbol("glUniform$(N)$(suffix)v") return :( $(glFunc)(location, 1, vector) ) end -@generated function uniform!(location::GLint, matrix::SMatrix{N, M, T}, transposed::Bool = false) where {N, M, T <: Real} +@generated function uniform!(location, matrix::SMatrix{N, M, T}, transposed::Bool = false) where {N, M, T <: Real} glFunc = Symbol( if N == M "glUniformMatrix$(N)fv" @@ -145,12 +145,12 @@ end return :( $(glFunc)(location, 1, transposed, Cfloat[matrix...]) ) end -function uniform!(location::GLint, vector::AbstractVector{T}) where {T <: Real} +function uniform!(location, vector::AbstractVector{T}) where {T <: Real} N = length(vector) uniform!(location, SVector{N, T}(vector...)) end -function uniform!(location::GLint, matrix::AbstractMatrix{T}, transposed::Bool = false) where {T <: Real} +function uniform!(location, matrix::AbstractMatrix{T}, transposed::Bool = false) where {T <: Real} N, M = size(matrix) uniform!(location, SMatrix{N, M, T}(matrix), transposed) end @@ -159,7 +159,7 @@ end Gets the location of the uniform variable identified by `name`. """ -getuniform(program::GLuint, name::SymString) = glGetUniformLocation(program, string(name)) +getuniform(program, name::SymString) = glGetUniformLocation(program, string(name)) """ @uniforms foo, bar, ... = program Get the location of `foo`, `bar` and `etc` from `program`, diff --git a/docs/Project.toml b/docs/Project.toml index 8d2b6b3..2f7c070 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -1,7 +1,7 @@ name = "MedEye3d" uuid = "48a1af7b-3279-4eeb-8f2b-7ca229bb51b1" authors = ["M.D Jakub Mitura <53857487+jakubMitura14@users.noreply.github.com>"] -version = "0.1.0" +version = "0.3.0" [deps] ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" diff --git a/docs/src/loadExampleData.jl b/docs/src/loadExampleData.jl index 4409860..1ca91b2 100644 --- a/docs/src/loadExampleData.jl +++ b/docs/src/loadExampleData.jl @@ -146,7 +146,152 @@ SegmentationDisplay.coordinateDisplay(textureSpecificationsPETCT ,fractionOfMain Main.SegmentationDisplay.passDataForScrolling(mainScrollDat); -using GLFW -GLFW.PollEvents() -# SegmentationDisplay \ No newline at end of file + + + + + + + + +# SegmentationDisplay + +#I use Simple ITK as most robust +using MedEye3d, Conda,PyCall,Pkg + +Conda.pip_interop(true) +Conda.pip("install", "SimpleITK") +Conda.pip("install", "h5py") +sitk = pyimport("SimpleITK") +np= pyimport("numpy") + +import MedEye3d +import MedEye3d.ForDisplayStructs +import MedEye3d.ForDisplayStructs.TextureSpec +using ColorTypes +import MedEye3d.SegmentationDisplay + +import MedEye3d.DataStructs.ThreeDimRawDat +import MedEye3d.DataStructs.DataToScrollDims +import MedEye3d.DataStructs.FullScrollableDat +import MedEye3d.ForDisplayStructs.KeyboardStruct +import MedEye3d.ForDisplayStructs.MouseStruct +import MedEye3d.ForDisplayStructs.ActorWithOpenGlObjects +import MedEye3d.OpenGLDisplayUtils +import MedEye3d.DisplayWords.textLinesFromStrings +import MedEye3d.StructsManag.getThreeDims + +""" +given directory (dirString) to file/files it will return the simple ITK image for futher processing +isMHD when true - data in form of folder with dicom files +isMHD when true - we deal with MHD data +""" +function getImageFromDirectory(dirString,isMHD::Bool, isDicomList::Bool) + #simpleITK object used to read from disk + reader = sitk.ImageSeriesReader() + if(isDicomList)# data in form of folder with dicom files + dicom_names = reader.GetGDCMSeriesFileNames(dirString) + reader.SetFileNames(dicom_names) + return reader.Execute() + elseif(isMHD) #mhd file + return sitk.ReadImage(dirString) + end +end#getPixelDataAndSpacing + +""" +becouse Julia arrays is column wise contiguus in memory and open GL expects row wise we need to rotate and flip images +pixels - 3 dimensional array of pixel data +""" +function permuteAndReverse(pixels) + pixels= permutedims(pixels, (3,2,1)) + sizz=size(pixels) + for i in 1:sizz[1] + for j in 1:sizz[3] + pixels[i,:,j] = reverse(pixels[i,:,j]) + end# + end# + return pixels + end#permuteAndReverse + +""" +given simple ITK image it reads associated pixel data - and transforms it by permuteAndReverse functions +it will also return voxel spacing associated with the image +""" +function getPixelsAndSpacing(image) + pixelsArr = np.array(sitk.GetArrayViewFromImage(image))# we need numpy in order for pycall to automatically change it into julia array + spacings = image.GetSpacing() + return ( permuteAndReverse(pixelsArr), spacings ) +end#getPixelsAndSpacing + +exampleLabel = "C:\\GitHub\\JuliaMedPipe\\data\\liverPrimData\\training-labels\\label\\liver-seg002.mhd" +exampleCTscann = "C:\\GitHub\\JuliaMedPipe\\data\\liverPrimData\\training-scans\\scan\\liver-orig002.mhd" + + + +imagePureCT= getImageFromDirectory(exampleCTscann,true,false) +imageMask= getImageFromDirectory(exampleLabel,true,false) + +ctPixelsPure, ctSpacingPure = getPixelsAndSpacing(imagePureCT) +maskPixels, maskSpacing =getPixelsAndSpacing(imageMask) + +datToScrollDimsB= MedEye3d.ForDisplayStructs.DataToScrollDims(imageSize= size(ctPixelsPure) ,voxelSize=ctSpacingPure, dimensionToScroll = 3 ); +# example of texture specification used - we need to describe all arrays we want to display +listOfTexturesSpec = [ + TextureSpec{UInt8}( + name = "goldStandardLiver", + numb= Int32(1), + color = RGB(1.0,0.0,0.0) + ,minAndMaxValue= Int8.([0,1]) + ), + TextureSpec{UInt8}( + name = "manualModif", + numb= Int32(2), + color = RGB(0.0,1.0,0.0) + ,minAndMaxValue= UInt8.([0,1]) + ,isEditable = true + ), + + TextureSpec{Int16}( + name= "CTIm", + numb= Int32(3), + isMainImage = true, + minAndMaxValue= Int16.([0,100])) + ]; + + fractionOfMainIm= Float32(0.8); + """ + If we want to display some text we need to pass it as a vector of SimpleLineTextStructs + """ + import MedEye3d.DisplayWords.textLinesFromStrings + + mainLines= textLinesFromStrings(["main Line1", "main Line 2"]); + supplLines=map(x-> textLinesFromStrings(["sub Line 1 in $(x)", "sub Line 2 in $(x)"]), 1:size(ctPixelsPure)[3] ); + + """ + If we want to pass 3 dimensional array of scrollable data""" + import MedEye3d.StructsManag.getThreeDims + + tupleVect = [("goldStandardLiver",maskPixels) ,("CTIm",ctPixelsPure),("manualModif",zeros(UInt8,size(ctPixelsPure)) ) ] + slicesDat= getThreeDims(tupleVect ) + + """ + Holds data necessary to display scrollable data + """ + mainScrollDat = FullScrollableDat(dataToScrollDims =datToScrollDimsB + ,dimensionToScroll=1 # what is the dimension of plane we will look into at the beginning for example transverse, coronal ... + ,dataToScroll= slicesDat + ,mainTextToDisp= mainLines + ,sliceTextToDisp=supplLines ); + + + SegmentationDisplay.coordinateDisplay(listOfTexturesSpec ,fractionOfMainIm ,datToScrollDimsB ,1000); + + Main.SegmentationDisplay.passDataForScrolling(mainScrollDat); + + + + + using GLFW + GLFW.PollEvents() + \ No newline at end of file diff --git a/src/display/GLFW/SegmentationDisplay.jl b/src/display/GLFW/SegmentationDisplay.jl index ba6f831..b995ed1 100644 --- a/src/display/GLFW/SegmentationDisplay.jl +++ b/src/display/GLFW/SegmentationDisplay.jl @@ -61,7 +61,7 @@ function coordinateDisplay(listOfTextSpecsPrim::Vector{TextureSpec} # than we set those ..Uniforms, open gl types and using data from arguments to fill texture specifications mainImageUnifs,listOfTextSpecsMapped= assignUniformsAndTypesToMasks(listOfTextSpecs,shader_program,windowControlStruct) - @info "listOfTextSpecsMapped" listOfTextSpecsMapped + #@info "listOfTextSpecsMapped" listOfTextSpecsMapped #initializing object that holds data reqired for interacting with opengl initializedTextures = initializeTextures(listOfTextSpecsMapped,calcDimStruct) diff --git a/src/display/GLFW/shadersEtc/Uniforms.jl b/src/display/GLFW/shadersEtc/Uniforms.jl index 21df125..4393396 100644 --- a/src/display/GLFW/shadersEtc/Uniforms.jl +++ b/src/display/GLFW/shadersEtc/Uniforms.jl @@ -5,7 +5,7 @@ managing uniform values - global values in shaders module Uniforms using StaticArrays,ModernGL,Rocket, ..ForDisplayStructs, Dictionaries, Parameters, ColorTypes -export changeMainTextureContribution,changeTextureContribution,coontrolMinMaxUniformVals,createStructsDict, setCTWindow,setMaskColor,setTextureVisibility, setTypeOfMainSampler! +export isMaskDiffViss,changeMainTextureContribution,changeTextureContribution,coontrolMinMaxUniformVals,createStructsDict, setCTWindow,setMaskColor,setTextureVisibility, setTypeOfMainSampler! export @uniforms export @uniforms! @@ -122,19 +122,19 @@ uniform!(myuniform, rand(Cfloat, 4, 4)) """ function uniform! end -@generated function uniform!(location::GLint, values::Vararg{T, N}) where {N, T <: Real} +@generated function uniform!(location, values::Vararg{T, N}) where {N, T <: Real} suffix = _type_suffix(T) glFunc = Symbol("glUniform$(N)$suffix") return :( $(glFunc)(location, values...) ) end -@generated function uniform!(location::GLint, vector::SVector{N, T}) where {N, T <: Real} +@generated function uniform!(location, vector::SVector{N, T}) where {N, T <: Real} suffix = _type_suffix(T) glFunc = Symbol("glUniform$(N)$(suffix)v") return :( $(glFunc)(location, 1, vector) ) end -@generated function uniform!(location::GLint, matrix::SMatrix{N, M, T}, transposed::Bool = false) where {N, M, T <: Real} +@generated function uniform!(location, matrix::SMatrix{N, M, T}, transposed::Bool = false) where {N, M, T <: Real} glFunc = Symbol( if N == M "glUniformMatrix$(N)fv" @@ -145,12 +145,12 @@ end return :( $(glFunc)(location, 1, transposed, Cfloat[matrix...]) ) end -function uniform!(location::GLint, vector::AbstractVector{T}) where {T <: Real} +function uniform!(location, vector::AbstractVector{T}) where {T <: Real} N = length(vector) uniform!(location, SVector{N, T}(vector...)) end -function uniform!(location::GLint, matrix::AbstractMatrix{T}, transposed::Bool = false) where {T <: Real} +function uniform!(location, matrix::AbstractMatrix{T}, transposed::Bool = false) where {T <: Real} N, M = size(matrix) uniform!(location, SMatrix{N, M, T}(matrix), transposed) end @@ -159,7 +159,7 @@ end Gets the location of the uniform variable identified by `name`. """ -getuniform(program::GLuint, name::SymString) = glGetUniformLocation(program, string(name)) +getuniform(program, name::SymString) = glGetUniformLocation(program, string(name)) """ @uniforms foo, bar, ... = program Get the location of `foo`, `bar` and `etc` from `program`, @@ -259,6 +259,18 @@ function setMaskColor(color::RGB, uniformsStore ::MaskTextureUniforms) end#setMaskColor +""" +sets color of the mask + +""" +function isMaskDiffViss( isMaskDiffrenceVisUnifs) + @uniforms! begin + isMaskDiffrenceVisUnifs:=1 + end + +end#isMaskDiffViss + + """ sets visibility of the texture diff --git a/src/display/reactingToMouseKeyboard/reactToKeyboard/MaskDiffrence.jl b/src/display/reactingToMouseKeyboard/reactToKeyboard/MaskDiffrence.jl index bbe80a6..6da3787 100644 --- a/src/display/reactingToMouseKeyboard/reactToKeyboard/MaskDiffrence.jl +++ b/src/display/reactingToMouseKeyboard/reactToKeyboard/MaskDiffrence.jl @@ -74,9 +74,10 @@ function displayMaskDiffrence(maskA::TextureSpec, maskB::TextureSpec,actor::Sync reactivateMainObj(shader_prog, newForDisp.vbo,actor.actor.calcDimsStruct ) activateTextures(listOfTextSpecsc ) #making diffrence visible - @uniforms! begin - dispObj.mainImageUniforms.isMaskDiffrenceVis:=1 - end + isMaskDiffViss(dispObj.mainImageUniforms.isMaskDiffrenceVis) + # @uniforms! begin + # dispObj.mainImageUniforms.isMaskDiffrenceVis:=1 + # end setTextureVisibility(false,maskA.uniforms ) setTextureVisibility(false,maskB.uniforms ) basicRender(actor.actor.mainForDisplayObjects.window)