SimonDanisch / GLPlot.jl

Plotting for Julia with OpenGL
Other
74 stars 8 forks source link

"createdisplay not defined" #34

Open joa-quim opened 7 years ago

joa-quim commented 7 years ago

... and after manually installing Plots.jl

julia> using GLPlot, GLAbstraction

julia> window = createdisplay()
ERROR: UndefVarError: createdisplay not defined
SimonDanisch commented 7 years ago

I'm guessing that you're on the master branches! The new api is:

using GLPlot; GLPlot.init()

Sorry for the inconvenience, these are the little things that I need to clarify/clean up before tagging ;)

joa-quim commented 7 years ago

Yes, master it is. And if this is of any use,

julia> GLPlot.init()
WARNING: FileIO.NotInstalledError(:ImageMagick,"")
 in checked_import(::Symbol) at c:\j\.julia\v0.5\FileIO\src\loadsave.jl:12
 in #load#17(::Array{Any,1}, ::Function, ::FileIO.File{FileIO.DataFormat{:PNG}}) at c:\j\.julia\v0.5\FileIO\src\loadsave.jl:81
 in load(::FileIO.File{FileIO.DataFormat{:PNG}}) at c:\j\.julia\v0.5\FileIO\src\loadsave.jl:73
 in #load#13(::Array{Any,1}, ::Function, ::String) at c:\j\.julia\v0.5\FileIO\src\loadsave.jl:45
 in imload(::String) at c:\j\.julia\v0.5\GLPlot\src\GLPlot.jl:20
 in init() at c:\j\.julia\v0.5\GLPlot\src\screen.jl:140
 in eval(::Module, ::Any) at .\boot.jl:234
 in eval_user_input(::Any, ::Base.REPL.REPLBackend) at .\REPL.jl:64
 in macro expansion at .\REPL.jl:95 [inlined]
 in (::Base.REPL.##3#4{Base.REPL.REPLBackend})() at .\event.jl:68
Library ImageMagick is not installed but can load format: FileIO.File{FileIO.DataFormat{:PNG}}("c:\\j\\.julia\\v0.5\\GLPlot\\src\\icons\\record.png")
should we install ImageMagick for you? (y/n):
y
INFO: Start installing ImageMagick...
INFO: Installing ImageMagick v0.1.8
INFO: Building Rmath
INFO: Building ImageMagick
WARNING: Base.WORD_SIZE is deprecated.
  likely near c:\j\.julia\v0.5\ImageMagick\deps\build.jl:42
INFO: Installing ImageMagick library
INFO: Package database updated
ERROR: MethodError: Cannot `convert` an object of type Void to an object of type Array{ColorTypes.BGRA{FixedPointNumbers.UFixed{UInt8,8}},2}
This may have arisen from a call to the constructor Array{ColorTypes.BGRA{FixedPointNumbers.UFixed{UInt8,8}},2}(...),
since type constructors fall back to convert methods.
 in Array{ColorTypes.BGRA{FixedPointNumbers.UFixed{UInt8,8}},2}(::Void) at .\sysimg.jl:53
 in imload(::String) at c:\j\.julia\v0.5\GLPlot\src\GLPlot.jl:20
 in init() at c:\j\.julia\v0.5\GLPlot\src\screen.jl:140
SimonDanisch commented 7 years ago

Uh I saw that exactly one time! And just closing Julia and reopening it solved it. Guess some problem with the compile cache.

joa-quim commented 7 years ago

Indeed, on another new julia window it now worked. But the example on the Image view page doesn´t work

 julia> a = Texture(Vec4[Vec4(i/512,j/512,0,1)for i=1:512, j=1:512])
ERROR: UndefVarError: Vec4 not defined
 in anonymous at .\<missing>:?

julia> c = Texture("examples/mypicture.png")
ERROR: UndefVarError: Texture not defined
SimonDanisch commented 7 years ago

Wow, these are very old... I really need to clean up examples and everything! Best way to test if GLVisualize works is Pkg.test("GLVisualize"). Since GLPlot is just a very thin wrapper over GLVisualize, GLPlot.init(); GLPlot.play_widget(1:10) should be a sufficient best test for now! If you want to do something specific, let me know! Plotting Images should be as straight forward as glplot(image). I'm still not handling any camera adaption for the plotted object, so the image quite likely will float somewhere in 3D space. In that case, this is right now the most straight forward way:

using GLPlot, Plots; GLPlot.init();glvisualize()
Plots.plot(image)
SimonDanisch commented 7 years ago

You can also use the camera control (especially center ( ) and the cube), to get the image full screen!

joa-quim commented 7 years ago

As you may have guessed this is related to the Mirone issue question. What I want is to be able to glplot(image) but in which image is just a mxnx3 UInt8 array with a band interleaved image. Can gplot handle that?

joa-quim commented 7 years ago

As you may have guessed this is related to the Mirone issue question. What I want is to be able to glplot(image) but in which image is just a mxnx3 UInt8 array with a band interleaved image.Can gplot handle that?

On Tue, Sep 27, 2016 at 2:56 PM, Simon notifications@github.com wrote:

Wow, these are very old... I really need to clean up examples and everything! Best way to test if GLVisualize works is Pkg.test("GLVisualize"). Since GLPlot is just a very thin wrapper over GLVisualize, GLPlot.init(); GLPlot.play_widget(1:10) should be a sufficient best test for now! If you want to do something specific, let me know! Plotting Images should be as straight forward as glplot(image). I'm still not handling any camera adaption for the plotted object, so the image quite likely will float somewhere in 3D space. In that case, this is right now the most straight forward way:

using GLPlot, Plots; GLPlot.init();glvisualize() Plots.plot(image)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/SimonDanisch/GLPlot.jl/issues/34#issuecomment-249872315, or mute the thread https://github.com/notifications/unsubscribe-auth/AAgy6QET25i4-APvOx0txW-zLsrik91iks5quSCigaJpZM4KHngv .

SimonDanisch commented 7 years ago

So something like this should work immediately:

img = [RGB(bil_img[x, y, :]...) for x=1:m, y=1:n]
glplot(img)

If that is too expensive, I could think about ways to display it directly ;)

