mirror of https://github.com/CGAL/cgal
Make a function for generating colors and use it in color_map_generation
This commit is contained in:
parent
fedc3eabef
commit
007f999feb
|
|
@ -3,6 +3,16 @@
|
|||
|
||||
#include <QColor>
|
||||
|
||||
inline QColor generate_color(double h, double s_min = 0.35)
|
||||
{
|
||||
std::size_t s_max=255;
|
||||
if(h >0.8 && h < 0,95) //span of ugly pink, desaturates make it less garish IMO
|
||||
s_max = 160;
|
||||
std::size_t s = std::rand() % (s_max-static_cast<std::size_t>(s_min*255)) +s_min*255;
|
||||
return QColor::fromHsvF(h,s/255.0,1.0);
|
||||
}
|
||||
|
||||
|
||||
template <typename Output_color_iterator>
|
||||
Output_color_iterator
|
||||
compute_color_map(QColor base_color,
|
||||
|
|
@ -12,24 +22,19 @@ compute_color_map(QColor base_color,
|
|||
qreal hue = base_color.hueF();
|
||||
const qreal step = ((qreal)1) / nb_of_colors;
|
||||
|
||||
int s = base_color.saturation(),
|
||||
v = base_color.value();
|
||||
s = s<90 ? s+90 : s;
|
||||
v = v<90 ? v+90 : v;
|
||||
float sf=s/256.0f,
|
||||
vf=v/256.0f;
|
||||
|
||||
qreal h = hue==-1 ? 0
|
||||
:hue;
|
||||
for(unsigned i = 0; i < nb_of_colors; ++i) {
|
||||
if (h!=-1) h += step;
|
||||
if ( h > 1 ) { h -= 1; }
|
||||
//avoid S and V near 0 to avoid having all the same colors
|
||||
*out++ = QColor::fromHsvF(h,
|
||||
sf,
|
||||
vf);
|
||||
*out++ = generate_color(h);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
inline QColor generate_random_color() {
|
||||
std::size_t h = static_cast<std::size_t>(std::rand() % 360);
|
||||
return generate_color(h/359.0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -60,8 +60,7 @@ std::size_t VSA_wrapper::add_one_proxy() {
|
|||
break;
|
||||
}
|
||||
if (nb_added == 1) {
|
||||
const std::size_t h = (rand_0_310()+ 340)%359, s = rand_70_255();
|
||||
m_proxy_colors.push_back(QColor::fromHsvF(h/359.0,s/255.0,1.0));
|
||||
m_proxy_colors.push_back(generate_random_color());
|
||||
}
|
||||
|
||||
return nb_added;
|
||||
|
|
@ -94,8 +93,7 @@ bool VSA_wrapper::split(const std::size_t px_idx, const std::size_t n, const std
|
|||
}
|
||||
if (splitted) {
|
||||
for (std::size_t i = m_proxy_colors.size(); i < number_of_proxies(); ++i) {
|
||||
const std::size_t h = (rand_0_310()+ 340)%359,s=rand_70_255();
|
||||
m_proxy_colors.push_back(QColor::fromHsvF(h/359.0,s/255.0,1.0));
|
||||
m_proxy_colors.push_back(generate_random_color());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -96,15 +96,6 @@ class VSA_WRAPPER_EXPORT VSA_wrapper {
|
|||
typedef CGAL::Variational_shape_approximation<SMesh, Vertex_point_map,
|
||||
Compact_metric, EPICK> Compact_approx;
|
||||
#endif
|
||||
|
||||
std::size_t rand_0_310() {
|
||||
return static_cast<std::size_t>(std::rand() % 310);
|
||||
}
|
||||
|
||||
std::size_t rand_70_255() {
|
||||
return static_cast<std::size_t>(std::rand() % 185 + 70);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
|
@ -165,8 +156,7 @@ public:
|
|||
m_proxy_colors.reserve(number_of_proxies());
|
||||
|
||||
for (std::size_t i = 0; i < number_of_proxies(); ++i) {
|
||||
const std::size_t h = (rand_0_310()+ 340)%360,s=rand_70_255();
|
||||
m_proxy_colors.push_back(QColor::fromHsvF(h/359.0,s/255.0,1.0));
|
||||
m_proxy_colors.push_back(generate_random_color());
|
||||
}
|
||||
|
||||
m_initialized = true;
|
||||
|
|
|
|||
Loading…
Reference in New Issue