Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 62 additions & 19 deletions include/openmc/plot.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -107,30 +114,35 @@ class PlottableInterface {
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;

const std::string& path_plot() const { return path_plot_; }
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);
Expand Down Expand Up @@ -166,6 +178,11 @@ class SlicePlotBase {

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
Expand Down Expand Up @@ -270,11 +287,11 @@ class Plot : public PlottableInterface, public SlicePlotBase {
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
Expand All @@ -294,17 +311,32 @@ class Plot : public PlottableInterface, public SlicePlotBase {
*/
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_; }

void print_info() const override;

const std::array<int, 2>& pixels() const { return pixels_; }
std::array<int, 2>& pixels() { return pixels_; }

virtual void print_info() const;
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
Expand All @@ -330,8 +362,6 @@ class RayTracePlot : public PlottableInterface {
*/
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);
Expand All @@ -341,8 +371,8 @@ class RayTracePlot : public PlottableInterface {

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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -496,7 +539,7 @@ class ProjectionRay : public Ray {
: 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
Expand All @@ -519,7 +562,7 @@ class PhongRay : public Ray {
result_color_ = plot_.not_found_;
}

virtual void on_intersection() override;
void on_intersection() override;

const RGBColor& result_color() { return result_color_; }

Expand Down
Loading
Loading