phylo_tree_radial.cpp
来自「ncbi源码」· C++ 代码 · 共 206 行
CPP
206 行
/* * =========================================================================== * PRODUCTION $Log: phylo_tree_radial.cpp,v $ * PRODUCTION Revision 1000.1 2004/06/01 21:11:43 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.7 * PRODUCTION * =========================================================================== *//* $Id: phylo_tree_radial.cpp,v 1000.1 2004/06/01 21:11:43 gouriano Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information * * This software/database is a "United States Government Work" under the * terms of the United States Copyright Act. It was written as part of * the author's official duties as a United States Government employee and * thus cannot be copyrighted. This software/database is freely available * to the public for use. The National Library of Medicine and the U.S. * Government have not placed any restriction on its use or reproduction. * * Although all reasonable efforts have been taken to ensure the accuracy * and reliability of the software and data, the NLM and the U.S. * Government do not and cannot warrant the performance or results that * may be obtained by using this software or data. The NLM and the U.S. * Government disclaim all warranties, express or implied, including * warranties of performance, merchantability or fitness for any particular * purpose. * * Please cite the author in any work or product based on this material. * * =========================================================================== * * Authors: Vladimir Tereshkov * * File Description: * */#include <ncbi_pch.hpp>#include <corelib/ncbistl.hpp>#include <gui/opengl/glhelpers.hpp>#include <gui/graph/igraph_utils.hpp>#include <gui/widgets/phylo_tree/phylo_tree_render.hpp>#include <gui/widgets/phylo_tree/phylo_tree_radial.hpp>#include <FL/Fl.H>#include <math.h>BEGIN_NCBI_SCOPECPhyloRadial::CPhyloRadial(){ }CPhyloRadial::~CPhyloRadial(){}void CPhyloRadial::x_Layout(CPhyloTreeDataSource& ds){ Int4 leafs = ds.GetSize(); Int4 width = ds.GetWidth(); m_xStep = (m_DimX - m_LeftMargin - m_RightMargin) / width; m_yStep = (m_DimY - m_TopMargin - m_BottomMargin) / (leafs-1); m_Radius = sqrt(m_xStep*m_xStep + m_yStep*m_yStep)/2; m_StartDegree = 0.0; m_ParentDegree = 0.0; if (ds.GetNormDistance() > 0){ //m_NormDistance = m_Radius / ds.GetNormDistance(false); m_NormDistance = (m_DimX - m_LeftMargin - m_RightMargin) / ds.GetNormDistance(); } x_Calculate(ds.GetTree()); // changing raster - x_Calculate for shure changed size in unpredictable way TModelRect newRect = ds.GetBoundRect(); m_RasterRect.Init(newRect.Left() - m_RightMargin, newRect.Top() - m_TopMargin, newRect.Right() + m_RightMargin, newRect.Bottom() + m_BottomMargin); }void CPhyloRadial::x_Render(CGlPane& pane, CPhyloTreeDataSource& ds){ pane.OpenOrtho(); x_DrawTree( ds.GetTree() ); pane.Close(); }void CPhyloRadial:: x_Calculate(CPhyloTreeNode * node){ if (!node->GetParent()){ // root node->XY().first = m_DimX / 2; node->XY().second = m_DimY / 2; node->SetAngle(0.); } else { node->XY().first = node->GetParent()->GetValue()->XY().first; node->XY().second = node->GetParent()->GetValue()->XY().second; // annulus wedge degree // double awd = min(node->GetAnnWedge(), // acos((m_Radius * (node->IDX().first-1)) / (m_Radius * node->IDX().first)) * 2 ); // that is for sure good place for thinking double awd = node->GetAnnWedge(); // start degree if (node == *node->GetParent()->SubNodeBegin()){ m_StartDegree = node->GetParent()->GetValue()->GetAngle() - node->GetParent()->GetValue()->GetAnnWedge()/2.0; } // setting angle and position for this vertex double angle = m_StartDegree + (awd / 2.0); node->SetAngle(angle); if (m_bDistMode){ m_Radius = node->GetDistance() * m_NormDistance; } node->XY().first += m_Radius * cos(angle); node->XY().second += m_Radius * sin(angle); m_StartDegree += awd; } if (!node->IsLeaf()) { for(CPhyloTreeNode::TNodeList_I it = node->SubNodeBegin(); it != node->SubNodeEnd(); it++ ) { x_Calculate((*it)->GetValue()); } } }void CPhyloRadial :: x_DrawTree(CPhyloTreeNode * node){ // label if (m_pLabelFont && node->IsLeaf()){ CGlPoint<int> labelPos(node->GetValue()->XY().first, node->GetValue()->XY().second); m_Label.Render(*m_pPane, labelPos, node->GetLabel(), node->GetSelected(), (node->GetAngle() < -1.57 || node->GetAngle()>1.57)); } // drawing leaf node if (node->GetParent()){ x_RenderLine(node->GetParent()->GetValue()->XY().first + m_LineWidth, node->GetParent()->GetValue()->XY().second, node->GetValue()->XY().first, node->GetValue()->XY().second, m_LineWidth, node->GetSelected()?m_LineSelColor:m_LineColor, node->GetSelected()?m_LineSelHiColor:m_LineHiColor); } for(CPhyloTreeNode::TNodeList_I it = node->SubNodeBegin(); it != node->SubNodeEnd(); it++ ) x_DrawTree((*it)->GetValue()); x_RenderNode(node->GetValue()->XY().first, node->GetValue()->XY().second, m_NodeSize, node->GetSelected()?m_NodeSelColor:m_NodeColor);} void CPhyloRadial :: x_CountLeafs(CPhyloTreeNode * node, Int4 & lfCount){ if (node->IsLeaf()) lfCount++; for (CPhyloTreeNode::TNodeList_I it = node->SubNodeBegin(); it != node->SubNodeEnd(); it++) x_CountLeafs((*it)->GetValue(), lfCount); }string CPhyloRadial::GetDescription(void){ return "Radial Tree";}END_NCBI_SCOPE/* * =========================================================================== * $Log: phylo_tree_radial.cpp,v $ * Revision 1000.1 2004/06/01 21:11:43 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.7 * * Revision 1.7 2004/05/21 22:27:54 gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.6 2004/05/06 19:42:21 tereshko * Rendering improvements * * Revision 1.5 2004/04/28 19:27:10 tereshko * Added support for distances rendering * * Revision 1.4 2004/04/20 21:57:19 tereshko * Major rendering, labeling and performance improvements * * Revision 1.3 2004/04/13 20:28:53 tereshko * Numerous renderers improvements * * Revision 1.2 2004/04/01 21:47:25 tereshko * Code clean-up * * Revision 1.1 2004/03/02 18:29:37 tereshko * Added radial tree layout * * =========================================================================== */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?