forked from RePAIRProject/AAFR
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new version now it should prepare and assemble a list of broken objec…
…ts, testing
- Loading branch information
freerafiki
committed
Jun 7, 2023
1 parent
dbdb681
commit b814e73
Showing
12 changed files
with
328 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# parameters for the pipeline | ||
pipeline_parameters = { | ||
# angles and translation parameters for initial "challenge" position | ||
'challenge_R_T' : [[0.2, 0.2, 0.1], [-0.5, -0.5, -0.5]], | ||
'processing_module' : "standard", | ||
'registration_module' : "teaser", | ||
'evaluation_metrics' : ["rms"] | ||
} | ||
|
||
# data_list | ||
num_of_points = 15000 # resampling to n points | ||
# see paper for details (graph creation) | ||
to = 100 | ||
tb = 0.1 | ||
dil = 0.01 | ||
thre = 0.93 | ||
N = 15 | ||
variables_as_list = [num_of_points, num_of_points, N, to, to, to, tb, tb, tb, dil, thre] | ||
|
||
import os, pdb, json | ||
name = f'drinkbottle_{num_of_points}' | ||
output_dir = os.path.join('3dvr_results', name) | ||
os.makedirs(output_dir, exist_ok=True) | ||
|
||
# list of broken objects (for now pairs) | ||
data_folder = 'data' | ||
data_list = [] | ||
|
||
for category_folder in os.listdir(data_folder): | ||
cat_ff = os.path.join(data_folder, category_folder) | ||
for fracture_folder in os.listdir(cat_ff): | ||
objects_folder = os.path.join(cat_ff, fracture_folder, 'objects') | ||
p_o1 = os.path.join(objects_folder, 'obj1_challenge.ply') | ||
p_o2 = os.path.join(objects_folder, 'obj2_challenge.ply') | ||
solution_folder = os.path.join(cat_ff, fracture_folder, 'solution') | ||
broken_obj_dict = { | ||
"path_obj1": p_o1, | ||
"path_obj2": p_o2, | ||
"category": category_folder, | ||
"fracture": fracture_folder | ||
} | ||
if os.path.exists(solution_folder): | ||
with open(os.path.join(solution_folder, 'solution.json'), 'r') as sj: | ||
solution = json.load(sj) | ||
broken_obj_dict['solution'] = solution | ||
|
||
data_list.append(broken_obj_dict) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# configuration file | ||
|
||
r : [0.2, 0.2, 0.1] | ||
t : [-0.5, -0.5, -0.5] | ||
|
||
voxel_size : 15000 | ||
move_to_origin : False | ||
|
||
output_folder : 'data' | ||
|
||
data_list : [ | ||
[ | ||
"/media/lucap/big_data/datasets/pairwise/ali/DrinkBottle/fractured_62/piece_0.obj", | ||
"/media/lucap/big_data/datasets/pairwise/ali/DrinkBottle/fractured_62/piece_1.obj" | ||
], | ||
[ | ||
"/media/lucap/big_data/datasets/pairwise/ali/DrinkBottle/fractured_70/piece_0.obj", | ||
"/media/lucap/big_data/datasets/pairwise/ali/DrinkBottle/fractured_70/piece_1.obj", | ||
] | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import numpy as np | ||
from helper import down_sample_to | ||
import open3d as o3d | ||
import json | ||
import argparse | ||
import yaml | ||
import os | ||
|
||
def read_obj(path, voxel_size): | ||
|
||
if path.endswith('.ply'): | ||
pcd1 = o3d.io.read_point_cloud(path) | ||
voxel_percentage = down_sample_to(pcd1,voxel_size) | ||
#print("my number is -> ",voxel_percentage) | ||
downpcd1 = pcd.voxel_down_sample(voxel_size=voxel_percentage) | ||
elif path.endswith('.obj'): | ||
mesh = o3d.io.read_triangle_mesh(path) | ||
downpcd1 = mesh.sample_points_uniformly(number_of_points=voxel_size) | ||
else: | ||
print("we only support .ply or .obj at the moment!\nFound", cfg['path_obj1']) | ||
return None, -1 | ||
|
||
return downpcd1, 0 | ||
|
||
def main(args): | ||
|
||
print('Config file:', args.cfg) | ||
with open(args.cfg, 'r') as yaml_file: | ||
cfg = yaml.safe_load(yaml_file) | ||
|
||
for obj_pair in cfg['data_list']: | ||
|
||
print('Preparing:') | ||
path_obj1 = obj_pair[0] | ||
path_obj2 = obj_pair[1] | ||
print(path_obj1) | ||
print(path_obj2) | ||
|
||
pcd1, ok1 = read_obj(path_obj1, voxel_size = cfg['voxel_size']) | ||
pcd2, ok2 = read_obj(path_obj2, voxel_size = cfg['voxel_size']) | ||
|
||
if ok1 == 0 and ok2 == 0: | ||
|
||
# moving to origin if we need it (see config file, default False) | ||
if cfg['move_to_origin']: | ||
c1 = np.mean(np.asarray(pcd1.points), axis=1) | ||
pcd1.translate(-c1) | ||
c2 = np.mean(np.asarray(pcd2.points), axis=1) | ||
pcd1.translate(-c2) | ||
|
||
r = np.asarray(cfg['r']) | ||
t = np.asarray(cfg['t']) | ||
rot_mat = o3d.geometry.get_rotation_matrix_from_xyz(r) | ||
trsf_mat = np.eye(4) | ||
trsf_mat[:3, :3] = rot_mat | ||
trsf_mat[:3, 3] = t | ||
r_inv = np.linalg.inv(rot_mat) | ||
t_inv = -t | ||
gt = np.eye(4) | ||
gt[:3, :3] = r_inv | ||
gt[:3, 3] = t_inv | ||
|
||
pcd2.transform(trsf_mat) | ||
|
||
category = path_obj1.split("/")[-3] | ||
fracture = path_obj1.split("/")[-2] | ||
output_dir = os.path.join(cfg['output_folder'], category, fracture) | ||
|
||
output_pcds = os.path.join(output_dir, 'objects') | ||
output_sol = os.path.join(output_dir, 'solution') | ||
os.makedirs(output_pcds, exist_ok=True) | ||
os.makedirs(output_sol, exist_ok=True) | ||
solution = { | ||
'T' : trsf_mat.tolist(), | ||
'r' : rot_mat.tolist(), | ||
't' : t.tolist(), | ||
'GT': gt.tolist(), | ||
'gt_r': r_inv.tolist(), | ||
'gt_t': t_inv.tolist() | ||
} | ||
with open(os.path.join(output_sol, 'solution.json'), 'w') as osj: | ||
json.dump(solution, osj, indent=3) | ||
o3d.io.write_point_cloud(os.path.join(output_pcds, 'obj1_challenge.ply'), pcd1) | ||
o3d.io.write_point_cloud(os.path.join(output_pcds, 'obj2_challenge.ply'), pcd2) | ||
print('Saved in', output_dir) | ||
else: | ||
print('something went wrong! please check config file and input paths.') | ||
print('FINISHED') | ||
|
||
if __name__ == '__main__': | ||
|
||
parser = argparse.ArgumentParser(description='Preparing challenge (moving objects)') | ||
parser.add_argument('--cfg', type=str, default='base', help='config file (.yaml)') | ||
args = parser.parse_args() | ||
main(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.