phylo_tree_rect_cladogram.cpp

来自「ncbi源码」· C++ 代码 · 共 310 行

CPP
310
字号
/* * =========================================================================== * PRODUCTION $Log: phylo_tree_rect_cladogram.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/01 21:11:48  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.9 * PRODUCTION * =========================================================================== *//*  $Id: phylo_tree_rect_cladogram.cpp,v 1000.1 2004/06/01 21:11:48 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_rect_cladogram.hpp>#include <FL/Fl.H>#include <math.h>BEGIN_NCBI_SCOPECPhyloRectCladogram::CPhyloRectCladogram(){  }CPhyloRectCladogram::~CPhyloRectCladogram(){}void  CPhyloRectCladogram::x_Layout(CPhyloTreeDataSource& ds){        CPhyloTreeNode * tree = ds.GetTree();            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);     if (ds.GetNormDistance() > 0){        m_NormDistance = (m_DimX - m_LeftMargin - m_RightMargin) / ds.GetNormDistance();    }    x_Calculate(ds.GetTree());    }void  CPhyloRectCladogram::x_Render(CGlPane& pane, CPhyloTreeDataSource& ds){        pane.OpenOrtho();        x_DrawTree(ds.GetTree());    pane.Close();   }void CPhyloRectCladogram:: x_Calculate(CPhyloTreeNode * node){        if (node->IsLeaf()) {                if (m_bDistMode){            node->XY().first  = m_LeftMargin + m_NormDistance * node->GetDistFromRoot();                       }        else {            node->XY().first  = (m_DimX - m_RightMargin);                                  // all leafs on the right        }        node->XY().second = (m_DimY - m_TopMargin - node->IDX().second * m_yStep);     // y coordinate         node->SetAngle(0); // for correct labeling    }    else {                for(CPhyloTreeNode::TNodeList_I  it = node->SubNodeBegin();  it != node->SubNodeEnd(); it++ )  x_Calculate((*it)->GetValue());                         CPhyloTreeNode::TNodeList_I fst = node->SubNodeBegin();        CPhyloTreeNode::TNodeList_I lst = node->SubNodeEnd();         lst--;                double yf = (*fst)->GetValue()->XY().second;        double yl = (*lst)->GetValue()->XY().second;                               if (m_bDistMode){                        node->XY().first  = m_LeftMargin + m_NormDistance * node->GetDistFromRoot();                       }        else {            node->XY().first  = (m_LeftMargin + node->IDX().first * m_xStep);        }            node->XY().second = (yl + (yf - yl)/2);                }   }void CPhyloRectCladogram:: x_DrawTree(CPhyloTreeNode * node){       if (node->IsLeaf()) {         // label        if (m_pLabelFont) {            CGlPoint<int> labelPos(node->GetValue()->XY().first, node->GetValue()->XY().second);            m_Label.Render(*m_pPane, labelPos, node->GetLabel(), node->GetSelected());            //x_RenderText(node->GetValue()->XY().first, node->GetValue()->XY().second, node->GetLabel());        }                    // drawing leaf node                             x_RenderLine(node->GetParent()->GetValue()->XY().first + m_LineWidth, node->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);               x_RenderNode(node->GetValue()->XY().first, node->GetValue()->XY().second, m_NodeSize,  node->GetSelected()?m_NodeSelColor:m_NodeColor);    }    else {        // drawing internal node                           CPhyloTreeNode::TNodeList_I fst = node->SubNodeBegin();        CPhyloTreeNode::TNodeList_I lst = node->SubNodeEnd();         lst--;        double ratio = m_pPane->GetScaleY()/m_pPane->GetScaleX();            // vertical line        x_RenderLine(node->GetValue()->XY().first, (*fst)->GetValue()->XY().second - m_LineWidth * ratio,                     node->GetValue()->XY().first, (*lst)->GetValue()->XY().second + m_LineWidth * ratio, m_LineWidth, node->GetSelected()?m_LineSelColor:m_LineColor, node->GetSelected()?m_LineSelHiColor:m_LineHiColor);                // horizontal line                double xleft = node->GetParent()?node->GetParent()->GetValue()->XY().first:m_LeftMargin;        bool   bSel  = (node->GetSelected() && (node->GetParent() && node->GetParent()->GetValue()->GetSelected()));               x_RenderLine(xleft + m_LineWidth, node->GetValue()->XY().second,                     node->GetValue()->XY().first + m_LineWidth, node->GetValue()->XY().second,m_LineWidth, bSel?m_LineSelColor:m_LineColor, bSel?m_LineSelHiColor:m_LineHiColor);                // drawing top corner                x_DrawCorner(node->GetValue()->XY().first, (*fst)->GetValue()->XY().second, eTop,    node->GetSelected()?m_LineSelColor:m_LineColor, node->GetSelected()?m_LineSelHiColor:m_LineHiColor);                // bottom corner        x_DrawCorner(node->GetValue()->XY().first, (*lst)->GetValue()->XY().second, eBottom, node->GetSelected()?m_LineSelColor:m_LineColor, node->GetSelected()?m_LineSelHiColor:m_LineHiColor);                        // middle on parent        if (node->GetParent() && (node!=*(node->GetParent()->SubNodeBegin()) && node!=*(--node->GetParent()->SubNodeEnd()))){            x_DrawCorner(xleft, node->GetValue()->XY().second, eMiddle, node->GetParent()->GetValue()->GetSelected()?m_LineSelColor:m_LineColor, node->GetParent()->GetValue()->GetSelected()?m_LineSelHiColor:m_LineHiColor);                }                //  node itself        x_RenderNode(node->GetValue()->XY().first, node->GetValue()->XY().second, m_NodeSize,   node->GetSelected()?m_NodeSelColor:m_NodeColor);        // draw childs         for(CPhyloTreeNode::TNodeList_I  it = node->SubNodeBegin();  it != node->SubNodeEnd(); it++ )  {            x_DrawTree((*it)->GetValue());                             }           }}    void  CPhyloRectCladogram::x_DrawCorner(double x, double y, ECorner corner, CGlColor color1, CGlColor color2){    // reset line width    glEnable(GL_BLEND);    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);      glLineWidth(1.0);            glShadeModel(GL_SMOOTH);    glEnable(GL_LINE_SMOOTH);    double ratio = m_pPane->GetScaleY()/m_pPane->GetScaleX();      double dx = m_LineWidth;    double dy = m_LineWidth * ratio * ((corner==eBottom || corner==eMiddle)? 1: -1);         if (corner==eTop || corner==eBottom){        glBegin(GL_QUADS);        glColor4fv(color2.GetGlColor());        glVertex2d(x, y+dy);         glColor4fv(color1.GetGlColor());        glVertex2d(x+dx,    y+dy);                 glColor4fv(color2.GetGlColor());        glVertex2d(x+dx, y);         glVertex2d(x, y);         glColor4fv(color2.GetGlColor());        glVertex2d(x, y);         glVertex2d(x+dx, y);         glColor4fv(color1.GetGlColor());        glVertex2d(x+dx, y-dy);         glVertex2d(x, y-dy);         glColor4fv(color2.GetGlColor());        glVertex2d(x, y+dy);         glVertex2d(x, y);         glColor4fv(color1.GetGlColor());        glVertex2d(x-dx, y);         glVertex2d(x-dx, y+dy);                 glEnd();        glBegin(GL_TRIANGLES);            glColor4fv(color2.GetGlColor());                glVertex2d(x, y);         glColor4fv(color1.GetGlColor());        glVertex2d(x, y-dy);         glVertex2d(x-dx, y);                glEnd();        glBegin(GL_LINES);            glColor4fv(color1.GetGlColor());                glVertex2d(x+dx, y-dy); glVertex2d(x, y-dy);            glVertex2d(x, y-dy);    glVertex2d(x-dx, y);                glVertex2d(x-dx, y);    glVertex2d(x-dx, y+dy);        glEnd();    }    else { // middle joint        glBegin(GL_QUADS);        glColor4fv(color2.GetGlColor());        glVertex2d(x+dx, y);         glVertex2d(x, y);         glVertex2d(x, y+dy);         glColor4fv(color1.GetGlColor());        glVertex2d(x+dx, y+dy);         glBegin(GL_QUADS);        glColor4fv(color2.GetGlColor());        glVertex2d(x, y-dy);         glVertex2d(x, y);         glVertex2d(x+dx, y);                 glColor4fv(color1.GetGlColor());        glVertex2d(x+dx, y-dy);         glEnd();    }    glDisable(GL_BLEND);    }string CPhyloRectCladogram::GetDescription(void){    return "Rectangle Cladogram";}END_NCBI_SCOPE/* * =========================================================================== * $Log: phylo_tree_rect_cladogram.cpp,v $ * Revision 1000.1  2004/06/01 21:11:48  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.9 * * Revision 1.9  2004/05/21 22:27:54  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.8  2004/05/06 19:42:21  tereshko * Rendering improvements * * Revision 1.7  2004/04/28 19:27:10  tereshko * Added support for distances rendering * * Revision 1.6  2004/04/20 21:57:19  tereshko * Major rendering, labeling and performance improvements * * Revision 1.5  2004/04/13 20:28:53  tereshko * Numerous renderers improvements * * Revision 1.4  2004/04/01 21:47:25  tereshko * Code clean-up * * Revision 1.3  2004/02/24 21:43:45  tereshko * Added support for rendering joints * * Revision 1.2  2004/02/23 22:52:27  tereshko * Rendering Improvements * * Revision 1.1  2004/02/13 17:05:08  tereshko * Phylogenetic Tree Widget initial revision * * =========================================================================== */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?