Exemple #1
0
def test_remove_all_duplicate_polygons():
    data = numpy.zeros(5, dtype=Mesh.dtype)
    data['vectors'][0] = numpy.array([[0, 0, 0],
                                      [0, 0, 0],
                                      [0, 0, 0]])
    data['vectors'][1] = numpy.array([[1, 0, 0],
                                      [0, 0, 0],
                                      [0, 0, 0]])
    data['vectors'][2] = numpy.array([[2, 0, 0],
                                      [0, 0, 0],
                                      [0, 0, 0]])
    data['vectors'][3] = numpy.array([[3, 0, 0],
                                      [0, 0, 0],
                                      [0, 0, 0]])
    data['vectors'][4] = numpy.array([[3, 0, 0],
                                      [0, 0, 0],
                                      [0, 0, 0]])

    mesh = Mesh(data, remove_duplicate_polygons=False)
    assert mesh.data.size == 5
    Mesh.remove_duplicate_polygons(mesh.data, RemoveDuplicates.NONE)

    mesh = Mesh(data, remove_duplicate_polygons=RemoveDuplicates.ALL)
    assert mesh.data.size == 3

    assert (mesh.vectors[0] == numpy.array([[0, 0, 0],
                                            [0, 0, 0],
                                            [0, 0, 0]])).all()
    assert (mesh.vectors[1] == numpy.array([[1, 0, 0],
                                            [0, 0, 0],
                                            [0, 0, 0]])).all()
    assert (mesh.vectors[2] == numpy.array([[2, 0, 0],
                                            [0, 0, 0],
                                            [0, 0, 0]])).all()
Exemple #2
0
def test_remove_all_duplicate_polygons():
    data = numpy.zeros(5, dtype=Mesh.dtype)
    data['vectors'][0] = numpy.array([[0, 0, 0],
                                      [0, 0, 0],
                                      [0, 0, 0]])
    data['vectors'][1] = numpy.array([[1, 0, 0],
                                      [0, 0, 0],
                                      [0, 0, 0]])
    data['vectors'][2] = numpy.array([[2, 0, 0],
                                      [0, 0, 0],
                                      [0, 0, 0]])
    data['vectors'][3] = numpy.array([[3, 0, 0],
                                      [0, 0, 0],
                                      [0, 0, 0]])
    data['vectors'][4] = numpy.array([[3, 0, 0],
                                      [0, 0, 0],
                                      [0, 0, 0]])

    mesh = Mesh(data, remove_duplicate_polygons=False)
    assert mesh.data.size == 5
    Mesh.remove_duplicate_polygons(mesh.data, RemoveDuplicates.NONE)

    mesh = Mesh(data, remove_duplicate_polygons=RemoveDuplicates.ALL)
    assert mesh.data.size == 3

    assert (mesh.vectors[0] == numpy.array([[0, 0, 0],
                                            [0, 0, 0],
                                            [0, 0, 0]])).all()
    assert (mesh.vectors[1] == numpy.array([[1, 0, 0],
                                            [0, 0, 0],
                                            [0, 0, 0]])).all()
    assert (mesh.vectors[2] == numpy.array([[2, 0, 0],
                                            [0, 0, 0],
                                            [0, 0, 0]])).all()
Exemple #3
0
def test_remove_all_duplicate_polygons():

    mesh = Mesh(your_mesh, remove_duplicate_polygons=False)
    assert mesh.data.size == 9
    Mesh.remove_duplicate_polygons(mesh.data, RemoveDuplicates.NONE)

    mesh = Mesh(your_mesh, remove_duplicate_polygons=RemoveDuplicates.ALL)
    assert mesh.data.size == 9

    assert (your_mesh.points[0][0:3] == your_mesh.v0[0]).all()
    assert (your_mesh.points[0][3:6] == your_mesh.v1[0]).all()
    assert (your_mesh.points[0][6:9] == your_mesh.v2[0]).all()
