Build a Numpy boolean mask (0-1) from an IGES file using a Python Library

Hello there dear community and fellow developers!

I hope you are having a great day and big hugs to everyone helping out others.
I am currently working with .IGES ( or STEP as well) files from FreeCAD. The purpose is to build a Python Library that can process the input file as parameter, process it from its Data Entry basic entities like Circular Arc, Composite Curve, Plane, Line, etc and build a 3D boolean mask of 0-1 that recreats this geometry parameters in an 3D binary matrix. This 3D boolean mask will be then saved in a HDF5 geometry file and used in other simulation applications.

I attach the following code which does something analogous but using a .SAT parameter file that builds the boolean mask out of the processing and creation of a Python Directory of Surfaces and Points.

 # Recorre el directorio de 'Surfaces'
    for s in range(len(entities['Surfaces'])):

        #Si la Superficie en el directorio de 'Surfaces' en [s][-1] == 'x'
        if entities['Surfaces'][s][-1] == 'x':

            #Guarda la posición x de la superficie
            x_pos = entities['Surfaces'][s][0]
            #Agrega a la mascara booleana 0 en la posición (x_pos,:,:)

            data[x_pos,:,:] = 0
        elif entities['Surfaces'][s][-1] == 'y':
            y_pos = entities['Surfaces'][s][1]
            data[:,y_pos,:] = 0
        elif entities['Surfaces'][s][-1] == 'z':
            z_pos = entities['Surfaces'][s][2]
            data[:,:,z_pos] = 0
        else:
            pass

    print(data.shape[0])
    print(data.shape[1])
    print(data.shape[2])

    #Recorre la matrix booleana (0-1) del archivo HDF5 de geometria
    for i in range(data.shape[0]):
        for j in range(data.shape[1]):
            for k in range(data.shape[2]):

                #Si el pixel en las coordenadas [i,j,k] es 0 (hay geometria) y los pixeles adyacentes de eje
                #Entonces se establece 1 en la mascara booleana
                if data[i,j,k] == 0 and data[i-1,j,k] == 0 and data[i,j-1,k] == 0 and data[i,j,k-1] == 0:
                    data[i,j,k] = 1
                elif data[i-1,j,k] == 1 and data[i,j-1,k] == 0 and data[i,j,k-1] == 0:
                    data[i,j,k] = 1
                elif data[i-1,j,k] == 0 and data[i,j-1,k] == 1 and data[i,j,k-1] == 0:
                    data[i,j,k] = 1
                elif data[i-1,j,k] == 0 and data[i,j-1,k] == 0 and data[i,j,k-1] == 1:
                    data[i,j,k] = 1
                else:
                    pass

I would really appreciate your help.
Best to everyone
Diego

Hello Diego,

did you have a question?

It sounds like what you want to do is called voxelisation. In your case, I found this article: 3D Cad to Binary Voxel Numpy Array | by Vishwajeet Sawant | Analytics Vidhya | Medium

It requires simplifying your shapes (ie converting your shapes to point-cloud or 3D mesh). Once you’ve done that, you could also use Open3D to voxelise: Voxelization — Open3D latest (664eff5) documentation

Simplifying can be done in CAD, or manually in Python with some maths