SimonDanisch / GLPlot.jl

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

3d isosurfaces #15

Open carlosloslas opened 9 years ago

carlosloslas commented 9 years ago

HI @SimonDanisch ,

I am a student doing a hydrodynamics research project and would like to use Julia for part of it. I would need to visualise 3d vector fields and isosurfaces.

My options at the moment are python+paraview or Julia+GLPlot. I personally would like to use Julia, since it is much faster and is something to learn at some point in the future. I have the uncertainty of how reliable GLPlot is atm and how much help I am going to be able to find online. My knowledge is limited but my will and time could make up for it.

Please could you give me some advice? Thanks for your time in advance

SimonDanisch commented 9 years ago

3D Vector fields should be quite easy to include and I actually wanted to implement them over the weekend, but like always I didn't get to it ;) How do you represent the Vector fields? What kind of isosurfaces? If you have a 3D array with intensity values, iso surfaces are readily available ;) Just try examples/volume.jl GLPlot is semi reliable. It should work on most computers with a decent graphic card. It offers a relatively solid basis, but is not very well documented and some important features might be missing. It should be relatively fast compared to other libraries, as I tried to write fairly modern OpenGL code. It's definitely not as fast as highly optimized libraries, but depending on your hardware and use case it might be comparable. Currently you need to work with master: Pkg.checkout("GLPlot"); Pkg.checkout("GLWindow"); Pkg.checkout("GLAbstraction"); Pkg.checkout("ModernGL")

SimonDanisch commented 9 years ago

I'd definitely be happy to help you and improve GLPlot and if you want to contribute I'd be even more happy!

carlosloslas commented 9 years ago

My work is for a third year individual research project. I would be incredibly happy to develop contribute to GLPlot or more to the bug-finding.

I would need to be able to at least start GLPlot and visualise the 3D velocity arrays (U,V,W) fields I have obtained from simple matlab scripts, which i could quickly translate into Julia. The fields represent the induced velocity due to a vortex ring, and at a later stage I would need to plot the isosurfaces corresponding to the lambda2 criterion. Would this be possible with the current state of GLPlot?

carlosloslas commented 9 years ago

I have managed, after a while to get the GLFW library, GLPlot passed the test GLWindow same ModernGL same GLAbstraction failed, INFO: loaded GLFW 3.0.4 Cocoa NSGL chdir menubar dynamic from libglfw 1
2 #version 130 3 in vec2 vertex; 4
5 void main() { 6 gl_Position = vec4(vertex, 0.0, 1.0); 7 } 8
ERROR: vertex ERROR: 0:2: '' : version '130' is not supported ERROR: 0:3: '' : #version required and missing.

in error at error.jl:21 in readshader at /Users/closadalastra/.julia/v0.3/GLAbstraction/src/GLShader.jl:48 in GLProgram at /Users/closadalastra/.julia/v0.3/GLAbstraction/src/GLShader.jl:114 in include at /Applications/Julia-0.3.2.app/Contents/Resources/julia/lib/julia/sys.dylib in include_from_node1 at loading.jl:128 in process_options at /Applications/Julia-0.3.2.app/Contents/Resources/julia/lib/julia/sys.dylib in _start at /Applications/Julia-0.3.2.app/Contents/Resources/julia/lib/julia/sys.dylib (repeats 2 times) while loading /Users/closadalastra/.julia/v0.3/GLAbstraction/test/runtests.jl, in expression starting on line 55

============================[ ERROR: GLAbstraction ]============================

failed process: Process(/Applications/Julia-0.3.2.app/Contents/Resources/julia/bin/julia /Users/closadalastra/.julia/v0.3/GLAbstraction/test/runtests.jl, ProcessExited(1)) [1]

INFO: No packages to install, update or remove ERROR: GLAbstraction had test errors in error at error.jl:21 in test at pkg/entry.jl:715 in anonymous at pkg/dir.jl:28 in cd at /Applications/Julia-0.3.2.app/Contents/Resources/julia/lib/julia/sys.dylib in cd at pkg/dir.jl:28 in test at pkg.jl:67

