#!/usr/bin/env python3
# coding: utf-8

"""
A demo for rendering mesh generated by `main.py`
"""

from rendering import cfg, _to_ctype, RenderPipeline
import scipy.io as sio
import imageio
import numpy as np
import matplotlib.pyplot as plt


def test():
    # 1. first, using main.py to generate dense vertices, like emma_input_0.mat
    fp = '../samples/emma_input_0.mat'
    vertices = sio.loadmat(fp)['vertex'].T  # 3xm
    print(vertices.shape)
    img = imageio.imread('../samples/emma_input.jpg').astype(np.float32) / 255.

    # 2. render it
    # triangles = sio.loadmat('tri_refine.mat')['tri']  # mx3
    triangles = sio.loadmat('../visualize/tri.mat')['tri'].T - 1  # mx3
    print(triangles.shape)
    triangles = _to_ctype(triangles).astype(np.int32)  # for type compatible
    app = RenderPipeline(**cfg)
    img_render = app(vertices, triangles, img)

    plt.imshow(img_render)
    plt.show()


def main():
    test()


if __name__ == '__main__':
    main()
