From 4df3f507f72107704ffc352ff7f87f38bc9b65d7 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 26 Feb 2019 07:50:03 -0600 Subject: [PATCH] Adding the start of a plot module for the capi. --- openmc/capi/__init__.py | 5 ++-- openmc/capi/plot.py | 62 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 openmc/capi/plot.py diff --git a/openmc/capi/__init__.py b/openmc/capi/__init__.py index 1015df216..e162387ff 100644 --- a/openmc/capi/__init__.py +++ b/openmc/capi/__init__.py @@ -12,7 +12,8 @@ objects in the :mod:`openmc.capi` subpackage, for example: """ -from ctypes import CDLL, c_bool +from ctypes import CDLL, c_bool, c_int +import numpy as np import os import sys @@ -42,7 +43,6 @@ else: def _dagmc_enabled(): return c_bool.in_dll(_dll, "dagmc_enabled").value - from .error import * from .core import * from .nuclide import * @@ -53,3 +53,4 @@ from .filter import * from .tally import * from .settings import settings from .math import * +from .plot import * diff --git a/openmc/capi/plot.py b/openmc/capi/plot.py new file mode 100644 index 000000000..fea300aed --- /dev/null +++ b/openmc/capi/plot.py @@ -0,0 +1,62 @@ +from ctypes import c_int, c_double, c_ushort, POINTER, Structure + +from . import _dll +from .core import _DLLGlobal + +import numpy as np + +_dll.openmc_get_image_data.argtypes = [c_int, c_int, c_int, c_int, c_int, + POINTER(c_double*3), c_double, + c_double, POINTER(c_double)] +_dll.openmc_get_image_data.restype = c_double + +class _Position(Structure): + pass + +_Position._fields_ = [('x', c_double), + ('y', c_double), + ('z', c_double)] + +class _RGBColor(Structure): + pass + +_RGBColor._fields_ = [('red', c_ushort), + ('green', c_ushort), + ('blue', c_ushort)] + +class _Plot(Structure): + pass + +_Plot._fields_ = [('id_', c_int), + ('type_', c_int), + ('color_by_', c_int), + ('origin_', _Position), + ('width_', _Position), + ('basis_', c_int), + ('pixels_', c_int*3), + ('meshlines_width_', c_int), + ('level_', c_int), + ('index_meshlines_mesh_', c_int), + ('meshlines_color_', _RGBColor), + ('not_found_', _RGBColor), + ('colors_', POINTER(_RGBColor))] + + +_dll.image_for_plot.argtypes= [POINTER(_Plot),] +_dll.image_for_plot.restype = c_int + +def get_image_data(): + origin = np.array([0.0, 0.0, 0.0]) + + val = np.array(1.0) + + out = _dll.openmc_get_image_data(0, 0, 0, 0, 0, origin.ctypes.data_as(POINTER(c_double*3)), 0.0, 0.0, val.ctypes.data_as(POINTER(c_double))) + print(val) + return out + + +def image_data_for_plot(plot): + img_data = np.zeros((plot.pixels_[0], plot.pixels_[1], 3), dtype = float) + + out = _dll.image_for_plot(POINTER(_Plot)(plot), img_data.ctypes.data_as(POINTER(c_double))) + return img_data