Example #1
0
"""
Export a VoxelFuse model as a .vxc file that can be imported into VoxCad.

----

Copyright 2020 - Cole Brauer, Dan Aukes
"""

from voxelfuse.voxel_model import VoxelModel
from voxelfuse.mesh import Mesh
from voxelfuse.primitives import *

if __name__ == '__main__':
    # app1 = qg.QApplication(sys.argv)

    model1 = cube(5, (0, 0, 0), material=1)
    model2 = cube(5, (4, 0, 3), material=8)
    model3 = cube(5, (8, 0, 6), material=3)

    modelResult = (model1 + model2).scaleValues() | model3

    # Save VXC file
    modelResult.saveVXC("test-file", compression=False)
    modelResult.saveVF("test-file")

    # Create mesh data
    mesh1 = Mesh.fromVoxelModel(modelResult)

    # Create plot
    mesh1.viewer()
Example #2
0
        mold_model = mold_model.difference(printed_components.dilate(moldGap, plane=Axes.XY))

        if fixture: # Generate a fixture around the full part to support mold
            print('Generating Fixture')
            coupon = coupon | coupon.web('laser', 1, 5).setMaterial(3)

        # Add mold to coupon model
        coupon = coupon | mold_model.setMaterial(3)

    end = time.time()
    processingTime = (end - start)
    print("Processing time = %s" % processingTime)

    # Create mesh data
    print('Meshing')
    mesh1 = Mesh.fromVoxelModel(coupon)

    # Create plot
    print('Plotting')
    plot1 = Plot(mesh1, grids=True)
    plot1.show()
    app1.processEvents()

    if export:
        print('Exporting')

        # Get non-cast components
        # Find all voxels containing <50% material 2
        material_vector = np.zeros(len(material_properties) + 1)
        material_vector[0] = 1
        material_vector[3] = 0.5
Example #3
0
    M = cylinder(30, 60).translate((30, 30, 0))
    M = M.setCoords((0, 0, 0))

    t = T.voxels.shape[0]
    size = M.voxels.shape

    # Create empty model to hold result
    V = VoxelModel.empty(size)

    # Add tiled lattice elements
    for x in range(int(np.ceil(size[0] / t))):
        for y in range(int(np.ceil(size[1] / t))):
            for z in range(int(np.ceil(size[2] / t))):
                T = T.setCoords((M.coords[0] + (x * t), M.coords[1] + (y * t),
                                 M.coords[2] + (z * t)))
                V = V | T

    # Intersect lattice with target volume
    V = M & V

    # Create Mesh
    mesh1 = Mesh.fromVoxelModel(T)
    mesh2 = Mesh.fromVoxelModel(M)
    mesh3 = Mesh.fromVoxelModel(V)

    mesh1.export('T.stl')
    mesh2.export('M.stl')
    mesh3.export('V.stl')

    # Create Plot
    mesh3.viewer()
Example #4
0
Import a mesh file and convert it to voxels.

----

