ediloren / EM-Workbench-for-FreeCAD

This project is dedicated to building an ElectroMagnetic workbench for FreeCAD. FreeCAD is a free 3D parametric CAD. FreeCAD is used as pre-processor interfacing to the open source electromagnetic field solvers FastHenry and FasterCap.
GNU Lesser General Public License v2.1
56 stars 16 forks source link

improved voxelization speed #11

Closed hellsync closed 7 months ago

ediloren commented 7 months ago

@hellsync thanks for the improvement proposal and for the fix. Actually the original code for the VoxHenry workbench is a bit crude and was designed to be a fast draft implementation allowing to create simple input files for VoxHenry. However, for the fast voxelization algorithm, I was considering Patil S and Ravi B. "Voxel-based representation, display and thickness analysis of intricate shapes". Ninth International Conference on Computer Aided Design and Computer Graphics (CAD/CG 2005), of which also a Matlab implementation exists (see https://www.mathworks.com/matlabcentral/fileexchange/27390-mesh-voxelisation). I believe this implementation is faster, as it never need to test for inshape(), however it requires a fast ray intersection algorithm. I tried using foraminate() but it is not really fast enough as inside the routine it simply executes a for loop for the meshed faces instead of using e.g. octtree search or similar. If you have any good idea or can come up with a nice implementation I would welcome that. Your proposal here is anyway a big improvement, I will check and pull it in if ok.

ediloren commented 7 months ago

merged - works well - thanks!

hellsync commented 7 months ago

Great to hear! Yeah I left the Shape.isInside() checks of the voxelised "shell" in to try and prevent existing geometries from being voxelised differently, but with a sufficiently fine mesh and a sane value for delta it wouldn't matter if the exact voxelisation differs by a few blocks.

I expected to find a voxelisation implementation in OpenCascade (FreeCAD's geometry kernel), but I think it might have got pulled and/or refactored into something else.

In terms of speed, this (ie improve-voxelization-speed) implementation is slowest with large diagonal mesh facets. An improvement would be limiting facet size by splitting, but I couldn't see a simple way to do that.

If the algorithm you mention is mainly based on ray intersections its probably a good candidate for offloading to GPU. Perhaps OCCT could be tricked into doing the work using its rendering stuff.

I see the VoxHenry as a great addition to FreeCAD's simulation stuff, since the problem formulation is easy (geometry -> port definitions -> simple voxel meshing) -> simulation). Is the C++ implementation of VoxHenry at a point where you'd be happy to put it public? It would be nice to ditch the octave dependency and maybe even package a VoxHenry binary with FreeCAD.