wu_xinjun
2022-06-27 1292adc7aafa34a7c93c80390826bdc5b6d05cbf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from aifc import Error
import os,sys
from tkinter import E
import numpy as np
from tqdm import tqdm
 
from .core import merge_ply
from ..utils import read_ply,write_ply,file_fliter
from ..microwave.deviceTools import udp2bin_tool,bin2ply_tool
 
def manual_merge(folder,alpha,beta,gamma,savename):
    """ 
    merge the ply files according to the sub folder name, like 0, 20, -30 ...
    """
 
    for root, dirs, files in os.walk(folder,topdown=True):
        break
    
    dirs.sort(key = lambda x:float(x))
    dir_List = dirs
 
    angle = []
    index = 0 
    for i,degree in enumerate([alpha,beta,gamma]):
        if degree == "auto":
            degree = dir_List
            index = i
        angle.append(degree)
 
    data = []
    
    print("reading ply files ...")
    # iterate the auto angle degree
    for an in tqdm(angle[index]):
        ply_with_mutiangle = []
        for z in angle:
            if isinstance(z,list):
                z = an
            ply_with_mutiangle.append(-float(z))
        ply_name_list = file_fliter(os.path.join(folder,an), "ply",lambda x:int(x.split(".")[0]))
        if len(ply_name_list) == 0:
            try:
                udp2bin_tool(os.path.join(folder,an))
                bin2ply_tool(os.path.join(folder,an))
                ply_name_list = file_fliter(os.path.join(folder,an), "ply",lambda x:int(x.split(".")[0]))
            except Exception as e:
                raise ValueError(f"Can't find any .udp .bin or .ply files in folder {os.path.join(folder,an)}")
        else:
            pass
 
        # select the all ply files
        for i in range(len(ply_name_list)):
            ply_with_mutiangle_copy = ply_with_mutiangle.copy()
            ply = read_ply(os.path.join(folder,an,ply_name_list[i]))
            ply_with_mutiangle_copy.append(ply)
            data.append(ply_with_mutiangle_copy)
 
    # compose muti ply files to one ply file
    cloudpoint = merge_ply(data)
 
    # write the file
    print("Writing the data to disk ...")
    write_ply(cloudpoint, folder, savename)