phylo_tree_node.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:4k
源码类别:

生物技术

开发平台:

C/C++

  1. /*
  2.  * ===========================================================================
  3.  * PRODUCTION $Log: phylo_tree_node.cpp,v $
  4.  * PRODUCTION Revision 1000.1  2004/06/01 21:11:39  gouriano
  5.  * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.7
  6.  * PRODUCTION
  7.  * ===========================================================================
  8.  */
  9. /*  $Id: phylo_tree_node.cpp,v 1000.1 2004/06/01 21:11:39 gouriano Exp $
  10.  * ===========================================================================
  11.  *
  12.  *                            PUBLIC DOMAIN NOTICE
  13.  *               National Center for Biotechnology Information
  14.  *
  15.  *  This software/database is a "United States Government Work" under the
  16.  *  terms of the United States Copyright Act.  It was written as part of
  17.  *  the author's official duties as a United States Government employee and
  18.  *  thus cannot be copyrighted.  This software/database is freely available
  19.  *  to the public for use. The National Library of Medicine and the U.S.
  20.  *  Government have not placed any restriction on its use or reproduction.
  21.  *
  22.  *  Although all reasonable efforts have been taken to ensure the accuracy
  23.  *  and reliability of the software and data, the NLM and the U.S.
  24.  *  Government do not and cannot warrant the performance or results that
  25.  *  may be obtained by using this software or data. The NLM and the U.S.
  26.  *  Government disclaim all warranties, express or implied, including
  27.  *  warranties of performance, merchantability or fitness for any particular
  28.  *  purpose.
  29.  *
  30.  *  Please cite the author in any work or product based on this material.
  31.  *
  32.  * ===========================================================================
  33.  *
  34.  * Authors:  Vladimir Tereshkov
  35.  *
  36.  * File Description:
  37.  *
  38.  */
  39. #include <ncbi_pch.hpp>
  40. #include <gui/widgets/phylo_tree/phylo_tree_node.hpp>
  41. BEGIN_NCBI_SCOPE
  42. CPhyloTreeNode::CPhyloTreeNode()
  43. {    
  44.     m_ID       = -1;
  45.     m_Label    = "";
  46.     m_Distance = -1;
  47.     m_AnnWedge = 0;
  48.     m_Selected = false;
  49.     SetValue(this);
  50. }
  51. CPhyloTreeNode::CPhyloTreeNode(int id, string label, double dist)
  52. {
  53.     m_ID        = id;
  54.     m_Label     = label;
  55.     m_Distance  = dist;
  56.     m_Selected  = false;
  57.     SetValue(this);
  58. }
  59. CPhyloTreeNode::~CPhyloTreeNode()
  60. {
  61. }
  62. const string & CPhyloTreeNode::GetLabel(void) const
  63. {
  64.     return m_Label;
  65. }
  66. const double CPhyloTreeNode::GetDistance(void) const
  67. {
  68.     return m_Distance > 0 ? m_Distance : 0;
  69. }
  70. void CPhyloTreeNode::SetLabel(string label)
  71. {
  72.     m_Label = label;
  73. }
  74. void CPhyloTreeNode::SetDistance(double dist)
  75. {
  76.     m_Distance = dist;
  77. }
  78. Int4 CPhyloTreeNode::CountLeafs(void)
  79. {
  80.     Int4 lfCount = 0;
  81.     x_CountLeafs(this, lfCount);
  82.     return lfCount;   
  83. }
  84. void CPhyloTreeNode :: x_CountLeafs(CPhyloTreeNode * node, Int4 & lfCount)
  85. {     
  86.     if (node->IsLeaf()) lfCount++;    
  87.     for (CPhyloTreeNode::TNodeList_I  it = node->SubNodeBegin();  it != node->SubNodeEnd(); it++) x_CountLeafs((*it)->GetValue(), lfCount);    
  88. }
  89. const double    CPhyloTreeNode :: GetDistFromRoot(void) const
  90. {
  91.     double fullDist = GetDistance();
  92.     CPhyloTreeNode * node = GetValue();
  93.     
  94.     while (node->GetParent()) {
  95.         node = node->GetParent()->GetValue();
  96.         fullDist += node->GetDistance();
  97.     }
  98.     return fullDist;
  99. }
  100. END_NCBI_SCOPE
  101. /*
  102.  * ===========================================================================
  103.  * $Log: phylo_tree_node.cpp,v $
  104.  * Revision 1000.1  2004/06/01 21:11:39  gouriano
  105.  * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.7
  106.  *
  107.  * Revision 1.7  2004/05/21 22:27:54  gorelenk
  108.  * Added PCH ncbi_pch.hpp
  109.  *
  110.  * Revision 1.6  2004/04/28 19:27:10  tereshko
  111.  * Added support for distances rendering
  112.  *
  113.  * Revision 1.5  2004/04/20 21:57:19  tereshko
  114.  * Major rendering, labeling and performance improvements
  115.  *
  116.  * Revision 1.4  2004/03/30 17:11:44  tereshko
  117.  * Added support for events broadcasting
  118.  *
  119.  * Revision 1.3  2004/03/02 18:28:32  tereshko
  120.  * Added support for calculating annual vertex weight
  121.  *
  122.  * Revision 1.2  2004/02/17 23:44:41  tereshko
  123.  * Changes due to integration into viewer
  124.  *
  125.  * Revision 1.1  2004/02/13 17:05:03  tereshko
  126.  * Phylogenetic Tree Widget initial revision
  127.  *
  128.  * ===========================================================================
  129.  */