App: code cleanup of Color models
This commit is contained in:
@@ -31,124 +31,83 @@
|
||||
using namespace App;
|
||||
|
||||
|
||||
ColorModel::ColorModel (unsigned short usCt)
|
||||
: _usColors(usCt), _pclColors(0)
|
||||
{
|
||||
if (usCt > 0)
|
||||
_pclColors = new Color[usCt];
|
||||
}
|
||||
|
||||
ColorModel::ColorModel (const ColorModel &rclM)
|
||||
: _pclColors(0)
|
||||
{
|
||||
*this = rclM;
|
||||
}
|
||||
|
||||
ColorModel::~ColorModel ()
|
||||
{
|
||||
delete [] _pclColors;
|
||||
}
|
||||
|
||||
ColorModel& ColorModel::operator = (const ColorModel &rclM)
|
||||
{
|
||||
// first check if both objects are identical
|
||||
if (this == &rclM)
|
||||
return *this;
|
||||
|
||||
delete [] _pclColors;
|
||||
_pclColors = 0;
|
||||
|
||||
_usColors = rclM._usColors;
|
||||
if (_usColors == 0)
|
||||
return *this;
|
||||
|
||||
_pclColors = new Color[rclM._usColors];
|
||||
for (int i = 0; i < rclM._usColors; i++)
|
||||
_pclColors[i] = rclM._pclColors[i];
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ColorField::ColorField (void)
|
||||
: _clModel(ColorModelTria())
|
||||
ColorField::ColorField ()
|
||||
: colorModel(ColorModelTria())
|
||||
{
|
||||
set(ColorModelTria(), -1.0f, 1.0f, 13);
|
||||
}
|
||||
|
||||
ColorField::ColorField (const ColorModel &rclModel, float fMin, float fMax, unsigned short usCt)
|
||||
: _clModel(ColorModelTria())
|
||||
ColorField::ColorField (const ColorModel &rclModel, float fMin, float fMax, std::size_t usCt)
|
||||
: colorModel(ColorModelTria())
|
||||
{
|
||||
set(rclModel, fMin, fMax, usCt);
|
||||
}
|
||||
|
||||
ColorField::~ColorField ()
|
||||
{
|
||||
}
|
||||
|
||||
ColorField::ColorField (const ColorField &rclCF)
|
||||
: _clModel(rclCF._clModel),
|
||||
_fMin(rclCF._fMin),
|
||||
_fMax(rclCF._fMax),
|
||||
_fAscent(rclCF._fAscent),
|
||||
_fConstant(rclCF._fConstant),
|
||||
_usCtColors(rclCF._usCtColors),
|
||||
_aclField(rclCF._aclField)
|
||||
: colorModel(rclCF.colorModel),
|
||||
fMin(rclCF.fMin),
|
||||
fMax(rclCF.fMax),
|
||||
fAscent(rclCF.fAscent),
|
||||
fConstant(rclCF.fConstant),
|
||||
ctColors(rclCF.ctColors),
|
||||
colorField(rclCF.colorField)
|
||||
{
|
||||
}
|
||||
|
||||
ColorField& ColorField::operator = (const ColorField &rclCF)
|
||||
{
|
||||
_aclField = rclCF._aclField;
|
||||
colorField = rclCF.colorField;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void ColorField::set (const ColorModel &rclModel, float fMin, float fMax, unsigned short usCt)
|
||||
void ColorField::set (const ColorModel &rclModel, float fMin, float fMax, std::size_t usCt)
|
||||
{
|
||||
_clModel = rclModel;
|
||||
_fMin = std::min<float>(fMin, fMax);
|
||||
_fMax = std::max<float>(_fMin + CCR_EPS, fMax);
|
||||
_usCtColors = std::max<unsigned short>(usCt, _clModel._usColors);
|
||||
colorModel = rclModel;
|
||||
this->fMin = std::min<float>(fMin, fMax);
|
||||
this->fMax = std::max<float>(this->fMin + CCR_EPS, fMax);
|
||||
ctColors = std::max<std::size_t>(usCt, colorModel.getCountColors());
|
||||
rebuild();
|
||||
}
|
||||
|
||||
void ColorField::setColorModel (const ColorModel &rclModel)
|
||||
{
|
||||
_clModel = rclModel;
|
||||
colorModel = rclModel;
|
||||
rebuild();
|
||||
}
|
||||
|
||||
void ColorField::rebuild (void)
|
||||
void ColorField::rebuild ()
|
||||
{
|
||||
unsigned short usInd1, usInd2, usStep, i;
|
||||
std::size_t usInd1, usInd2, usStep, i;
|
||||
|
||||
_aclField.resize(_usCtColors);
|
||||
colorField.resize(ctColors);
|
||||
|
||||
|
||||
usStep = std::min<unsigned short>(_usCtColors / (_clModel._usColors-1), _usCtColors-1);
|
||||
usStep = std::min<std::size_t>(ctColors / (colorModel.getCountColors() - 1), ctColors - 1);
|
||||
usInd1 = 0;
|
||||
usInd2 = usStep;
|
||||
for (i = 0; i < (_clModel._usColors - 1); i++) {
|
||||
interpolate(_clModel._pclColors[i], usInd1, _clModel._pclColors[i+1], usInd2);
|
||||
for (i = 0; i < (colorModel.getCountColors() - 1); i++) {
|
||||
interpolate(colorModel.colors[i], usInd1, colorModel.colors[i+1], usInd2);
|
||||
usInd1 = usInd2;
|
||||
if ((i + 1) == (_clModel._usColors - 2))
|
||||
usInd2 = _usCtColors - 1;
|
||||
if ((i + 1) == (colorModel.getCountColors() - 2))
|
||||
usInd2 = ctColors - 1;
|
||||
else
|
||||
usInd2 += usStep;
|
||||
}
|
||||
|
||||
_fAscent = float(_usCtColors) / (_fMax - _fMin);
|
||||
_fConstant = -_fAscent * _fMin;
|
||||
fAscent = float(ctColors) / (fMax - fMin);
|
||||
fConstant = -fAscent * fMin;
|
||||
}
|
||||
|
||||
// fuellt das Array von Farbe 1, Index 1 bis Farbe 2, Index 2
|
||||
void ColorField::interpolate (Color clCol1, unsigned short usInd1, Color clCol2, unsigned short usInd2)
|
||||
void ColorField::interpolate (Color clCol1, std::size_t usInd1, Color clCol2, std::size_t usInd2)
|
||||
{
|
||||
unsigned short i;
|
||||
std::size_t i;
|
||||
float ucR, ucG, ucB;
|
||||
float fR, fG, fB, fStep = 1.0f, fLen = float(usInd2 - usInd1);
|
||||
|
||||
_aclField[usInd1] = clCol1;
|
||||
_aclField[usInd2] = clCol2;
|
||||
colorField[usInd1] = clCol1;
|
||||
colorField[usInd2] = clCol2;
|
||||
|
||||
fR = (float(clCol2.r) - float(clCol1.r)) / fLen;
|
||||
fG = (float(clCol2.g) - float(clCol1.g)) / fLen;
|
||||
@@ -158,115 +117,83 @@ void ColorField::interpolate (Color clCol1, unsigned short usInd1, Color clCol2,
|
||||
ucR = clCol1.r + fR * fStep;
|
||||
ucG = clCol1.g + fG * fStep;
|
||||
ucB = clCol1.b + fB * fStep;
|
||||
_aclField[i] = Color(ucR, ucG, ucB);
|
||||
colorField[i] = Color(ucR, ucG, ucB);
|
||||
fStep += 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ColorGradient::ColorGradient (void)
|
||||
: _tColorModel(TRIA),
|
||||
_tStyle(ZERO_BASED),
|
||||
_bOutsideGrayed(false),
|
||||
_clTotal(ColorModelTria()),
|
||||
_clTop(ColorModelTriaTop()),
|
||||
_clBottom(ColorModelTriaBottom())
|
||||
ColorGradient::ColorGradient ()
|
||||
: tColorModel(TRIA),
|
||||
tStyle(ZERO_BASED),
|
||||
outsideGrayed(false),
|
||||
totalModel(ColorModelTria()),
|
||||
topModel(ColorModelTriaTop()),
|
||||
bottomModel(ColorModelTriaBottom())
|
||||
{
|
||||
setColorModel();
|
||||
set(-1.0f, 1.0f, 13, ZERO_BASED, false);
|
||||
}
|
||||
|
||||
ColorGradient::ColorGradient (float fMin, float fMax, unsigned short usCtColors, TStyle tS, bool bOG)
|
||||
: _tColorModel(TRIA),
|
||||
_tStyle(tS),
|
||||
_bOutsideGrayed(false),
|
||||
_clTotal(ColorModelTria()),
|
||||
_clTop(ColorModelTriaTop()),
|
||||
_clBottom(ColorModelTriaBottom())
|
||||
ColorGradient::ColorGradient (float fMin, float fMax, std::size_t usCtColors, TStyle tS, bool bOG)
|
||||
: tColorModel(TRIA),
|
||||
tStyle(tS),
|
||||
outsideGrayed(false),
|
||||
totalModel(ColorModelTria()),
|
||||
topModel(ColorModelTriaTop()),
|
||||
bottomModel(ColorModelTriaBottom())
|
||||
{
|
||||
setColorModel();
|
||||
set(fMin, fMax, usCtColors, tS, bOG);
|
||||
}
|
||||
|
||||
ColorGradient::ColorGradient (const ColorGradient &rclCR)
|
||||
: _clColFld1(rclCR._clColFld1),
|
||||
_clColFld2(rclCR._clColFld2),
|
||||
_tColorModel(rclCR._tColorModel),
|
||||
_tStyle(rclCR._tStyle),
|
||||
_fMin(rclCR._fMin),
|
||||
_fMax(rclCR._fMax),
|
||||
_usCtColors(rclCR._usCtColors),
|
||||
_bOutsideGrayed(rclCR._bOutsideGrayed),
|
||||
_clTotal(rclCR._clTotal),
|
||||
_clTop(rclCR._clTop),
|
||||
_clBottom(rclCR._clBottom)
|
||||
{
|
||||
}
|
||||
|
||||
ColorGradient& ColorGradient::operator = (const ColorGradient &rclCR)
|
||||
{
|
||||
_tColorModel = rclCR._tColorModel;
|
||||
_clTotal = rclCR._clTotal;
|
||||
_clTop = rclCR._clTop;
|
||||
_clBottom = rclCR._clBottom;
|
||||
_bOutsideGrayed = rclCR._bOutsideGrayed;
|
||||
_clColFld1 = rclCR._clColFld1;
|
||||
_clColFld2 = rclCR._clColFld2;
|
||||
_tStyle = rclCR._tStyle;
|
||||
_fMin = rclCR._fMin;
|
||||
_fMax = rclCR._fMax;
|
||||
_usCtColors = rclCR._usCtColors;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void ColorGradient::set (float fMin, float fMax, unsigned short usCt, TStyle tS, bool bOG)
|
||||
void ColorGradient::set (float fMin, float fMax, std::size_t usCt, TStyle tS, bool bOG)
|
||||
{
|
||||
_fMin = std::min<float>(fMin, fMax);
|
||||
_fMax = std::max<float>(_fMin + CCR_EPS, fMax);
|
||||
_usCtColors = std::max<unsigned short>(usCt, getMinColors());
|
||||
_tStyle = tS;
|
||||
_bOutsideGrayed = bOG;
|
||||
ctColors = std::max<std::size_t>(usCt, getMinColors());
|
||||
tStyle = tS;
|
||||
outsideGrayed = bOG;
|
||||
rebuild();
|
||||
}
|
||||
|
||||
void ColorGradient::rebuild (void)
|
||||
void ColorGradient::rebuild ()
|
||||
{
|
||||
switch (_tStyle)
|
||||
switch (tStyle)
|
||||
{
|
||||
case FLOW:
|
||||
{
|
||||
_clColFld1.set(_clTotal, _fMin, _fMax, _usCtColors);
|
||||
colorField1.set(totalModel, _fMin, _fMax, ctColors);
|
||||
break;
|
||||
}
|
||||
case ZERO_BASED:
|
||||
{
|
||||
if ((_fMin < 0.0f) && (_fMax > 0.0f))
|
||||
{
|
||||
_clColFld1.set(_clBottom, _fMin, 0.0f, _usCtColors / 2);
|
||||
_clColFld2.set(_clTop, 0.0f, _fMax, _usCtColors / 2);
|
||||
colorField1.set(bottomModel, _fMin, 0.0f, ctColors / 2);
|
||||
colorField2.set(topModel, 0.0f, _fMax, ctColors / 2);
|
||||
}
|
||||
else if (_fMin >= 0.0f)
|
||||
_clColFld1.set(_clTop, 0.0f, _fMax, _usCtColors);
|
||||
colorField1.set(topModel, 0.0f, _fMax, ctColors);
|
||||
else
|
||||
_clColFld1.set(_clBottom, _fMin, 0.0f, _usCtColors);
|
||||
colorField1.set(bottomModel, _fMin, 0.0f, ctColors);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned short ColorGradient::getMinColors (void) const
|
||||
std::size_t ColorGradient::getMinColors () const
|
||||
{
|
||||
switch (_tStyle)
|
||||
switch (tStyle)
|
||||
{
|
||||
case FLOW:
|
||||
return _clColFld1.getMinColors();
|
||||
return colorField1.getMinColors();
|
||||
case ZERO_BASED:
|
||||
{
|
||||
if ((_fMin < 0.0f) && (_fMax > 0.0f))
|
||||
return _clColFld1.getMinColors() + _clColFld2.getMinColors();
|
||||
return colorField1.getMinColors() + colorField2.getMinColors();
|
||||
else
|
||||
return _clColFld1.getMinColors();
|
||||
return colorField1.getMinColors();
|
||||
}
|
||||
}
|
||||
return 2;
|
||||
@@ -274,75 +201,75 @@ unsigned short ColorGradient::getMinColors (void) const
|
||||
|
||||
void ColorGradient::setColorModel (TColorModel tModel)
|
||||
{
|
||||
_tColorModel = tModel;
|
||||
tColorModel = tModel;
|
||||
setColorModel();
|
||||
rebuild();
|
||||
}
|
||||
|
||||
void ColorGradient::setColorModel (void)
|
||||
void ColorGradient::setColorModel ()
|
||||
{
|
||||
switch (_tColorModel)
|
||||
switch (tColorModel)
|
||||
{
|
||||
case TRIA:
|
||||
{
|
||||
_clTotal = ColorModelTria();
|
||||
_clTop = ColorModelTriaTop();
|
||||
_clBottom = ColorModelTriaBottom();
|
||||
totalModel = ColorModelTria();
|
||||
topModel = ColorModelTriaTop();
|
||||
bottomModel = ColorModelTriaBottom();
|
||||
break;
|
||||
}
|
||||
case INVERSE_TRIA:
|
||||
{
|
||||
_clTotal = ColorModelInverseTria();
|
||||
_clTop = ColorModelInverseTriaTop();
|
||||
_clBottom = ColorModelInverseTriaBottom();
|
||||
totalModel = ColorModelInverseTria();
|
||||
topModel = ColorModelInverseTriaTop();
|
||||
bottomModel = ColorModelInverseTriaBottom();
|
||||
break;
|
||||
}
|
||||
case GRAY:
|
||||
{
|
||||
_clTotal = ColorModelGray();
|
||||
_clTop = ColorModelGrayTop();
|
||||
_clBottom = ColorModelGrayBottom();
|
||||
totalModel = ColorModelGray();
|
||||
topModel = ColorModelGrayTop();
|
||||
bottomModel = ColorModelGrayBottom();
|
||||
break;
|
||||
}
|
||||
case INVERSE_GRAY:
|
||||
{
|
||||
_clTotal = ColorModelInverseGray();
|
||||
_clTop = ColorModelInverseGrayTop();
|
||||
_clBottom = ColorModelInverseGrayBottom();
|
||||
totalModel = ColorModelInverseGray();
|
||||
topModel = ColorModelInverseGrayTop();
|
||||
bottomModel = ColorModelInverseGrayBottom();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (_tStyle)
|
||||
switch (tStyle)
|
||||
{
|
||||
case FLOW:
|
||||
{
|
||||
_clColFld1.setColorModel(_clTotal);
|
||||
_clColFld2.setColorModel(_clBottom);
|
||||
colorField1.setColorModel(totalModel);
|
||||
colorField2.setColorModel(bottomModel);
|
||||
break;
|
||||
}
|
||||
case ZERO_BASED:
|
||||
{
|
||||
_clColFld1.setColorModel(_clTop);
|
||||
_clColFld2.setColorModel(_clBottom);
|
||||
colorField1.setColorModel(topModel);
|
||||
colorField2.setColorModel(bottomModel);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ColorLegend::ColorLegend (void)
|
||||
: _bOutsideGrayed(false)
|
||||
ColorLegend::ColorLegend ()
|
||||
: outsideGrayed(false)
|
||||
{
|
||||
// default green, red
|
||||
_aclColorFields.emplace_back(0, 1, 0);
|
||||
_aclColorFields.emplace_back(1, 0, 0);
|
||||
colorFields.emplace_back(0, 1, 0);
|
||||
colorFields.emplace_back(1, 0, 0);
|
||||
|
||||
_aclNames.push_back("Min");
|
||||
_aclNames.push_back("Max");
|
||||
names.push_back("Min");
|
||||
names.push_back("Max");
|
||||
|
||||
_aclValues.push_back(-1.0f);
|
||||
_aclValues.push_back(0.0f);
|
||||
_aclValues.push_back(1.0f);
|
||||
values.push_back(-1.0f);
|
||||
values.push_back(0.0f);
|
||||
values.push_back(1.0f);
|
||||
}
|
||||
|
||||
ColorLegend::ColorLegend (const ColorLegend &rclCL)
|
||||
@@ -352,38 +279,38 @@ ColorLegend::ColorLegend (const ColorLegend &rclCL)
|
||||
|
||||
ColorLegend& ColorLegend::operator = (const ColorLegend &rclCL)
|
||||
{
|
||||
_aclColorFields = rclCL._aclColorFields;
|
||||
_aclNames = rclCL._aclNames;
|
||||
_aclValues = rclCL._aclValues;
|
||||
_bOutsideGrayed = rclCL._bOutsideGrayed;
|
||||
colorFields = rclCL.colorFields;
|
||||
names = rclCL.names;
|
||||
values = rclCL.values;
|
||||
outsideGrayed = rclCL.outsideGrayed;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool ColorLegend::operator == (const ColorLegend &rclCL) const
|
||||
{
|
||||
return (_aclColorFields.size() == rclCL._aclColorFields.size()) &&
|
||||
(_aclNames.size() == rclCL._aclNames.size()) &&
|
||||
(_aclValues.size() == rclCL._aclValues.size()) &&
|
||||
std::equal(_aclColorFields.begin(), _aclColorFields.end(), rclCL._aclColorFields.begin()) &&
|
||||
std::equal(_aclNames.begin(), _aclNames.end(), rclCL._aclNames.begin()) &&
|
||||
std::equal(_aclValues.begin(), _aclValues.end(), rclCL._aclValues.begin()) &&
|
||||
_bOutsideGrayed == rclCL._bOutsideGrayed;
|
||||
return (colorFields.size() == rclCL.colorFields.size()) &&
|
||||
(names.size() == rclCL.names.size()) &&
|
||||
(values.size() == rclCL.values.size()) &&
|
||||
std::equal(colorFields.begin(), colorFields.end(), rclCL.colorFields.begin()) &&
|
||||
std::equal(names.begin(), names.end(), rclCL.names.begin()) &&
|
||||
std::equal(values.begin(), values.end(), rclCL.values.begin()) &&
|
||||
outsideGrayed == rclCL.outsideGrayed;
|
||||
}
|
||||
|
||||
float ColorLegend::getValue (unsigned long ulPos) const
|
||||
{
|
||||
if (ulPos < _aclValues.size())
|
||||
return _aclValues[ulPos];
|
||||
if (ulPos < values.size())
|
||||
return values[ulPos];
|
||||
else
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
bool ColorLegend::setValue (unsigned long ulPos, float fVal)
|
||||
{
|
||||
if (ulPos < _aclValues.size())
|
||||
if (ulPos < values.size())
|
||||
{
|
||||
_aclValues[ulPos] = fVal;
|
||||
values[ulPos] = fVal;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -392,8 +319,8 @@ bool ColorLegend::setValue (unsigned long ulPos, float fVal)
|
||||
|
||||
Color ColorLegend::getColor (unsigned long ulPos) const
|
||||
{
|
||||
if (ulPos < _aclColorFields.size())
|
||||
return _aclColorFields[ulPos];
|
||||
if (ulPos < colorFields.size())
|
||||
return colorFields[ulPos];
|
||||
else
|
||||
return Color();
|
||||
}
|
||||
@@ -407,49 +334,49 @@ uint32_t ColorLegend::getPackedColor (unsigned long ulPos) const
|
||||
|
||||
std::string ColorLegend::getText (unsigned long ulPos) const
|
||||
{
|
||||
if (ulPos < _aclNames.size())
|
||||
return _aclNames[ulPos];
|
||||
if (ulPos < names.size())
|
||||
return names[ulPos];
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
bool ColorLegend::addMin (const std::string &rclName)
|
||||
{
|
||||
_aclNames.push_front(rclName);
|
||||
_aclValues.push_front(*_aclValues.begin() - 1.0f);
|
||||
names.push_front(rclName);
|
||||
values.push_front(*values.begin() - 1.0f);
|
||||
|
||||
Color clNewRGB;
|
||||
clNewRGB.r = ((float)rand() / (float)RAND_MAX);
|
||||
clNewRGB.g = ((float)rand() / (float)RAND_MAX);
|
||||
clNewRGB.b = ((float)rand() / (float)RAND_MAX);
|
||||
|
||||
_aclColorFields.push_front(clNewRGB);
|
||||
colorFields.push_front(clNewRGB);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ColorLegend::addMax (const std::string &rclName)
|
||||
{
|
||||
_aclNames.push_back(rclName);
|
||||
_aclValues.push_back(*(_aclValues.end()-1) + 1.0f);
|
||||
names.push_back(rclName);
|
||||
values.push_back(*(values.end()-1) + 1.0f);
|
||||
|
||||
Color clNewRGB;
|
||||
clNewRGB.r = ((float)rand() / (float)RAND_MAX);
|
||||
clNewRGB.g = ((float)rand() / (float)RAND_MAX);
|
||||
clNewRGB.b = ((float)rand() / (float)RAND_MAX);
|
||||
|
||||
_aclColorFields.push_back(clNewRGB);
|
||||
colorFields.push_back(clNewRGB);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ColorLegend::remove (unsigned long ulPos)
|
||||
{
|
||||
if (ulPos < _aclColorFields.size())
|
||||
if (ulPos < colorFields.size())
|
||||
{
|
||||
_aclColorFields.erase(_aclColorFields.begin() + ulPos);
|
||||
_aclNames.erase(_aclNames.begin() + ulPos);
|
||||
_aclValues.erase(_aclValues.begin() + ulPos);
|
||||
colorFields.erase(colorFields.begin() + ulPos);
|
||||
names.erase(names.begin() + ulPos);
|
||||
values.erase(values.begin() + ulPos);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -457,40 +384,40 @@ bool ColorLegend::remove (unsigned long ulPos)
|
||||
return false;
|
||||
}
|
||||
|
||||
void ColorLegend::removeFirst (void)
|
||||
void ColorLegend::removeFirst ()
|
||||
{
|
||||
if (_aclColorFields.size() > 0)
|
||||
if (colorFields.size() > 0)
|
||||
{
|
||||
_aclColorFields.erase(_aclColorFields.begin());
|
||||
_aclNames.erase(_aclNames.begin());
|
||||
_aclValues.erase(_aclValues.begin());
|
||||
colorFields.erase(colorFields.begin());
|
||||
names.erase(names.begin());
|
||||
values.erase(values.begin());
|
||||
}
|
||||
}
|
||||
|
||||
void ColorLegend::removeLast (void)
|
||||
void ColorLegend::removeLast ()
|
||||
{
|
||||
if (_aclColorFields.size() > 0)
|
||||
if (colorFields.size() > 0)
|
||||
{
|
||||
_aclColorFields.erase(_aclColorFields.end()-1);
|
||||
_aclNames.erase(_aclNames.end()-1);
|
||||
_aclValues.erase(_aclValues.end()-1);
|
||||
colorFields.erase(colorFields.end()-1);
|
||||
names.erase(names.end()-1);
|
||||
values.erase(values.end()-1);
|
||||
}
|
||||
}
|
||||
|
||||
void ColorLegend::resize (unsigned long ulCt)
|
||||
{
|
||||
if ((ulCt < 2) || (ulCt == _aclColorFields.size()))
|
||||
if ((ulCt < 2) || (ulCt == colorFields.size()))
|
||||
return;
|
||||
|
||||
if (ulCt > _aclColorFields.size())
|
||||
if (ulCt > colorFields.size())
|
||||
{
|
||||
int k = ulCt - _aclColorFields.size();
|
||||
int k = ulCt - colorFields.size();
|
||||
for (int i = 0; i < k; i++)
|
||||
addMin("new");
|
||||
}
|
||||
else
|
||||
{
|
||||
int k = _aclColorFields.size() - ulCt;
|
||||
int k = colorFields.size() - ulCt;
|
||||
for (int i = 0; i < k; i++)
|
||||
removeLast();
|
||||
}
|
||||
@@ -498,9 +425,9 @@ void ColorLegend::resize (unsigned long ulCt)
|
||||
|
||||
bool ColorLegend::setColor (unsigned long ulPos, float ucRed, float ucGreen, float ucBlue)
|
||||
{
|
||||
if (ulPos < _aclNames.size())
|
||||
if (ulPos < names.size())
|
||||
{
|
||||
_aclColorFields[ulPos] = Color(ucRed, ucGreen, ucBlue);
|
||||
colorFields[ulPos] = Color(ucRed, ucGreen, ucBlue);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -518,9 +445,9 @@ bool ColorLegend::setColor (unsigned long ulPos, unsigned long ulColor)
|
||||
|
||||
bool ColorLegend::setText (unsigned long ulPos, const std::string &rclName)
|
||||
{
|
||||
if (ulPos < _aclNames.size())
|
||||
if (ulPos < names.size())
|
||||
{
|
||||
_aclNames[ulPos] = rclName;
|
||||
names[ulPos] = rclName;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -45,211 +45,214 @@ public:
|
||||
virtual Color getColor(float fVal) const = 0;
|
||||
|
||||
protected:
|
||||
ValueFloatToRGB (void) {}
|
||||
virtual ~ValueFloatToRGB () {}
|
||||
ValueFloatToRGB () = default;
|
||||
virtual ~ValueFloatToRGB () = default;
|
||||
};
|
||||
|
||||
|
||||
class AppExport ColorModel
|
||||
{
|
||||
public:
|
||||
ColorModel (unsigned short usCt);
|
||||
ColorModel (const ColorModel &rclM);
|
||||
virtual ~ColorModel ();
|
||||
ColorModel& operator = (const ColorModel &rclM);
|
||||
unsigned short _usColors;
|
||||
Color *_pclColors;
|
||||
ColorModel (std::size_t usCt) {
|
||||
colors.resize(usCt);
|
||||
}
|
||||
ColorModel(const ColorModel&) = default;
|
||||
virtual ~ColorModel () = default;
|
||||
ColorModel& operator = (const ColorModel&) = default;
|
||||
std::size_t getCountColors() const {
|
||||
return colors.size();
|
||||
}
|
||||
std::vector<Color> colors;
|
||||
};
|
||||
|
||||
class AppExport ColorModelTria : public ColorModel
|
||||
{
|
||||
public:
|
||||
ColorModelTria (void) : ColorModel(5)
|
||||
ColorModelTria () : ColorModel(5)
|
||||
{
|
||||
_pclColors[0] = Color( 0, 0, 1);
|
||||
_pclColors[1] = Color( 0, 1, 1);
|
||||
_pclColors[2] = Color( 0, 1, 0);
|
||||
_pclColors[3] = Color( 1, 1, 0);
|
||||
_pclColors[4] = Color( 1, 0, 0);
|
||||
colors[0] = Color( 0, 0, 1);
|
||||
colors[1] = Color( 0, 1, 1);
|
||||
colors[2] = Color( 0, 1, 0);
|
||||
colors[3] = Color( 1, 1, 0);
|
||||
colors[4] = Color( 1, 0, 0);
|
||||
}
|
||||
};
|
||||
|
||||
class AppExport ColorModelTriaBottom : public ColorModel
|
||||
{
|
||||
public:
|
||||
ColorModelTriaBottom (void) : ColorModel(3)
|
||||
ColorModelTriaBottom () : ColorModel(3)
|
||||
{
|
||||
_pclColors[0] = Color( 0, 0, 1);
|
||||
_pclColors[1] = Color( 0, 1, 1);
|
||||
_pclColors[2] = Color( 0, 1, 0);
|
||||
colors[0] = Color( 0, 0, 1);
|
||||
colors[1] = Color( 0, 1, 1);
|
||||
colors[2] = Color( 0, 1, 0);
|
||||
}
|
||||
};
|
||||
|
||||
class AppExport ColorModelTriaTop : public ColorModel
|
||||
{
|
||||
public:
|
||||
ColorModelTriaTop (void) : ColorModel(3)
|
||||
ColorModelTriaTop () : ColorModel(3)
|
||||
{
|
||||
_pclColors[0] = Color( 0, 1, 0);
|
||||
_pclColors[1] = Color( 1, 1, 0);
|
||||
_pclColors[2] = Color( 1, 0, 0);
|
||||
colors[0] = Color( 0, 1, 0);
|
||||
colors[1] = Color( 1, 1, 0);
|
||||
colors[2] = Color( 1, 0, 0);
|
||||
}
|
||||
};
|
||||
|
||||
class AppExport ColorModelInverseTria : public ColorModel
|
||||
{
|
||||
public:
|
||||
ColorModelInverseTria (void) : ColorModel(5)
|
||||
ColorModelInverseTria () : ColorModel(5)
|
||||
{
|
||||
_pclColors[0] = Color( 1, 0, 0);
|
||||
_pclColors[1] = Color( 1, 1, 0);
|
||||
_pclColors[2] = Color( 0, 1, 0);
|
||||
_pclColors[3] = Color( 0, 1, 1);
|
||||
_pclColors[4] = Color( 0, 0, 1);
|
||||
colors[0] = Color( 1, 0, 0);
|
||||
colors[1] = Color( 1, 1, 0);
|
||||
colors[2] = Color( 0, 1, 0);
|
||||
colors[3] = Color( 0, 1, 1);
|
||||
colors[4] = Color( 0, 0, 1);
|
||||
}
|
||||
};
|
||||
|
||||
class AppExport ColorModelInverseTriaTop : public ColorModel
|
||||
{
|
||||
public:
|
||||
ColorModelInverseTriaTop (void) : ColorModel(3)
|
||||
ColorModelInverseTriaTop () : ColorModel(3)
|
||||
{
|
||||
_pclColors[2] = Color( 0, 0, 1);
|
||||
_pclColors[1] = Color( 0, 1, 1);
|
||||
_pclColors[0] = Color( 0, 1, 0);
|
||||
colors[2] = Color( 0, 0, 1);
|
||||
colors[1] = Color( 0, 1, 1);
|
||||
colors[0] = Color( 0, 1, 0);
|
||||
}
|
||||
};
|
||||
|
||||
class AppExport ColorModelInverseTriaBottom : public ColorModel
|
||||
{
|
||||
public:
|
||||
ColorModelInverseTriaBottom (void) : ColorModel(3)
|
||||
ColorModelInverseTriaBottom () : ColorModel(3)
|
||||
{
|
||||
_pclColors[2] = Color( 0, 1, 0);
|
||||
_pclColors[1] = Color( 1, 1, 0);
|
||||
_pclColors[0] = Color( 1, 0, 0);
|
||||
colors[2] = Color( 0, 1, 0);
|
||||
colors[1] = Color( 1, 1, 0);
|
||||
colors[0] = Color( 1, 0, 0);
|
||||
}
|
||||
};
|
||||
|
||||
class AppExport ColorModelGray : public ColorModel
|
||||
{
|
||||
public:
|
||||
ColorModelGray (void) : ColorModel(2)
|
||||
ColorModelGray () : ColorModel(2)
|
||||
{
|
||||
_pclColors[0] = Color( 0, 0, 0);
|
||||
_pclColors[1] = Color( 1, 1, 1);
|
||||
colors[0] = Color( 0, 0, 0);
|
||||
colors[1] = Color( 1, 1, 1);
|
||||
}
|
||||
};
|
||||
|
||||
class AppExport ColorModelGrayBottom : public ColorModel
|
||||
{
|
||||
public:
|
||||
ColorModelGrayBottom (void) : ColorModel(2)
|
||||
ColorModelGrayBottom () : ColorModel(2)
|
||||
{
|
||||
_pclColors[0] = Color( 0.0f, 0.0f, 0.0f);
|
||||
_pclColors[1] = Color( 0.5f, 0.5f, 0.5f);
|
||||
colors[0] = Color( 0.0f, 0.0f, 0.0f);
|
||||
colors[1] = Color( 0.5f, 0.5f, 0.5f);
|
||||
}
|
||||
};
|
||||
|
||||
class AppExport ColorModelGrayTop : public ColorModel
|
||||
{
|
||||
public:
|
||||
ColorModelGrayTop (void) : ColorModel(2)
|
||||
ColorModelGrayTop () : ColorModel(2)
|
||||
{
|
||||
_pclColors[0] = Color( 0.5f, 0.5f, 0.5f);
|
||||
_pclColors[1] = Color( 1.0f, 1.0f, 1.0f);
|
||||
colors[0] = Color( 0.5f, 0.5f, 0.5f);
|
||||
colors[1] = Color( 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
};
|
||||
|
||||
class AppExport ColorModelInverseGray : public ColorModel
|
||||
{
|
||||
public:
|
||||
ColorModelInverseGray (void) : ColorModel(2)
|
||||
ColorModelInverseGray () : ColorModel(2)
|
||||
{
|
||||
_pclColors[0] = Color( 1, 1, 1);
|
||||
_pclColors[1] = Color( 0, 0, 0);
|
||||
colors[0] = Color( 1, 1, 1);
|
||||
colors[1] = Color( 0, 0, 0);
|
||||
}
|
||||
};
|
||||
|
||||
class AppExport ColorModelInverseGrayBottom : public ColorModel
|
||||
{
|
||||
public:
|
||||
ColorModelInverseGrayBottom (void) : ColorModel(2)
|
||||
ColorModelInverseGrayBottom () : ColorModel(2)
|
||||
{
|
||||
_pclColors[0] = Color( 1.0f, 1.0f, 1.0f);
|
||||
_pclColors[1] = Color( 0.5f, 0.5f, 0.5f);
|
||||
colors[0] = Color( 1.0f, 1.0f, 1.0f);
|
||||
colors[1] = Color( 0.5f, 0.5f, 0.5f);
|
||||
}
|
||||
};
|
||||
|
||||
class AppExport ColorModelInverseGrayTop : public ColorModel
|
||||
{
|
||||
public:
|
||||
ColorModelInverseGrayTop (void) : ColorModel(2)
|
||||
ColorModelInverseGrayTop () : ColorModel(2)
|
||||
{
|
||||
_pclColors[0] = Color( 0.5f, 0.5f, 0.5f);
|
||||
_pclColors[1] = Color( 0.0f, 0.0f, 0.0f);
|
||||
colors[0] = Color( 0.5f, 0.5f, 0.5f);
|
||||
colors[1] = Color( 0.0f, 0.0f, 0.0f);
|
||||
}
|
||||
};
|
||||
|
||||
class AppExport ColorField
|
||||
{
|
||||
public:
|
||||
ColorField (void);
|
||||
ColorField ();
|
||||
ColorField (const ColorField &rclCF);
|
||||
ColorField (const ColorModel &rclModel, float fMin, float fMax, unsigned short usCt);
|
||||
virtual ~ColorField ();
|
||||
ColorField (const ColorModel &rclModel, float fMin, float fMax, std::size_t usCt);
|
||||
virtual ~ColorField () = default;
|
||||
|
||||
ColorField& operator = (const ColorField &rclCF);
|
||||
|
||||
unsigned short getCountColors (void) const { return _usCtColors; }
|
||||
void set (const ColorModel &rclModel, float fMin, float fMax, unsigned short usCt);
|
||||
void setCountColors (unsigned short usCt) { set(_clModel, _fMin, _fMax, usCt); }
|
||||
void setRange (float fMin, float fMax) { set(_clModel, fMin, fMax, _usCtColors); }
|
||||
void getRange (float &rfMin, float &rfMax) { rfMin = _fMin; rfMax = _fMax; }
|
||||
unsigned short getMinColors (void) const { return _clModel._usColors; }
|
||||
std::size_t getCountColors () const { return ctColors; }
|
||||
void set (const ColorModel &rclModel, float fMin, float fMax, std::size_t usCt);
|
||||
void setCountColors (std::size_t usCt) { set(colorModel, fMin, fMax, usCt); }
|
||||
void setRange (float fMin, float fMax) { set(colorModel, fMin, fMax, ctColors); }
|
||||
void getRange (float &rfMin, float &rfMax) { rfMin = fMin; rfMax = fMax; }
|
||||
std::size_t getMinColors () const { return colorModel.getCountColors(); }
|
||||
void setColorModel (const ColorModel &rclModel);
|
||||
const ColorModel& getColorModel (void) const { return _clModel; }
|
||||
void setDirect (unsigned short usInd, Color clCol) { _aclField[usInd] = clCol; }
|
||||
float getMinValue (void) const { return _fMin; }
|
||||
float getMaxValue (void) const { return _fMax; }
|
||||
const ColorModel& getColorModel () const { return colorModel; }
|
||||
void setDirect (std::size_t usInd, Color clCol) { colorField[usInd] = clCol; }
|
||||
float getMinValue () const { return fMin; }
|
||||
float getMaxValue () const { return fMax; }
|
||||
|
||||
Color getColor (unsigned short usIndex) const { return _aclField[usIndex]; }
|
||||
Color getColor (std::size_t usIndex) const { return colorField[usIndex]; }
|
||||
inline Color getColor (float fVal) const;
|
||||
inline unsigned short getColorIndex (float fVal) const;
|
||||
inline std::size_t getColorIndex (float fVal) const;
|
||||
|
||||
protected:
|
||||
ColorModel _clModel;
|
||||
float _fMin, _fMax;
|
||||
float _fAscent, _fConstant; // Index := _fConstant + _fAscent * WERT
|
||||
unsigned short _usCtColors;
|
||||
std::vector<Color> _aclField;
|
||||
ColorModel colorModel;
|
||||
float fMin, fMax;
|
||||
float fAscent, fConstant; // Index := _fConstant + _fAscent * WERT
|
||||
std::size_t ctColors;
|
||||
std::vector<Color> colorField;
|
||||
|
||||
void rebuild (void);
|
||||
void interpolate (Color clCol1, unsigned short usPos1, Color clCol2, unsigned short usPos2);
|
||||
void rebuild ();
|
||||
void interpolate (Color clCol1, std::size_t usPos1, Color clCol2, std::size_t usPos2);
|
||||
};
|
||||
|
||||
inline Color ColorField::getColor (float fVal) const
|
||||
{
|
||||
#if 1
|
||||
// if the value is outside or at the border of the range
|
||||
unsigned short ct = _clModel._usColors-1;
|
||||
if ( fVal <= _fMin )
|
||||
return _clModel._pclColors[0];
|
||||
else if ( fVal >= _fMax )
|
||||
return _clModel._pclColors[ct];
|
||||
std::size_t ct = colorModel.getCountColors() - 1;
|
||||
if ( fVal <= fMin )
|
||||
return colorModel.colors[0];
|
||||
else if ( fVal >= fMax )
|
||||
return colorModel.colors[ct];
|
||||
|
||||
// get the color field position (with 0 < t < 1)
|
||||
float t = (fVal-_fMin) / (_fMax-_fMin);
|
||||
float t = (fVal - fMin) / (fMax - fMin);
|
||||
Color col(1.0f, 1.0f, 1.0f); // white as default
|
||||
for ( unsigned short i=0; i<ct; i++ )
|
||||
for ( std::size_t i=0; i<ct; i++ )
|
||||
{
|
||||
float r = (float)(i+1)/(float)ct;
|
||||
if ( t < r )
|
||||
{
|
||||
// calculate the exact position in the subrange
|
||||
float s = t*(float)ct-(float)i;
|
||||
Color c1 = _clModel._pclColors[i];
|
||||
Color c2 = _clModel._pclColors[i+1];
|
||||
Color c1 = colorModel.colors[i];
|
||||
Color c2 = colorModel.colors[i+1];
|
||||
col.r = (1.0f-s) * c1.r + s * c2.r;
|
||||
col.g = (1.0f-s) * c1.g + s * c2.g;
|
||||
col.b = (1.0f-s) * c1.b + s * c2.b;
|
||||
@@ -258,14 +261,11 @@ inline Color ColorField::getColor (float fVal) const
|
||||
}
|
||||
|
||||
return col;
|
||||
#else
|
||||
return _aclField[getColorIndex(fVal)];
|
||||
#endif
|
||||
}
|
||||
|
||||
inline unsigned short ColorField::getColorIndex (float fVal) const
|
||||
inline std::size_t ColorField::getColorIndex (float fVal) const
|
||||
{
|
||||
return (unsigned short)(std::min<int>(std::max<int>(int(_fConstant + _fAscent * fVal), 0), int(_usCtColors-1)));
|
||||
return (std::size_t)(std::min<int>(std::max<int>(int(fConstant + fAscent * fVal), 0), int(ctColors - 1)));
|
||||
}
|
||||
|
||||
|
||||
@@ -275,49 +275,48 @@ public:
|
||||
enum TStyle { FLOW, ZERO_BASED };
|
||||
enum TColorModel { TRIA, INVERSE_TRIA, GRAY, INVERSE_GRAY };
|
||||
|
||||
ColorGradient (void);
|
||||
ColorGradient (float fMin, float fMax, unsigned short usCtColors, TStyle tS, bool bOG = false);
|
||||
ColorGradient (const ColorGradient &rclCR);
|
||||
ColorGradient ();
|
||||
ColorGradient (float fMin, float fMax, std::size_t usCtColors, TStyle tS, bool bOG = false);
|
||||
ColorGradient (const ColorGradient &) = default;
|
||||
ColorGradient& operator = (const ColorGradient &) = default;
|
||||
|
||||
ColorGradient& operator = (const ColorGradient &rclCR);
|
||||
|
||||
void set (float fMin, float fMax, unsigned short usCt, TStyle tS, bool bOG);
|
||||
void setRange (float fMin, float fMax) { set(fMin, fMax, _usCtColors, _tStyle, _bOutsideGrayed); }
|
||||
void set (float fMin, float fMax, std::size_t usCt, TStyle tS, bool bOG);
|
||||
void setRange (float fMin, float fMax) { set(fMin, fMax, ctColors, tStyle, outsideGrayed); }
|
||||
void getRange (float &rfMin, float &rfMax) const { rfMin = _fMin; rfMax = _fMax; }
|
||||
unsigned short getCountColors (void) const { return _usCtColors; }
|
||||
void setCountColors (unsigned short usCt) { set(_fMin, _fMax, usCt, _tStyle, _bOutsideGrayed); }
|
||||
void setStyle (TStyle tS) { set(_fMin, _fMax, _usCtColors, tS, _bOutsideGrayed); }
|
||||
unsigned short getMinColors (void) const;
|
||||
TStyle getStyle (void) const { return _tStyle; }
|
||||
void setOutsideGrayed (bool bGrayed) { _bOutsideGrayed = bGrayed; }
|
||||
bool isOutsideGrayed (void) const { return _bOutsideGrayed; }
|
||||
std::size_t getCountColors () const { return ctColors; }
|
||||
void setCountColors (std::size_t usCt) { set(_fMin, _fMax, usCt, tStyle, outsideGrayed); }
|
||||
void setStyle (TStyle tS) { set(_fMin, _fMax, ctColors, tS, outsideGrayed); }
|
||||
std::size_t getMinColors () const;
|
||||
TStyle getStyle () const { return tStyle; }
|
||||
void setOutsideGrayed (bool bGrayed) { outsideGrayed = bGrayed; }
|
||||
bool isOutsideGrayed () const { return outsideGrayed; }
|
||||
void setColorModel (TColorModel tModel);
|
||||
TColorModel getColorModelType (void) const { return _tColorModel; }
|
||||
inline const ColorModel& getColorModel (void) const;
|
||||
float getMinValue (void) const { return _fMin; }
|
||||
float getMaxValue (void) const { return _fMax; }
|
||||
TColorModel getColorModelType () const { return tColorModel; }
|
||||
inline const ColorModel& getColorModel () const;
|
||||
float getMinValue () const { return _fMin; }
|
||||
float getMaxValue () const { return _fMax; }
|
||||
|
||||
inline Color getColor (float fVal) const;
|
||||
inline unsigned short getColorIndex (float fVal) const;
|
||||
inline std::size_t getColorIndex (float fVal) const;
|
||||
|
||||
protected:
|
||||
ColorField _clColFld1, _clColFld2;
|
||||
TColorModel _tColorModel;
|
||||
TStyle _tStyle;
|
||||
ColorField colorField1, colorField2;
|
||||
TColorModel tColorModel;
|
||||
TStyle tStyle;
|
||||
float _fMin, _fMax;
|
||||
unsigned short _usCtColors;
|
||||
bool _bOutsideGrayed;
|
||||
ColorModel _clTotal, _clTop, _clBottom;
|
||||
std::size_t ctColors;
|
||||
bool outsideGrayed;
|
||||
ColorModel totalModel, topModel, bottomModel;
|
||||
|
||||
void rebuild (void);
|
||||
void setColorModel (void);
|
||||
void rebuild ();
|
||||
void setColorModel ();
|
||||
};
|
||||
|
||||
|
||||
class AppExport ColorLegend
|
||||
{
|
||||
public:
|
||||
ColorLegend (void);
|
||||
ColorLegend ();
|
||||
ColorLegend (const ColorLegend &rclCL);
|
||||
virtual ~ColorLegend () {}
|
||||
|
||||
@@ -329,8 +328,8 @@ public:
|
||||
bool addMin (const std::string &rclName);
|
||||
bool addMax (const std::string &rclName);
|
||||
bool remove (unsigned long ulPos);
|
||||
void removeFirst (void);
|
||||
void removeLast (void);
|
||||
void removeFirst ();
|
||||
void removeLast ();
|
||||
|
||||
Color getColor (unsigned long ulPos) const;
|
||||
uint32_t getPackedColor (unsigned long ulPos) const;
|
||||
@@ -340,143 +339,143 @@ public:
|
||||
bool setValue (unsigned long ulPos, float fVal);
|
||||
std::string getText (unsigned long ulPos) const;
|
||||
bool setText (unsigned long ulPos, const std::string &rclName);
|
||||
unsigned long hasNumberOfFields (void) const { return (unsigned long)_aclColorFields.size(); }
|
||||
void setOutsideGrayed (bool bOS) { _bOutsideGrayed = bOS; }
|
||||
bool isOutsideGrayed (void) const { return _bOutsideGrayed; }
|
||||
inline float getMinValue (void) const;
|
||||
inline float getMaxValue (void) const;
|
||||
unsigned long hasNumberOfFields () const { return (unsigned long)colorFields.size(); }
|
||||
void setOutsideGrayed (bool bOS) { outsideGrayed = bOS; }
|
||||
bool isOutsideGrayed () const { return outsideGrayed; }
|
||||
inline float getMinValue () const;
|
||||
inline float getMaxValue () const;
|
||||
|
||||
inline Color getColor (float fVal) const;
|
||||
inline unsigned short getColorIndex (float fVal) const;
|
||||
inline std::size_t getColorIndex (float fVal) const;
|
||||
|
||||
protected:
|
||||
std::deque<Color> _aclColorFields;
|
||||
std::deque<std::string> _aclNames;
|
||||
std::deque<float> _aclValues;
|
||||
bool _bOutsideGrayed;
|
||||
std::deque<Color> colorFields;
|
||||
std::deque<std::string> names;
|
||||
std::deque<float> values;
|
||||
bool outsideGrayed;
|
||||
};
|
||||
|
||||
inline Color ColorLegend::getColor (float fVal) const
|
||||
{
|
||||
std::deque<float>::const_iterator pI;
|
||||
for (pI = _aclValues.begin(); pI != _aclValues.end(); ++pI)
|
||||
for (pI = values.begin(); pI != values.end(); ++pI)
|
||||
{
|
||||
if (fVal < *pI)
|
||||
break;
|
||||
}
|
||||
|
||||
if (_bOutsideGrayed == true)
|
||||
if (outsideGrayed == true)
|
||||
{
|
||||
if ((pI == _aclValues.begin()) || (pI == _aclValues.end()))
|
||||
if ((pI == values.begin()) || (pI == values.end()))
|
||||
return Color(0.5f, 0.5f, 0.5f);
|
||||
else
|
||||
return _aclColorFields[pI - _aclValues.begin() - 1];
|
||||
return colorFields[pI - values.begin() - 1];
|
||||
}
|
||||
|
||||
if (pI == _aclValues.begin())
|
||||
return *_aclColorFields.begin();
|
||||
else if (pI == _aclValues.end())
|
||||
return *(_aclColorFields.end()-1);
|
||||
if (pI == values.begin())
|
||||
return *colorFields.begin();
|
||||
else if (pI == values.end())
|
||||
return *(colorFields.end()-1);
|
||||
else
|
||||
return _aclColorFields[pI - _aclValues.begin() - 1];
|
||||
return colorFields[pI - values.begin() - 1];
|
||||
}
|
||||
|
||||
inline unsigned short ColorLegend::getColorIndex (float fVal) const
|
||||
inline std::size_t ColorLegend::getColorIndex (float fVal) const
|
||||
{
|
||||
std::deque<float>::const_iterator pI;
|
||||
for (pI = _aclValues.begin(); pI != _aclValues.end(); ++pI)
|
||||
for (pI = values.begin(); pI != values.end(); ++pI)
|
||||
{
|
||||
if (fVal < *pI)
|
||||
break;
|
||||
}
|
||||
|
||||
if (pI == _aclValues.begin())
|
||||
if (pI == values.begin())
|
||||
return 0;
|
||||
else if (pI == _aclValues.end())
|
||||
return (unsigned short)(_aclColorFields.size() - 1);
|
||||
else if (pI == values.end())
|
||||
return (std::size_t)(colorFields.size() - 1);
|
||||
else
|
||||
return pI - _aclValues.begin() - 1;
|
||||
return pI - values.begin() - 1;
|
||||
}
|
||||
|
||||
inline float ColorLegend::getMinValue (void) const
|
||||
inline float ColorLegend::getMinValue () const
|
||||
{
|
||||
return *_aclValues.begin();
|
||||
return *values.begin();
|
||||
}
|
||||
|
||||
inline float ColorLegend::getMaxValue (void) const
|
||||
inline float ColorLegend::getMaxValue () const
|
||||
{
|
||||
return *(_aclValues.end()-1);
|
||||
return *(values.end()-1);
|
||||
}
|
||||
|
||||
inline Color ColorGradient::getColor (float fVal) const
|
||||
{
|
||||
if (_bOutsideGrayed == true)
|
||||
if (outsideGrayed == true)
|
||||
{
|
||||
if ((fVal < _fMin) || (fVal > _fMax))
|
||||
return Color(0.5f, 0.5f, 0.5f);
|
||||
}
|
||||
switch (_tStyle)
|
||||
switch (tStyle)
|
||||
{
|
||||
case ZERO_BASED:
|
||||
{
|
||||
if ((_fMin < 0.0f) && (_fMax > 0.0f))
|
||||
{
|
||||
if (fVal < 0.0f)
|
||||
return _clColFld1.getColor(fVal);
|
||||
return colorField1.getColor(fVal);
|
||||
else
|
||||
return _clColFld2.getColor(fVal);
|
||||
return colorField2.getColor(fVal);
|
||||
}
|
||||
else
|
||||
return _clColFld1.getColor(fVal);
|
||||
return colorField1.getColor(fVal);
|
||||
}
|
||||
|
||||
default:
|
||||
case FLOW:
|
||||
{
|
||||
return _clColFld1.getColor(fVal);
|
||||
return colorField1.getColor(fVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline unsigned short ColorGradient::getColorIndex (float fVal) const
|
||||
inline std::size_t ColorGradient::getColorIndex (float fVal) const
|
||||
{
|
||||
switch (_tStyle)
|
||||
switch (tStyle)
|
||||
{
|
||||
case ZERO_BASED:
|
||||
{
|
||||
if ((_fMin < 0.0f) && (_fMax > 0.0f))
|
||||
{
|
||||
if (fVal < 0.0f)
|
||||
return _clColFld1.getColorIndex(fVal);
|
||||
return colorField1.getColorIndex(fVal);
|
||||
else
|
||||
return (unsigned short)(_clColFld1.getCountColors() + _clColFld2.getColorIndex(fVal));
|
||||
return (std::size_t)(colorField1.getCountColors() + colorField2.getColorIndex(fVal));
|
||||
}
|
||||
else
|
||||
return _clColFld1.getColorIndex(fVal);
|
||||
return colorField1.getColorIndex(fVal);
|
||||
}
|
||||
|
||||
default:
|
||||
case FLOW:
|
||||
{
|
||||
return _clColFld1.getColorIndex(fVal);
|
||||
return colorField1.getColorIndex(fVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline const ColorModel& ColorGradient::getColorModel (void) const
|
||||
inline const ColorModel& ColorGradient::getColorModel () const
|
||||
{
|
||||
if ( _tStyle == ZERO_BASED )
|
||||
if ( tStyle == ZERO_BASED )
|
||||
{
|
||||
if ( _fMax <= 0.0f )
|
||||
return _clBottom;
|
||||
return bottomModel;
|
||||
else if ( _fMin >= 0.0f )
|
||||
return _clTop;
|
||||
return topModel;
|
||||
else
|
||||
return _clTotal;
|
||||
return totalModel;
|
||||
}
|
||||
else
|
||||
{
|
||||
return _clTotal;
|
||||
return totalModel;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -250,7 +250,7 @@ void SoFCColorGradient::setColorStyle (App::ColorGradient::TStyle tStyle)
|
||||
void SoFCColorGradient::rebuildGradient()
|
||||
{
|
||||
App::ColorModel model = _cColGrad.getColorModel();
|
||||
int uCtColors = (int)model._usColors;
|
||||
int uCtColors = (int)model.getCountColors();
|
||||
|
||||
coords->point.setNum(2*uCtColors);
|
||||
for ( int i=0; i<uCtColors; i++ )
|
||||
@@ -285,7 +285,7 @@ void SoFCColorGradient::rebuildGradient()
|
||||
mat->diffuseColor.setNum(2*uCtColors);
|
||||
for ( int k=0; k<uCtColors; k++ )
|
||||
{
|
||||
App::Color col = model._pclColors[uCtColors-k-1];
|
||||
App::Color col = model.colors[uCtColors-k-1];
|
||||
mat->diffuseColor.set1Value(2*k, col.r, col.g, col.b);
|
||||
mat->diffuseColor.set1Value(2*k+1, col.r, col.g, col.b);
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ void SoFCColorLegend::setColorModel( App::ColorGradient::TColorModel tModel )
|
||||
{
|
||||
_cColRamp.setColorModel( tModel );
|
||||
App::ColorModel model = _cColRamp.getColorModel();
|
||||
int uCtColors = (int)model._usColors;
|
||||
int uCtColors = (int)model.getCountColors();
|
||||
|
||||
// don't know why the parameter range isn't between [-1,+1]
|
||||
float fMinX= 4.0f, fMaxX=4.5f;
|
||||
@@ -225,7 +225,7 @@ void SoFCColorLegend::setColorModel( App::ColorGradient::TColorModel tModel )
|
||||
mat->diffuseColor.setNum(2*uCtColors);
|
||||
for ( int k=0; k<uCtColors; k++ )
|
||||
{
|
||||
App::Color col = model._pclColors[uCtColors-k-1];
|
||||
App::Color col = model.colors[uCtColors-k-1];
|
||||
mat->diffuseColor.set1Value(2*k, col.r, col.g, col.b);
|
||||
mat->diffuseColor.set1Value(2*k+1, col.r, col.g, col.b);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user