mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 14:15:42 -04:00
Modifications to C++ plots for interactive raytrace plots (#3776)
This commit is contained in:
parent
04bee9c49f
commit
6efc9db7b3
2 changed files with 170 additions and 104 deletions
|
|
@ -88,14 +88,21 @@ const RGBColor BLACK {0, 0, 0};
|
|||
* is designed to be implemented by classes that produce plot-relevant data
|
||||
* which can be visualized.
|
||||
*/
|
||||
|
||||
typedef xt::xtensor<RGBColor, 2> ImageData;
|
||||
class PlottableInterface {
|
||||
public:
|
||||
PlottableInterface() = default;
|
||||
|
||||
void set_default_colors();
|
||||
|
||||
private:
|
||||
void set_id(pugi::xml_node plot_node);
|
||||
int id_; // unique plot ID
|
||||
|
||||
void set_bg_color(pugi::xml_node plot_node);
|
||||
void set_universe(pugi::xml_node plot_node);
|
||||
void set_default_colors(pugi::xml_node plot_node);
|
||||
void set_color_by(pugi::xml_node plot_node);
|
||||
void set_user_colors(pugi::xml_node plot_node);
|
||||
void set_overlap_color(pugi::xml_node plot_node);
|
||||
void set_mask(pugi::xml_node plot_node);
|
||||
|
|
@ -107,9 +114,15 @@ protected:
|
|||
public:
|
||||
enum class PlotColorBy { cells = 0, mats = 1 };
|
||||
|
||||
// Generates image data based on plot parameters and returns it
|
||||
virtual ImageData create_image() const = 0;
|
||||
|
||||
// Creates the output image named path_plot_
|
||||
virtual void create_output() const = 0;
|
||||
|
||||
// Write populated image data to file
|
||||
void write_image(const ImageData& data) const;
|
||||
|
||||
// Print useful info to the terminal
|
||||
virtual void print_info() const = 0;
|
||||
|
||||
|
|
@ -117,20 +130,19 @@ public:
|
|||
std::string& path_plot() { return path_plot_; }
|
||||
int id() const { return id_; }
|
||||
int level() const { return level_; }
|
||||
PlotColorBy color_by() const { return color_by_; }
|
||||
|
||||
// Public color-related data
|
||||
PlottableInterface(pugi::xml_node plot_node);
|
||||
virtual ~PlottableInterface() = default;
|
||||
int level_; // Universe level to plot
|
||||
bool color_overlaps_; // Show overlapping cells?
|
||||
int level_ {-1}; // Universe level to plot
|
||||
bool color_overlaps_ {false}; // Show overlapping cells?
|
||||
PlotColorBy color_by_; // Plot coloring (cell/material)
|
||||
RGBColor not_found_ {WHITE}; // Plot background color
|
||||
RGBColor overlap_color_ {RED}; // Plot overlap color
|
||||
vector<RGBColor> colors_; // Plot colors
|
||||
};
|
||||
|
||||
typedef xt::xtensor<RGBColor, 2> ImageData;
|
||||
|
||||
struct IdData {
|
||||
// Constructor
|
||||
IdData(size_t h_res, size_t v_res);
|
||||
|
|
@ -166,6 +178,11 @@ public:
|
|||
|
||||
enum class PlotBasis { xy = 1, xz = 2, yz = 3 };
|
||||
|
||||
// Accessors
|
||||
|
||||
const std::array<size_t, 3>& pixels() const { return pixels_; }
|
||||
std::array<size_t, 3>& pixels() { return pixels_; }
|
||||
|
||||
// Members
|
||||
public:
|
||||
Position origin_; //!< Plot origin in geometry
|
||||
|
|
@ -270,11 +287,11 @@ private:
|
|||
public:
|
||||
// Add mesh lines to ImageData
|
||||
void draw_mesh_lines(ImageData& data) const;
|
||||
void create_image() const;
|
||||
ImageData create_image() const override;
|
||||
void create_voxel() const;
|
||||
|
||||
virtual void create_output() const;
|
||||
virtual void print_info() const;
|
||||
void create_output() const override;
|
||||
void print_info() const override;
|
||||
|
||||
PlotType type_; //!< Plot type (Slice/Voxel)
|
||||
int meshlines_width_; //!< Width of lines added to the plot
|
||||
|
|
@ -294,17 +311,32 @@ public:
|
|||
*/
|
||||
class RayTracePlot : public PlottableInterface {
|
||||
public:
|
||||
RayTracePlot() = default;
|
||||
RayTracePlot(pugi::xml_node plot);
|
||||
|
||||
// Standard getters. No setting since it's done from XML.
|
||||
const Position& camera_position() const { return camera_position_; }
|
||||
Position& camera_position() { return camera_position_; }
|
||||
const Position& look_at() const { return look_at_; }
|
||||
Position& look_at() { return look_at_; }
|
||||
|
||||
const double& horizontal_field_of_view() const
|
||||
{
|
||||
return horizontal_field_of_view_;
|
||||
}
|
||||
double& horizontal_field_of_view() { return horizontal_field_of_view_; }
|
||||
|
||||
virtual void print_info() const;
|
||||
void print_info() const override;
|
||||
|
||||
const std::array<int, 2>& pixels() const { return pixels_; }
|
||||
std::array<int, 2>& pixels() { return pixels_; }
|
||||
|
||||
const Direction& up() const { return up_; }
|
||||
Direction& up() { return up_; }
|
||||
|
||||
//! brief Updates the cached camera-to-model matrix after changes to
|
||||
//! camera parameters.
|
||||
void update_view();
|
||||
|
||||
protected:
|
||||
Direction camera_x_axis() const
|
||||
|
|
@ -330,8 +362,6 @@ protected:
|
|||
*/
|
||||
std::pair<Position, Direction> get_pixel_ray(int horiz, int vert) const;
|
||||
|
||||
std::array<int, 2> pixels_; // pixel dimension of resulting image
|
||||
|
||||
private:
|
||||
void set_look_at(pugi::xml_node node);
|
||||
void set_camera_position(pugi::xml_node node);
|
||||
|
|
@ -341,8 +371,8 @@ private:
|
|||
|
||||
double horizontal_field_of_view_ {70.0}; // horiz. f.o.v. in degrees
|
||||
Position camera_position_; // where camera is
|
||||
Position look_at_; // point camera is centered looking at
|
||||
|
||||
Position look_at_; // point camera is centered looking at
|
||||
std::array<int, 2> pixels_; // pixel dimension of resulting image
|
||||
Direction up_ {0.0, 0.0, 1.0}; // which way is up
|
||||
|
||||
/* The horizontal thickness, if using an orthographic projection.
|
||||
|
|
@ -377,8 +407,9 @@ class WireframeRayTracePlot : public RayTracePlot {
|
|||
public:
|
||||
WireframeRayTracePlot(pugi::xml_node plot);
|
||||
|
||||
virtual void create_output() const;
|
||||
virtual void print_info() const;
|
||||
ImageData create_image() const override;
|
||||
void create_output() const override;
|
||||
void print_info() const override;
|
||||
|
||||
private:
|
||||
void set_opacities(pugi::xml_node node);
|
||||
|
|
@ -434,10 +465,22 @@ class SolidRayTracePlot : public RayTracePlot {
|
|||
friend class PhongRay;
|
||||
|
||||
public:
|
||||
SolidRayTracePlot() = default;
|
||||
|
||||
SolidRayTracePlot(pugi::xml_node plot);
|
||||
|
||||
virtual void create_output() const;
|
||||
virtual void print_info() const;
|
||||
ImageData create_image() const override;
|
||||
void create_output() const override;
|
||||
void print_info() const override;
|
||||
|
||||
const std::unordered_set<int>& opaque_ids() const { return opaque_ids_; }
|
||||
std::unordered_set<int>& opaque_ids() { return opaque_ids_; }
|
||||
|
||||
const Position& light_location() const { return light_location_; }
|
||||
Position& light_location() { return light_location_; }
|
||||
|
||||
const double& diffuse_fraction() const { return diffuse_fraction_; }
|
||||
double& diffuse_fraction() { return diffuse_fraction_; }
|
||||
|
||||
private:
|
||||
void set_opaque_ids(pugi::xml_node node);
|
||||
|
|
@ -496,7 +539,7 @@ public:
|
|||
: Ray(r, u), plot_(plot), line_segments_(line_segments)
|
||||
{}
|
||||
|
||||
virtual void on_intersection() override;
|
||||
void on_intersection() override;
|
||||
|
||||
private:
|
||||
/* Store a reference to the plot object which is running this ray, in order
|
||||
|
|
@ -519,7 +562,7 @@ public:
|
|||
result_color_ = plot_.not_found_;
|
||||
}
|
||||
|
||||
virtual void on_intersection() override;
|
||||
void on_intersection() override;
|
||||
|
||||
const RGBColor& result_color() { return result_color_; }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue