void VisualClusterTree::SetNodeColorStyle(const QString& style, const QColor& color) { Log::Inst().Debug("VisualClusterTree::SetNodeColorStyle(...)"); if(!m_activeSystem || !m_tree) return; if(style == "Single colour") { m_nodeColorStyle = VisualNode::SINGLE_COLOR; SetNodeColor(color); return; } else if(style == "Propogate continuous") m_nodeColorStyle = VisualNode::PROPOGATE_CONTINUOUS_COLOR; else if(style == "Propogate weighted") m_nodeColorStyle = VisualNode::PROPOGATE_WEIGHTED_COLOR; else if(style == "Propogate discrete") m_nodeColorStyle = VisualNode::PROPOGATE_DISCRETE_COLOR; // set node colors QList<VisualNode*> postOrderNodes = m_tree->PostOrder(); if(postOrderNodes.size() == 1) return; // there is only a root node foreach(VisualNode* node, postOrderNodes) { QColor nodeColor; if(node->IsLeaf()) { // set color of node based on legend Sample sample; if(!m_activeSystem->GetSamples()->GetSample(node->GetName(), sample)) Log::Inst().Error("Invalid sample specified setting node colour: " + node->GetName()); nodeColor = sample.GetColor(); } else { // set color of node based on color of children QList<VisualNode*> children = node->GetChildren(); if(m_nodeColorStyle == VisualNode::PROPOGATE_DISCRETE_COLOR) { nodeColor = children.at(0)->GetColor(); for(int j = 0; j < children.size(); ++j) { if(children.at(j)->GetColor() != nodeColor) nodeColor = Qt::black; } } else if(m_nodeColorStyle == VisualNode::PROPOGATE_CONTINUOUS_COLOR) { float red = 0.0f, green = 0.0f, blue = 0.0f; for(int j = 0; j < children.size(); ++j) { QColor color = children.at(j)->GetColor(); red += color.redF(); green += color.greenF(); blue += color.blueF(); } nodeColor.setRedF(red / children.size()); nodeColor.setGreenF(green / children.size()); nodeColor.setBlueF(blue / children.size()); } else // m_nodeColorStyle == VisualNode::PROPOGATE_WEIGHTED_COLOR { float red = 0.0f, green = 0.0f, blue = 0.0f; uint totalWeight = 0; for(int j = 0; j < children.size(); ++j) { uint weight = children.at(j)->GetWeightedNumberOfSeqs(); totalWeight += weight; QColor color = children.at(j)->GetColor(); red += color.redF() * weight; green += color.greenF() * weight; blue += color.blueF() * weight; } nodeColor.setRedF(red / totalWeight); nodeColor.setGreenF(green / totalWeight); nodeColor.setBlueF(blue / totalWeight); } } node->SetColor(nodeColor); node->update(); }