def test_00_generate_layers(self):
        """Generate some layers and validate them"""
        print "\nGenerating a set of simple slices on my head."
        stl = helpers.get_head()
        surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, 1024, 1024)
        ctx = cairo.Context (surf)
        ctx.scale (1024, 1024)
        ctx.set_source_rgb (0.8, 0.2, 0.5)
        for facet in stl._facets:
            x,y,z = facet['p'][0]
            ctx.move_to(0.5+x/30, 0.5+y/30)

            x,y,z = facet['p'][1]
            ctx.line_to(0.5+x/30,0.5+y/30)
            x,y,z = facet['p'][2]
            ctx.line_to(0.5+x/30,0.5+y/30)
        ctx.set_line_width (0.001)
        ctx.stroke()

        #outpath = os.path.join(
            #os.path.dirname(__file__),
            #'out', 'stl-topview.png')
        #surf.write_to_png(outpath)

        model = Model.from_stl(stl)
        #layers = model.generate_planar_intersections(-0, 1, 10)
        now=time.time()
        layers = model.generate_planar_intersections(0, 0.1, 30, processes=1)
        print "Simple planar intersections: That took %5.5f seconds" % (time.time()-now)
        p = Pool(cpu_count()*4)
Пример #2
0
    def test_00_generate_layers(self):
        """Generate some layers and validate them"""
        print "\nGenerating a set of simple slices on my head."
        stl = helpers.get_head()
        surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, 1024, 1024)
        ctx = cairo.Context(surf)
        ctx.scale(1024, 1024)
        ctx.set_source_rgb(0.8, 0.2, 0.5)
        for facet in stl._facets:
            x, y, z = facet['p'][0]
            ctx.move_to(0.5 + x / 30, 0.5 + y / 30)

            x, y, z = facet['p'][1]
            ctx.line_to(0.5 + x / 30, 0.5 + y / 30)
            x, y, z = facet['p'][2]
            ctx.line_to(0.5 + x / 30, 0.5 + y / 30)
        ctx.set_line_width(0.001)
        ctx.stroke()

        #outpath = os.path.join(
        #os.path.dirname(__file__),
        #'out', 'stl-topview.png')
        #surf.write_to_png(outpath)

        model = Model.from_stl(stl)
        #layers = model.generate_planar_intersections(-0, 1, 10)
        now = time.time()
        layers = model.generate_planar_intersections(0, 0.1, 30, processes=1)
        print "Simple planar intersections: That took %5.5f seconds" % (
            time.time() - now)
        p = Pool(cpu_count() * 4)
    def test_slicing(self):
        """Test initial slicer prototype"""
        stl = helpers.get_box()
        model = Model.from_stl(stl)
        layers = model.generate_planar_intersections(0.4, 1, 31)

        for (zlevel, intersections) in layers:
            for intersection in intersections:
                start, end = intersection
                assert start != end
    def test_02_complex_insets(self):
        """Test a complicated set of insets, on the head model."""
        print "\nPerforming a series of profiling and insetting, " \
                "on a model of rantenki's head."
        stl = helpers.get_head()
        model = Model.from_stl(stl)
        now=time.time()
        layers = [
                (plane[0], Layer.from_CGAL_intersections(plane[1])) for
                    plane in
                    model.generate_planar_intersections(0, 0.5, 30)
                    if len(plane[1])]
        print "Generating slices for %d layers took %3.3f seconds." % (len(layers), time.time()-now)



        now = time.time()
        for layer in layers:
            polys = list(layer[1].polys)

            for erosion in [0.15, 0.3, .45]:
                eroded = [poly.buffer(-erosion) for poly in polys]
        print "Insetting perimeters for 3 loops for %d layers took %3.3f seconds." % (len(layers), time.time()-now)


        return #We don't need to dump files now.
        now = time.time()
        for layer in layers:
            outpath = os.path.join(
                os.path.dirname(__file__),
                'out',
                "layer-%3.3fz.png" % layer[0])
            surf = get_cairo_surf(outpath)
            polys = list(layer[1].polys)
            draw_cairo_polys(polys, surf, (0,0,0.5,1))

            for erosion in [0.15, 0.3, .45]:
                eroded = [poly.buffer(-erosion) for poly in polys]
                draw_cairo_polys(eroded, surf, (0.2, 2*erosion, 0.2, 1))

                for internal in poly.interiors:
                    draw_cairo_polys(internal, surf, (0.2, 0.2, 2*erosion, 1))
            surf.write_to_png(outpath)
        print "Generating hires pngs of the sliced/inset layers took %3.3f seconds." % (time.time()-now)
Пример #5
0
    def test_02_complex_insets(self):
        """Test a complicated set of insets, on the head model."""
        print "\nPerforming a series of profiling and insetting, " \
                "on a model of rantenki's head."
        stl = helpers.get_head()
        model = Model.from_stl(stl)
        now = time.time()
        layers = [(plane[0], Layer.from_CGAL_intersections(plane[1]))
                  for plane in model.generate_planar_intersections(0, 0.5, 30)
                  if len(plane[1])]
        print "Generating slices for %d layers took %3.3f seconds." % (
            len(layers), time.time() - now)

        now = time.time()
        for layer in layers:
            polys = list(layer[1].polys)

            for erosion in [0.15, 0.3, .45]:
                eroded = [poly.buffer(-erosion) for poly in polys]
        print "Insetting perimeters for 3 loops for %d layers took %3.3f seconds." % (
            len(layers), time.time() - now)

        return  #We don't need to dump files now.
        now = time.time()
        for layer in layers:
            outpath = os.path.join(os.path.dirname(__file__), 'out',
                                   "layer-%3.3fz.png" % layer[0])
            surf = get_cairo_surf(outpath)
            polys = list(layer[1].polys)
            draw_cairo_polys(polys, surf, (0, 0, 0.5, 1))

            for erosion in [0.15, 0.3, .45]:
                eroded = [poly.buffer(-erosion) for poly in polys]
                draw_cairo_polys(eroded, surf, (0.2, 2 * erosion, 0.2, 1))

                for internal in poly.interiors:
                    draw_cairo_polys(internal, surf,
                                     (0.2, 0.2, 2 * erosion, 1))
            surf.write_to_png(outpath)
        print "Generating hires pngs of the sliced/inset layers took %3.3f seconds." % (
            time.time() - now)
Пример #6
0
    def test_01_generate_insets(self):
        """Generate some layers and inset them"""
        print "\nUltra simple box model, planar inset testing."
        stl = helpers.get_box()
        model = Model.from_stl(stl)
        now = time.time()
        layers = [
            Layer.from_CGAL_intersections(plane[1])
            for plane in model.generate_planar_intersections(0, 0.1, 30)
            if len(plane[1])
        ]
        for layer in layers:
            eroded_layer = layer.eroded(0.2)
            for poly in eroded_layer.polys:
                exterior = tuple(poly.exterior.coords)
                self.assertEquals(exterior,
                                  ((9.8, -9.8), (-9.8, -9.8), (-9.8, 9.8),
                                   (9.8, 9.8), (9.8, -9.8)))

        print "Generating eroded layer planes took %5.5f seconds" % (
            time.time() - now)
    def test_01_generate_insets(self):
        """Generate some layers and inset them"""
        print "\nUltra simple box model, planar inset testing."
        stl = helpers.get_box()
        model = Model.from_stl(stl)
        now=time.time()
        layers = [
                Layer.from_CGAL_intersections(plane[1]) for
                    plane in
                    model.generate_planar_intersections(0, 0.1, 30)
                    if len(plane[1])]
        for layer in layers:
            eroded_layer = layer.eroded(0.2)
            for poly in eroded_layer.polys:
                exterior = tuple(poly.exterior.coords)
                self.assertEquals(exterior,
                    (
                        (9.8, -9.8), (-9.8, -9.8),
                        (-9.8, 9.8), (9.8, 9.8),
                        (9.8, -9.8)))

        print "Generating eroded layer planes took %5.5f seconds" % (time.time()-now)
 def test_model_numpy(self):
     """Test that the numpy model is structured right."""
     stl = helpers.get_box()
     model = Model.from_stl(stl)
     self.assertEquals(BOX_MODEL_OUT, model.mesh)
 def test_stl2model(self):
     """Test loading an stl and making a model"""
     stl = helpers.get_box()
     model = Model.from_stl(stl)