Plots working as before using the single loop.

This commit is contained in:
Patrick Shriwise 2019-03-13 15:19:01 -05:00
parent 4c50cbcda8
commit 09258c5b79
2 changed files with 19 additions and 61 deletions

View file

@ -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<double>(width);
// double out_pixel = (pl.width_[1])/static_cast<double>(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);}