1+ import matplotlib .pyplot as plt
2+ import re
3+ import sys
4+
5+ def plot_geometry (file_path ):
6+ fig , ax = plt .subplots (figsize = (8 , 6 ))
7+ found_geometry = False
8+
9+ with open (file_path , 'r' ) as f :
10+ for line in f :
11+ # Box check: #box: x1 y1 z1 x2 y2 z2 material
12+ if line .startswith ('#box:' ):
13+ parts = line .split (': ' )[1 ].split ()
14+ x1 , y1 , x2 , y2 = float (parts [0 ]), float (parts [1 ]), float (parts [3 ]), float (parts [4 ])
15+ rect = plt .Rectangle ((x1 , y1 ), x2 - x1 , y2 - y1 , edgecolor = 'r' , fill = False , label = 'Box' )
16+ ax .add_patch (rect )
17+ found_geometry = True
18+
19+ # Cylinder check: #cylinder: x y z_start z_end radius material
20+ elif line .startswith ('#cylinder:' ):
21+ parts = line .split (': ' )[1 ].split ()
22+ x , y , r = float (parts [0 ]), float (parts [1 ]), float (parts [4 ])
23+ circle = plt .Circle ((x , y ), r , color = 'b' , fill = False , label = 'Cylinder' )
24+ ax .add_patch (circle )
25+ found_geometry = True
26+
27+ if not found_geometry :
28+ print ("❌ No geometry found to plot!" )
29+ sys .exit (1 )
30+
31+ ax .set_aspect ('equal' )
32+ plt .title ("gprMax Geometry Preview (X-Y Plane)" )
33+ plt .xlabel ("X (m)" )
34+ plt .ylabel ("Y (m)" )
35+ plt .grid (True )
36+ plt .savefig ('.github/workflows/geometry_preview.png' )
37+ print ("✅ Geometry plot saved as geometry_preview.png" )
38+
39+ if __name__ == "__main__" :
40+ plot_geometry ('user_model.in' )
0 commit comments