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

Polyhedron demo - Use subdomain's color only when meshing from labeled images #7800

Merged
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
2 changes: 2 additions & 0 deletions Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Mesh_3_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,8 @@ treat_result(Scene_item& source_item,
float((bbox.ymin() + bbox.ymax())/2.f),
float((bbox.zmin() + bbox.zmax())/2.f));

bool input_is_labeled_img = dynamic_cast<Scene_image_item*>(&source_item) != nullptr;
result_item->setUseSubdomainColors(input_is_labeled_img);
result_item->setColor(source_item.color());
result_item->setRenderingMode(source_item.renderingMode());
result_item->set_data_item(&source_item);
Expand Down
2 changes: 1 addition & 1 deletion Polyhedron/demo/Polyhedron/Scene_image_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Image_accessor<Word_type>::Image_accessor(const Image& im, int dx, int dy, int d
}

const double nb_Colors = colors_.size()+1;
double i=1;
double i=0;
const double starting_hue = default_color.hueF();
for ( auto it = colors_.begin(),
end = colors_.end() ; it != end ; ++it, i += 1.)
Expand Down
39 changes: 25 additions & 14 deletions Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ struct Scene_triangulation_3_item_priv {
QVector<QColor> colors;
QVector<QColor> colors_subdomains;
boost::dynamic_bitset<> visible_subdomain;
bool use_subdomain_colors = false;
std::bitset<24> bs[4] = {16777215, 16777215, 16777215, 16777215};
bool show_tetrahedra;
bool is_aabb_tree_built;
Expand Down Expand Up @@ -884,30 +885,34 @@ Scene_triangulation_3_item_priv::compute_color_map(const QColor& c)
{
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.)
{
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);
}
Comment on lines +889 to +897
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ange-clement I have an issue with the demo, and it is caused by this old PR (merged Nov 6 2023).

I think the issue is with this loop (and the next one, that is similar).

Let's suppose nb_patch_indices==1. At the first iteration of the loop, i is equal to -1, and the expression

                 c.hueF() + 1. / double(nb_patch_indices) * i

is equal to

                 c.hueF() - 1.

and then is almost certainly an invalid hue (the only valid negative hue is -1.f, for achromatic colors).

Why start i at -1 instead of 0 like it was before?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is more, but that is not directly related to your PR, hue should be in float instead of double.


const size_type nb_domains = subdomain_indices_.size();
double i = 0;
i = -1;
for (Indices::iterator it = subdomain_indices_.begin(),
end = subdomain_indices_.end(); it != end; ++it, i += 1.)
{
double hue = c.hueF() + 1. / double(nb_domains) * i;
if (hue > 1) { hue -= 1.; }
colors_subdomains[*it] = QColor::fromHsvF(hue, c.saturationF(), c.valueF());
}
const size_type nb_patch_indices = surface_patch_indices_.size();
i = 0;
double patch_hsv_value = fmod(c.valueF() + .5, 1.);
for (Indices::iterator it = surface_patch_indices_.begin(),
end = surface_patch_indices_.end(); it != end; ++it, i += 1.)
{
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);
}

for (std::unordered_map<int, int>::iterator it = visible_surface_patch_to_subdomain.begin(),
end = visible_surface_patch_to_subdomain.end(); it != end; ++it)
if (use_subdomain_colors)
{
colors[it->first] = colors_subdomains[it->second];
for (std::unordered_map<int, int>::iterator it = visible_surface_patch_to_subdomain.begin(),
end = visible_surface_patch_to_subdomain.end(); it != end; ++it)
{
colors[it->first] = colors_subdomains[it->second];
}
}
}

Expand Down Expand Up @@ -1526,6 +1531,12 @@ Scene_triangulation_3_item::setColor(QColor c)
}
}

void
Scene_triangulation_3_item::setUseSubdomainColors(bool b)
{
d->use_subdomain_colors = b;
}

void Scene_triangulation_3_item::show_grid(bool b)
{
d->is_grid_shown = b;
Expand Down
1 change: 1 addition & 0 deletions Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ using namespace CGAL::Three;


void setColor(QColor c) Q_DECL_OVERRIDE;
void setUseSubdomainColors(bool use_subdomain_colors);

void invalidateOpenGLBuffers() Q_DECL_OVERRIDE;

Expand Down