Skip to main content
fixed inadvertent error
Source Link

I found that with Mathematica 10 one can use the region functions/distance+watershed to achieve something similar but much faster. Something along these lines can generate ~1 million voxels in a couple of seconds in my machine:

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}]
  ]

And then

spikey = Import["ExampleData/spikey.stl", "Graphics3D"];"MeshRegion"];
Image3D[voxelify[spikey, 100]]

voxelized spikey

I found that with Mathematica 10 one can use the region functions/distance+watershed to achieve something similar but much faster. Something along these lines can generate ~1 million voxels in a couple of seconds in my machine:

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}]
  ]

And then

spikey = Import["ExampleData/spikey.stl", "Graphics3D"];
Image3D[voxelify[spikey, 100]]

voxelized spikey

I found that with Mathematica 10 one can use the region functions/distance+watershed to achieve something similar but much faster. Something along these lines can generate ~1 million voxels in a couple of seconds in my machine:

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}]
  ]

And then

spikey = Import["ExampleData/spikey.stl", "MeshRegion"];
Image3D[voxelify[spikey, 100]]

voxelized spikey

made "Graphics3D" import element explicit for newer versions
Source Link

I found that with MathematicaMathematica 10 one can use the region functions/distance+watershed to achieve something similar but much faster. Something along these lines can generate ~1 million voxels in a couple of seconds in my machine:

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}]
  ]

And then

spikey = Import["ExampleData/spikey.stl"];stl", "Graphics3D"];
Image3D[voxelify[spikey, 100]]

enter image description herevoxelized spikey

I found that with Mathematica 10 one can use the region functions/distance+watershed to achieve something similar but much faster. Something along these lines can generate ~1 million voxels in a couple of seconds in my machine:

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}]
  ]

And then

spikey = Import["ExampleData/spikey.stl"];
Image3D[voxelify[spikey, 100]]

enter image description here

I found that with Mathematica 10 one can use the region functions/distance+watershed to achieve something similar but much faster. Something along these lines can generate ~1 million voxels in a couple of seconds in my machine:

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}]
  ]

And then

spikey = Import["ExampleData/spikey.stl", "Graphics3D"];
Image3D[voxelify[spikey, 100]]

voxelized spikey

added 1 character in body
Source Link
franjesus
  • 161
  • 1
  • 3

I found that with Mathematica 10 one can use the region functions/distance+watershed to achieve something similar but much faster. Something along these lines can generate ~1 million voxels in a couple of seconds in my machine:

voxelify[graph_Graphics3Dvoxelify[region_?RegionQ, res_]res_?NumericQ] := 
 Module[{region, f, bounds, boxsize, voxsize, data, d2},
  region = SelectFirst[Flatten[List @@ geom], RegionQ];
  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}]
  ]

And then

spikey = Import["ExampleData/spikey.stl"];
Image3D[voxelify[spikey, 100]]

enter image description here

I found that with Mathematica 10 one can use the region functions/distance+watershed to achieve something similar but much faster. Something along these lines can generate ~1 million voxels in a couple of seconds in my machine:

voxelify[graph_Graphics3D, res_] := 
 Module[{region, f, bounds, boxsize, voxsize, data, d2},
  region = SelectFirst[Flatten[List @@ geom], RegionQ];
  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}]
  ]

And then

spikey = Import["ExampleData/spikey.stl"];
Image3D[voxelify[spikey, 100]]

enter image description here

I found that with Mathematica 10 one can use the region functions/distance+watershed to achieve something similar but much faster. Something along these lines can generate ~1 million voxels in a couple of seconds in my machine:

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}]
  ]

And then

spikey = Import["ExampleData/spikey.stl"];
Image3D[voxelify[spikey, 100]]

enter image description here

added 1 character in body
Source Link
franjesus
  • 161
  • 1
  • 3
Loading
Working with newer versions of Mathematica
Source Link
franjesus
  • 161
  • 1
  • 3
Loading
added 7 characters in body
Source Link
franjesus
  • 161
  • 1
  • 3
Loading
added 129 characters in body
Source Link
franjesus
  • 161
  • 1
  • 3
Loading
Source Link
franjesus
  • 161
  • 1
  • 3
Loading