From daffe0923dfbed78ee1d36f2589e33116c3b2ee7 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 2 Nov 2018 22:33:09 -0500 Subject: [PATCH] Removing RGB index defs. Writing to ppm more cleanly. --- include/openmc/plot.h | 27 +-------------------------- src/plot.cpp | 21 +++++++++------------ 2 files changed, 10 insertions(+), 38 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index fb379ae46..fa9ca171f 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -18,10 +18,6 @@ namespace openmc { // Global variables //=============================================================================== -constexpr int RED = 0; -constexpr int GREEN = 1; -constexpr int BLUE = 2; - extern int PLOT_LEVEL_LOWEST; //!< lower bound on plot universe level extern std::unordered_map plot_map; //!< map of plot ids to index @@ -38,7 +34,7 @@ extern std::vector plots; //!< Plot instance container struct RGBColor { //Constructors RGBColor() : red(0), green(0), blue(0) { }; - RGBColor(const int v[3]) : red(v[RED]), green(v[GREEN]), blue(v[BLUE]) { }; + RGBColor(const int v[3]) : red(v[0]), green(v[1]), blue(v[2]) { }; RGBColor(int r, int g, int b) : red(r), green(g), blue(b) { }; RGBColor(const std::vector &v) { @@ -48,27 +44,6 @@ struct RGBColor { blue = v[2]; } - // Index operators - const unsigned char& operator[](int i) const { - switch (i) { - case 0: return red; - case 1: return green; - case 2: return blue; - default: - throw std::out_of_range{"Index in RGBColor must be between 0 and 2."}; - } - } - - unsigned char& operator[](int i) { - switch (i) { - case 0: return red; - case 1: return green; - case 2: return blue; - default: - throw std::out_of_range{"Index in RGBColor must be between 0 and 2."}; - } - } - // Members uint8_t red, green, blue; }; diff --git a/src/plot.cpp b/src/plot.cpp index 3a538f2dd..f0f647679 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -481,13 +481,7 @@ Plot::set_meshlines(pugi::xml_node plot_node) err_msg << "Bad RGB for meshlines color in plot " << id_; fatal_error(err_msg); } - meshlines_color_[0] = ml_rgb[0]; - meshlines_color_[1] = ml_rgb[1]; - meshlines_color_[2] = ml_rgb[2]; - } else { - meshlines_color_[0] = 0; - meshlines_color_[1] = 0; - meshlines_color_[2] = 0; + meshlines_color_ = ml_rgb; } // Set mesh based on type @@ -710,11 +704,10 @@ void output_ppm(Plot pl, const ImageData& data) for (int y = 0; y < pl.pixels_[1]; y++) { for (int x = 0; x < pl.pixels_[0]; x++) { RGBColor rgb = data(x,y); - of.write(reinterpret_cast(&rgb[RED]), 1); - of.write(reinterpret_cast(&rgb[GREEN]), 1); - of.write(reinterpret_cast(&rgb[BLUE]), 1); + of << rgb.red << rgb.green << rgb.blue; } } + // Close file // THIS IS HERE TO MATCH FORTRAN VERSION, NOT TECHNICALLY NECESSARY of << "\n"; @@ -902,7 +895,6 @@ void create_voxel(Plot pl) RGBColor rgb; int id; for (int x = 0; x < pl.pixels_[0]; x++) { - // TODO: progress bar here pb.set_value(100.*(double)x/(double)(pl.pixels_[0]-1)); for (int y = 0; y < pl.pixels_[1]; y++) { for (int z = 0; z < pl.pixels_[2]; z++) { @@ -968,7 +960,12 @@ voxel_finalize(hid_t dspace, hid_t dset, hid_t memspace) } RGBColor random_color() { - return {int(prn()*255), int(prn()*255), int(prn()*255)}; + RGBColor rgb; + rgb.red = int(prn()*255); + rgb.green = int(prn()*255); + rgb.blue = int(prn()*255); + return rgb; + // return {int(prn()*255), int(prn()*255), int(prn()*255)}; } } // namespace openmc