From 39ad29d82e429b5e6f18cfb5f369bbfdddd93ed5 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 28 Feb 2025 13:50:35 -0600 Subject: [PATCH] Fix reading of horizontal field of view for ray-traced plots (#3330) Co-authored-by: Patrick Shriwise --- openmc/plots.py | 78 +++++++++++++++++++ src/plot.cpp | 12 +-- .../plot_projections/results_true.dat | 2 +- 3 files changed, 86 insertions(+), 6 deletions(-) diff --git a/openmc/plots.py b/openmc/plots.py index 9c1e31575..40fcf0c78 100644 --- a/openmc/plots.py +++ b/openmc/plots.py @@ -1312,6 +1312,50 @@ class WireframeRayTracePlot(RayTracePlot): Attributes ---------- + id : int + Unique identifier + name : str + Name of the plot + pixels : Iterable of int + Number of pixels to use in each direction + filename : str + Path to write the plot to + color_by : {'cell', 'material'} + Indicate whether the plot should be colored by cell or by material + background : Iterable of int or str + Color of the background + mask_components : Iterable of openmc.Cell or openmc.Material or int + The cells or materials (or corresponding IDs) to mask + mask_background : Iterable of int or str + Color to apply to all cells/materials listed in mask_components + show_overlaps : bool + Indicate whether or not overlapping regions are shown + overlap_color : Iterable of int or str + Color to apply to overlapping regions + colors : dict + Dictionary indicating that certain cells/materials should be + displayed with a particular color. The keys can be of type + :class:`~openmc.Cell`, :class:`~openmc.Material`, or int (ID for a + cell/material). + level : int + Universe depth to plot at + horizontal_field_of_view : float + Field of view horizontally, in units of degrees, defaults to 70. + camera_position : tuple or list of ndarray + Position of the camera in 3D space. Defaults to (1, 0, 0). + look_at : tuple or list of ndarray + The center of the camera's image points to this place in 3D space. + Set to (0, 0, 0) by default. + up : tuple or list of ndarray + Which way is up for the camera. Must not be parallel to the + line between look_at and camera_position. Set to (0, 0, 1) by default. + orthographic_width : float + If set to a nonzero value, an orthographic projection is used. + All rays traced from the orthographic pixel array travel in the + same direction. The width of the starting array must be specified, + unlike with the default perspective projection. The height of the + array is deduced from the ratio of pixel dimensions for the image. + Defaults to zero, i.e. using perspective projection. wireframe_thickness : int Line thickness employed for drawing wireframes around cells or material regions. Can be set to zero for no wireframes at all. Defaults to one @@ -1512,6 +1556,40 @@ class SolidRayTracePlot(RayTracePlot): Attributes ---------- + id : int + Unique identifier + name : str + Name of the plot + pixels : Iterable of int + Number of pixels to use in each direction + filename : str + Path to write the plot to + color_by : {'cell', 'material'} + Indicate whether the plot should be colored by cell or by material + overlap_color : Iterable of int or str + Color to apply to overlapping regions + colors : dict + Dictionary indicating that certain cells/materials should be + displayed with a particular color. The keys can be of type + :class:`~openmc.Cell`, :class:`~openmc.Material`, or int (ID for a + cell/material). + horizontal_field_of_view : float + Field of view horizontally, in units of degrees, defaults to 70. + camera_position : tuple or list of ndarray + Position of the camera in 3D space. Defaults to (1, 0, 0). + look_at : tuple or list of ndarray + The center of the camera's image points to this place in 3D space. + Set to (0, 0, 0) by default. + up : tuple or list of ndarray + Which way is up for the camera. Must not be parallel to the + line between look_at and camera_position. Set to (0, 0, 1) by default. + orthographic_width : float + If set to a nonzero value, an orthographic projection is used. + All rays traced from the orthographic pixel array travel in the + same direction. The width of the starting array must be specified, + unlike with the default perspective projection. The height of the + array is deduced from the ratio of pixel dimensions for the image. + Defaults to zero, i.e. using perspective projection. light_position : tuple or list of float Position of the light source in 3D space. Defaults to None, which places the light at the camera position. diff --git a/src/plot.cpp b/src/plot.cpp index 093f89f8c..dbc25b21e 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -1083,7 +1083,7 @@ WireframeRayTracePlot::WireframeRayTracePlot(pugi::xml_node node) void WireframeRayTracePlot::set_wireframe_color(pugi::xml_node plot_node) { - // Copy plot background color + // Copy plot wireframe color if (check_for_node(plot_node, "wireframe_color")) { vector w_rgb = get_node_array(plot_node, "wireframe_color"); if (w_rgb.size() == 3) { @@ -1503,13 +1503,15 @@ void RayTracePlot::set_look_at(pugi::xml_node node) void RayTracePlot::set_field_of_view(pugi::xml_node node) { // Defaults to 70 degree horizontal field of view (see .h file) - if (check_for_node(node, "field_of_view")) { - double fov = std::stod(get_node_value(node, "field_of_view", true)); + if (check_for_node(node, "horizontal_field_of_view")) { + double fov = + std::stod(get_node_value(node, "horizontal_field_of_view", true)); if (fov < 180.0 && fov > 0.0) { horizontal_field_of_view_ = fov; } else { - fatal_error(fmt::format( - "Field of view for plot {} out-of-range. Must be in (0, 180).", id())); + fatal_error(fmt::format("Horizontal field of view for plot {} " + "out-of-range. Must be in (0, 180) degrees.", + id())); } } } diff --git a/tests/regression_tests/plot_projections/results_true.dat b/tests/regression_tests/plot_projections/results_true.dat index 672280fdd..d5c6a7a58 100644 --- a/tests/regression_tests/plot_projections/results_true.dat +++ b/tests/regression_tests/plot_projections/results_true.dat @@ -1 +1 @@ -025804f1522eafd6e0e9566ce6b9b5603962f278de222c842fe3e06471290bb575676255bcd55e4f084bdcca4ee56d3c219827cb1ef2b5c3a90f7666986b55e9 \ No newline at end of file +6b90dfcf3059f86d623bb6496bb92d5b6ea2788b79639b61f865b31b503b84df9af64e59eacb04ccb02a225cfdb51bb7fa4b4f71e8e6ea20b2714266b34886ce \ No newline at end of file