I'm not sure what is going wrong, could you please give me a hand?

SimonDanisch commented 9 years ago

If GLPlot passes everything should be fine... I think I hard coded something in GLAbstraction, which is not compatible with your video card;) On 8 Dec 2014 22:17, "carlosloslas" notifications@github.com wrote:

I have managed, after a while to get the GLFW library, GLPlot passed the test GLWindow same ModernGL same GLAbstraction failed, INFO: loaded GLFW 3.0.4 Cocoa NSGL chdir menubar dynamic from libglfw 1

2 #version 130 3 in vec2 vertex; 4

5 void main() { 6 gl_Position = vec4(vertex, 0.0, 1.0); 7 } 8

ERROR: vertex ERROR: 0:2: '' : version '130' is not supported ERROR: 0:3: '' : #version required and missing.

in error at error.jl:21 in readshader at /Users/closadalastra/.julia/v0.3/GLAbstraction/src/GLShader.jl:48 in GLProgram at /Users/closadalastra/.julia/v0.3/GLAbstraction/src/GLShader.jl:114 in include at /Applications/Julia-0.3.2.app/Contents/Resources/julia/lib/julia/sys.dylib in include_from_node1 at loading.jl:128 in process_options at /Applications/Julia-0.3.2.app/Contents/Resources/julia/lib/julia/sys.dylib in _start at /Applications/Julia-0.3.2.app/Contents/Resources/julia/lib/julia/sys.dylib (repeats 2 times) while loading /Users/closadalastra/.julia/v0.3/GLAbstraction/test/runtests.jl, in expression starting on line 55

============================[ ERROR: GLAbstraction ]============================

failed process: Process(/Applications/Julia-0.3.2.app/Contents/Resources/julia/bin/julia /Users/closadalastra/.julia/v0.3/GLAbstraction/test/runtests.jl, ProcessExited(1)) [1]

INFO: No packages to install, update or remove ERROR: GLAbstraction had test errors in error at error.jl:21 in test at pkg/entry.jl:715 in anonymous at pkg/dir.jl:28 in cd at /Applications/Julia-0.3.2.app/Contents/Resources/julia/lib/julia/sys.dylib in cd at pkg/dir.jl:28 in test at pkg.jl:67

I'm not sure what is going wrong, could you please give me a hand?

— Reply to this email directly or view it on GitHub https://github.com/SimonDanisch/GLPlot.jl/issues/15#issuecomment-66188893 .

SimonDanisch commented 9 years ago

If the installation of GLFW wasn't self explanatory, would you mind to file an issue? I wanted to work on that anyway... So back to your question. If I understand you correctly, what you have is a cube described like this:

Immutable Velocity{T}
u::T
v::T
w::T
end
velocities::Array{Velocity{T}, 3} = some_calculation()
#T is hopefully a Float32, as you wouldn't need conversion than. 

Then you probably want to have these visualizations: vectorfield The origin of the vector would be, for example, the middle point of the grid cell? Then you probably want the magnitude of the vector visualized, as a volume rendering or so? And then a surface at all the cells, where your lambda2 criterion holds? All of this should be possible with some modification of the current visualization methods. If we have some more time, we could make it even nice, and probably create trails and such...

Cheers, Simon

carlosloslas commented 9 years ago

Hi Simon,

The GLFW issue wasn't too bad, but I was very close to stop trying. I will file an issue tomorrow detailing roughly what I did (im based at Southampton, UK and its early morning atm). In terms of visualisation of velocity fields what you talk say makes perfect sense and would fit with my needs. Timingwise I would need to be able to plot vector fields (arrows) within the next week or so. And isosurfaces by the end of this year. How would this fit in your plans? I know its quite tight but the visualisation is the main part of the project.

SimonDanisch commented 9 years ago

Okay cool. I'll look into this today. It shouldn't be a big problem, if it doesn't have to be completely polished from the beginning!

carlosloslas commented 9 years ago

