From be10bc17810a7ece6d7276bcc22e6a5ff5452b63 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 31 Oct 2018 15:26:32 -0500 Subject: [PATCH] Making RGBColor a struct. --- include/openmc/plot.h | 40 ++++++++++++++++++++++++++++++++++++++-- src/plot.cpp | 2 +- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index a71b8926c..512306068 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -35,8 +35,44 @@ extern std::vector plots; //!< Plot instance container // RGBColor holds color information for plotted objects //=============================================================================== -typedef std::array RGBColor; - +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(int r, int g, int b) : red(r), green(g), blue(b) { }; + + RGBColor(const std::vector &v) { + assert(v.size() == 3); + red = v[0]; + green = v[1]; + blue = v[2]; + } + + // Index operators + const unsigned char& operator[](int i) const { + switch (i) { + case 0: return red; + case 1: return blue; + case 2: return green; + 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 blue; + case 2: return green; + default: + throw std::out_of_range{"Index in RGBColor must be between 0 and 2."}; + } + } + + // Members + unsigned char red, green, blue; +}; + typedef xt::xtensor ImageData; enum class PlotType { diff --git a/src/plot.cpp b/src/plot.cpp index e08606787..6f80dbe4c 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -37,7 +37,7 @@ int n_plots; std::vector plots; -const RGBColor WHITE {static_cast(255), static_cast(255), static_cast(255)}; + const RGBColor WHITE(255,255,255);// {static_cast(255), static_cast(255), static_cast(255)}; const RGBColor NULLRGB = {0, 0, 0}; //==============================================================================