-1

I am playing around with rgl and I have created a 3D rendering of the mouse brain, in which structures can be isolated and coloured separately. The original data is a 3D array containing evenly spaced voxels.

Every voxel is coded with a structure ID.

Every structure is rendered separately as a mesh by marching cubes, and smoothed using Laplacian smoothing as implemented by Rvcg.

Some of these structures can be quite small, and it would make sense to look at them within the context of the whole brain structure.

One of the options is to create a low-threshold mesh of the whole set of voxels, so that only the outer surface of the brain is included in the mesh.

This surface can be smoothed and represented using a low alpha in rgl::shade3d colouring faces. This however seems to be quite taxing for the viewport as it slows down rotation etc especially when alpha levels are quite low.

I was wondering if there is any way to implement some sort of cel shading in rgl, e.g. outlining in solid colours the alpha hull of the 2D projection to the viewport in real time.

In case my description was not clear, here's a photoshopped example of what I'd need. Ideally I would not render the gray transparent shell, only the outline.

Cel shading example

Does anybody know how to do that without getting deep into OpenGL?

gdagstn
  • 1
  • 3

1 Answers1

0

Rendering transparent surfaces is slow because OpenGL requires the triangles making them up to be sorted from back to front. The sort order changes as you rotate, so you'll be doing a lot of sorting.

I can't think of any fast way to render the outline you want. One thing that might work given that you are starting from evenly spaced voxels is to render the outside surface using front="points", back="points", size = 1. Doing this with the ?surface3d example gives this fake transparency:

screenshot

If that's not transparent enough, you might be able to improve it by getting rid of lighting (lit = FALSE), plotting in a colour close to the background (color = "gray90"), or some other thing like that. Doing both of those gives this:

screenshot 2

You may also be able to cull your data so the surface has fewer vertices.

user2554330
  • 37,248
  • 4
  • 43
  • 90