joa-quim commented 7 years ago

Hmm, sorry. What is RGB? I get a

ERROR: UndefVarError: RGB not defined

Let's say I have a

img  = rand(UInt8, 32,32,3)

What I want is to be able to display this without any further reformating/conversion. Just like we would do in Matlab/imahe(img) or Pyplot/imshow(img)

SimonDanisch commented 7 years ago

Well, I'd be surprised, if they don't do any conversions ;) We can always define some function like imshow to do this conversion automatically, but for a function like plot/glplot, this is too broad of a type. RGB comes from ColorTypes/Colors.jl. ;) It should come with GLVisualize, but you have to use it!

joa-quim commented 7 years ago

No, it doesn't come with GLVisualize

julia> using GLVisualize, GLPlot

julia> RGB()
ERROR: UndefVarError: RGB not defined

julia> using Colors

julia> RGB()
RGB{U8}(0.0,0.0,0.0)

but I'm still not there with it's use

img=rand(UInt8, 32,32,3);
julia> image = [RGB(img[x, y, :]...) for x=1:32, y=1:32]
ERROR: ArgumentError: (0x9e,0x39,0x3a) are integers in the range 0-255, but integer inputs are encoded with the UFixed8
  type, an 8-bit type representing 256 discrete values between 0 and 1.
  Consider dividing your input values by 255, for example: RGB{UFixed8}(158/255,57/255,58/255)
  See the READMEs for FixedPointNumbers and ColorTypes for more information.

I ofc don't know what happens in the Matlab internals but this seam pretty direct-no-conversion to me. If hImg is an handle to an image Matlab object, I can do

set(hImg,'CData', img)

and i have the image displayed. Basically what I was trying to avoid is having to make a copy of the image data in order to display it.

