mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-26 21:25:36 -04:00
Added alpha compositing scheme to Python API Plot class to highlight domains
This commit is contained in:
parent
64a7cd9607
commit
372d751fa6
1 changed files with 57 additions and 3 deletions
|
|
@ -270,7 +270,7 @@ class Plot(object):
|
|||
Params
|
||||
------
|
||||
geometry : openmc.Geometry
|
||||
The geometry for which the plot is created
|
||||
The geometry for which the plot is defined
|
||||
seed : Integral
|
||||
The random number seed used to generate the color scheme
|
||||
|
||||
|
|
@ -284,7 +284,7 @@ class Plot(object):
|
|||
if self.color is 'mat':
|
||||
domains = geometry.get_all_materials()
|
||||
else:
|
||||
domains = geometry.get_all_materials()
|
||||
domains = geometry.get_all_cells()
|
||||
|
||||
# Set the seed for the random number generator
|
||||
np.random.seed(seed)
|
||||
|
|
@ -295,9 +295,63 @@ class Plot(object):
|
|||
r = np.random.randint(0, 255)
|
||||
g = np.random.randint(0, 255)
|
||||
b = np.random.randint(0, 255)
|
||||
self.col_spec[domain.id] = (r, g, b)
|
||||
self.col_spec[domain] = (r, g, b)
|
||||
|
||||
|
||||
def highlight_domains(self, geometry, domains, seed=1,
|
||||
alpha=0.5, background='grey'):
|
||||
"""Use alpha compositing to highlight one or more domains in the plot.
|
||||
|
||||
This routine generates a color scheme and applies alpha compositing
|
||||
to make all domains except the highlighted ones partially transparent.
|
||||
|
||||
Params
|
||||
------
|
||||
geometry : openmc.Geometry
|
||||
The geometry for which the plot is defined
|
||||
domains : Iterable of Integral
|
||||
A collection of the domain IDs to highlight in the plot
|
||||
seed : Integral
|
||||
The random number seed used to generate the color scheme
|
||||
alpha : Real in [0,1]
|
||||
The value to apply in alpha compisiting
|
||||
background : 3-tuple of Integral or 'white' or 'black' or 'grey'
|
||||
The background color to apply in alpha compisiting
|
||||
|
||||
"""
|
||||
|
||||
cv.check_iterable_type('domains', domains, Integral)
|
||||
cv.check_type('alpha', alpha, Real)
|
||||
cv.check_greater_than('alpha', alpha, 0., equality=True)
|
||||
cv.check_less_than('alpha', alpha, 1., equality=True)
|
||||
|
||||
# Get a background (R,G,B) tuple to apply in alpha compositing
|
||||
if isinstance(background, basestring):
|
||||
if background == 'white':
|
||||
background = (255, 255, 255)
|
||||
elif background == 'black':
|
||||
background = (0, 0, 0)
|
||||
elif background == 'grey':
|
||||
background = (160, 160, 160)
|
||||
else:
|
||||
msg = 'The background "{}" is not defined'.format(background)
|
||||
raise ValueError(msg)
|
||||
|
||||
cv.check_iterable_type('background', background, Integral)
|
||||
|
||||
# Generate a color scheme
|
||||
self.colorize(geometry, seed)
|
||||
|
||||
# Apply alpha compositing to the colors for all domains
|
||||
# other than those the user wishes to highlight
|
||||
for domain_id in self.col_spec:
|
||||
if domain_id not in domains:
|
||||
r, g, b = self.col_spec[domain_id]
|
||||
r = int(((1-alpha) * background[0]) + (alpha * r))
|
||||
g = int(((1-alpha) * background[1]) + (alpha * g))
|
||||
b = int(((1-alpha) * background[2]) + (alpha * b))
|
||||
self._col_spec[domain_id] = (r, g, b)
|
||||
|
||||
def get_plot_xml(self):
|
||||
"""Return XML representation of the plot
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue