Commit c696fcfd authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Removing package radixcolor.

parent 2cfdb731
/home/jap/projects/tutela/TriBITS/
\ No newline at end of file
......@@ -2,7 +2,6 @@ TRIBITS_PACKAGE_DEFINE_DEPENDENCIES(
SUBPACKAGES_DIRS_CLASSIFICATIONS_OPTREQS
bug radixbug SS OPTIONAL
math radixmath SS OPTIONAL
color radixcolor SS OPTIONAL
io radixio SS OPTIONAL
geometry radixgeometry SS OPTIONAL
plot radixplot SS OPTIONAL
......
TRIBITS_SUBPACKAGE(color)
SET(SOURCE
color.cc
colorset.cc
)
SET(HEADERS
color.hh
colorset.hh
)
#
# Add library
TRIBITS_ADD_LIBRARY(radixcolor
SOURCES ${SOURCE}
)
#
# Add testing directory
TRIBITS_ADD_TEST_DIRECTORIES(tests)
INSTALL(FILES ${HEADERS} DESTINATION "include/radixcolor/")
TRIBITS_SUBPACKAGE_POSTPROCESS()
TRIBITS_PACKAGE_DEFINE_DEPENDENCIES(
LIB_REQUIRED_PACKAGES radixmath radixbug
LIB_OPTIONAL_PACKAGES
TEST_REQUIRED_PACKAGES testframework
TEST_OPTIONAL_PACKAGES
LIB_REQUIRED_TPLS
LIB_OPTIONAL_TPLS
TEST_REQUIRED_TPLS
TEST_OPTIONAL_TPLS
)
#include "radixcolor/color.hh"
#include "radixmath/matrix.hh"
namespace radix
{
TMatrix<3,3> Color::bradford_matrix = TMatrix<3,3>({{1.047835, 0.022897, -0.050147}
,{0.029556, 0.990481, -0.017056}
,{-0.009238, 0.015050, 0.752034}});
TMatrix<3,3> Color::srgb_matrix = TMatrix<3,3>({{0.412424, 0.357579, 0.180464}
,{0.212656, 0.715158, 0.072186}
,{0.019332, 0.119193, 0.950444}});
TMatrix<3,3> Color::bradford_srgb_matrix = Color::bradford_matrix
* Color::srgb_matrix;
Color::Color()
: mR(255)
, mG(255)
, mB(255)
{
}
radix::Color::Color(int r, int g, int b)
: mR(r)
, mG(g)
, mB(b)
{
}
int Color::r() const
{
return mR;
}
void Color::setR(int r)
{
mR = r;
}
int Color::g() const
{
return mG;
}
void Color::setG(int g)
{
mG = g;
}
int Color::b() const
{
return mB;
}
void Color::setB(int b)
{
mB = b;
}
LAB Color::toLAB() const
{
LAB r;
Real fXX0 = 0.;
Real fYY0 = 0.;
Real fZZ0 = 0.;
TMatrix<3,1> gMat({{Color::g(Real(mR)/255.)}
,{Color::g(Real(mG)/255.)}
,{Color::g(Real(mB)/255.)}});
TMatrix<3,1> XYZ = Color::bradford_srgb_matrix * gMat;
radix_line("XYZ={{" << XYZ.data()[0][0]
<< "},{" << XYZ.data()[1][0]
<< "},{" << XYZ.data()[2][0]
<< "}}");
tmatrix_value_t X0 = 0.964221;
tmatrix_value_t Y0 = 1.0;
tmatrix_value_t Z0 = 0.825213;
fXX0 = Color::f(XYZ.data()[0][0]/X0);
fYY0 = Color::f(XYZ.data()[1][0]/Y0);
fZZ0 = Color::f(XYZ.data()[2][0]/Z0);
radix_line("x0=" << fXX0
<< ", y0=" << fYY0
<< ", z0=" << fZZ0);
r.setL(116.0 * fYY0 - 16.0);
r.setA(500.0 * (fXX0 - fYY0));
r.setB(200.0 * (fYY0 - fZZ0));
return r;
}
Real Color::f(Real z)
{
if(z > 0.008856452)
{
return std::pow(z, 1.0/3.0);
} else
{
return 7.787037037*z + 4./29.0;
}
}
Real Color::g(Real z)
{
if(z > 0.04045)
{
return std::pow((z+0.055)/1.055, 2.4);
} else
{
return z/12.92;
}
}
LAB::LAB()
: mL(0.)
, mA(0.)
, mB(0.)
{
}
LAB::LAB(Real l, Real a, Real b)
: mL(l)
, mA(a)
, mB(b)
{
}
} // namespace radix
#ifndef RADIX_RADIXCOLOR_COLOR_HH_
#define RADIX_RADIXCOLOR_COLOR_HH_
#include "radixmath/constants.hh"
#include "radixmath/matrix.hh"
namespace radix
{
class LAB
{
Real mL, mA, mB;
public:
LAB();
LAB(Real l, Real a, Real b);
Real l() const { return mL; }
void setL(Real v) { mL = v; }
Real a() const { return mA; }
void setA(Real v) { mA = v; }
Real b() const { return mB; }
void setB(Real v) { mB = v; }
};
/**
* @brief The Color(rgb) class
*/
class Color
{
int mR, mG, mB;
public:
/**
* @brief Color default constructor (white)
*/
Color();
/**
* @brief Color
* @param r red [0, 255)
* @param g green [0, 255)
* @param b blue [0, 255)
*/
Color(int r, int g, int b);
int r() const;
void setR(int r);
int g() const;
void setG(int g);
int b() const;
void setB(int b);
LAB toLAB() const;
static TMatrix<3,3> bradford_matrix;
static TMatrix<3,3> srgb_matrix;
static TMatrix<3,3> bradford_srgb_matrix;
private:
static Real f(Real z);
static Real g(Real z);
}; // class Color
} // namespace radix
#endif /** RADIX_RADIXCOLOR_COLOR_HH_ */
#include "radixcolor/colorset.hh"
#include <random>
#include "radixbug/bug.hh"
#include "radixcolor/color.hh"
namespace radix
{
int ColorSet::size() const
{
return mSize;
}
void ColorSet::setSize(int size)
{
radix_check(size > 0);
mSize = size;
}
const std::vector<Color>& ColorSet::colors() const
{
if(mColors.size() != (size_t)mSize)
{
//lazy initialization of color set
evaluate();
}
return mColors;
}
Color ColorSet::next() const
{
if(mColors.size() != (size_t)mSize)
{
// lazy initialization of color set
evaluate();
}
if(mIndex == mColors.size())
{
mIndex = 0;
}
return mColors[mIndex++];
}
void ColorSet::evaluate() const
{
// random device for generator
std::random_device rd;
// mersienne twister algorithm
std::mt19937 gen(rd());
std::uniform_int_distribution<> rgb_dis(0,255);
// initialize mColors to mSize random colors
mColors.resize(mSize);
std::vector<LAB> labs(mSize);
for(int i = 0; i < mSize; ++i)
{
mColors[i].setR(rgb_dis(gen));
mColors[i].setG(rgb_dis(gen));
mColors[i].setB(rgb_dis(gen));
radix_line("Random color[" << mColors[i].r()
<< "," << mColors[i].g()
<< "," << mColors[i].b()
<< "]");
// convert RGB to LAB spectrum
labs[i] = mColors[i].toLAB();
}
//
// define energy function
//
// define temperature function
//
// define next_function
//
// annealing algorithm
}
ColorSet::ColorSet()
: mSize(10)
{
}
ColorSet::ColorSet(int n)
: mSize(n)
{
radix_check(mSize != 0);
}
} //namespace radix
#ifndef RADIX_RADIXCOLOR_COLORSET_HH_
#define RADIX_RADIXCOLOR_COLORSET_HH_
#include <vector>
#include <cstdlib>
namespace radix
{
class Color;
class ColorSet
{
private:
/**
* @brief mIndex index for next() request
*/
mutable size_t mIndex;
/**
* @brief mSize The number of requested unique colors
*/
int mSize;
/**
* @brief mColors The computed unique colors
*/
mutable std::vector<Color> mColors;
void evaluate() const;
public:
/**
* @brief ColorSet Defaults to 10 unique colors
*/
ColorSet();
/**
* @brief ColorSet
* @param n Number of unique colors
*/
ColorSet(int n);
int size() const;
void setSize(int size);
const std::vector<Color>& colors() const;
Color next() const;
}; // class Color
} // namespace radix
#endif /** RADIX_RADIXCOLOR_COLORSET_HH_ */
INCLUDE(GoogleTest)
ADD_GOOGLE_TEST(tstColor.cc NP 1)
#include "gtest/gtest.h"
#include "radixcolor/color.hh"
#include "radixcolor/colorset.hh"
using namespace radix;
TEST(Radix, RGBtoLAB)
{
{
Color rgb(255, 255, 255);
LAB lab = rgb.toLAB();
EXPECT_FLOAT_EQ(100, lab.l());
EXPECT_FLOAT_EQ(8.5893182e-05, lab.a());
EXPECT_FLOAT_EQ(0.00010726118, lab.b());
}
{
Color rgb(100, 255, 1);
LAB lab = rgb.toLAB();
EXPECT_FLOAT_EQ(89.170418, lab.l());
EXPECT_FLOAT_EQ(-68.176277, lab.a());
EXPECT_FLOAT_EQ(82.658813, lab.b());
}
}
TEST(Radix, ColorSet)
{
ColorSet set;
Color first = set.next();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment