From b8324d2a502321d40ba1fb5afc29428ea741e1c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Tayeb?= Date: Tue, 8 Jun 2010 15:17:34 +0000 Subject: [PATCH] Add colors to dihedral angle histogram. --- Mesh_3/demo/Mesh_3/Scene_c3t3_item.cpp | 27 ++++++++++++++++++++++---- Mesh_3/demo/Mesh_3/Scene_c3t3_item.h | 1 + 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Mesh_3/demo/Mesh_3/Scene_c3t3_item.cpp b/Mesh_3/demo/Mesh_3/Scene_c3t3_item.cpp index dda39886829..1948c7bdc1b 100644 --- a/Mesh_3/demo/Mesh_3/Scene_c3t3_item.cpp +++ b/Mesh_3/demo/Mesh_3/Scene_c3t3_item.cpp @@ -325,6 +325,9 @@ Scene_c3t3_item::build_histogram() max_size = (std::max)(max_size,*it); } + // colored histogram + int j = 0; + // draw int i=left_margin; for ( std::vector::iterator it = histo_data.begin(), end = histo_data.end() ; @@ -333,7 +336,11 @@ Scene_c3t3_item::build_histogram() int line_height = std::ceil(static_cast(drawing_height) * static_cast(*it)/static_cast(max_size)); - painter.drawRect(i, drawing_height+top_margin-line_height, cell_width, line_height); + painter.fillRect(i, + drawing_height+top_margin-line_height, + cell_width, + line_height, + get_histogram_color(j++)); } // draw bottom horizontal line @@ -349,12 +356,11 @@ Scene_c3t3_item::build_histogram() const int max_tr_width = 2*((histo_data.size()-std::floor(max_value))*cell_width + left_margin); const int tr_y = drawing_height + top_margin + text_margin; - if ( min_value < 5 ) { painter.setPen(Qt::red); } - else { painter.setPen(Qt::darkGreen); } - + painter.setPen(get_histogram_color(min_value)); QRect min_text_rect (0, tr_y, min_tr_width, text_height); painter.drawText(min_text_rect, Qt::AlignCenter, tr("%1").arg(min_value,0,'f',1)); + painter.setPen(get_histogram_color(max_value)); QRect max_text_rect (width - max_tr_width, tr_y, max_tr_width, text_height); painter.drawText(max_text_rect, Qt::AlignCenter, tr("%1").arg(max_value,0,'f',1)); } @@ -419,6 +425,19 @@ create_histogram(const C3t3& c3t3, double& min_value, double& max_value) } +QColor +Scene_c3t3_item::get_histogram_color(const double v) const +{ + if ( v < 5 ) { return Qt::red; } + else if ( v < 10 ) { return QColor(215,108,0); } + else if ( v < 15 ) { return QColor(138,139,0); } + else if ( v < 165 ) { return Qt::darkGreen; } + else if ( v < 170 ) { return QColor(138,139,1); } + else if ( v < 175 ) { return QColor(215,108,0); } + else /* 175