Making RGBColor a struct.

This commit is contained in:
Patrick Shriwise 2018-10-31 15:26:32 -05:00
parent 43488e0286
commit be10bc1781
2 changed files with 39 additions and 3 deletions

View file

@ -35,8 +35,44 @@ extern std::vector<Plot> plots; //!< Plot instance container
// RGBColor holds color information for plotted objects
//===============================================================================
typedef std::array<unsigned char, 3> 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<int> &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<RGBColor, 2> ImageData;
enum class PlotType {