59
$\begingroup$

Is there an interface or API that allows using Blender as a tool for mathematical and scientific visualization? It should allow Blender to read in data (a la gnuplot or matlab, perhaps using scipy) and interface with Blender's primitives and rendering engine to create the output.

Detailed Example:

I was imagining (hoping for) an API that would take matplotlib-like calls (e.g., plt.{x,y,z}label, plt.gca, plt.plot(cos(x in range(0,2*pi,0.01*pi)) ), etc.) but instead of drawing to a canvas, it would generate a scene. It would be fantastic to be able to map data or functions to texture coordinates, to add more sophisticated visualization techniques than color maps allow. Also nice would be to input functions as parameters to textures or meshes, so I could "plot" a catenary path, and then make a polygon follow that path to make a mathematically precise arch.

$\endgroup$
  • $\begingroup$ what kind of API calls are you looking for, specifically? $\endgroup$ – zeffii Jun 19 '13 at 20:18
  • $\begingroup$ Could you make an example of what you want to achieve? $\endgroup$ – miceterminator Jun 19 '13 at 20:24
  • 1
    $\begingroup$ I was imagining (hoping for) an API that would take matplotlib-like calls (e.g., plt.{x,y,z}label, plt.gca, plt.plot(cos(x in range(0,2*pi,0.01*pi)) ), etc.) but instead of drawing to a canvas, it would generate a scene. It would be fantastic to be able to map data or functions to texture coordinates, to add more sophisticated visualization techniques than color maps allow. Also nice would be to input functions as parameters to textures or meshes, so I could "plot" a catenary path, and then make a polygon follow that path to make a mathematically precise arch. $\endgroup$ – KDN Jun 20 '13 at 1:00
44
$\begingroup$

Blender is the tool and bpy is the API.

If you want to render geometry you can use bpy to deal with any meaningful input. Blender has been used effectively to display data for scientific publications for many years. I'll add a non-exhaustive list below. But if you are expecting ready made functions to plot a 3D scatter plot with scales and cube grid, with evenly spaced intelligent sub-ticks, I'm not aware of any. However, once written you can pump similar data through that routine in the future. This might be a lot of work the first time, but then you learn how to do it and can customize your visualizations meticulously.

The more you can prime your data in those packages like matlab, octave, numpy, and scipy prior to bringing it into Blender the better. (ie. find the min / max / scale / appropriate dimensioning values, tag your data set ..etc). If you are using matplotlib, it is possible to retrieve generated plot data (like autoscaling margins..etc) and use that to build your custom scene.

In recent official builds (and from builder.blender.org/download/) the numeric Python library numpy is included by default. Allowing you to speed up a lot of heavy computations which don't rely directly on bpy.

Useful plotting addons:

Add Mesh / Add 3d Function Surface: Takes formulae for x, y and z axis and generates the surface mesh.

Sverchok: This node based geometry generation add-on is developed primarily with Architecture and Design in mind, but it can generate meshes from any kind of data, or a combination of its 150+ nodes. If the data type isn't supported by default you can easily write an importer or ask on our Github issue tracker for advice.

Examples of scientific usage of Blender

Mathieu Gibert
This researcher at the Max Planck Institute for Dynamics and Self-Organization used it here: http://www.gibert.biz/downloads/3dscatterplotswithblender (with an example script, and data) There's a thread over at BlenderArtists about his forays into visualizing that data.

BioBlender
http://bioblender.eu/ with some fantastic renderings of molecular structures. From version 1.0 onwards this has become an addon, and has its own Github repository

excerpt from the site:

BioBlender is the result of a collaboration, driven by the SciVis group at the CNR in Pisa (Italy), between scientists of different disciplines (biology, chemistry, physics, computer sciences) and artists, using Blender in a rigorous but at the same time creative way.

Visualize Color Spaces
Interesting visualization from Mark Meyer to show color spaces. http://www.photo-mark.com/notes/2013/mar/13/color-theory-blender/

CellBlender
http://mcell.org/ (combines matplotlib and Blender 2.6x)

