def doExport(inputFilePath, outputFilePath, resolution, FOLDERNAME):
    mesh = list(stl_reader.read_stl_verticies(inputFilePath))
    (scale, shift, bounding_box) = slice.calculateScaleAndShift(mesh, resolution)
    mesh = list(slice.scaleAndShiftMesh(mesh, scale, shift))
    #Note: vol should be addressed with vol[z][x][y]
    vol = np.zeros((bounding_box[2],bounding_box[0],bounding_box[1]), dtype=bool)
    for height in range(bounding_box[2]):
        print('Processing layer %d/%d'%(height+1,bounding_box[2]))
        lines = slice.toIntersectingLines(mesh, height)
        prepixel = np.zeros((bounding_box[0], bounding_box[1]), dtype=bool)
        perimeter.linesToVoxels(lines, prepixel)
        vol[height] = prepixel
    vol, bounding_box = padVoxelArray(vol)
    outputFilePattern, outputFileExtension = os.path.splitext(outputFilePath)
    currentPath = os.getcwd()
    outputFilePath = os.path.join(currentPath, outputFilePath)
    if outputFileExtension == '.png':
        exportPngs(vol, bounding_box, outputFilePath)
    elif outputFileExtension == '.xyz':
        exportXyz(vol, bounding_box, outputFilePath)
    elif outputFileExtension == '.svx':
        exportSvx(vol, bounding_box, outputFilePath, scale, shift)
    voxelSum(FOLDERNAME)
    for i in range(2):    
        os.chdir('..')
예제 #2
0
def voxelsFromStl (inputFilePath, resolution):
    mesh = list(stl_reader.read_stl_verticies(inputFilePath))
    (scale, shift, bounding_box) = slice.calculateScaleAndShift(mesh, resolution)
    mesh = list(slice.scaleAndShiftMesh(mesh, scale, shift))
    #Note: vol should be addressed with vol[z][x][y]
    vol = np.zeros((bounding_box[2],bounding_box[0],bounding_box[1]), dtype=bool)
    for height in range(bounding_box[2]):
        # print('Processing layer %d/%d'%(height+1,bounding_box[2]))
        lines = slice.toIntersectingLines(mesh, height)
        prepixel = np.zeros((bounding_box[0], bounding_box[1]), dtype=bool)
        perimeter.linesToVoxels(lines, prepixel)
        vol[height] = prepixel
    vol, bounding_box = padVoxelArray(vol)
    # outputFilePattern, outputFileExtension = os.path.splitext(outputFilePath)
    return vol
예제 #3
0
def doExport(inputFilePath, outputFilePath, resolution, pad):
    mesh = stl_reader.read_stl_verticies(inputFilePath)
    (scale, shift, bounding_box) = slice.calculateScaleAndShift(mesh, resolution)
    if not any(scale):
        print('Too small resolution: %d' % resolution)
        return
    mesh = slice.scaleAndShiftMesh(mesh, scale, shift)

    vol, bounding_box = slice.meshToPlane(mesh, bounding_box, pad)

    outputFilePattern, outputFileExtension = os.path.splitext(outputFilePath)
    if outputFileExtension == '.png':
        exportPngs(vol, bounding_box, outputFilePath)
    elif outputFileExtension == '.xyz':
        exportXyz(vol, bounding_box, outputFilePath)
    elif outputFileExtension == '.svx':
        exportSvx(vol, bounding_box, outputFilePath, scale, shift)
예제 #4
0
def voxelsFromStl(inputFilePath, resolution):
    mesh = list(stl_reader.read_stl_verticies(inputFilePath))
    (scale, shift,
     bounding_box) = slice.calculateScaleAndShift(mesh, resolution)
    mesh = list(slice.scaleAndShiftMesh(mesh, scale, shift))
    #Note: vol should be addressed with vol[z][x][y]
    vol = np.zeros((bounding_box[2], bounding_box[0], bounding_box[1]),
                   dtype=bool)
    for height in range(bounding_box[2]):
        # print('Processing layer %d/%d'%(height+1,bounding_box[2]))
        lines = slice.toIntersectingLines(mesh, height)
        prepixel = np.zeros((bounding_box[0], bounding_box[1]), dtype=bool)
        perimeter.linesToVoxels(lines, prepixel)
        vol[height] = prepixel
    vol, bounding_box = padVoxelArray(vol)
    # outputFilePattern, outputFileExtension = os.path.splitext(outputFilePath)
    return vol