SimonDanisch commented 7 years ago

Sorry, that wasn't very clear. I meant its installed when adding GLVisualize, but you need to using it.

The error message spells it all out:

(0x9e,0x39,0x3a) are integers in the range 0-255, but integer inputs are encoded with the UFixed8 type, an 8-bit type representing 256 discrete values between 0 and 1.
  Consider dividing your input values by 255, for example: RGB{UFixed8}(158/255,57/255,58/255)

Admittedly, Colors.jl should just have exactly that constructor, when the error message already knows exactly what to do :D

Yeah, there could be a lot of things going on in set ;)... I've started implementing something like set for GLPlot as well, and it should be relatively simply to add these kind of conversions. If you have good reasons for still not wanting to copy, it's not a big deal to write an operator that directly displays it ;) But it might actually be a bit slower not to copy! I'm not a 100% sure, but these kind of things are very hardware sensitive.

SimonDanisch commented 7 years ago

Admittedly, Colors.jl should just have exactly that constructor, when the error message already knows exactly what to do :D

I guess it's because reinterpret(RGB{U8}, Array(UInt8, 3, m,)) is the preferred way! But still, it really could offer that constructor...

joa-quim commented 7 years ago

My main reason to avoid copies is to avoid memory usage duplication. For big files it may make a difference but I also know that I'm biased by my Matlab experience in Mirone that for compiler reasons has to restrict to the 32 bit world.

SimonDanisch commented 7 years ago

Avoiding copies has been indeed my philosophy as well ;) But the question is, if it makes sense in this particular case. If you run into memory problems, let me know!

joa-quim commented 7 years ago

You are much better suited for judge on that, but I would say there are a lot of operations/memory usage (floating point divisions of an MxNX3 array) involved in RGB{UFixed8}(R/255,G/255,B/255)

I have not memory problems with the problems I work but in future or with lower end computers they are always waiting around the corner.

On Tue, Sep 27, 2016 at 6:28 PM, Simon notifications@github.com wrote:

Avoiding copies has been indeed my philosophy as well ;) But the question is, if it makes sense in this particular case. If you run into memory problems, let me know!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/SimonDanisch/GLPlot.jl/issues/34#issuecomment-249936546, or mute the thread https://github.com/notifications/unsubscribe-auth/AAgy6RJ67OKF9SiD_lSYGSPRoNz388Uxks5quVIqgaJpZM4KHngv .

SimonDanisch commented 7 years ago

That's why reinterpret(RGB{U8}, Array(UInt8, 3, m,n), (m,n)) is preferable ;)

joa-quim commented 7 years ago

Ok, more on this.

julia> using Colors
julia> img=reinterpret(RGB{U8}, rand(UInt8, 32,32,3), (32,32));
julia> using GLPlot; GLPlot.init()
glplot(img)

works, but than clicking on the second from bottom icon ... Tons of warnings (some in red)