MCell and CellBlender development is an ongoing collaboration between researchers at the Pittsburgh Supercomputing Center, the Department of Computational and Systems Biology of the University of Pittsburgh, and the Computational Neurobiology Laboratory at the Salk Institute, with support from the National Institutes of Health, the Howard Hughes Medical Institute, and the National Science Foundation.

AstroBlend:
An Astrophysical Visualization Package for Blender. http://www.astroblend.com/

From the abstract to this paper, which is introductory to AstroBlend

an open-source Python library for use within (...) Blender. (...) AstroBlend combines the three dimensional capabilities of Blender with the analysis tools of the widely used astrophysical toolset, yt, to afford both computational and observational astrophysicists the ability to simultaneously analyze their data and create informative and appealing visualizations

Elsewhere
A swift google search for blender for scientific visualization returns many examples of people using Blender with their data.

I started a github repo with scripts that may be of use for understanding how to create 3d meshes from functions, called BlenderSciViz. It is still rather minimal but I welcome any reasonable feature requests if you can provide me with representative data sets so I can test and fine tune the resulting geometry algorithms.

$\endgroup$
  • 4
    $\begingroup$ I remember doing this search about a year or so ago, and coming up dry, so I was excited for this SE site to make beta. Good to see more people using Blender for more things now. $\endgroup$ – KDN Jun 20 '13 at 1:02
  • 1
    $\begingroup$ +1 Also note that due to bpy using Python, you may be able to use some parts matplotlib instead of writing your own plot code $\endgroup$ – Tobias Kienzler Jun 20 '13 at 8:18
  • $\begingroup$ @TobiasKienzler, a small bit of sample code would help solidify this point, if you are willing. $\endgroup$ – zeffii Jun 20 '13 at 8:35
  • 1
    $\begingroup$ @zeffii It's merely an idea so far, I haven't dug into it. I don't know much about matplotlib's internals, but I'd probably try to subclass either figure or axes and redirect the drawing to bpy, but maybe the matplotlib API provides smarter means $\endgroup$ – Tobias Kienzler Jun 20 '13 at 8:41
7
$\begingroup$

What we do is use ParaView for the scientific visualization and export the scenes into a format that Blender can use (X3D I believe, it's been awhile). Then we pull in the data and render much better looking scenes in Blender.

We have also toyed with the idea of using ParaView CoProcessing to take our simulation data in-situ, generate our data, and then pass it through to Blender through the Python interface for rendering in-situ. However, we never figured out the way to get through the Fortran->C->Python 2.* (Paraview)->Python 3.* (Blender).

$\endgroup$
5
$\begingroup$

If you want to put some color on stuctures based on a certain data field, have a look at my addon

ColorMesh

The examples are done using Suzanne as the stucture and an artificial data field. If you can process your data in python, you can save your data field and read it in blender.

$\endgroup$
3
$\begingroup$

You can also install matplotlib, but it's quite a pain. I'm using Blender 2.76 with python 3.4. So these are the steps I needed to do:

  1. Download python from the same version like in the Blender (3.4)
  2. Copy the folder ‘distutils’ from your new python3.4 to Blender’s python lib folder (../blender-2.76-rc2/2.76/python/lib/python3.4)
  3. Download get-pip.py (https://bootstrap.pypa.io/get-pip.py) and run Blender’s python (be sure you are running Blender’s python!): python3.4 get-pip.py --user
  4. Find your pip installation (whereis pip). If you used --user, is suppose to be in /usr/local/bin/pip3
  5. Run from Blender’s python: python3.4: /usr/local/bin/pip3.4 install matplotlib --user
  6. Try to import matplotlib.pyplot. If you are getting the following error, ImportError: No module named _tkinter, you should try to change your backend (Agg for example) before importing pyplot (more information can be found here)

    import matplotlib as mpl

    mpl.use('Agg')

    import matplotlib.pyplot as plt

$\endgroup$
1
$\begingroup$

enter image description here

This is a simple Sverchok example to visualize your formula.

GIST (for node tree): https://gist.github.com/3f43dc89bbb1e931aa7eed2c37ca1f32

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.