Skip to content

Commit 561e2ad

Browse files
committed
various pyvista fixes
1 parent 4e35ac9 commit 561e2ad

4 files changed

Lines changed: 161 additions & 3 deletions

File tree

api/pyvista_api.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def render_volume(gvolume, gconfiguration):
184184
pars = get_dimensions(gvolume)
185185
bcenter = get_center(gvolume)
186186
mstyle = "surface" if gvolume.style in (1, 2) else "wireframe"
187-
mlinewidth = 1.0 if gvolume.style in (1, 2) else 10
187+
mlinewidth = 1.0 if gvolume.style in (1, 2) else 1.0
188188
if gvolume.visible == 0:
189189
alpha = 0.05 # nearly invisible
190190
mlinewidth = 1.0
@@ -232,8 +232,20 @@ def render_volume(gvolume, gconfiguration):
232232
)
233233
configure_actor_lighting(cloud_actor, metallic=False)
234234
else:
235-
actor = gconfiguration.add_mesh(mesh, color=rgb, smooth_shading=smooth_shading, opacity=alpha,
236-
style=mstyle, line_width=mlinewidth)
235+
if mstyle == "wireframe":
236+
# Render only feature edges so that triangulated solids (e.g. G4Tubs) show
237+
# clean outlines rather than every triangle edge looking like a solid surface.
238+
edges = mesh.extract_feature_edges(
239+
feature_angle=30,
240+
boundary_edges=True,
241+
feature_edges=True,
242+
manifold_edges=False,
243+
non_manifold_edges=False,
244+
)
245+
actor = gconfiguration.add_mesh(edges, color=rgb, opacity=alpha, line_width=mlinewidth)
246+
else:
247+
actor = gconfiguration.add_mesh(mesh, color=rgb, smooth_shading=smooth_shading,
248+
opacity=alpha, style=mstyle, line_width=mlinewidth)
237249
configure_actor_lighting(actor, metallic=metallic)
238250

