Skip to content

Commit 6efc9db

Browse files
authored
Modifications to C++ plots for interactive raytrace plots (#3776)
1 parent 04bee9c commit 6efc9db

2 files changed

Lines changed: 170 additions & 104 deletions

File tree

‎include/openmc/plot.h‎

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,21 @@ const RGBColor BLACK {0, 0, 0};
8888
* is designed to be implemented by classes that produce plot-relevant data
8989
* which can be visualized.
9090
*/
91+
92+
typedef xt::xtensor<RGBColor, 2> ImageData;
9193
class PlottableInterface {
94+
public:
95+
PlottableInterface() = default;
96+
97+
void set_default_colors();
98+
9299
private:
93100
void set_id(pugi::xml_node plot_node);
94101
int id_; // unique plot ID
95102

96103
void set_bg_color(pugi::xml_node plot_node);
97104
void set_universe(pugi::xml_node plot_node);
98-
void set_default_colors(pugi::xml_node plot_node);
105+
void set_color_by(pugi::xml_node plot_node);
99106
void set_user_colors(pugi::xml_node plot_node);
100107
void set_overlap_color(pugi::xml_node plot_node);
101108
void set_mask(pugi::xml_node plot_node);
@@ -107,30 +114,35 @@ class PlottableInterface {
107114
public:
108115
enum class PlotColorBy { cells = 0, mats = 1 };
109116

117+
// Generates image data based on plot parameters and returns it
118+
virtual ImageData create_image() const = 0;
119+
110120
// Creates the output image named path_plot_
111121
virtual void create_output() const = 0;
112122

123+
// Write populated image data to file
124+
void write_image(const ImageData& data) const;
125+
113126
// Print useful info to the terminal
114127
virtual void print_info() const = 0;
115128

116129
const std::string& path_plot() const { return path_plot_; }
117130
std::string& path_plot() { return path_plot_; }
118131
int id() const { return id_; }
119132
int level() const { return level_; }
133+
PlotColorBy color_by() const { return color_by_; }
120134

121135
// Public color-related data
122136
PlottableInterface(pugi::xml_node plot_node);
123137
virtual ~PlottableInterface() = default;
124-
int level_; // Universe level to plot
125-
bool color_overlaps_; // Show overlapping cells?
138+
int level_ {-1}; // Universe level to plot
139+
bool color_overlaps_ {false}; // Show overlapping cells?
126140
PlotColorBy color_by_; // Plot coloring (cell/material)
127141
RGBColor not_found_ {WHITE}; // Plot background color
128142
RGBColor overlap_color_ {RED}; // Plot overlap color
129143
vector<RGBColor> colors_; // Plot colors
130144
};
131145

132-
typedef xt::xtensor<RGBColor, 2> ImageData;
133-
134146
struct IdData {
135147
// Constructor
136148
IdData(size_t h_res, size_t v_res);
@@ -166,6 +178,11 @@ class SlicePlotBase {
166178

167179
enum class PlotBasis { xy = 1, xz = 2, yz = 3 };
168180

181+
// Accessors
182+
183+
const std::array<size_t, 3>& pixels() const { return pixels_; }
184+
std::array<size_t, 3>& pixels() { return pixels_; }
185+
169186
// Members
170187
public:
171188
Position origin_; //!< Plot origin in geometry
@@ -270,11 +287,11 @@ class Plot : public PlottableInterface, public SlicePlotBase {
270287
public:
271288
// Add mesh lines to ImageData
272289
void draw_mesh_lines(ImageData& data) const;
273-
void create_image() const;
290+
ImageData create_image() const override;
274291
void create_voxel() const;
275292

276-
virtual void create_output() const;
277-
virtual void print_info() const;
293+
void create_output() const override;
294+
void print_info() const override;
278295

279296
PlotType type_; //!< Plot type (Slice/Voxel)
280297
int meshlines_width_; //!< Width of lines added to the plot
@@ -294,17 +311,32 @@ class Plot : public PlottableInterface, public SlicePlotBase {
294311
*/
295312
class RayTracePlot : public PlottableInterface {
296313
public:
314+
RayTracePlot() = default;
297315
RayTracePlot(pugi::xml_node plot);
298316

299317
// Standard getters. No setting since it's done from XML.
300318
const Position& camera_position() const { return camera_position_; }
319+
Position& camera_position() { return camera_position_; }
301320
const Position& look_at() const { return look_at_; }
321+
Position& look_at() { return look_at_; }
322+
302323
const double& horizontal_field_of_view() const
303324
{
304325
return horizontal_field_of_view_;
305326
}
327+
double& horizontal_field_of_view() { return horizontal_field_of_view_; }
328+
329+
void print_info() const override;
330+
331+
const std::array<int, 2>& pixels() const { return pixels_; }
332+
std::array<int, 2>& pixels() { return pixels_; }
306333

307-
virtual void print_info() const;
334+
const Direction& up() const { return up_; }
335+
Direction& up() { return up_; }
336+
337+
//! brief Updates the cached camera-to-model matrix after changes to
338+
//! camera parameters.
339+
void update_view();
308340

309341
protected:
310342
Direction camera_x_axis() const
@@ -330,8 +362,6 @@ class RayTracePlot : public PlottableInterface {
330362
*/
331363
std::pair<Position, Direction> get_pixel_ray(int horiz, int vert) const;
332364

333-
std::array<int, 2> pixels_; // pixel dimension of resulting image
334-
335365
private:
336366
void set_look_at(pugi::xml_node node);
337367
void set_camera_position(pugi::xml_node node);
@@ -341,8 +371,8 @@ class RayTracePlot : public PlottableInterface {
341371

342372
double horizontal_field_of_view_ {70.0}; // horiz. f.o.v. in degrees
343373
Position camera_position_; // where camera is
344-
Position look_at_; // point camera is centered looking at
345-
374+
Position look_at_; // point camera is centered looking at
375+
std::array<int, 2> pixels_; // pixel dimension of resulting image
346376
Direction up_ {0.0, 0.0, 1.0}; // which way is up
347377

348378
/* The horizontal thickness, if using an orthographic projection.
@@ -377,8 +407,9 @@ class WireframeRayTracePlot : public RayTracePlot {
377407
public:
378408
WireframeRayTracePlot(pugi::xml_node plot);
379409

380-
virtual void create_output() const;
381-
virtual void print_info() const;
410+
ImageData create_image() const override;
411+
void create_output() const override;
412+
void print_info() const override;
382413

383414
private:
384415
void set_opacities(pugi::xml_node node);
@@ -434,10 +465,22 @@ class SolidRayTracePlot : public RayTracePlot {
434465
friend class PhongRay;
435466

436467
public:
468+
SolidRayTracePlot() = default;
469+
437470
SolidRayTracePlot(pugi::xml_node plot);
438471

439-
virtual void create_output() const;
440-
virtual void print_info() const;
472+
ImageData create_image() const override;
473+
void create_output() const override;
474+
void print_info() const override;
475+
476+
const std::unordered_set<int>& opaque_ids() const { return opaque_ids_; }
477+
std::unordered_set<int>& opaque_ids() { return opaque_ids_; }
478+
479+
const Position& light_location() const { return light_location_; }
480+
Position& light_location() { return light_location_; }
481+
482+
const double& diffuse_fraction() const { return diffuse_fraction_; }
483+
double& diffuse_fraction() { return diffuse_fraction_; }
441484

442485
private:
443486
void set_opaque_ids(pugi::xml_node node);
@@ -496,7 +539,7 @@ class ProjectionRay : public Ray {
496539
: Ray(r, u), plot_(plot), line_segments_(line_segments)
497540
{}
498541

499-
virtual void on_intersection() override;
542+
void on_intersection() override;
500543

501544
private:
502545
/* Store a reference to the plot object which is running this ray, in order
@@ -519,7 +562,7 @@ class PhongRay : public Ray {
519562
result_color_ = plot_.not_found_;
520563
}
521564

522-
virtual void on_intersection() override;
565+
void on_intersection() override;
523566

524567
const RGBColor& result_color() { return result_color_; }
525568

0 commit comments

Comments
 (0)