from utilities import get_INTER_and_EXTER_Orientations
from utilities import frustum_culling
from utilities import HPR
from utilities import pointcloud2pixelcoord

from utilities import generation_syntheticImg_nadir

path_Imgs = "./data/nadir_imgs_data/Images/"
file_Ori = "./data/nadir_imgs_data/All Camera Orientations/txt/extOri.txt"

file_XYZ = "./data/nadir_imgs_data/features_dense_LiDAR_cloud_5cm/Data_xyz.txt"
file_Features = "./data/nadir_imgs_data/features_dense_LiDAR_cloud_5cm/X.txt"
file_Labels = "./data/nadir_imgs_data/features_dense_LiDAR_cloud_5cm/y.txt"

save_path = "./results/nadir/"
make_if_not_exists(save_path)

print("reading data from txt file...")
start_time = time.time()
pt_xyz = np.loadtxt(file_XYZ)
pt_features = np.loadtxt(file_Features)
pt_labels = np.loadtxt(file_Labels)
duration = time.time() - start_time
print("which costs {0}s\n".format(duration))

index = np.asarray([_ for _ in range(pt_labels.shape[0])]).astype(np.int)

img_list = os.listdir(path_Imgs)
for i in tqdm(range(len(img_list))):

    img_name = img_list[i]
import math
import tifffile
"""
    ** Code for generation of depth image
"""

# Global varianbles
path_reference = "/run/user/1001/gvfs/smb-share:server=141.58.125.9,share=s-platte/ShuFangwen/results/lvl4_nadir/validation_set/4_colorlabel"  # where provide a list of visible images

path_Imgs = "/run/user/1001/gvfs/smb-share:server=141.58.125.9,share=s-platte/ShuFangwen/data/Nadir_level3_level4_level5/ImgTexture/Level_4/"
path_Ori = "/run/user/1001/gvfs/smb-share:server=141.58.125.9,share=s-platte/ShuFangwen/data/Nadir_level3_level4_level5/Ori/Level_4/"

file_XYZ = "/run/user/1001/gvfs/smb-share:server=141.58.125.9,share=s-platte/ShuFangwen/data/Data_11_1_19_5cm/val_xyz_y.txt"

save_path = "/data/fangwen/depth_img_lvl4_nadir/validation_set"
utilities.make_if_not_exists(save_path)

# Reading data
print("read points cloud from txt file...")
start_time = time.time()
pt_xyz = np.loadtxt(file_XYZ)[:, :3]
duration = time.time() - start_time
print("which needs {0}s\n".format(duration))

# Processing
img_list = os.listdir(
    path_reference)  # length = 416, as for 5cm LiDAR pointcloud

for img_name in img_list:

    ori_name = img_name.replace("tif", "ori")