Commit 89dee68c authored by Hans-Christian Ebke's avatar Hans-Christian Ebke
Browse files

Unified color generator interfaces.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@18332 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 1dd192d8
......@@ -49,31 +49,18 @@
namespace ACG {
/**
* The ColorGenerator tries to generate a set of well distinguishable
* and esthetically somewhat pleasing colors.
*
* Note that it intentionally behaves totally deterministic. (Because
* reproducibility rocks.)
* The ColorGenerator interface provides a generic interface
* for color generators with different strategies.
*/
class ACGDLLEXPORT ColorGenerator {
public:
/**
* Constructor
*
* @param _alpha The alpha value for all the colors.
*
* @param _baseHue The HSV-hue from which to start. This is the
* hue of the first requested color. Default is an utterly
* delighting shade of blue awesomeness.
*/
ColorGenerator(
float _alpha = 1.0f,
float _baseHue = 0.5694f);
virtual ~ColorGenerator() {};
/**
* @return A new color.
*/
Vec4f generateNextColor();
virtual Vec4f generateNextColor() = 0;
/**
* Put a bunch of colors into the output iterator.
......@@ -90,29 +77,8 @@ class ACGDLLEXPORT ColorGenerator {
template <class OUTPUT_ITERATOR>
void generateNextNColors(int n, OUTPUT_ITERATOR oit) {
for (int i = 0; i < n; ++i)
*oit++ = generateNextColor();
*oit++ = this->generateNextColor();
}
/**
* Convenience method if you just need a bunch of
* colors and don't need to instantiate a ColorGenerator.
*
* See description of generateNextNColors() for details.
*/
template <class OUTPUT_ITERATOR>
static void generateNColors(int n, OUTPUT_ITERATOR oit) {
ColorGenerator cg;
cg.generateNextNColors(n, oit);
}
private:
int currentSubdiv_;
int currentIt_;
int currentTriadIt_;
float alpha_;
float baseHue_;
const float defaultSaturation_, defaultValue_;
};
} /* namespace ACG */
......
......@@ -163,12 +163,16 @@ ACG::Vec4f HaltonColors::HSL2RGB(double h, double sl, double l)
return Vec4f((float)r, (float)g, (float)b, 1.0f);
}
ACG::Vec4f HaltonColors::generateNextColor() {
float h = random_interval(0, 0.0f , 0.9f ); // 0.9 instead of 1.0 to suppress natural bias towards red
float s = random_interval(1, 0.40f, 0.80f); // saturation between 40% and 80%
float l = random_interval(2, 0.30f, 0.60f); // lightness between 30% and 60%
return HSL2RGB(h, s, l);
}
ACG::Vec4f HaltonColors::get_next_color()
{
float h = random_interval(0, 0.0f , 0.9f ); // 0.9 instead of 1.0 to suppress natural bias towards red
float s = random_interval(1, 0.40f, 0.80f); // saturation between 40% and 80%
float l = random_interval(2, 0.30f, 0.60f); // lightness between 30% and 60%
return HSL2RGB(h, s, l);
return generateNextColor();
}
......
......@@ -56,6 +56,7 @@
#include <ACG/Math/VectorT.hh>
#include "../Config/ACGDefines.hh"
#include "ColorGenerator.hh"
//== NAMESPACES ===============================================================
......@@ -69,16 +70,19 @@ namespace ACG {
independent of the number of colors required.
Simply instantiate and use get_next_color().
*/
class ACGDLLEXPORT HaltonColors {
class ACGDLLEXPORT HaltonColors : public ColorGenerator {
public:
/// Default constructor
HaltonColors(int skip = 250);
/// Generate the next color
/// Generate the next color (legacy method)
ACG::Vec4f get_next_color();
/// Generate the next color
virtual ACG::Vec4f generateNextColor();
private:
float halton(int index);
......
......@@ -40,7 +40,7 @@
* *
\*===========================================================================*/
#include "ColorGenerator.hh"
#include "HuePartitioningColors.hh"
#include <cmath>
#include <QColor>
......@@ -50,9 +50,10 @@ namespace ACG {
#define DEFAULT_SATURATION 1.0f
#define DEFAULT_VALUE 1.0f
ColorGenerator::ColorGenerator(float _alpha, float _baseHue) :
HuePartitioningColors::HuePartitioningColors(float _alpha, float _baseHue) :
currentSubdiv_(2), currentIt_(0), currentTriadIt_(0),
alpha_(_alpha), baseHue_(_baseHue),defaultSaturation_(DEFAULT_SATURATION),defaultValue_(DEFAULT_VALUE) {
alpha_(_alpha), baseHue_(_baseHue),
defaultSaturation_(DEFAULT_SATURATION), defaultValue_(DEFAULT_VALUE) {
}
static inline float wrap01(float v) {
......@@ -62,7 +63,7 @@ static inline float wrap01(float v) {
return v;
}
Vec4f ColorGenerator::generateNextColor() {
Vec4f HuePartitioningColors::generateNextColor() {
const float resultHue =
baseHue_
+ .33333333f / currentSubdiv_ * currentIt_
......@@ -70,7 +71,8 @@ Vec4f ColorGenerator::generateNextColor() {
// Convert color to RGB and store result.
double r, g, b, a;
QColor::fromHsvF(wrap01(resultHue), defaultSaturation_, defaultValue_, alpha_).getRgbF(
QColor::fromHsvF(wrap01(resultHue), defaultSaturation_,
defaultValue_, alpha_).getRgbF(
&r, &g, &b, &a);
const Vec4f result(r, g, b, alpha_);
......
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2014 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $Author$ *
* $Date$ *
* *
\*===========================================================================*/
#ifndef HUEPARTITIONINGCOLORS_HH_
#define HUEPARTITIONINGCOLORS_HH_
#include <ACG/Math/VectorT.hh>
#include "../Config/ACGDefines.hh"
#include "ColorGenerator.hh"
namespace ACG {
/**
* The HuePartitioningColors generator tries to generate a set of well
* distinguishable and esthetically somewhat pleasing colors.
*
* Note that it intentionally behaves totally deterministic. (Because
* reproducibility rocks.)
*/
class ACGDLLEXPORT HuePartitioningColors : public ColorGenerator {
public:
/**
* Constructor
*
* @param _alpha The alpha value for all the colors.
*
* @param _baseHue The HSV-hue from which to start. This is the
* hue of the first requested color. Default is an utterly
* delighting shade of blue awesomeness.
*/
HuePartitioningColors(
float _alpha = 1.0f,
float _baseHue = 0.5694f);
/**
* @return A new color.
*/
virtual Vec4f generateNextColor();
/**
* Convenience method if you just need a bunch of
* colors and don't need to instantiate a ColorGenerator.
*
* See description of generateNextNColors() for details.
*/
template <class OUTPUT_ITERATOR>
static void generateNColors(int n, OUTPUT_ITERATOR oit) {
HuePartitioningColors cg;
cg.generateNextNColors(n, oit);
}
private:
int currentSubdiv_;
int currentIt_;
int currentTriadIt_;
float alpha_;
float baseHue_;
const float defaultSaturation_, defaultValue_;
};
} /* namespace ACG */
#endif /* HUEPARTITIONINGCOLORS_HH_ */
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