From 09258c5b79c6d66d1735a824dcdb5cfc670008c9 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 13 Mar 2019 15:19:01 -0500 Subject: [PATCH] Plots working as before using the single loop. --- include/openmc/plot.h | 4 +-- src/plot.cpp | 76 ++++++++++--------------------------------- 2 files changed, 19 insertions(+), 61 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index b879dbe36..54035fd85 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -88,8 +88,8 @@ enum class PlotBasis { }; enum class PlotColorBy { - cells = 1, - mats = 2 + cells = 0, + mats = 1 }; //=============================================================================== diff --git a/src/plot.cpp b/src/plot.cpp index da3bdf549..5e960b8d2 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -30,6 +30,7 @@ namespace openmc { const RGBColor WHITE {255, 255, 255}; constexpr int PLOT_LEVEL_LOWEST {-1}; //!< lower bound on plot universe level +constexpr int32_t VOID {-2}; constexpr int32_t NOT_FOUND {-1}; IdData::IdData(int h_res, int v_res) { @@ -40,7 +41,10 @@ void IdData::set_value(int y, int x, const Particle& p, int level) { Cell* c = model::cells[p.coord_[level].cell].get(); data(y,x,0) = c->id_; - if (c->type_ != FILL_UNIVERSE && p.material_ != MATERIAL_VOID) { + if (p.material_ == MATERIAL_VOID) { + data(y,x,1) = VOID; + return; + } else if (c->type_ != FILL_UNIVERSE) { Material* m = model::materials[p.material_].get(); data(y,x,1) = m->id_; } @@ -131,73 +135,27 @@ void create_ppm(Plot pl) size_t width = pl.pixels_[0]; size_t height = pl.pixels_[1]; - // double in_pixel = (pl.width_[0])/static_cast(width); - // double out_pixel = (pl.width_[1])/static_cast(height); - ImageData data({width, height}); xt::view(data, xt::all(), xt::all()) = pl.not_found_; -// int in_i, out_i; -// Position r; -// switch(pl.basis_) { -// case PlotBasis::xy : -// in_i = 0; -// out_i = 1; -// r.x = pl.origin_[0] - pl.width_[0] / 2.; -// r.y = pl.origin_[1] + pl.width_[1] / 2.; -// r.z = pl.origin_[2]; -// break; -// case PlotBasis::xz : -// in_i = 0; -// out_i = 2; -// r.x = pl.origin_[0] - pl.width_[0] / 2.; -// r.y = pl.origin_[1]; -// r.z = pl.origin_[2] + pl.width_[1] / 2.; -// break; -// case PlotBasis::yz : -// in_i = 1; -// out_i = 2; -// r.x = pl.origin_[0]; -// r.y = pl.origin_[1] - pl.width_[0] / 2.; -// r.z = pl.origin_[2] + pl.width_[1] / 2.; -// break; -// } - -// Direction u {0.5, 0.5, 0.5}; - -// #pragma omp parallel -// { -// Particle p; -// p.r() = r; -// p.u() = u; -// p.coord_[0].universe = model::root_universe; - -// #pragma omp for -// for (int y = 0; y < height; y++) { -// p.r()[out_i] = r[out_i] - out_pixel * y; -// for (int x = 0; x < width; x++) { -// // local variables -// RGBColor rgb; -// int id; -// p.r()[in_i] = r[in_i] + in_pixel * x; -// position_rgb(p, pl, rgb, id); -// data(x,y) = rgb; -// } -// } -// } - auto ids = pl.get_id_map(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { - RGBColor color; + auto id = ids.data(y, x, pl.color_by_); + // no setting needed if not found + if (id == NOT_FOUND) { continue; } if (PlotColorBy::cells == pl.color_by_) { - data(x,y) = pl.colors_[model::cell_map[ids.data(y,x,0)]]; + data(x,y) = pl.colors_[model::cell_map[id]]; } else if (PlotColorBy::mats == pl.color_by_) { - data(x,y) = pl.colors_[model::material_map[ids.data(y,x,1)]]; - } - } - } + if (id == VOID) { + data(x,y) = WHITE; + continue; + } + data(x,y) = pl.colors_[model::material_map[id]]; + } // color_by if-else + } // x for loop + } // y for loop // draw mesh lines if present if (pl.index_meshlines_mesh_ >= 0) {draw_mesh_lines(pl, data);}