239251

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/usr/bin/env python3
2+
from gconfiguration import autogeometry
3+
from gvolume import GVolume
4+
from gmaterial import GMaterial
5+
6+
cfg = autogeometry("examples", "material")
7+
8+
world_size = 50
9+
world = GVolume("root")
10+
world.description = "World"
11+
world.make_box(world_size * 0.5, world_size * 0.5, world_size * 0.5)
12+
world.material = "G4_AIR"
13+
world.color = "ghostwhite"
14+
world.visible = 0
15+
world.publish(cfg)
16+
17+
# Five tubes: 10 cm diameter, 1 cm thick, along z-axis starting at z=0.
18+
# Each tube is separated from the next by 3 cm (edge to edge), so centers
19+
# are 4 cm apart (1 cm thickness + 3 cm gap).
20+
radius = 5 # cm, giving 10 cm diameter
21+
half_thickness = 0.5 # cm, giving 1 cm total thickness
22+
z_step = 4 # cm center-to-center spacing
23+
24+
# --- Tube 1: Geant4 built-in material ---
25+
tube1 = GVolume("tube_carbon")
26+
tube1.mother = "root"
27+
tube1.description = "Carbon tube using the Geant4 built-in G4_C (graphite) material"
28+
tube1.make_tube(0, radius, half_thickness, 0, 360)
29+
tube1.material = "G4_C"
30+
tube1.color = "808080"
31+
tube1.set_position(0, 0, 0.5)
32+
tube1.publish(cfg)
33+
34+
# --- Tube 2: Custom material by molecular composition ---
35+
water = GMaterial("custom_water")
36+
water.description = "Water defined by molecular composition (H2O)"
37+
water.density = 1.0
38+
water.addNAtoms("H", 2)
39+
water.addNAtoms("O", 1)
40+
water.publish(cfg)
41+
42+
tube2 = GVolume("tube_water")
43+
tube2.mother = "root"
44+
tube2.description = "Tube made of custom water defined by molecular composition"
45+
tube2.make_tube(0, radius, half_thickness, 0, 360)
46+
tube2.material = "custom_water"
47+
tube2.color = "1565C0"
48+
tube2.set_position(0, 0, 0.5 + z_step)
49+
tube2.publish(cfg)
50+
51+
# --- Tube 3: Custom material by fractional masses ---
52+
mixture = GMaterial("air_water_mixture")
53+
mixture.description = "80% air / 20% water mixture defined by fractional masses"
54+
mixture.density = 0.9601
55+
mixture.addMaterialWithFractionalMass("G4_AIR", 0.80)
56+
mixture.addMaterialWithFractionalMass("G4_WATER", 0.20)
57+
mixture.publish(cfg)
58+
59+
tube3 = GVolume("tube_mixture")
60+
tube3.mother = "root"
61+
tube3.description = "Tube made of an air/water mixture defined by fractional masses"
62+
tube3.make_tube(0, radius, half_thickness, 0, 360)
63+
tube3.material = "air_water_mixture"
64+
tube3.color = "2E7D32"
65+
tube3.set_position(0, 0, 0.5 + 2 * z_step)
66+
tube3.publish(cfg)
67+
68+
# --- Tube 4: Scintillator with fast/slow emission components ---
69+
scint_energy = "2.0*eV 2.5*eV 3.0*eV 3.5*eV 4.0*eV"
70+
71+
scintillator = GMaterial("my_scintillator")
72+
scintillator.description = "NaI-like scintillator with fast and slow emission components"
73+
scintillator.density = 3.67
74+
scintillator.addNAtoms("Na", 1)
75+
scintillator.addNAtoms("I", 1)
76+
scintillator.photonEnergy = scint_energy
77+
scintillator.fastcomponent = "1.0 0.9 0.8 0.7 0.6"
78+
scintillator.slowcomponent = "0.5 0.4 0.3 0.2 0.1"
79+
scintillator.scintillationyield = 1000
80+
scintillator.resolutionscale = 1.0
81+
scintillator.fasttimeconstant = 6
82+
scintillator.slowtimeconstant = 88
83+
scintillator.yieldratio = 0.8
84+
scintillator.birksConstant = 0.00152
85+
scintillator.publish(cfg)
86+
87+
tube4 = GVolume("tube_scintillator")
88+
tube4.mother = "root"
89+
tube4.description = "Tube made of a NaI-like scintillating material"
90+
tube4.make_tube(0, radius, half_thickness, 0, 360)
91+
tube4.material = "my_scintillator"
92+
tube4.color = "F57F17"
93+
tube4.style = 0
94+
tube4.set_position(0, 0, 0.5 + 3 * z_step)
95+
tube4.publish(cfg)
96+
97+
# --- Tube 5: Optical glass with index of refraction (Cherenkov radiator) ---
98+
photon_energy = "2.0*eV 3.0*eV 4.0*eV 5.0*eV"
99+
100+
optical_glass = GMaterial("optical_glass")
101+
optical_glass.description = "SiO2 optical glass with a refractive index for Cherenkov applications"
102+
optical_glass.density = 2.5
103+
optical_glass.addNAtoms("Si", 1)
104+
optical_glass.addNAtoms("O", 2)
105+
optical_glass.photonEnergy = photon_energy
106+
optical_glass.indexOfRefraction = "1.458 1.466 1.476 1.490"
107+
optical_glass.absorptionLength = "3*m 3*m 3*m 3*m"
108+
optical_glass.publish(cfg)
109+
110+
tube5 = GVolume("tube_optical")
111+
tube5.mother = "root"
112+
tube5.description = "Tube made of SiO2 optical glass with a refractive index for Cherenkov radiation"
113+
tube5.make_tube(0, radius, half_thickness, 0, 360)
114+
tube5.material = "optical_glass"
115+
tube5.color = "00BCD4"
116+
tube5.style = 2
117+
tube5.set_position(0, 0, 0.5 + 4 * z_step)
118+
tube5.publish(cfg)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
experiment: examples
2+
runno: 1
3+
nthreads: 1
4+
5+
verbosity:
6+
- g4system: 1
7+
- gemc: 1
8+
9+
gsystem:
10+
- name: material
11+
factory: sqlite
12+
13+
gstreamer:
14+
- format: csv
15+
filename: material
16+
- format: root
17+
filename: material
18+
19+
phys_list: FTFP_BERT + G4OpticalPhysics
20+
21+
gparticle:
22+
- name: proton
23+
p: 2000
24+
vz: -3
25+
delta_vx: 0.1
26+
delta_vy: 0.1
27+
multiplicity: 10

releases/0.2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,5 @@ Both x86_64 and ARM64 platforms are supported.
9696
- Adjusted system_template to provide simpler geometry and methane target material
9797
- Adjusted simple_flux target material to G4_lH2
9898
- Added handling of style=2 in pyvista: using cloud
99+
- Fixed wirefr
99100
- Various code cleanups

0 commit comments

Comments
 (0)