From 0734bc51df54c656e7e4823180f777596c901d4f Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Wed, 15 Mar 2017 10:41:50 +0100 Subject: [PATCH] Add initialization of colors for the Scene_surface_mesh_item --- .../demo/Polyhedron/Scene_polyhedron_item.cpp | 2 +- .../Polyhedron/Scene_surface_mesh_item.cpp | 25 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.cpp b/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.cpp index 13da8f5855c..038d78366c8 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.cpp @@ -32,6 +32,7 @@ #include #include "triangulate_primitive.h" +#include "Color_map.h" namespace PMP = CGAL::Polygon_mesh_processing; typedef Polyhedron::Traits Traits; @@ -875,7 +876,6 @@ Scene_polyhedron_item::~Scene_polyhedron_item() } } -#include "Color_map.h" void Scene_polyhedron_item_priv:: diff --git a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp index 2343d441bbb..3df77688098 100644 --- a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp @@ -1,5 +1,6 @@ #include "Scene_surface_mesh_item.h" +#include "Color_map.h" #include #include #include @@ -49,6 +50,8 @@ struct Scene_surface_mesh_item_priv{ } } + void initialize_colors(); + void initializeBuffers(CGAL::Three::Viewer_interface *) const; void addFlatData(Point, Kernel::Vector_3, CGAL::Color *) const; @@ -221,7 +224,7 @@ void Scene_surface_mesh_item_priv::compute_elements() smesh_->add_property_map("v:normal").first; SMesh::Property_map fnormals = - smesh_->add_property_map("v:normal").first; + smesh_->add_property_map("f:normal").first; CGAL::Polygon_mesh_processing::compute_face_normals(*smesh_,fnormals); typedef boost::graph_traits::face_descriptor face_descriptor; @@ -295,6 +298,9 @@ void Scene_surface_mesh_item_priv::compute_elements() has_fpatch_id = smesh_->property_map("f:patch_id").second; + if(has_fpatch_id && colors_.empty()){ + initialize_colors(); + } //compute the Flat data flat_vertices.clear(); flat_normals.clear(); @@ -404,6 +410,23 @@ void Scene_surface_mesh_item_priv::compute_elements() } QApplication::restoreOverrideCursor(); } + + +void Scene_surface_mesh_item_priv::initialize_colors() +{ + // Fill indices map and get max subdomain value + int max = 0; + int min = (std::numeric_limits::max)(); + BOOST_FOREACH(face_descriptor fd, faces(*smesh_)){ + max = (std::max)(max, fpatch_id_map[fd]); + min = (std::min)(min, fpatch_id_map[fd]); + } + + colors_.clear(); + compute_color_map(item->color(), (std::max)(0, max + 1 - min), + std::back_inserter(colors_)); +} + void Scene_surface_mesh_item_priv::initializeBuffers(CGAL::Three::Viewer_interface* viewer)const { SMesh::Property_map positions =