Hi Simon,

I think everything reads very nicely and if we work together this could have a very good result. Both for the development of GLPlot and my project.

I have been encouraged by my supervisor to make a decision about which language route to take (ParaView+Python or Julia+GLPlot). I have given myself until thursday to solidly work on Julia+GLPlot, and if I don't manage to convince him switch to the other option, which is way less interesting. The important thing I would need to visualise would be isosurfaces where Lamda2 holds (Jeong&Husain1994) and next year (around February) 3d volume rendering.

The vector plots are a good starting point but its not the aim of the project. Although if you could send me some sample code to generate something similar to the pic you sent me would be very much appreciated. (if the full development of the arrow plots could slow down the development of the isosurfaces, I would encourage you to fully develop the isosurface stuff first)

I understand all this is under development, so Im not asking for wonderful colours and patterns but more something that works and has some scope of colour variation just to distinguish the changes if variables.

I hope this clarifies both my great interest in Julia+GLPlot and my needs to be able to continue with this option.

SimonDanisch commented 9 years ago

If you can create an array of the type Array{Float32, 3}, that is one where lamda2 holds and zero elsewhere, you can already plot that. It's a little bit wasteful, but would do the job I guess ;)

SimonDanisch commented 9 years ago

Okay proof of concept for the vector field is running: Vectorfield

carlosloslas commented 9 years ago

Perfect, thats a very promising and quick start! Which function should I call from the GLPlot package to plot/display the vector field?

SimonDanisch commented 9 years ago

None, I haven't pushed the change yet ;)

2014-12-09 18:21 GMT+01:00 carlosloslas notifications@github.com:

Perfect, thats a very promising and quick start! Which function should I call from the GLPlot package to plot/display the vector field?

— Reply to this email directly or view it on GitHub https://github.com/SimonDanisch/GLPlot.jl/issues/15#issuecomment-66320622 .

carlosloslas commented 9 years ago

ok, no problem, well done for achieving it ;) I don't think it needs more visual side of things, other than some kind of direction. If you just slightly increase the diameter of one side of the cylinder creating a cone could work instead of trying to create an arrow.(assuming thats how you plot those segments)(sorry if this is something completely different, I am keen on helping but don't have experience in creating graphics.)

should I update GLAbstraction? I read further up that there has been a commit. (GLAbstraction.jl 17)

SimonDanisch commented 9 years ago

That's not necessary, it was the error that you got from the test, which was an error in the test file itself, not GLAbstraction. Well, you can use any 3D object you want! I've an OBJ importer, which is one of the most common 3D formats out there. But having something like a cone seems to be a good idea!

2014-12-09 18:33 GMT+01:00 carlosloslas notifications@github.com:

ok, no problem, well done for achieving it ;) I don't think it needs more visual side of things, other than some kind of direction. If you just slightly increase the diameter of one side of the cylinder creating a cone could work instead of trying to create an arrow.(assuming thats how you plot those segments)(sorry if this is something completely different, I am keen on helping but don't have experience in creating graphics.)

should I update GLAbstraction? I read further up that there has been a commit. (GLAbstraction.jl 17)

— Reply to this email directly or view it on GitHub https://github.com/SimonDanisch/GLPlot.jl/issues/15#issuecomment-66322605 .

SimonDanisch commented 9 years ago

Okay merged! just look at examples/vectorfield.jl Its still only a cube, but I guess that can wait for now ;)

carlosloslas commented 9 years ago

seem to be getting some errors, not sure why though,

julia> window = createdisplay(w=1000,h=1000,eyeposition=Vec3(1.,1.,1.), lookat=Vec3(0.,0.,0.)); ERROR: key not found: Window(GLPlot) in update at /Users/closadalastra/.julia/v0.3/GLWindow/src/reactglfw.jl:69 in window_position at /Users/closadalastra/.julia/v0.3/GLWindow/src/reactglfw.jl:90 in createwindow at /Users/closadalastra/.julia/v0.3/GLWindow/src/reactglfw.jl:264 in createdisplay at /Users/closadalastra/.julia/v0.3/GLPlot/src/GLPlot.jl:47

