MVA-2021 / npm3d / hw1_basics / code / transformation.py
transformation.py
Raw
import numpy as np
from ply import write_ply, read_ply

if __name__ == '__main__':

    # Load point cloud
    # ****************
    #

    # Path of the file
    file_path = '../data/bunny.ply'

    # Load point cloud
    data = read_ply(file_path)

    # Concatenate x, y, and z in a (N*3) point matrix
    points = np.vstack((data['x'], data['y'], data['z'])).T

    # Concatenate R, G, and B channels in a (N*3) color matrix
    colors = np.vstack((data['red'], data['green'], data['blue'])).T

    # Transform point cloud
    centroid = np.mean(points, axis=0)
    transformed_points = points - centroid
    transformed_points /= 2.0
    transformed_points += centroid
    transformed_points += np.array([0,-0.10,0])

    # Save point cloud
    # *********************
    #
    #   Save your result file
    #   (See write_ply function)
    #

    # Save point cloud
    write_ply('../little_bunny.ply', [transformed_points, colors], ['x', 'y', 'z', 'red', 'green', 'blue'])

    print('Done')