Copyright 2019 - Cole Brauer, Dan Aukes
"""

import PyQt5.QtGui as qg
import sys
from voxelfuse.voxel_model import VoxelModel
from voxelfuse.mesh import Mesh
from voxelfuse.plot import Plot

if __name__ == '__main__':
    app1 = qg.QApplication(sys.argv)

    # Import model file
    model = VoxelModel.fromMeshFile('axes.stl', (0, 0, 0))

    # To use a copy of gmsh on the system path, replace line 21 with the following:
    # model = VoxelModel.fromMeshFile('axes.stl', (0, 0, 0), gmsh_on_path=True)

    # Create new mesh data for plotting
    mesh1 = Mesh.fromVoxelModel(model)

    # Create plot
    plot1 = Plot(mesh1, grids=True)
    plot1.show()

    app1.processEvents()
    app1.exec_()
            model.coords = (0, 0, 0)

        # Apply scale factor
        # model = model.scale(scaleFactor)

        # Apply rubber material
        # modelRubber = model.isolateMaterial(1)
        # modelRubber = modelRubber.setMaterial(5)
        # model = modelRubber | model

        # Cleanup operations
        if cleanup:
            model.materials = np.round(model.materials, 3)
            model = model.removeDuplicateMaterials()
            model.saveVF(file)

        # Create stl files
        if export:
            for m in range(1, len(model.materials)):
                mesh = Mesh.fromVoxelModel(model.isolateMaterial(m).fitWorkspace(), 5)
                mesh.export(file + '-' + str(m) + '.stl')

        # Display viewer window
        if display:
            mesh = Mesh.fromVoxelModel(model)

            # Create Plot
            plot1 = Plot(mesh, grids=True)
            plot1.show()
            app1.processEvents()
            app1.exec_()
Example #6
0
        fixture_model = fixture_model.setMaterial(3)
        coupon_supported = coupon_supported.union(fixture_model)

    # Get non-cast components
    # Find all voxels containing <50% material 2
    material_vector = np.zeros(len(material_properties) + 1)
    material_vector[0] = 1
    material_vector[3] = 0.5
    printed_components = coupon_supported - coupon_supported.setMaterialVector(
        material_vector)
    printed_components.materials = np.around(printed_components.materials, 0)
    printed_components = printed_components.scaleValues()
    printed_components = printed_components.setMaterial(1)

    # Create mesh data
    mesh1 = Mesh.fromVoxelModel(coupon_supported)

    # Create plot
    plot1 = Plot(mesh1, grids=True)
    plot1.show()
    app1.processEvents()

    if export:
        mesh2 = Mesh.fromVoxelModel(printed_components)
        plot2 = Plot(mesh2, grids=True)
        plot2.show()
        app1.processEvents()
        mesh2.export('modified-coupon-' + tabDesign + '.stl')

    app1.exec_()
            if (model_cropped.voxels[x+1, y, z] != 0) and (model_cropped.voxels[x+1, y, z] != materialToMeasure):
                totalSurfaceCount = totalSurfaceCount + 1
        if x-1 >= 0:
            if (model_cropped.voxels[x-1, y, z] != 0) and (model_cropped.voxels[x-1, y, z] != materialToMeasure):
                totalSurfaceCount = totalSurfaceCount + 1

        if y+1 < y_len:
            if (model_cropped.voxels[x, y+1, z] != 0) and (model_cropped.voxels[x, y+1, z] != materialToMeasure):
                totalSurfaceCount = totalSurfaceCount + 1
        if y-1 >= 0:
            if (model_cropped.voxels[x, y-1, z] != 0) and (model_cropped.voxels[x, y-1, z] != materialToMeasure):
                totalSurfaceCount = totalSurfaceCount + 1

        if z+1 < z_len:
            if (model_cropped.voxels[x, y, z+1] != 0) and (model_cropped.voxels[x, y, z+1] != materialToMeasure):
                totalSurfaceCount = totalSurfaceCount + 1
        if z-1 >= 0:
            if (model_cropped.voxels[x, y, z-1] != 0) and (model_cropped.voxels[x, y, z-1] != materialToMeasure):
                totalSurfaceCount = totalSurfaceCount + 1

    print('\nNumber of contact surfaces: ' + str(totalSurfaceCount))
    print('Surface area: ' + str(totalSurfaceCount*(1/res)*(1/res)) + ' mm^2')

    if display:
        mesh = Mesh.fromVoxelModel(model_single_material.setMaterial(4) | model_cropped.setMaterial(3) | model)

        # Create Plot
        plot1 = Plot(mesh, grids=True)
        plot1.show()
        app1.processEvents()
        app1.exec_()
            transition = transition & coupon  # Trim excess voxels
            coupon = transition | coupon  # Add to result

        coupon = coupon.round(materialStep)
        coupon = coupon.removeDuplicateMaterials()
        coupon.resolution = res

        end = time.time()
        processingTime = (end - start)
        print("Processing time = %s" % processingTime)

        if display:
            # Create mesh data
            print('Meshing')
            mesh1 = Mesh.fromVoxelModel(
                coupon_input.difference(transition_regions).setMaterial(3)
                | coupon,
                resolution=res)

            # Create plot
            print('Plotting')
            plot1 = Plot(mesh1,
                         grids=True,
                         drawEdges=True,
                         positionOffset=(35, 2, 0),
                         viewAngle=(50, 40, 200),
                         resolution=(720, 720),
                         name=filename)
            plot1.show()
            app1.processEvents()

        if save:
    # Create base model
    box1 = cuboid((box_x, box_y, box_z), (0, 0, 0), 1)
    box2 = cuboid((box_x, box_y, box_z), (box_x, 0, 0), 3)
    result1 = box1.union(box2)
    print('Model Created')

    # Process Model
    ditherResult = dither(result1, int(round(box_x/2)), use_full=False, y_error=1/3)

    # Scale result
    ditherResult = ditherResult.scale(5) # 15

    # Isolate materials
    result1 = ditherResult.isolateMaterial(1)
    result2 = ditherResult.isolateMaterial(2)

    result1 = result1.closing(2, Axes.XY) # 7
    result1 = thin(result1, 3) #100

    # Save result
    result1.saveVF('thin-test')

    # Create mesh
    ditherMesh = Mesh.fromVoxelModel(result1)

    # Create plot
    plot1 = Plot(ditherMesh)
    plot1.show()

    app1.processEvents()
    app1.exec_()
    max_radius = 6  # max radius that results in a viable lattice element

    # Import Models
    latticeModel = VoxelModel.fromVoxFile(
        'lattice_elements/lattice_element_1_30x30.vox')
    lattice_size = latticeModel.voxels.shape[0]

    start = time.time()

    # Process Model
    modelResult = VoxelModel.copy(latticeModel)
    modelResult1 = modelResult.dilateBounded(min_radius)
    modelResult2 = modelResult.dilateBounded(max_radius)

    end = time.time()
    m1Time = (end - start)
    print(m1Time)

    # Create Mesh
    mesh1 = Mesh.fromVoxelModel(modelResult1)
    mesh2 = Mesh.fromVoxelModel(modelResult2)

    # Create Plot
    plot1 = Plot(mesh1)
    plot1.show()

    plot2 = Plot(mesh2)
    plot2.show()

    app1.processEvents()
    app1.exec_()
Example #11
0
    resultModel = resultModel.difference(marker3.setCoords((750 + markerSize, 200 + 2 * clearance + markerSize, 0)))
    resultModel = resultModel.difference(marker1.setCoords((0 + markerSize, 1300 - 2 * clearance + markerSize, 0)))
    resultModel = resultModel.difference(marker2.setCoords((350 + markerSize, 1400 - clearance + markerSize, 0)))
    resultModel = resultModel.difference(marker3.setCoords((750 + markerSize, 1500 + markerSize, 0)))

    # Rotate models
    dModel = dModel.rotate90()
    nModel = nModel.rotate90()

    # Add horizontal coupons
    resultModel = resultModel | dModel.setCoords((0, 100 + clearance, 0))
    resultModel = resultModel | nModel.setCoords((100 + clearance, 100 + clearance, 0))
    resultModel = resultModel | dModel.setCoords((550, 300, 0))
    resultModel = resultModel | nModel.setCoords((950, 450, 0))
    resultModel = resultModel | dModel.setCoords((1300, 650 - clearance, 0))
    resultModel = resultModel | nModel.setCoords((1400 + clearance, 650 - clearance, 0))

    resultModel = resultModel.difference(marker1.setCoords((0 + markerSize, 100 + clearance + markerSize, 0)))
    resultModel = resultModel.difference(marker1.setCoords((100 + clearance + markerSize, 100 + clearance + markerSize, 0)))
    resultModel = resultModel.difference(marker2.setCoords((550 + markerSize, 300 + markerSize, 0)))
    resultModel = resultModel.difference(marker2.setCoords((950 + markerSize, 450 + markerSize, 0)))
    resultModel = resultModel.difference(marker3.setCoords((1300 + markerSize, 650 - clearance + markerSize, 0)))
    resultModel = resultModel.difference(marker3.setCoords((1400 + clearance + markerSize, 650 - clearance + markerSize, 0)))

    # Clean up
    resultModel = resultModel.removeDuplicateMaterials()

    # Create stl files
    for m in range(1, len(resultModel.materials)):
        mesh = Mesh.fromVoxelModel(resultModel.isolateMaterial(len(resultModel.materials) - m), resolution=res)
        mesh.export((outputFolder + str(len(resultModel.materials) - m) + '_FLX95585-DM_00A.stl'))
Example #12
0
    ]
    # files = ['output_J', 'output_K']

    model = empty(resolution=res)
    for i in range(len(files)):
        new_model = VoxelModel.openVF(outputFolder + files[i])
        new_model = new_model.setCoords((0, i * 110, 0))
        model = model | new_model

    # Cleanup operations
    if cleanup:
        model.materials = np.round(model.materials, 1)
        model = model.removeDuplicateMaterials()
        model.saveVF(outputFolder + outputFile)

    # Create stl files
    if export:
        for m in range(1, len(model.materials)):
            mesh = Mesh.fromVoxelModel(model.isolateMaterial(m),
                                       resolution=res)
            mesh.export(
                (outputFolder + str(m) + '_' + couponStandard + '_A.stl'))

    if display:
        mesh = Mesh.fromVoxelModel(model)

        # Create Plot
        plot1 = Plot(mesh)
        plot1.show()
        app1.processEvents()
        app1.exec_()
Example #13
0
Copyright 2020 - Cole Brauer, Dan Aukes
"""

