Exemplo n.º 1
0
def geometry(settings, layer, feat, geom):
  polygons = []
  zs = []
  for polygon in geom.polygons:
    bnds = []
    zsum = zcount = 0
    for boundary in polygon:
      bnds.append([[pt.x, pt.y] for pt in boundary])
      zsum += sum([pt.z for pt in boundary], -boundary[0].z)
      zcount += len(boundary) - 1
    polygons.append(bnds)
    zs.append(zsum / zcount)

  g = {"polygons": polygons}

  if layer.prop.type_index == 0:  # Extruded
    g["zs"] = zs
    g["h"] = feat.values[2] * settings.mapTo3d().multiplierZ

  else:   # Overlay
    #TODO: mb and ms
    # border
    #if feat.values[2] is not None:
    #  g["mb"] = layer.materialManager.getLineBasicIndex(feat.values[2], feat.values[1])

    # side
    if feat.values[3]:
      #g["ms"] = layer.materialManager.getMeshLambertIndex(feat.values[4], feat.values[1], doubleSide=True)

      # bottom height of side
      g["sb"] = feat.values[5] * settings.mapTo3d().multiplierZ

    # If height mode is relative to DEM, height from DEM. Otherwise from zero altitude.
    # Vertical shift is not considered (will be shifted in JS).
    g["h"] = feat.relativeHeight() * settings.mapTo3d().multiplierZ

    polygons = []
    triangles = Triangles()
    for polygon in geom.split_polygons:
      boundary = polygon[0]
      if len(polygon) == 1 and len(boundary) == 4:
        triangles.addTriangle(boundary[0], boundary[2], boundary[1])    # vertex order should be counter-clockwise
      else:
        bnds = [[[pt.x, pt.y] for pt in bnd] for bnd in polygon]
        polygons.append(bnds)

    if triangles.vertices:
      g["triangles"] = {"v": [[pt.x, pt.y] for pt in triangles.vertices], "f": triangles.faces}

    if polygons:
      g["split_polygons"] = polygons

  if geom.centroids:
    g["centroids"] = [[pt.x, pt.y, pt.z] for pt in geom.centroids]

  return g
Exemplo n.º 2
0
    def geometry(cls, settings, layer, feat, geom):
        if layer.prop.isHeightRelativeToDEM():
            g = {}

            polygons = []
            triangles = Triangles()
            for polygon in geom.polygons:
                boundary = polygon[0]
                if len(polygon) == 1 and len(boundary) == 4:
                    triangles.addTriangle(
                        boundary[0], boundary[2], boundary[1]
                    )  # vertex order should be counter-clockwise
                else:
                    bnds = [[[pt.x, pt.y, pt.z] for pt in bnd]
                            for bnd in polygon]
                    polygons.append(bnds)

            if triangles.vertices:
                g["triangles"] = {
                    "v": [[pt.x, pt.y, pt.z] for pt in triangles.vertices],
                    "f": triangles.faces
                }

            if polygons:
                g["split_polygons"] = polygons

            if geom.centroids:
                g["centroids"] = [[pt.x, pt.y, pt.z] for pt in geom.centroids]

        else:
            g = PolygonBasicTypeBase.geometry(settings, layer, feat, geom)

        g["h"] = feat.altitude * settings.mapTo3d().multiplierZ

        #TODO: [Polygon - Overlay] border
        # if feat.values[2] is not None:
        #   g["mb"] = layer.materialManager.getLineBasicIndex(feat.values[2], feat.values[1])

        return g
