From 0a1ecead083a1493576bc4ea854c2ea5b4a20da0 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Sun, 6 Dec 2015 18:44:05 +0100 Subject: [PATCH] Do not use a std::set to find the at most 8 different labels --- CGAL_ImageIO/include/CGAL/Image_3.h | 55 ++++++++++++++++++----------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/CGAL_ImageIO/include/CGAL/Image_3.h b/CGAL_ImageIO/include/CGAL/Image_3.h index e1846e174ab..e50b50b2eed 100644 --- a/CGAL_ImageIO/include/CGAL/Image_3.h +++ b/CGAL_ImageIO/include/CGAL/Image_3.h @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -445,42 +446,56 @@ Image_3::labellized_trilinear_interpolation(const Coord_type& x, const int k1 = (int)(lx); const int i2 = i1 + 1; const int j2 = j1 + 1; - const int k2 = k1 + 1; - std::set labels; - labels.insert(((Image_word_type*)image()->data)[(i1 * dimy + j1) * dimx + k1]); - labels.insert(((Image_word_type*)image()->data)[(i1 * dimy + j1) * dimx + k2]); - labels.insert(((Image_word_type*)image()->data)[(i1 * dimy + j2) * dimx + k1]); - labels.insert(((Image_word_type*)image()->data)[(i1 * dimy + j2) * dimx + k2]); - labels.insert(((Image_word_type*)image()->data)[(i2 * dimy + j1) * dimx + k1]); - labels.insert(((Image_word_type*)image()->data)[(i2 * dimy + j1) * dimx + k2]); - labels.insert(((Image_word_type*)image()->data)[(i2 * dimy + j2) * dimx + k1]); - labels.insert(((Image_word_type*)image()->data)[(i2 * dimy + j2) * dimx + k2]); + CGAL::cpp11::array index; + index[0] = (i1 * dimy + j1) * dimx + k1; + index[1] = index[0] + 1; + index[2] = (i1 * dimy + j2) * dimx + k1; + index[3] = index[2] + 1; + index[4] = (i2 * dimy + j1) * dimx + k1; + index[5] = index[4] + 1; + index[6] = (i2 * dimy + j2) * dimx + k1; + index[7] = index[6] + 1; + + CGAL::cpp11::array labels; + + labels[0] = ((Image_word_type*)image()->data)[index[0]]; + int lc = 1; + for(int lci=1; lci<8; ++lci){ + bool found = false; + Image_word_type iwt = ((Image_word_type*)image()->data)[index[lci]]; + for(int lcj=0; lcj < lc; ++lcj){ + if(iwt == labels[lcj]){ + found = true; + break; + } + } + if(found) continue; + labels[lc] = iwt; + ++lc; + } CGAL_HISTOGRAM_PROFILER( "Number of labels around a vertex, Image_3::labellized_trilinear_interpolation()", - static_cast(labels.size())); + static_cast(lc)); - if(labels.size() == 1) { - return *(labels.begin()); + if(lc == 1) { + return labels[0]; } - + typedef ImageIO::Indicator Indicator; double best_value = 0.; Image_word_type best = 0; - for(typename std::set::const_iterator - label_it = labels.begin(), - end = labels.end(); - label_it != end; ++label_it) + BOOST_FOREACH(Image_word_type iwt, labels) { const double r = trilinear_interpolation( - x, y, z, value_outside, Indicator(*label_it)); + x, y, z, value_outside, Indicator(iwt)); CGAL_assertion(r >= 0.); CGAL_assertion(r <= 1.); if(r > best_value) { - best = *label_it; + best = iwt; best_value = r; } }