import numpy as np
from voxelfuse.voxel_model import VoxelModel
from voxelfuse.mesh import Mesh

if __name__ == '__main__':
    # User preferences
    modelName = 'joint2.2.vox'

    # Import model
    modelIn = VoxelModel.fromVoxFile(modelName)

    # Define the material vector for the model
    materialVector = np.zeros(len(modelIn.materials[0]))
    materialVector[0] = 1
    materialVector[2] = 0.3
    materialVector[3] = 0.7

    # Apply material
    model = modelIn.setMaterialVector(materialVector)

    # Apply dither
    modelDither = model.dither()

    # Create mesh data
    for m in range(1, len(modelDither.materials)):
        currentMaterial = modelDither.isolateMaterial(m)
        currentMesh = Mesh.fromVoxelModel(currentMaterial)
        currentMesh.export('full_dither_' + str(m) + '.stl')
            transition = transition & coupon  # Trim excess voxels
            coupon = transition | coupon  # Add to result

        coupon = coupon.round(materialStep)
        coupon = coupon.removeDuplicateMaterials()
        coupon.resolution = res

        end = time.time()
        processingTime = (end - start)
        print("Processing time = %s" % processingTime)

        if display:
            # Create mesh data
            print('Meshing')
            mesh1 = Mesh.fromVoxelModel(coupon, resolution=res)

            # Create plot
            print('Plotting')
            plot1 = Plot(mesh1,
                         grids=True,
                         drawEdges=True,
                         positionOffset=(35, 2, 0),
                         viewAngle=(50, 40, 200),
                         resolution=(720, 720),
                         name=filename)
            plot1.show()
            app1.processEvents()
            app1.exec_()

        if save:
