Exemple #1
0
def main():
    gl = libcutsim.GLData()  # this class holds lines, triangles, or quads for OpenGL drawing
    iso = libcutsim.MarchingCubes()  # this is the algorithm that produces GLData from the stock-model
    octree_size = 10.0  # size of 'world'
    octree_max_depth = 8
    cs = libcutsim.Cutsim(octree_size, octree_max_depth, gl, iso) # this is the cutting simulation
    print(cs)

    cs.init(3)  # initialize by subdividing octree n-times
    print(cs)

    # create stock material
    vol = libcutsim.SphereVolume()  # a volume with which we operate on the stock
    vol.setRadius(4)
    vol.setCenter(0, 0, 0)
    cs.sum_volume(vol)  # sum the volume to the stock, creating new stock material

    # resize/position the same sphere for a cut
    vol.setRadius(1)
    vol.setCenter(0, 4, 0)
    cs.diff_volume(vol)  # subtract the volume from the stock

    cs.updateGL()  # this updates the GLData so we can draw the stock

    # generate an stl file
    dir = os.path.dirname(__file__)
    file_name = "libcutsim.stl"
    file_path = dir + os.sep + file_name
    stl_file_path = gl.get_stl(file_path, True)  # second parameter True for binary stl, False for assci
    print("stl file written:", stl_file_path)
Exemple #2
0
def main():
    gl = libcutsim.GLData(
    )  # this class holds lines, triangles, or quads for OpenGL drawing
    iso = libcutsim.MarchingCubes(
    )  # this is the algorithm that produces GLData from the stock-model
    cs = libcutsim.Cutsim(20.0, 9, gl, iso)  # this is the cutting simulation
    print(cs)

    cs.init(3)  # initialize by subdividing octree n-times
    print(cs)

    vol = libcutsim.CubeVolume()  # a volume with which we operate on the stock
    vol.setSide(10)
    vol.setCenter(0, 0, -5)

    cs.sum_volume(vol)  # sum the volume to the stock, creating new material

    # the volume with which we cut

    cutter = libcutsim.SphereVolume()
    cutter.setRadius(float(0.7))
    # move around the cutter and subtract at each point
    t_before = time.time()
    Nmax = 100
    for n in range(Nmax):
        x = 3 * math.cos(0.1 * n)
        y = -3 + 0.08 * n
        #print x,y
        cutter.setCenter(x, y, 0.1)
        cs.diff_volume(cutter)  # subtract the volume from the stock
        #cs.updateGL()
    t_after = time.time()
    print(Nmax, " diff() calls took ", t_after - t_before, " seconds")
    cs.updateGL()
    # this updates the GLData so we can draw the stock

    print(cs)
    print(gl)

    # create a VTK view for drawing
    w = 1024
    h = 1024
    myscreen = myvtk.VTKScreen(width=w, height=h)

    myvtk.drawTriangles(myscreen, gl.get_triangles())

    myscreen.render()
    myscreen.iren.Start()
Exemple #3
0
def main():
    gl = libcutsim.GLData(
    )  # this class holds lines, triangles, or quads for OpenGL drawing
    iso = libcutsim.MarchingCubes(
    )  # this is the algorithm that produces GLData from the stock-model
    octree_size = 10.0  # size of 'world'
    octree_max_depth = 8
    cs = libcutsim.Cutsim(octree_size, octree_max_depth, gl,
                          iso)  # this is the cutting simulation
    print cs

    cs.init(3)  # initialize by subdividing octree n-times
    print cs

    # create stock material
    vol = libcutsim.SphereVolume(
    )  # a volume with which we operate on the stock
    vol.setRadius(4)
    vol.setCenter(0, 0, 0)
    cs.sum_volume(
        vol)  # sum the volume to the stock, creating new stock material

    # resize/position the same sphere for a cut
    vol.setRadius(1)
    vol.setCenter(0, 4, 0)
    cs.diff_volume(vol)  # subtract the volume from the stock

    cs.updateGL()  # this updates the GLData so we can draw the stock

    print cs
    print gl

    # create a VTK view for drawing
    w = 1024
    h = 1024
    myscreen = myvtk.VTKScreen(width=w, height=h)

    myvtk.drawTriangles(myscreen, gl.get_triangles())

    myscreen.render()
    myscreen.iren.Start()
Exemple #4
0
import libcutsim  # https://github.com/aewallin/libcutsim

gl = libcutsim.GLData()  # holds GL-data for drawing
iso = libcutsim.MarchingCubes()  # isosurface algorithm
world_size = 10.0
max_tree_depth = 5
cs = libcutsim.Cutsim(world_size, max_tree_depth, gl,
                      iso)  # cutting simulation
print cs

cs.init(3)  # initial subdivision of octree
print cs

vol = libcutsim.SphereVolume()  # a volume for adding/subtracting
vol.setRadius(4)
vol.setCenter(0, 0, 0)

cs.sum_volume(vol)  # add volume to octree
cs.updateGL()

print cs
print gl