def genLayoutDepthMap(scene, size): depthMap = np.zeros(size) for y in range(0, size[0]): for x in range(0, size[1]): coords = utils.pos2coords((y,x), size) coordsT = utils.posTranspose(coords) vec = utils.coords2xyz(coordsT, 1) if y <= int(size[0]/2): plane = scene.label.getLayoutCeiling().planeEquation else: plane = scene.label.getLayoutFloor().planeEquation point = utils.vectorPlaneHit(vec, plane) depth = 0 if point is None else utils.pointsDistance((0,0,0), point) depthMap[y,x] = depth for wall in scene.label.getLayoutWalls(): if wall.planeEquation[3] > 0: continue isCross, polygon = genWallPolygon2d(size, wall) if not isCross: utils.imageDrawWallDepth(depthMap, polygon, wall) else: utils.imageDrawWallDepth(depthMap, polygon[0], wall) utils.imageDrawWallDepth(depthMap, polygon[1], wall) return depthMap
def imageDrawWallDepth(data, polygon, wall): size = (data.shape[1], data.shape[0]) polyx = np.array([p[0] for p in polygon]) polyy = np.array([p[1] for p in polygon]) posy, posx = draw.polygon(polyy, polyx) for i in range(len(posy)): coords = utils.pos2coords((posx[i], posy[i]), size) vec = utils.coords2xyz(coords, 1) point = utils.vectorPlaneHit(vec, wall.planeEquation) depth = 0 if point is None else utils.pointsDistance((0, 0, 0), point) color = (depth, depth, depth) draw.set_color(data, [posy[i], posx[i]], list(color))