julia> function funcy(x,y,z) Vec3(sin(x),cos(y),sin(z)) end funcy (generic function with 1 method)

julia> N = 20;

julia> directions = Vec3[funcy(4x/N,4y/N,4z/N) for x=1:N,y=1:N, z=1:N];

julia> obj = glplot(directions); ERROR: pcamera not defined in glplot at /Users/closadalastra/.julia/v0.3/GLPlot/src/GLPlot.jl:24

julia> renderloop(window) signal (15): Terminated: 15 kevent at /usr/lib/system/libsystem_kernel.dylib (unknown line) Terminated: 15

Im hoping is a package missing or something like that.

SimonDanisch commented 9 years ago

Did you do Pkg.checkout("GLWindow")?

carlosloslas commented 9 years ago

Sorry, I pulled and checked out manually GLPlot (from git in the directory with the terminal) and didn't do the same for the rest of the GL packages, posted error, and followed your answer checking out 'Pkg.checkout("...")' for all the GL packages (GLPlot, GLWindow, GLAbstraction, ModernGL). The vector field works very nicely, will start to implement that on the project's algorithms.

Thank you very much, everything is looking great! Hope the rest of the things come as quickly as this one, ;) (isosurfaces would be more than amazing, not sure how advance is the development of those)

There was some errors during the checkout of the packages, not sure if they are of any relevance, post them just in case.

julia> Pkg.checkout("GLPlot") INFO: Checking out GLPlot master... ERROR: GLPlot is dirty, bailing in error at error.jl:21 in anonymous at pkg/entry.jl:178 in transact at pkg/git.jl:81 in _checkout at pkg/entry.jl:177 in checkout at pkg/entry.jl:192 in anonymous at pkg/dir.jl:28 in cd at /Applications/Julia-0.3.2.app/Contents/Resources/julia/lib/julia/sys.dylib in cd at pkg/dir.jl:28 in checkout at pkg.jl:33

julia> Pkg.checkout("GLWindow") INFO: Checking out GLWindow master... INFO: Pulling GLWindow latest master... INFO: No packages to install, update or remove

julia> Pkg.checkout("GLAbstraction") INFO: Checking out GLAbstraction master... INFO: Pulling GLAbstraction latest master... INFO: Cloning cache of Datetime from git://github.com/quinnj/Datetime.jl.git INFO: Cloning cache of Lumberjack from git://github.com/forio/Lumberjack.jl.git INFO: Cloning cache of UUID from git://github.com/forio/UUID.jl.git INFO: Installing Datetime v0.1.7 INFO: Installing Lumberjack v0.0.3 INFO: Installing UUID v0.0.2 INFO: Building Datetime WARNING: The Datetime.jl package is deprecated, but will remain maintained for the 0.3 release. Please consider using the Dates.jl package instead, which mirrors the Dates module in Base Julia in 0.4

julia> Pkg.checkout("ModernGL") INFO: Checking out ModernGL master... INFO: Pulling ModernGL latest master... INFO: No packages to install, update or remove

SimonDanisch commented 9 years ago

No worries =) I'm looking forward to the graphics! ERROR: GLPlot is dirty, bailing isn't good. But if the vector field works, it should mean you have the newest version! I always just do git pull origin master in the folder and if something is dirty i do git reset --hard HEAD ;) Well as I said, the iso-surfaces should be working already. Try examples/volume.jl, and use your own Array{Float32,3}, if you want something to play around with. I actually just ported the marching tetrahedra algorithm from Meshes.jl and optimized it to work with GLPlot. Haven't wrapped it into the api yet, but it works pretty well! So I'd say we're on the save side with your demands =)

carlosloslas commented 9 years ago

I think this looks as if it could work very well! I haven't got around implementing the algorithms I had in another language, but as you said the tools so everything should work. Will comment on outcome of meeting with supervisor and what else he thinks I will need to be able to do.