def calcWaterline(zh, cutter,s):
    #wl = ocl.Waterline()
    wl = ocl.AdaptiveWaterline()
    wl.setSTL(s)
    wl.setCutter(cutter)
    wl.setZ(zh)
    wl.setSampling(0.01)
    wl.setThreads(4)
    t_before = time.time() 
    wl.run()
    t_after = time.time()
    calctime = t_after-t_before
    print " Waterline done in ", calctime," s"
    out = []
    out.append(wl.getLoops())
    out.append(wl.getXFibers())
    out.append(wl.getYFibers())
    return out
Пример #2
0
    #wl.setThreads(5)
    t_before = time.time() 
    wl.run2()
    t_after = time.time()
    calctime = t_after-t_before
    print " Waterline done in ", calctime," s"
    cutter_loops = wl.getLoops()
    for l in cutter_loops:
        loops.append(l)
    """
    sampling = 1
    minSampling = 0.1

    aloops = []
    for zh in zheights:
        awl = ocl.AdaptiveWaterline()
        awl.setSTL(s)
        awl.setCutter(cutter)
        awl.setZ(zh)
        awl.setSampling(sampling)
        awl.setMinSampling(minSampling)
        #wl.setThreads(5)
        t_before = time.time()
        awl.run()
        t_after = time.time()
        calctime = t_after - t_before
        print " AdaptiveWaterline done in ", calctime, " s"
        acutter_loops = awl.getLoops()
        for l in acutter_loops:
            aloops.append(l)
Пример #3
0
    def generate(self):

        self.set_tool(tool=self._tool)

        stepdown = min(self.stepdown * self.material_factor,
                       2) * self.tool.diameter
        boundary = self.get_boundary()

        if isinstance(self.boundary, (tuple, list)):
            minx, miny, maxx, maxy = self.boundary
            self.boundary = Polygon((
                (minx, miny),
                (minx, maxy),
                (maxx, maxy),
                (maxy, miny),
            ))

        cutter = self.ocl_cutter()
        minz = self.minZ if self.minZ is not None else self.surface.range[2][0]
        maxz = self.maxZ if self.maxZ is not None else self.surface.range[2][1]
        clearz = self.clearZ or maxz

        if self.adaptive:
            wl = ocl.AdaptiveWaterline(
            )  # this is slower, ca 60 seconds on i7 CPU
            wl.setMinSampling(0.01)
        else:
            wl = ocl.Waterline()  # total time 14 seconds on i7 CPU

        surf = self.surface.get_ocl_stl_surf()
        wl.setSTL(surf)  # surface MUST be saved in a variable first
        wl.setCutter(cutter)
        wl.setSampling(
            0.0314
        )  # this should be smaller than the smallest details in the STL file

        for zh in frange(maxz, minz, stepdown):
            wl.reset()
            wl.setZ(zh)  # height for this waterline
            wl.run()

            for path in wl.getLoops():
                fpath = self.filter_path(path, self.tolerance)

                coords = [(a.x, a.y, a.z) for a in fpath]
                coords.append(coords[0])
                ls = LineString(coords)
                inter = boundary.intersection(ls)
                if isinstance(inter, MultiLineString):
                    print "MULTI"
                    for lx in inter:
                        self.cut_linestring(lx, zh, clearz=clearz)
                        #Line(lx.coords).graph(fig=fig)
                elif isinstance(inter, LineString):
                    print "SINGLE"
                    self.cut_linestring(inter, zh, clearz=clearz)
                    #Line(inter.coords).graph(fig=fig)
                elif isinstance(inter, GeometryCollection):
                    for foo in inter:
                        print "COLLECTION", foo.__class__
                        sys.exit(0)
                else:
                    print "WEIRD", inter.__class__
                    sys.exit(0)