Exemplo n.º 3
0
def write(writer, layer, feat):
    vals = feat.propValues()
    polygons = []
    zs = []
    for polygon in feat.geom.polygons:
        bnds = []
        zsum = zcount = 0
        for boundary in polygon:
            bnds.append(map(lambda pt: [pt.x, pt.y], boundary))
            zsum += sum(map(lambda pt: pt.z, boundary), -boundary[0].z)
            zcount += len(boundary) - 1
        polygons.append(bnds)
        zs.append(zsum / zcount)

    d = {"polygons": polygons}

    if feat.prop.type_index == 0:  # Extruded
        d["m"] = layer.materialManager.getMeshLambertIndex(vals[0], vals[1])
        d["zs"] = zs
        d["h"] = float(vals[2]) * writer.settings.mapTo3d().multiplierZ

    else:  # Overlay
        if vals[0] == ColorTextureWidgetFunc.MAP_CANVAS:
            d["m"] = layer.materialManager.getCanvasImageIndex(vals[1])
        elif isinstance(vals[0], list):  # LAYER
            size = writer.settings.mapSettings.outputSize()
            extent = writer.settings.baseExtent
            d["m"] = layer.materialManager.getLayerImageIndex(
                vals[0], size.width(), size.height(), extent, vals[1])
        else:
            d["m"] = layer.materialManager.getMeshLambertIndex(
                vals[0], vals[1], True)

        # border
        if vals[2] is not None:
            d["mb"] = layer.materialManager.getLineBasicIndex(vals[2], vals[1])

        # side
        if vals[3]:
            d["ms"] = layer.materialManager.getMeshLambertIndex(
                vals[4], vals[1], doubleSide=True)

            # bottom height of side
            d["sb"] = vals[5] * writer.settings.mapTo3d().multiplierZ

        # If height mode is relative to DEM, height from DEM. Otherwise from zero altitude.
        # Vertical shift is not considered (will be shifted in JS).
        d["h"] = feat.relativeHeight() * writer.settings.mapTo3d().multiplierZ

        polygons = []
        triangles = Triangles()
        for polygon in feat.geom.split_polygons:
            boundary = polygon[0]
            if len(polygon) == 1 and len(boundary) == 4:
                triangles.addTriangle(
                    boundary[0], boundary[2],
                    boundary[1])  # vertex order should be counter-clockwise
            else:
                bnds = [map(lambda pt: [pt.x, pt.y], bnd) for bnd in polygon]
                polygons.append(bnds)

        if triangles.vertices:
            d["triangles"] = {
                "v": map(lambda pt: [pt.x, pt.y], triangles.vertices),
                "f": triangles.faces
            }

        if polygons:
            d["split_polygons"] = polygons

    if feat.geom.centroids:
        d["centroids"] = map(lambda pt: [pt.x, pt.y, pt.z],
                             feat.geom.centroids)

    writer.writeFeature(d)
Exemplo n.º 4
0
def write(writer, layer, feat):
  vals = feat.propValues()
  polygons = []
  zs = []
  for polygon in feat.geom.polygons:
    bnds = []
    zsum = zcount = 0
    for boundary in polygon:
      bnds.append(map(lambda pt: [pt.x, pt.y], boundary))
      zsum += sum(map(lambda pt: pt.z, boundary), -boundary[0].z)
      zcount += len(boundary) - 1
    polygons.append(bnds)
    zs.append(zsum / zcount)

  d = {"polygons": polygons}

  if feat.prop.type_index == 0:  # Extruded
    d["m"] = layer.materialManager.getMeshLambertIndex(vals[0], vals[1])
    d["zs"] = zs
    d["h"] = float(vals[2]) * writer.settings.mapTo3d().multiplierZ

  else:   # Overlay
    if vals[0] == ColorTextureWidgetFunc.MAP_CANVAS:
      d["m"] = layer.materialManager.getCanvasImageIndex(vals[1])
    elif isinstance(vals[0], list):   # LAYER
      size = writer.settings.mapSettings.outputSize()
      extent = writer.settings.baseExtent
      d["m"] = layer.materialManager.getLayerImageIndex(vals[0], size.width(), size.height(), extent, vals[1])
    else:
      d["m"] = layer.materialManager.getMeshLambertIndex(vals[0], vals[1], True)

    # border
    if vals[2] is not None:
      d["mb"] = layer.materialManager.getLineBasicIndex(vals[2], vals[1])

    # side
    if vals[3]:
      d["ms"] = layer.materialManager.getMeshLambertIndex(vals[4], vals[1], doubleSide=True)

      # bottom height of side
      d["sb"] = vals[5] * writer.settings.mapTo3d().multiplierZ

    # If height mode is relative to DEM, height from DEM. Otherwise from zero altitude.
    # Vertical shift is not considered (will be shifted in JS).
    d["h"] = feat.relativeHeight() * writer.settings.mapTo3d().multiplierZ

    polygons = []
    triangles = Triangles()
    for polygon in feat.geom.split_polygons:
      boundary = polygon[0]
      if len(polygon) == 1 and len(boundary) == 4:
        triangles.addTriangle(boundary[0], boundary[2], boundary[1])    # vertex order should be counter-clockwise
      else:
        bnds = [map(lambda pt: [pt.x, pt.y], bnd) for bnd in polygon]
        polygons.append(bnds)

    if triangles.vertices:
      d["triangles"] = {"v": map(lambda pt: [pt.x, pt.y], triangles.vertices), "f": triangles.faces}

    if polygons:
      d["split_polygons"] = polygons

  if feat.geom.centroids:
    d["centroids"] = map(lambda pt: [pt.x, pt.y, pt.z], feat.geom.centroids)

  writer.writeFeature(d)