Example #15
0
import sys

from voxelfuse.mesh import Mesh
from voxelfuse.plot import Plot
from voxelfuse.voxel_model import VoxelModel

from dithering.thin import thin

if __name__ == '__main__':
    app1 = qg.QApplication(sys.argv)

    box_x = 25
    box_y = 10
    box_z = 10

    # Create base model
    result1 = VoxelModel.fromVoxFile('centerline-test.vox')
    print('Model Created')

    # Process Model
    result1 = thin(result1, 50)

    # Create mesh
    mesh1 = Mesh.fromVoxelModel(result1)

    # Create plot
    plot1 = Plot(mesh1)
    plot1.show()

    app1.processEvents()
    app1.exec_()
Example #16
0
from voxelfuse.primitives import sphere
from voxelfuse.periodic import gyroid

if __name__=='__main__':
    # User preferences
    modelRadius = 60
    infillScale = 30
    infillThickness = 1
    shellThickness = 1

    # Create volume model
    volume = sphere(radius=modelRadius, material=1)
    volume = volume.setCoords((0,0,0))

    # Display
    mesh1 = Mesh.fromVoxelModel(volume)
    mesh1.viewer(name='Input Model')

    # Create infill structure
    infillN, infillP = gyroid(size=(modelRadius*2, modelRadius*2, modelRadius*2), scale=infillScale, material1=2, material2=2)
    infillN = infillN.dilate(infillThickness)
    infillP = infillP.dilate(infillThickness)
    infill = infillN & infillP

    # Display
    mesh2 = Mesh.fromVoxelModel(infillN.setMaterial(3) | infillP)
    mesh2.viewer(name='Infill Volume Halves')

    # Display
    mesh3 = Mesh.fromVoxelModel(infill)
    mesh3.viewer(name='Infill Surface')