trim = True # Remove end bumps
    cleanup = False # Remove duplicate materials and save file
    export = True # STL file for slicing
    display = False # Display output

    # Open File
    location = 'stl_files_v3_combined/output-'
    variations = ['A', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K']

    for var in variations:
        file = location + var + '.vf'
        model = VoxelModel.openVF(file)

        # Remove end bumps
        if trim:
            modelCutTool1 = cuboid((model.voxels.shape[0], model.voxels.shape[1], 12), (0, 0, model.voxels.shape[2] - 12), 3)
            modelCutTool2 = cuboid((1, model.voxels.shape[1], model.voxels.shape[2]), (0, 0, 0), 3)
            modelCutTool3 = cuboid((1, model.voxels.shape[1], model.voxels.shape[2]), (model.voxels.shape[0] - 1, 0, 0), 3)
            model = model.difference(modelCutTool1 | modelCutTool2 | modelCutTool3)
            model = model.fitWorkspace()
            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
Esempio n. 2
0
"""
Export a simulation of a single falling object.

----

Copyright 2020 - Cole Brauer, Dan Aukes
"""

from voxelfuse.voxel_model import VoxelModel
from voxelfuse.primitives import cube, cuboid
from voxelfuse.simulation import Simulation, StopCondition

if __name__ == '__main__':
    cubeModel = cube(5, (0, 0, 10), material=5)
    planeModel = cuboid((9, 9, 1), (-2, -2, 0), material=5)

    modelResult = planeModel | cubeModel
    modelResult = modelResult.scale(1)
    modelResult = modelResult.removeDuplicateMaterials()

    simulation = Simulation(modelResult)  # Initialize a simulation
    simulation.setCollision()  # Enable self-collision
    # simulation.setStopCondition(StopCondition.TIME_VALUE, 0.01) # Set simulation time limit
    simulation.runSimVoxCad(
        'collision_sim_1',
        delete_files=False)  # Launch simulation, save simulation file
Esempio n. 3
0
if __name__ == '__main__':
    app1 = qg.QApplication(sys.argv)
    process_times = []

    plt.subplot(2, 1, 1)
    plt.subplots_adjust(left=0.12, right=0.95, hspace=0.6)

    scales = [1, 2, 3, 4, 5]
    for scale in scales:
        mem_psutil = []
        time_process_started = time.time()
        box_x = round(25 * scale)
        box_y = round(40 * scale)
        box_z = round(40 * scale)

        box1 = cuboid((box_x, box_y, box_z), (0, 0, 0), 1)
        mem_psutil.append(memory_usage_psutil())
        box2 = cuboid((box_x, box_y, box_z), (box_x, 0, 0), 3)
        mem_psutil.append(memory_usage_psutil())
        box3 = cuboid((box_x, box_y, box_z), (box_x * 2, 0, 0), 1)
        mem_psutil.append(memory_usage_psutil())
        baseModel = box1 | box2 | box3
        mem_psutil.append(memory_usage_psutil())
        print('Model Created')

        # Process Models
        # blurResult = baseModel.blur(int(round(box_x/2)))
        # mem_psutil.append(memory_usage_psutil())
        ditherResult, mem_psutil = dither(baseModel,
                                          int(round(box_x / 2)),
                                          mem_use_log=mem_psutil)
Esempio n. 4
0
    def addBoundaryConditionBox(self,
                                position: Tuple[float, float,
                                                float] = (0.0, 0.0, 0.0),
                                size: Tuple[float, float,
                                            float] = (1.0, 1.0, 0.01),
                                fixed_dof: int = 0b111111,
                                force: Tuple[float, float, float] = (0, 0, 0),
                                displacement: Tuple[float, float,
                                                    float] = (0, 0, 0),
                                torque: Tuple[float, float, float] = (0, 0, 0),
                                angular_displacement: Tuple[float, float,
                                                            float] = (0, 0,
                                                                      0)):
        """
        Add a box-shaped boundary condition.

        Boundary condition position and size are expressed as percentages of the
        overall model size. The fixed DOF value should be set as a 6-bit binary
        value (e.g. 0b111111) and the bits correspond to: Rz, Ry, Rx, Z, Y, X.
        If a bit is set to 0, the corresponding force/torque will be applied. If
        a bit is set to 1, the DOF will be fixed and the displacement will be
        applied.

        :param position: Box corner position (0-1)
        :param size: Box size (0-1)
        :param fixed_dof: Fixed degrees of freedom
        :param force: Force vector in N
        :param displacement: Displacement vector in mm
        :param torque: Torque values in Nm
        :param angular_displacement: Angular displacement values in deg
        :return: None
        """
        self.__bcRegions.append([
            BCShape.BOX, position, size, 0, (0.6, 0.4, 0.4, .5), fixed_dof,
            force, torque, displacement, angular_displacement
        ])

        x_len = int(self.__model.voxels.shape[0])
        y_len = int(self.__model.voxels.shape[1])
        z_len = int(self.__model.voxels.shape[2])

        regionSize = np.ceil(
            [size[0] * x_len, size[1] * y_len,
             size[2] * z_len]).astype(np.int32)
        regionPosition = np.floor([
            position[0] * x_len + self.__model.coords[0],
            position[1] * y_len + self.__model.coords[1],
            position[2] * z_len + self.__model.coords[2]
        ]).astype(np.int32)
        bcRegion = cuboid(regionSize, regionPosition) & self.__model

        x_offset = int(bcRegion.coords[0])
        y_offset = int(bcRegion.coords[1])
        z_offset = int(bcRegion.coords[2])

        bcVoxels = []
        for x in tqdm(range(x_len), desc='Finding constrained voxels'):
            for y in range(y_len):
                for z in range(z_len):
                    if bcRegion.voxels[x, y, z] != 0:
                        bcVoxels.append(
                            [x + x_offset, y + y_offset, z + z_offset])

        self.__bcVoxels.append(bcVoxels)