r/Simulated•
PrecRa

Data visualization techniques

Question

I'd like to visualize the output of a 2d fluid simulation I'm writing. Basically, anything that will animate a 2d scalar field will fit the bill. I have yet to find a suitable tool and would appreciate any help at all! Thanks!

Posted Dec 19, 2015, 8:43 PM UTC

26
Rexjericho•

The marching squares algorithm, which is a 2d generalization of the marching cubes algorithm can be used to convert a scalar field to a triangle mesh.

Marching Squares

Polygonising a Scalar Field (Marching Cubes)

1
PrecRaOP•

Thanks so much for this! I'll likely implement it. Is there any software that is capable of rendering the data?

1
Rexjericho•

You should be able to render a 2d triangle mesh in any 3d modelling program. Blender is free and widely used. Once you have a series of triangles representing the fluid, you'll need to encode that data into a supported triangle mesh file format such as .obj or .ply so that you will be able to import it into the software.

2
PrecRaOP•

Is there an opportunity to have that triangle mesh be time dependent? I'd like to view the output of my simulation as an animation.

It will look something like this: https://www.youtube.com/watch?v=cF0oNLrUqbs

1
moby3Blender•

Maybe have a look at the format that Blender saves its native (3D) fluid simulations in. That way you could create a new fluid simulation object and point it towards your files, and you'd be able to use it exactly as you would a simulation created in Blender

2
Rexjericho•

You would have to create a new triangle mesh for each frame of the animation. You would then end up with a sequence of images that you could sequence together into a video. The FFmpeg tool can be used to convert a sequence of numbered images into a video.

For an animation like the video above, the marching squares algorithm may not be the best choice for rendering your scalar field. The marching cubes algorithm turns your scalar field into a field that only has two states (inside/outside) and creates a definitive border around the fluid surface. The above animation doesn't have a defined border around the fluid surface and is instead smooth.

A method of rendering your scalar field like the above video would be to convert the field to a 2d array of pixels. For example, a large scalar field value could map to white, and a low value could map to black, and a value in between could map to some blending of black/white. You could then encode the 2d array of pixels into an image using an image encoding library (LodePNG for PNGs if your using C/C++).

If you want the image resolution to be larger than your scalar field resolution, you could either upscale your scalar field by applying a bicubic interpolation filter, or just upscale the output images in a batch image processing program such as ImageMagik.

1