-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_answers_to_simulator.py
More file actions
102 lines (75 loc) · 2.99 KB
/
convert_answers_to_simulator.py
File metadata and controls
102 lines (75 loc) · 2.99 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python3
"""
Convert all out.json files in gc_dataset_answers to simulator format.
Uses the convert_ir_to_simulator function from src/tools/convert_to_simulator.py
"""
import json
import sys
from pathlib import Path
# Add the project root to the path
sys.path.insert(0, str(Path(__file__).parent))
from src.tools.convert_to_simulator import convert_ir_to_simulator
def convert_file(input_path: Path, output_path: Path) -> bool:
"""Convert a single IR JSON file to simulator format."""
try:
with open(input_path, 'r') as f:
ir_data = json.load(f)
# Check if it's a flatpattern IR
if ir_data.get("ir_kind") != "flatpattern":
print(f" Warning: {input_path.name} is not a flatpattern IR (ir_kind={ir_data.get('ir_kind')})")
return False
# Convert to simulator format
sim_data, diagnostics = convert_ir_to_simulator(ir_data)
# Get units from the IR
units = ir_data.get("units", "cm")
# Set units_in_meter based on units
if units.lower() in ("in", "inch", "inches"):
units_in_meter = 1.0 / 0.0254
elif units.lower() in ("cm", "centimeter", "centimeters"):
units_in_meter = 100.0
elif units.lower() in ("mm", "millimeter", "millimeters"):
units_in_meter = 1000.0
else:
units_in_meter = 1.0
# Build final output with expected format
final_out = {
"pattern": sim_data.get("pattern", {}),
"parameters": {},
"parameter_order": [],
"properties": {
"curvature_coords": "relative",
"normalize_panel_translation": False,
"normalized_edge_loops": True,
"units_in_meter": units_in_meter,
}
}
# Write output
with open(output_path, 'w') as f:
json.dump(final_out, f, indent=2)
return True
except Exception as e:
print(f" Error: {e}")
return False
def main():
answers_dir = Path("/home/raynaaro/GarmentDSL/gc_dataset_answers")
# Find all example directories
example_dirs = sorted([d for d in answers_dir.iterdir() if d.is_dir() and d.name.startswith("example_")])
print(f"Found {len(example_dirs)} example directories")
success_count = 0
fail_count = 0
for example_dir in example_dirs:
input_file = example_dir / "out.json"
output_file = example_dir / "out_simulator.json"
if not input_file.exists():
print(f" {example_dir.name}: No out.json found, skipping")
fail_count += 1
continue
if convert_file(input_file, output_file):
success_count += 1
else:
fail_count += 1
print(f"\n=== Summary ===")
print(f"Success: {success_count}")
print(f"Failed/Skipped: {fail_count}")
if __name__ == "__main__":
main()