Ejemplo n.º 1
0
 def __init__(self, tag=None, layout=None, offset=1):
     # handles:
     # - file-based (tag=foo, layout=None)
     # - layout-based (tag=None, layout=[[[(1, 'Stone')]]])
     if tag is None and layout is None:
         raise AttributeError('tag or layout must be specified')
     if layout is None:
         filename = 'schematics/%s.schematic' % tag
         if not os.path.exists(filename):
             raise IOError('no file found')
         else:
             schem = mclevel.fromFile(filename)
             self.layout = [[
                 Schematic.compressrow([(1, (int(schem.Blocks[elemX, elemZ,
                                                              elemY]),
                                             int(schem.Data[elemX, elemZ,
                                                            elemY])))
                                        for elemY in xrange(schem.Height)])
                 for elemZ in xrange(schem.Length)
             ] for elemX in xrange(schem.Width)]
     else:
         self.layout = layout
     self.offset = offset
     self.width = len(self.layout)
     self.length = len(self.layout[0])
     self.height = height(self.layout[0][0])
Ejemplo n.º 2
0
 def __init__(self, tag=None, layout=None, offset=1):
     # handles:
     # - file-based (tag=foo, layout=None)
     # - layout-based (tag=None, layout=[[[(1, 'Stone')]]])
     if tag == None and layout == None:
         raise AttributeError, "tag or layout must be specified"
     if layout == None:
         filename = "%s.schematic" % tag
         if not os.path.exists(filename):
             raise IOError, "no file found"
         else:
             schem = mclevel.fromFile(filename)
             self.layout = [
                 [
                     Schematic.compressrow(
                         [
                             (1, (int(schem.Blocks[elemX, elemZ, elemY]), int(schem.Data[elemX, elemZ, elemY])))
                             for elemY in xrange(schem.Height)
                         ]
                     )
                     for elemZ in xrange(schem.Length)
                 ]
                 for elemX in xrange(schem.Width)
             ]
     else:
         self.layout = layout
     self.offset = offset
     self.width = len(self.layout)
     self.length = len(self.layout[0])
     self.height = height(self.layout[0][0])
Ejemplo n.º 3
0
    def place(x, y, z, lcval, crustval, bathyval, doSchematics, r=None, g=None, b=None, ir=None):
        try:
            Terrain.terdict[lcval]
        except KeyError:
            print "lcval value %s not found!" % lcval
        (y, column, tree) = Terrain.terdict.get(lcval, Terrain.terdict[0])(x, y, z, crustval, bathyval, doSchematics)
        merged = [ (depth, (block, 0)) if type(block) is not tuple else (depth, block) for (depth, block) in column ]
        # y=0 is always bedrock
        blocks = [ (0, materialNamed('Bedrock')) ]
        datas = [ (0, 0) ]
        core = [ ((y - height(merged)), ('End Stone', 0)) ] + merged
        base = 0
        while core:
            (depth, (block, data)) = core.pop(0)
            [ blocks.append((y, materialNamed(block) if type(block) is str else block)) for y in xrange(base, base+depth) if y > 0 ]
            [ datas.append((y, data)) for y in xrange(base, base+depth) if y > 0 ]
            base += depth

        water = materialNamed('Water')
        water = water(0) if type(water) is tuple else water 
        iswater = (block == 'Water') if type(block) is str else (block == water)
        if haveOrthoColors and not(iswater):
            [block, data] = mcBlockData.nearest(r, g, b, ir, not(lcval >= 22 and lcval <=25))
            blocks[-1] = (blocks[-1][0], block)
            datas[-1] = (datas[-1][0], data)

        return blocks, datas, tree
Ejemplo n.º 4
0
 def place(x, y, z, lcval, crustval, bathyval, doSchematics):
     try:
         Terrain.terdict[lcval]
     except KeyError:
         print "lcval value %s not found!" % lcval
     (y, column,
      tree) = Terrain.terdict.get(lcval,
                                  Terrain.terdict[0])(x, y, z, crustval,
                                                      bathyval,
                                                      doSchematics)
     merged = [(depth, block) if isinstance(block, tuple) else
               (depth, (block, 0)) for (depth, block) in column]
     # y=0 is always bedrock
     blocks = [(0, materialNamed('Bedrock'))]
     datas = [(0, 0)]
     core = [((y - height(merged)), ('End Stone', 0))] + merged
     base = 0
     while core:
         (depth, (block, data)) = core.pop(0)
         [
             blocks.append((y, materialNamed(block) if isinstance(
                 block, basestring) else block))
             for y in xrange(base, base + depth) if y > 0
         ]
         [
             datas.append((y, data)) for y in xrange(base, base + depth)
             if y > 0
         ]
         base += depth
     return blocks, datas, tree
