phylo_tree_render.cpp

来自「ncbi源码」· C++ 代码 · 共 529 行 · 第 1/2 页

CPP
529
字号
        glVertex2d(x2+dx, y2+dy); glVertex2d(x1+dx, y1+dy);        //glVertex2d(x1-dx, y1-dy); glVertex2d(x2-dx, y2-dy);             //glVertex2d(x2+dx, y2+dy); glVertex2d(x1+dx, y1+dy);         glEnd();    }    else {        glBegin(GL_LINES);                    glColor4fv(color1.GetGlColor());         glVertex2d(x1, y1);            glVertex2d(x2, y2);                 glEnd();       }          glDisable(GL_BLEND); }void   IPhyloTreeRenderer::x_RenderSpline(double x1, double y1, double x2, double y2){    m_Curve.SetPoint(0, CVect3<float>(x1, y1, 0.0f));    m_Curve.SetPoint(1, CVect3<float>(x1+10, y1+10, 0.0f));        m_Curve.SetPoint(2, CVect3<float>(x1+10, y1+10, 0.0f));        m_Curve.SetPoint(3, CVect3<float>(x2, y2, 0.0f));            m_Curve.Recalc();    m_Curve.Draw(CGlCurve<CCurveBezier>::eRender_Lines);}void IPhyloTreeRenderer::x_RenderNode(double x, double y, double size, CGlColor color){    double ratio = m_pPane->GetScaleY()/m_pPane->GetScaleX();      int num_lines = 20;       CGlColor col(color);    glBegin(GL_TRIANGLE_FAN);        for(int i =0;i<num_lines;i++){            double angle = i*2*3.14/num_lines;       col.Set(col.GetRed()+0.03, col.GetGreen()+0.03, col.GetBlue()+0.03, col.GetAlpha());      glColor4fv(col.GetGlColor());      glVertex2f(x+size*cos(angle), y-size*sin(angle)*ratio);          }    glEnd();    }CPhyloTreeNode * IPhyloTreeRenderer::x_TestForNode(CPhyloTreeNode * node){    CPhyloTreeNode * selNode = NULL;    int hit = m_NodeSize * 2;    int x1  = m_pPane->UnProjectX(m_StartPoint.X())-hit;    int y1  = m_pPane->UnProjectY(m_pHost->HMGH_GetVPPosByY(m_StartPoint.Y()))+hit;    int x2  = m_pPane->UnProjectX(m_StartPoint.X())+hit;    int y2  = m_pPane->UnProjectY(m_pHost->HMGH_GetVPPosByY(m_StartPoint.Y()))-hit;        if ((node->XY().first  >= x1 &&  node->XY().first  <=x2)&&        (node->XY().second >= y2 &&  node->XY().second <=y1)){        selNode = node;    }               if (!node->IsLeaf()) {                for(CPhyloTreeNode::TNodeList_I  it = node->SubNodeBegin();  it != node->SubNodeEnd(); it++ )  {                        if (!selNode) selNode = x_TestForNode((*it)->GetValue());                    }    }        return selNode;}bool IPhyloTreeRenderer::x_SelectByPoint(CPhyloTreeNode * node){    CPhyloTreeNode * selNode = x_TestForNode(node);    if (selNode) {        m_DS->SetSelection(selNode, true, true);        m_SelectedIDs.push_back(selNode->GetID());    }               m_Dlist.Invalidate();    return (selNode!=NULL);}bool IPhyloTreeRenderer::x_SelectByRect(CPhyloTreeNode * node){    int x1 = m_pPane->UnProjectX(m_StartPoint.X());    int y1 = m_pPane->UnProjectY(m_pHost->HMGH_GetVPPosByY(m_StartPoint.Y()));    int x2 = m_pPane->UnProjectX(m_DragPoint.X());    int y2 = m_pPane->UnProjectY(m_pHost->HMGH_GetVPPosByY(m_DragPoint.Y()));    bool bSel = false;    if (x1 > x2) swap(x1, x2);    if (y2 > y1) swap(y1, y2);        if ((node->XY().first  >= x1 &&  node->XY().first  <=x2)&&        (node->XY().second >= y2 &&  node->XY().second <=y1)){        m_DS->SetSelection(node, true, true);        m_SelectedIDs.push_back(node->GetID());        bSel = true;            }               if (!node->IsLeaf()) {                for(CPhyloTreeNode::TNodeList_I  it = node->SubNodeBegin();  it != node->SubNodeEnd(); it++ )  {                                                  x_SelectByRect((*it)->GetValue());        }    }        else if (!bSel){ // check for label, space for improvement here        CGlPoint<int>   ptNode(node->XY().first, node->XY().second);         CGlRect<int>    lblRect = m_Label.GetRect(*m_pPane, ptNode, node->GetLabel(), (node->GetAngle() < -1.57 ||  node->GetAngle()>1.57));        CGlRect<int>    selRect(x1, y2, x2, y1);        if (lblRect.Intersects(selRect)){            m_DS->SetSelection(node, true, true);            m_SelectedIDs.push_back(node->GetID());            bSel = true;                        }    }    m_Dlist.Invalidate();        return bSel;}int   IPhyloTreeRenderer::handle(CGUIEvent& event, CGlPane& pane){        m_pPane = &pane;    int res = 0;    switch(event.GetFLTKEvent())   {    case FL_PUSH: res =  x_OnMousePush(event); break;    case FL_DRAG: res =  x_OnMouseDrag(event); break;    case FL_RELEASE: res =  x_OnMouseRelease(event); break;    case FL_MOVE: res =  x_OnMouseMove(); break;    case FL_KEYDOWN: res =  x_OnKeyDown(); break;    case FL_KEYUP: res =  x_OnKeyUp(); break;    }    //m_pPane = NULL;    return res;}void IPhyloTreeRenderer::Layout(CPhyloTreeDataSource& ds){       x_Layout(ds);}void IPhyloTreeRenderer::Render(CGlPane& pane, CPhyloTreeDataSource& ds){        m_pPane = &pane;    m_DS    = &ds;            /*    if (m_Dlist.IsValid()) {		        m_Dlist.Call();                x_RenderSelection(pane);            } else {                CGlDisplayListCompile COMPILE(m_Dlist, CGlDisplayList::eCompileAndExecute);                    x_Render(pane, ds);            }     */    x_Render(pane, ds);            x_RenderSelection(pane); }bool    IPhyloTreeRenderer::TC_NeedTooltip(int x, int y){    m_StartPoint.m_X = x;  m_StartPoint.m_Y = y;    return (x_TestForNode(m_DS->GetTree())!=NULL);}string  IPhyloTreeRenderer::TC_GetTooltip(int& x, int& y, int& w, int& h){    m_StartPoint.m_X = x;  m_StartPoint.m_Y = y;    CPhyloTreeNode * hoverNode = x_TestForNode(m_DS->GetTree());            string ttText = "";    ttText += ("Node Name: " + (hoverNode->GetLabel().size()?hoverNode->GetLabel():string("No Name")) + "\n");    ttText += ("Distance : " + NStr::DoubleToString(hoverNode->GetDistance()));    return ttText;}void IPhyloTreeRenderer::SetSelectedIDs(const vector<int> & vect){        m_SelectedIDs.resize(vect.size());    copy(vect.begin(), vect.end(), m_SelectedIDs.begin());    m_DS->SetSelection(m_DS->GetTree(), false, true);                    for (vector<int>::const_iterator it=vect.begin(); it!=vect.end(); it++){        CPhyloTreeNode * node = m_DS->GetNode(*it);        if (node)   m_DS->SetSelection(node, true, true);                    }    m_pHost->HMGH_Redraw();}bool IPhyloTreeRenderer :: IsSelected(CPhyloTreeNode * node){   return (find(m_SelectedIDs.begin(), m_SelectedIDs.end(), node->GetID())!=m_SelectedIDs.end());}// default metricsconst double IPhyloTreeRenderer::GetDimX(void) {return 1000.0;}const double IPhyloTreeRenderer::GetDimY(void) {return 1000.0;}END_NCBI_SCOPE/* * =========================================================================== * $Log: phylo_tree_render.cpp,v $ * Revision 1000.2  2004/06/02 20:24:36  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.15 * * Revision 1.15  2004/06/02 16:39:28  tereshko * Fixed selections and popup behavior under windows * * Revision 1.14  2004/05/21 22:27:54  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.13  2004/05/11 20:53:12  tereshko * Work in progress * * Revision 1.12  2004/05/06 19:42:21  tereshko * Rendering improvements * * Revision 1.11  2004/04/28 19:27:10  tereshko * Added support for distances rendering * * Revision 1.10  2004/04/20 21:57:19  tereshko * Major rendering, labeling and performance improvements * * Revision 1.9  2004/04/14 20:34:00  tereshko * Fixed labels truncation * * Revision 1.8  2004/04/13 20:28:53  tereshko * Numerous renderers improvements * * Revision 1.7  2004/04/01 21:47:25  tereshko * Code clean-up * * Revision 1.6  2004/03/30 17:11:44  tereshko * Added support for events broadcasting * * Revision 1.5  2004/03/03 21:42:06  tereshko * Added tooltips support * * Revision 1.4  2004/03/02 18:29:38  tereshko * Added radial tree layout * * Revision 1.3  2004/02/23 22:52:27  tereshko * Rendering Improvements * * Revision 1.2  2004/02/17 23:44:41  tereshko * Changes due to integration into viewer * * Revision 1.1  2004/02/13 17:05:09  tereshko * Phylogenetic Tree Widget initial revision * * =========================================================================== */

⌨️ 快捷键说明

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