I am interested in converting stl files and found this interesting discussion in StackExchange:
https://mathematica.stackexchange.com/questions/40858/how-do-i-convert-imported-stl-files-to-3d-images/125296#125296
A very neat solution is provided:
voxelify[region_?RegionQ, res_?NumericQ] :=
Module[{f, bounds, boxsize, voxsize, data, d2},
f = RegionDistance[region];
bounds = RegionBounds[region];
boxsize = -Subtract @@ # & /@ bounds;
voxsize = Max[boxsize]/res;
data = ParallelArray[f[{##}] &, Round[boxsize/voxsize], bounds];
d2 = HeavisideTheta[data - voxsize];
2 - ReplaceAll[WatershedComponents[Image3D[1 - d2]], {0 -> 2}]
]
spikey = Import["ExampleData/spikey.stl", "MeshRegion"];
Image3D[voxelify[spikey, 100]]
Unfortunately the code no longer works in MMA 11.3, due to a problem with ParallelArray:
ParallelArray::nopar1: Array[f[{##1}]&,{100,95,81},{{-1.54435,1.54435},{-1.46876,1.46876},{-1.2494,1.2494}},List] cannot be parallelized; proceeding with sequential evaluation.
The sequential evaluation is far too slow for practical purposes.
Does anyone have any idea why the parallelization fails? Or can they suggest a workaround?