Ejemplo n.º 5
0
    def check(self, verbose=False):
        if not all([len(row) == self.length for row in self.layout]):
            raise AttributeError('not all rows are the same width')

        if not all([height(col) == self.height for row in self.layout for col in row]):
            raise AttributeError('not all cols are the same height')

        if verbose:
            print "schematic has dimensions %dX x %dY x %dZ" % (self.length, self.height, self.width)
Ejemplo n.º 6
0
    def separate_cubes(self, mask):
        contours = self.find_contours(mask)[0]
        total_areas = []

        for cnt in contours:
            cnt = utils.approx_hull(cnt)
            area = cv2.contourArea(cnt)
            total_areas.append(area)
            avg_area = sum(total_areas) / len(total_areas)
            if len(cnt) > 3 and area > 100 and area / avg_area >= 1.5:
                aspect_ratio = utils.rotated_aspect_ratio(cnt)
                reversed_aspect_ratio = utils.reversed_rotated_aspect_ratio(
                    cnt)
                if 3 > reversed_aspect_ratio >= 0.7 or 3 > aspect_ratio >= 0.7:
                    side = max(utils.width(cnt),
                               utils.height(cnt),
                               key=utils.index0)[0]
                    (x1, y1), (x2, y2) = min(utils.width(cnt),
                                             utils.height(cnt),
                                             key=utils.index0)[1:]
                    cubes = round(
                        max(
                            aspect_ratio / (utils.power_cube['width'] /
                                            utils.power_cube['height']),
                            reversed_aspect_ratio) /
                        (utils.power_cube['height'] /
                         utils.power_cube['width']))
                    single_cube = side / cubes
                    vertical = 0
                    horizontal = 0
                    if utils.width(cnt) >= utils.height(cnt):
                        vertical = 1
                    else:
                        horizontal = 1
                    for i in range(1, cubes + 1):
                        cv2.line(mask,
                                 (int(x2 + single_cube * vertical * i),
                                  int(y2 + single_cube * horizontal * i)),
                                 (int(x1 + single_cube * vertical * i),
                                  int(y1 + single_cube * horizontal * i)),
                                 (0, 0, 0),
                                 thickness=15)

        return mask
Ejemplo n.º 7
0
    def check(self, verbose=False):
        if not all([len(row) == self.length for row in self.layout]):
            raise AttributeError('not all rows are the same width')

        if not all(
            [height(col) == self.height for row in self.layout
             for col in row]):
            raise AttributeError('not all cols are the same height')

        if verbose:
            print "schematic has dimensions %dX x %dY x %dZ" % (
                self.length, self.height, self.width)
Ejemplo n.º 8
0
 def place(x, y, z, lcval, crustval, bathyval, doSchematics):
     try:
         Terrain.terdict[lcval]
     except KeyError:
         print "lcval value %s not found!" % lcval
     (y, column, tree) = Terrain.terdict.get(lcval, Terrain.terdict[0])(x, y, z, crustval, bathyval, doSchematics)
     merged = [ (depth, (block, 0)) if type(block) is not tuple else (depth, block) for (depth, block) in column ]
     # y=0 is always bedrock
     blocks = [ (0, materialNamed('Bedrock')) ]
     datas = [ (0, 0) ]
     core = [ ((y - height(merged)), ('End Stone', 0)) ] + merged
     base = 0
     while core:
         (depth, (block, data)) = core.pop(0)
         [ blocks.append((y, materialNamed(block) if type(block) is str else block)) for y in xrange(base, base+depth) if y > 0 ]
         [ datas.append((y, data)) for y in xrange(base, base+depth) if y > 0 ]
         base += depth
     return blocks, datas, tree