Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab - Fix color from meshes with only one domain #8187

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Lab/demo/Lab/Color_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,30 @@ compute_color_map(QColor base_color,
return out;
}

template <typename Output_color_iterator>
Output_color_iterator
compute_deterministic_color_map(QColor base_color,
std::size_t nb_of_colors,
Output_color_iterator out)
{
qreal hue = base_color.hueF();
qreal saturation = base_color.saturationF();
qreal value = base_color.valueF();
const qreal hue_step = (hue == -1) ? 0 : (static_cast<qreal>(1)) / nb_of_colors;

if (hue == -1)
hue = 0;
for(std::size_t i=0; i<nb_of_colors; ++i)
{
hue += hue_step;
if(hue > 1)
hue -= 1;
*out++ = QColor::fromHsvF(hue, saturation, value);
}

return out;
}

inline QColor generate_random_color()
{
std::size_t h = static_cast<std::size_t>(std::rand() % 360);
Expand Down
18 changes: 10 additions & 8 deletions Lab/demo/Lab/Scene_image_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <CGAL/use.h>
#include <QApplication>

#include "Color_map.h"

// -----------------------------------
// Internal classes
// -----------------------------------
Expand Down Expand Up @@ -88,15 +90,15 @@ Image_accessor<Word_type>::Image_accessor(const Image& im, int dx, int dy, int d
}
}

const double nb_Colors = colors_.size()+1;
double i=0;
const double starting_hue = default_color.hueF();
for ( auto it = colors_.begin(),
end = colors_.end() ; it != end ; ++it, i += 1.)
// Compute subdomains colors (the background has no color)

std::vector<QColor> subdomain_colors;
compute_deterministic_color_map(default_color, colors_.size(), std::back_inserter(subdomain_colors));

int i = 0;
for (auto& it : colors_)
{
double hue = starting_hue + 1./nb_Colors * i;
if ( hue > 1. ) { hue -= 1.; }
it->second = QColor::fromHsvF(hue, default_color.saturationF(), default_color.valueF());
it.second = subdomain_colors[i++];
}
}

Expand Down
42 changes: 26 additions & 16 deletions Lab/demo/Lab/Scene_triangulation_3_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <CGAL/IO/Color.h>

#include "Scene_polygon_soup_item.h"
#include "Color_map.h"


typedef CGAL::AABB_triangulation_3_cell_primitive<EPICK,
Expand Down Expand Up @@ -941,31 +942,40 @@ Scene_triangulation_3_item::update_histogram()
}

void
Scene_triangulation_3_item_priv::compute_color_map(const QColor& c)
Scene_triangulation_3_item_priv::compute_color_map(const QColor& base_color)
{
typedef Indices::size_type size_type;

const size_type nb_patch_indices = surface_patch_indices_.size();
double i = -1;
double patch_hsv_value = use_subdomain_colors ? fmod(c.valueF() + .5, 1.) : c.valueF();
for (Indices::iterator it = surface_patch_indices_.begin(),
end = surface_patch_indices_.end(); it != end; ++it, i += 1.)
// Set colors of surface patches
std::vector<QColor> surface_colors;
// the first color is the background and is unused
surface_colors.push_back(base_color);
float patch_hsv_value = use_subdomain_colors ? fmod(base_color.valueF() + .5, 1.) : base_color.valueF();
if (surface_patch_indices_.size() > 1)
compute_deterministic_color_map(
QColor::fromHsvF(base_color.hueF(), base_color.saturationF(), patch_hsv_value),
surface_patch_indices_.size()-1, std::back_inserter(surface_colors));

int i = 0;
for (Indices::iterator it = surface_patch_indices_.begin(); it != surface_patch_indices_.end(); ++it)
{
double hue = c.hueF() + 1. / double(nb_patch_indices) * i;
if (hue > 1) { hue -= 1.; }
colors[*it] = QColor::fromHsvF(hue, c.saturationF(), patch_hsv_value);
colors[*it] = surface_colors[i++];
}

const size_type nb_domains = subdomain_indices_.size();
i = -1;
for (Indices::iterator it = subdomain_indices_.begin(),
end = subdomain_indices_.end(); it != end; ++it, i += 1.)
// Set colors of subdomains
std::vector<QColor> subdomain_colors;
// the first color is either the background or the unique domain
subdomain_colors.push_back(base_color);
if (subdomain_indices_.size() > 1)
compute_deterministic_color_map(base_color, subdomain_indices_.size()-1, std::back_inserter(subdomain_colors));

i = 0;
for (Indices::iterator it = subdomain_indices_.begin(); it != subdomain_indices_.end(); ++it)
{
double hue = c.hueF() + 1. / double(nb_domains) * i;
if (hue > 1) { hue -= 1.; }
colors_subdomains[*it] = QColor::fromHsvF(hue, c.saturationF(), c.valueF());
colors_subdomains[*it] = subdomain_colors[i++];
}

// Update surface patches colors to the domain
if (use_subdomain_colors)
{
for (std::unordered_map<int, int>::iterator it = visible_surface_patch_to_subdomain.begin(),
Expand Down