예제 #5
0
def doExport(inputFilePath, outputFilePath, resolution, size):
    mesh = list(stl_reader.read_stl_verticies(inputFilePath))
    scale, shift, bounding_box = slice.calculateScaleAndShift(mesh, resolution)
    if size:
        size = np.array(size)
        # Here, bounding box is still (x,y,z)
        for i, d in enumerate(['x', 'y', 'z']):
            if size[i] < bounding_box[i]:
                raise ValueError("Supplied size for Dimension {} ({}) is less than computed bounding box ({})!".format(d, size[i], bounding_box[i]))
        print("Overwriting computed size {} with new size {}".format(bounding_box, size), file=sys.stderr)
        # Need to adjust the scale in order to center the image in the frame
        offset = (size - bounding_box) / 2
        # apply scaling
        offset /= scale
        # Add to shift
        shift += offset
        # set new bounding box
        bounding_box = size

    mesh = list(slice.scaleAndShiftMesh(mesh, scale, shift))
    #Note: vol should be addressed with vol[z][x][y]
    vol = np.empty((bounding_box[2], bounding_box[0], bounding_box[1]), dtype=bool)
    for height in tqdm.tqdm(range(bounding_box[2]), desc='Processing Slice'):
        lines = slice.toIntersectingLines(mesh, height)
        prepixel = np.zeros((bounding_box[0], bounding_box[1]), dtype=bool)
        perimeter.linesToVoxels(lines, prepixel)
        vol[height] = prepixel

    if not size:
        # Adds two extra voxels
        # Only needed if bbox is not given explicitly
        vol, bounding_box = padVoxelArray(vol)

    _, outputFileExtension = os.path.splitext(outputFilePath)
    if outputFileExtension == '.png':
        exportPngs(vol, bounding_box, outputFilePath)
    elif outputFileExtension == '.xyz':
        exportXyz(vol, bounding_box, outputFilePath)
    elif outputFileExtension == '.svx':
        exportSvx(vol, bounding_box, outputFilePath, scale, shift)
    elif outputFileExtension == '.mhd':
        exportMhd(vol, bounding_box, outputFilePath, scale)
예제 #6
0
def doExport(inputFilePath, outputFilePath, resolution):
    mesh = list(stl_reader.read_stl_verticies(inputFilePath))
    (scale, shift,
     bounding_box) = slice.calculateScaleAndShift(mesh, resolution)
    mesh = list(slice.scaleAndShiftMesh(mesh, scale, shift))
    # Note: vol should be addressed with vol[z][x][y]
    vol = np.zeros((bounding_box[2], bounding_box[0], bounding_box[1]),
                   dtype=bool)

    events = slice.generateEvents(mesh)

    current_triangle_indecies = set()

    slice_height = -1
    for (z, status, tri_ind) in events:
        while z - slice_height >= 1:
            slice_height += 1
            print('Processing layer %d/%d' %
                  (slice_height + 1, bounding_box[2]))
            prepixel = np.zeros((bounding_box[0], bounding_box[1]), dtype=bool)
            mesh_subset = []
            for index in current_triangle_indecies:
                mesh_subset.append(mesh[index])
            lines = slice.toIntersectingLines(mesh_subset, slice_height)
            perimeter.linesToVoxels(lines, prepixel)
            vol[slice_height] = prepixel

        if status == 'start':
            assert tri_ind not in current_triangle_indecies
            current_triangle_indecies.add(tri_ind)
        elif status == 'end':
            assert tri_ind in current_triangle_indecies
            current_triangle_indecies.remove(tri_ind)

    vol, bounding_box = padVoxelArray(vol)
    outputFilePattern, outputFileExtension = os.path.splitext(outputFilePath)
    if outputFileExtension == '.png':
        exportPngs(vol, bounding_box, outputFilePath)
    elif outputFileExtension == '.xyz':
        exportXyz(vol, bounding_box, outputFilePath)
    elif outputFileExtension == '.svx':
        exportSvx(vol, bounding_box, outputFilePath, scale, shift)
예제 #7
0
def doExport(inputFilePath,
             outputFilePath,
             resolution=100,
             pad=1,
             parallel=False):
    org_mesh = stl_reader.read_stl_verticies(inputFilePath)
    vol_mesh, scale, shift, bounding_box = slice.scaleAndShiftMesh(
        org_mesh, resolution)
    if scale == 0:
        print('Too small resolution: %d' % resolution)
        return

    vol, bounding_box = slice.meshToPlane(vol_mesh, bounding_box, pad,
                                          parallel)

    outputFilePattern, outputFileExtension = os.path.splitext(outputFilePath)
    if outputFileExtension == '.png':
        exportPngs(vol, bounding_box, outputFilePath)
    elif outputFileExtension == '.xyz':
        exportXyz(vol, bounding_box, outputFilePath)
    elif outputFileExtension == '.svx':
        exportSvx(vol, bounding_box, outputFilePath, scale, shift)
예제 #8
0
def get_voxels(triangles, resolution):
    """
    Converts an .stl file into voxels
    :param triangles: Mesh of the object
    :param resolution: Resolution of the voxel cube
    :return: scale, shift, volume and bounding box of the voxel cube
    """
    mesh = triangles.data['vectors'].tolist()
    (scale, shift,
     bounding_box) = slice.calculateScaleAndShift(mesh, resolution)
    mesh = list(slice.scaleAndShiftMesh(mesh, scale, shift))
    # Note: vol should be addressed with vol[z][x][y]
    vol = np.zeros((bounding_box[2], bounding_box[0], bounding_box[1]),
                   dtype=bool)
    for height in range(bounding_box[2]):
        # print('Processing layer %d/%d' % (height + 1, bounding_box[2]))
        lines = slice.toIntersectingLines(mesh, height)
        prepixel = np.zeros((bounding_box[0], bounding_box[1]), dtype=bool)
        perimeter.linesToVoxels(lines, prepixel)
        vol[height] = prepixel

    vol, bounding_box = padVoxelArray(vol)
    return scale, shift, vol, bounding_box