From ffaea6187404ede60f5c62d70ae387533e942c85 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Tue, 18 Apr 2023 15:10:49 +0100 Subject: [PATCH] converting rgb to int --- openmc/universe.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/openmc/universe.py b/openmc/universe.py index 3743245b29..6863511f8a 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -1,3 +1,4 @@ +import typing from abc import ABC, abstractmethod from collections import OrderedDict from collections.abc import Iterable @@ -20,6 +21,14 @@ from .plots import _SVG_COLORS from .surface import _BOUNDARY_TYPES +def get_int_from_rgb(rgb: typing.Tuple[int, int, int]) -> int: + """Converts a tuple of ints into a single int""" + red = rgb[0] + green = rgb[1] + blue = rgb[2] + return (red << 16) + (green << 8) + blue + + class UniverseBase(ABC, IDManagerMixin): """A collection of cells that can be repeated. @@ -401,10 +410,14 @@ class Universe(UniverseBase): fig.set_size_inches(width, height) if outline: - combined_rgb = np.sum(img, 2) + + image_value = [ + [get_int_from_rgb(inner_entry) for inner_entry in outer_entry] + for outer_entry in img + ] axes.contour( - combined_rgb.reshape(img.shape[0], img.shape[1]), + image_value, #combined_rgb.reshape(img.shape[0], img.shape[1]), origin="upper", colors="k", linestyles="solid", @@ -988,4 +1001,4 @@ class DAGMCUniverse(UniverseBase): clone.volume = self.volume clone.auto_geom_ids = self.auto_geom_ids clone.auto_mat_ids = self.auto_mat_ids - return clone \ No newline at end of file + return clone