Beispiel #1
0
def _create_renderer_mesh(  # pylint: disable=too-many-arguments
        w=640,
        h=480,
        rt=np.zeros(3),
        t=np.zeros(3),
        f=None,
        c=None,
        k=None,
        near=1.,
        far=10.,
        texture=None):
    """Create a renderer for the specified parameters."""
    f = np.array([w, w]) / 2. if f is None else f
    c = np.array([w, h]) / 2. if c is None else c
    k = np.zeros(5) if k is None else k

    if texture is not None:
        rn = TexturedRenderer()
    else:
        rn = ColoredRenderer()

    rn.camera = ProjectPoints(rt=rt, t=t, f=f, c=c, k=k)
    rn.frustum = {'near': near, 'far': far, 'height': h, 'width': w}

    if texture is not None:
        rn.texture_image = np.asarray(texture, np.float64) / 255.
        rn.texture_image = rn.texture_image[:, :, ::-1]
        #print rn.texture_image.shape
    return rn
Beispiel #2
0
def create_renderer(w=640,
                    h=480,
                    rt=np.zeros(3),
                    t=np.zeros(3),
                    f=None,
                    c=None,
                    k=None,
                    near=.5,
                    far=10.,
                    mesh=None):
    f = np.array([w, w]) / 2. if f is None else f
    c = np.array([w, h]) / 2. if c is None else c
    k = np.zeros(5) if k is None else k

    if mesh is not None and hasattr(mesh, 'texture_image'):
        from opendr.renderer import TexturedRenderer
        rn = TexturedRenderer()
        rn.texture_image = mesh.texture_image
        if rn.texture_image.max() > 1:
            rn.texture_image[:] = rn.texture_image[:].r / 255.
        rn.ft = mesh.ft
        rn.vt = mesh.vt
    else:
        from opendr.renderer import ColoredRenderer
        rn = ColoredRenderer()

    rn.camera = ProjectPoints(rt=rt, t=t, f=f, c=c, k=k)
    rn.frustum = {'near': near, 'far': far, 'height': h, 'width': w}
    return rn