D-l-z / synthetic-ddsa

GNU General Public License v3.0
0 stars 1 forks source link

Convert vessel raw file to stl file for 3D printing #1

Closed Junang-Wang closed 1 month ago

Junang-Wang commented 2 months ago

Hi,

First of all, thank you for creating the synthetic-ddsa repository. It is extremely helpful for students. After generating the raw files of vessel models, we would like to convert them to STL files for 3D printing. We are inquiring whether it is possible to output the STL files or convert the files to STL format.

I appreciate any help you can provide. Cheers, JunAng Wang

D-l-z commented 2 months ago

Hi JunAng Wang,

I'm glad to hear that you found the synthetic-ddsa repository helpful for your studies.

Regarding your question about converting the raw files of vessel models to STL format for 3D printing. I have no experience with this, so I can't provide you with detailed steps.

However, I think you might also consider modifying the code that generates the raw files to directly output STL files instead of raw files.

I hope this information is helpful.

Sincerely, Lizhen Duan

eeulig commented 1 month ago

Hi Junang Wang,

not sure if still relevant but an easy (though less elegant) way would be to use marching cubes on the generated binary files directly, e.g. like so:

import numpy as np
from skimage import measure
from stl import mesh
from typing import Tuple

def raw2stl(file: str, savepath: str, shape: Tuple[int, int, int]):
    """Converts a raw file to an stl file.

    Parameters
    ----------
    file : str
        Input raw filepath.
    savepath : str
        Output stl filepath
    shape : Tuple[int, int, int]
        Shape of the raw file
    """
    vessel_vol = np.fromfile(file, dtype=np.uint8).reshape(*shape)
    verts, faces, _, _ = measure.marching_cubes(vessel_vol)
    m = mesh.Mesh(np.zeros(faces.shape[0], dtype=mesh.Mesh.dtype))
    for i, f in enumerate(faces):
        for j in range(3):
            m.vectors[i][j] = verts[f[j],:]
    m.save(savepath)

Hope this helps!

Best, Elias