 So, I am going to just do a quick talk on 3D visualization with DBTK and Maya V2. The outline is as follows, I am going to introduce basics of visualization. Okay, so I will just do a quick overview of graphics and then look at two tools which are very handy for the scientists called visual and MLAB just to quick demos of those. Then go over a graphics primer and then look at how you actually represent data, scientific data for 3D visualization and then actually get on to the details of VTK, TVTK and Maya V2. So I suspect I will only do the first part this morning. So the question is what is visualization? So what we are looking to do here is to make some visible representation of data and typically we are looking at scientific data and what we are really interested in it is in cross platform 2D and 3D visualization for scientists and engineers. Now most of 2D plotting itself like as we saw in the demo of matplotlib can be done very well by matplotlib and Chaco. If you want really interactive plots with all the power of traits and a very nice convenient object oriented model you would want to use Chaco. But all of these can be done with matplotlib and Chaco. However, if you have things that are more complex that are not 2D plots that are not simple scatter plots. So if you are looking to say slice through some 3D volume of data, you want to do volume rendering, you have a 3D data set that you want to contour, you have an unstructured grid, you have more complicated things that you want to visualize, it is not enough if you have matplotlib or Chaco. So you need something that does it in 3D and unfortunately it is not as easy as PyLab makes it. So it is not yet that easy, we are hoping that we will eventually get there and make it as easy as we can for the average scientist. So yes, there is a lot of work, lot of research, lot of code that lets you visualize 3D data, it is there, huge amounts of code. The problem is most scientists and engineers are not really interested in learning how to do visualization and typically they do need to get their jobs done as soon as possible and they are busy. So it is not easy, most scientists you look at really have their own things to do, they have their own algorithms to write, they are looking at the physics or some particular detail of a problem they are interested in and expecting a scientist to really be a master of 3D visualization is just too much. And if you look at the way matplotlib works, none of us, most users of matplotlib do not really know how it works underneath. They do not know that it uses an ag or it uses GTK or what are the primitives that it actually draws, they just say hey there is this data please plot it and it is plotted. The goal is to eventually get to a point where you make it as easy as possible to do the basic things and if there is something that is beyond that then you make it doable. So two layers, one layer where you say the basic scientist can do most of his 90% of his tasks on the basic tool set and that is very easy to do. On top of that you have a more sophisticated object model where you can do more sophisticated things. But we are not there yet but we hopefully get there. So given this there are a couple of tools that have been developed in the recent past which I am going to just show you to give you a kind of like a primer and a show. These are visual and MLAB. So visual is basically based on what is called V-Python's visual. There is a tool, there is a library, Python library called V-Python which lets you create 2D, sorry 3D graphics very easily and you are not talking of graphics at the level of OpenGL with that level of power, you are talking of very simple things. You want to create a sphere, you want to be able to move that sphere, you want to create a small ring and you want to create a small thing where you can demo physics applications. So you say here is a ball that is bouncing, it is nice to be able to say here is a ball that is bouncing but it is a completely different thing when you actually have it on a computer that is actually doing a simulation, it is very nice to be able to show that. So V-Python lets you do that. But the problem with V-Python is it uses OpenGL and it also cannot be quite used in the framework of traits and all of the other stuff that we have. Not that easy to do, it can be used. So Rashid Beg, a student of mine actually created a, he basically took the visual Python API and recreated it using TBTK and there are slight differences from V-Python and this basically works nicely from IPython-W thread and it uses traits. The difficulty is it is kind of a, it has just been built recently, it is a lot slower than V-Python but it does offer some very neat capabilities. Here for example is the example code of how to create the scene you see on the right. I will show you a demo of this. All you are doing here is you are creating a sphere, setting it at a position and you are saying the color is red. You are creating another sphere here, position at 1, 0, 0 with a different color and you create a box here. You can get more complex, you can now create now an animation. Here what I have done is I just create a box which is the left wall, a right wall here which is another box and the sphere is sitting here between these two. Now I set the ball to have the current time. I create an attribute called t time, time level is 0 and I say at dt is 0.5 over here. This is silly application but just bear with me and I set the velocity of this ball to be a vector. This is basically a convenience class wrapped around NumPy arrays, it is a three vector so you say vector dot x it will give you the x component. The idea is to mimic the v python API and then we have an animation function which basically says increment the ball's time and then move the ball such that the next position of the ball is position of the ball plus velocity times delta t and then if the ball exceeds the sides you reverse the sign of the motion. So it is a perfect reflection and then the last line here you say iterate this. So call this animation function such that the user interface is not blocked and you can use this. Similarly you can do things like create a curve, so there is a nice example which actually shows the Lorenz attractor, it is a pretty animation. So this is another example where you can actually create a curve, I have just created a simple spiral again look at the code most of it is just setting up the data and this one line says here are the bunch of points it set up this curve and it will set up a curve. So this is very convenient when you want to sort of show simple demos and things like that. The other thing is there is something called tbtk.tools.mlab and I am not going to really show you demos of this right away but here you get to do more complicated visualizations. There you just created simple primitives like a ball and a ellipsoid you can create a box you can create and move things around or you can create a curve and things like that. But in reality you have things like for example two days back we did an example of the sync function right or you take the lina case and you want to say let us say you want to see a 3D surface of that, you want to see a carpet plot of your Bessel function how would you do that? Do that with visual the way you do that is to use mlab and what it does is it provides very convenient less like pilab provides plot scatter things like that pi mlab tries to provide one liners so you can get these things done very quickly and the API that I have used in this case is what is called the there is a tool called Octaviz which is built for Octave and I just mimic the API because it is used and what it lets you do is various things it can set you can create glyphs at various points which is for example at every point in this room I could show a cone with a particular direction with the direction being the direction of the flow in that room. You can take 3D lines just like the one visual does you can plot a mesh a surface and other things so here is a simple example which actually shows you a surface defined so look at the f of x here it basically says it is sin of x plus y plus sin of x 2x minus y plus cosine of 3x plus 4y and x and y are simply arrays and I want this to basically map out an entire region so what happens is the surf regular takes these two does an axis change just like in the sync example you change the axis so you broadcast the array and you get an entire mesh and it evaluates this function on each of those points then so this basically shows you it adds this surface and shows it with contours so here I have done two things I have shown you the API by which you can add it and then pop it so what the pop command does here is once you add a particular visualization so let us do this let us do an example so if you notice here it is exactly the same code now what I am going to do is I am just going to call it for now what you see here is a nice 3D surface with contours okay but we are running out of time so what I am okay so let me spend little time on this so the way MLAP works is the following so let us say I want to create if you look at the code up there all you do is you say from TVT from n thought TVTK dot tools import MLAP now I say MLAP dot figure does not this remind you of pi lab dot figure it is the same thing or similar thing and you get a basic figure with which you can interact and create things on that now if you say oops okay I am going to be bad so now let us say I define f x y sin of x plus y and now I am going to create two arrays now I am going to create a surface I say MLAP dot surf regular with contours x y and sample the function f and it is generated the contours and stuff but I want to view it on this guy the way you do that is you say fig or f which is my figure oops oops so what I did was I lost my figure so I am going to close it I will say fig is MLAP dot figure we have a figure I say fig dot add s and there you go now I want to remove it I can say fig dot pop is gone so what the example over here showed you just that API oops yeah so this basically just showed you that you can actually pop out the last figure the other thing you notice here is this is fully interactive window on the left you have what is called a pipeline browser so what happens is MLAP underneath uses what is called VTK we will talk about that in the afternoon and VTK has what is called a pipeline architecture so you set up a pipeline in order to do a visualization and what this lets you do is it lets you configure that by looking at the pipeline as a tree so now if I go on this I could actually go double click it and change the properties for example you notice now it is changed to a wire frame I change that from the user interface on the left so basically this gives you a pipeline interface pipeline browser where you can actually go and edit things if you really want to change certain specific properties that the command line did not let you do and then if you click on save just like in PyLab you can save this to an image and use that or if you want to see a full view you can view it in full screen various ways by which you can set the view to what you want. So this is the basics of PyLab sorry MLAP and there is a lot more sophisticated functionality for example I want to show this particular surface anybody have an idea of what this is it is a spherical harmonic so here is the data that is being generated and just look at the two lines that I used to generate the data is just three lines of code that plot this data so you are given a surface a bunch of points and actually generates the thing and visualize it for you so if you say MLAP test surf so it is already there in the MLAP example so I am not going to type it out if I say f is fig and then I say MLAP test surf there you have it. Now this is a very large number of polygons so it actually when I rotate it it automatically down samples and goes to a point like representation so you can rotate interactively and again you have the interactive pipeline browser that you can use so that is kind of the idea of MLAP basically it makes doing visualizations just like PyLab easier and there are more examples in the source code which show you how you can do different things now instead of using TVTK TVTK is like a raw tool it is like a library I would like to be able to use MayaV because MayaV offers me a lot of nice convenient functionality so what we have done recently is to create an MLAP for MayaV itself which means with one line I can do a plot just like we did with TVTK MLAP use MayaV at the back end so I can actually use the full-fledged user interface of MayaV set up new things delete things do what I want construct more sophisticated visualizations the trouble is this interface is still under development it does work it does do quite a few useful things but it is still under heavy development in fact Gael Wahokwa is helping with development of this in fact he is driving lots of the development on the mailing list with this and I am not I don't have the time to keep up with him so here is another quick example of how the same thing runs with MayaV tools MLAP so here what we have done is I have purposefully shown you different examples in the previous MLAP and in this again here all I have done is created a data set with X arrays this is just another array and I am saying U and V velocities are simply cosine of X sine of X M grid basically does generates a mesh grid okay which basically creates a mesh of points with this write X values and the Y values and here what we do here is we basically calculate the velocities and this is a 2D plot of the velocity vectors we could do it in 3D but the 3D plot actually looks quite messy so what I will show you now is so you just need to say from n thought dot MayaV dot tools import MLAP and then you can say MLAP dot quiver XYW UVW okay in this case we are doing only 2D now this example is already built in so if you say MLAP dot test quiver 3D 2D data that's what it does I have just listed that out on the left there so let's call it and see what you get I hope it doesn't do it works and there you have it and note that this is done in MayaV so I have all the features of MayaV at my disposal I have my data I can configure objects change for example right now it's using arrows you see the arrows I want to change the arrows to something else it will do that so now I have the power of MayaV and I have the capability of being able to pop up a plot with couple of lines of one line of a few lines of code okay and notice that my interpreter is still completely active so there is another example quiver 3D which does the same thing in 3D and as you can see it looks like a mess because it's 3D collection of points but you can actually go in and see something but you get the idea the CLF function clears the screen so you basically get back an empty screen is just like PyLab CLF no difference so the idea is in the future we are trying to see if we can make MLAP just as easy to use as PyLab so you can actually just one line plots you want to do a scatter things like that it's not there yet so here's another example of an iso surface you see here so this is another test and that's it all of the code you see on the top here is just setting up the data and this simply takes contours and this one line generates an outline the last line just resets the view so it's sitting nicely so we run it there you have and these are actually slices that you can slice with so you can look at your data interactively