in send_value!(::WeakRef, ::Tuple{Int64,Int64,Int64}, ::Int64) at C:\j\.julia\v0.5\Reactive\src\core.jl:133
 in run(::Int64) at C:\j\.julia\v0.5\Reactive\src\core.jl:215
 in glplot_renderloop(::GLWindow.Screen, ::Reactive.Signal{Bool}, ::Reactive.Signal{Bool}) at C:\j\.julia\v0.5\GLPlot\src\screen.jl:54
 in (::GLPlot.##68#78{GLWindow.Screen})() at .\task.jl:360
while loading no file, in expression starting on line 0
WARNING: ErrorException("WriteBlob Failed `C:\\j\\Desktop\\glplot.png' @ error/png.c/MagickPNGErrorHandler/1630")
 in error(::ImageMagick.MagickWand) at C:\j\.julia\v0.5\ImageMagick\src\libmagickwand.jl:152
 in writeimage(::ImageMagick.MagickWand, ::String) at C:\j\.julia\v0.5\ImageMagick\src\libmagickwand.jl:249
 in save_(::String, ::Array{ColorTypes.RGBA{FixedPointNumbers.UFixed{UInt8,8}},2}, ::Bool) at C:\j\.julia\v0.5\ImageMagick\src\ImageMagick.jl:157
 in #save#9(::Array{Any,1}, ::Function, ::FileIO.File{FileIO.DataFormat{:PNG}}, ::Array{ColorTypes.RGBA{FixedPointNumbers.UFixed{UInt8,8}},2}, ::Vararg{Any,N}) at C:\j\.julia\v0.5\ImageMagick\src\ImageMagick.jl:67
 in save(::FileIO.File{FileIO.DataFormat{:PNG}}, ::Array{ColorTypes.RGBA{FixedPointNumbers.UFixed{UInt8,8}},2}, ::Vararg{Any,N}) at C:\j\.julia\v0.5\ImageMagick\src\ImageMagick.jl:67
 in #save#18(::Array{Any,1}, ::Function, ::FileIO.File{FileIO.DataFormat{:PNG}}, ::Array{ColorTypes.RGBA{FixedPointNumbers.UFixed{UInt8,8}},2}, ::Vararg{Any,N}) at C:\j\.julia\v0.5\FileIO\src\loadsave.jl:97
 in save(::FileIO.File{FileIO.DataFormat{:PNG}}, ::Array{ColorTypes.RGBA{FixedPointNumbers.UFixed{UInt8,8}},2}, ::Bool, ::Vararg{Bool,N}) at C:\j\.julia\v0.5\FileIO\src\loadsave.jl:91
 in #save#14(::Array{Any,1}, ::Function, ::String, ::Array{ColorTypes.RGBA{FixedPointNumbers.UFixed{UInt8,8}},2}, ::Vararg{Any,N}) at C:\j\.julia\v0.5\FileIO\src\loadsave.jl:54
 in save(::String, ::Array{ColorTypes.RGBA{FixedPointNumbers.UFixed{UInt8,8}},2}, ::Bool, ::Vararg{Bool,N}) at C:\j\.julia\v0.5\FileIO\src\loadsave.jl:54

....

 in send_value!(::WeakRef, ::Tuple{Int64,Int64,Int64}, ::Int64) at C:\j\.julia\v0.5\Reactive\src\core.jl:133
 in run(::Int64) at C:\j\.julia\v0.5\Reactive\src\core.jl:215
 in glplot_renderloop(::GLWindow.Screen, ::Reactive.Signal{Bool}, ::Reactive.Signal{Bool}) at C:\j\.julia\v0.5\GLPlot\src\screen.jl:54
 in (::GLPlot.##68#78{GLWindow.Screen})() at .\task.jl:360
Failed to push!
    (0,1,0)
joa-quim commented 7 years ago

Well, the reinterpret solution (as is) doesn't really work and actually make crashing the glplot window very easy. As an example, this works and show the correct image.

using GMT, PyPlot
PS = gmt("pscoast -R-10/-3/37/44 -JM12 -W1p -Ba -P");
img = gmt("psconvert =");
imshow(img.image)

but this shows no image and some clicking after it crashes

using GLPlot
GLPot.init()
im2=reinterpret(RGB{U8}, img.image, (size(img.image,1), size(img.image, 2)));
glplot(im2)
SimonDanisch commented 7 years ago

What's the error message? The above error comes from clicking the screenshot icon without having ImageMagick installed correctly. Or no write permission? As I said, you quite likely won't see anything because of this:

I'm still not handling any camera adaption for the plotted object, so the image quite likely will float somewhere in 3D space.
xiuliren commented 7 years ago

I replaced the create_window to GLPlot.init(), https://github.com/SimonDanisch/GLPlot.jl/pull/35

but not sure how to replace the renderloop(window) https://github.com/jingpengwu/GLPlot.jl/blob/77f3fcd925f8445b46ba565400336bdf2624a922/example/image.jl#L26