def toSTL(self):
    """
    Exports the current laminate as an STL file
    """
    from stl.mesh import Mesh  #Requires numpy-stl
    layerdef = self.layerdef
    laminate_verts = []
    for layer in layerdef.layers:
        shapes = self.geoms[layer]  #TODO Add it in for other shapes
        zvalue = layerdef.z_values[layer]
        thickness = layer.thickness
        if (len(shapes) == 0):  #In case there are no shapes.
            print("No shapes skipping")
            continue
        for s in shapes:
            shape_verts = s.extrudeVertices(thickness, z0=zvalue)
            laminate_verts.extend(shape_verts)

    laminate_verts = [
        point / popupcad.SI_length_scaling for point in laminate_verts
    ]
    # Or creating a new mesh (make sure not to overwrite the `mesh` import by
    # naming it `mesh`):
    VERTICE_COUNT = len(laminate_verts) // 3  #Number of verticies
    data = numpy.zeros(
        VERTICE_COUNT, dtype=Mesh.dtype
    )  #We create an array full of zeroes. Will edit it later.
    #Creates a mesh from the specified set of points
    for dtype, points in zip(data, numpy.array(laminate_verts).reshape(-1, 9)):
        points = points.reshape(-1, 3)  #Splits each triangle into points
        numpy.copyto(dtype[1],
                     points)  #Copies the list of points into verticies index

    data = Mesh.remove_duplicate_polygons(data)

    #This constructs the mesh objects, generates the normals and all
    your_mesh = Mesh(data, remove_empty_areas=True)

    filename = str(self.id) + '.stl'

    old_path = os.getcwd()  #Save old directory
    new_path = popupcad.exportdir + os.path.sep  #Load export directory
    os.chdir(new_path)  #Change to export directory
    print("Saving in " + str(new_path))
    your_mesh.save(filename)  #Apparently save does not like absolute paths
    print(filename + " has been saved")
    os.chdir(old_path)  #Change back to old directory
    def toSTL(self):
        """
        Exports the current laminate as an STL file
        """
        from stl.mesh import Mesh #Requires numpy-stl 
        layerdef = self.layerdef
        laminate_verts = []
        for layer in layerdef.layers:
            shapes = self.geoms[layer]#TODO Add it in for other shapes         
            zvalue = layerdef.zvalue[layer]      
            thickness = layer.thickness
            if (len(shapes) == 0) : #In case there are no shapes.
                print("No shapes skipping")            
                continue
            for s in shapes:
                shape_verts = s.extrudeVertices(thickness, z0=zvalue)
                laminate_verts.extend(shape_verts)
    
        laminate_verts = [point/popupcad.SI_length_scaling for point in laminate_verts]
        # Or creating a new mesh (make sure not to overwrite the `mesh` import by
        # naming it `mesh`):
        VERTICE_COUNT = len(laminate_verts)//3 #Number of verticies
        data = numpy.zeros(VERTICE_COUNT, dtype=Mesh.dtype) #We create an array full of zeroes. Will edit it later.
        #Creates a mesh from the specified set of points
        for dtype, points in zip(data, numpy.array(laminate_verts).reshape(-1,9)):
            points = points.reshape(-1, 3) #Splits each triangle into points
            numpy.copyto(dtype[1], points) #Copies the list of points into verticies index
        
        data = Mesh.remove_duplicate_polygons(data)
        
        #This constructs the mesh objects, generates the normals and all
        your_mesh = Mesh(data, remove_empty_areas=True)

        filename =  str(self.id) + '.stl'
                
        old_path = os.getcwd() #Save old directory
        new_path = popupcad.exportdir + os.path.sep #Load export directory
        os.chdir(new_path) #Change to export directory
        print("Saving in " + str(new_path))
        your_mesh.save(filename)#Apparently save does not like absolute paths
        print(filename + " has been saved")
        os.chdir(old_path) #Change back to old directory
Exemple #6
0
#    with open(tmp_file,'w+') as fh:
#        fh.write(tmp_file)
#        fh.seek(0)
#        mesh.Mesh.from_file(str(tmp_file), fh=fh, speedups=speedups)
#
#test_valid_ascii(cwd, 'speedups')
#
#def zero_runs(a):  # from link
#    iszero = np.concatenate(([0][0], np.equal(a, 0).view(np.int8), [0]))
#    absdiff = np.abs(np.diff(iszero))
#    ranges = np.where(absdiff == 1)[0].reshape(-1, 2)
#    return ranges

# Using an existing stl file:
your_mesh = mesh.Mesh.from_file("pistons.stl")
Mesh.remove_duplicate_polygons(mesh.data, RemoveDuplicates.NONE)
mesh = Mesh(your_mesh, remove_duplicate_polygons=RemoveDuplicates.ALL)

# =============================================================================
# To Plot the object using mathplotlib
# =============================================================================
# Create a new plot
#figure = pyplot.figure()
#axes = mplot3d.Axes3D(figure)
#
## Load the STL files and add the vectors to the plot
##axes.add_collection3d(mplot3d.art3d.Poly3DCollection(your_mesh.vectors[0:3500][:][:]))
#axes.add_collection3d(mplot3d.art3d.Poly3DCollection(your_mesh.vectors[0:2000][:][:],edgecolor='k'))
#
## Auto scale to the mesh size
#scale = your_mesh.points.flatten(-1)