trace_graph.cpp

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

CPP
926
字号
/* * =========================================================================== * PRODUCTION $Log: trace_graph.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/01 21:07:29  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.9 * PRODUCTION * =========================================================================== *//*  $Id: trace_graph.cpp,v 1000.1 2004/06/01 21:07:29 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:  Andrey Yazhuk * * File Description: * */#include <ncbi_pch.hpp>#include <corelib/ncbistd.hpp>#include <gui/widgets/aln_multiple/trace_graph.hpp>#include <gui/opengl/glhelpers.hpp>#include <gui/types.hpp>#include <math.h>BEGIN_NCBI_SCOPECTraceGraphProperties::CTraceGraphProperties():   m_SignalStyle(eCurve),    m_ConfGraphState(eExpanded),    m_SignalGraphState(eExpanded),    m_bReverseColors(true){}CTraceGraphProperties&      CTraceGraphProperties::operator=(const CTraceGraphProperties& orig){    m_SignalStyle = orig.m_SignalStyle;    m_ConfGraphState = orig.m_ConfGraphState;    m_SignalGraphState = orig.m_SignalGraphState;    return *this;}/////////////////////////////////////////////////////////////////////////////////// CTraceGraphconst static int kGradColors = 32;CTraceGraph::CTraceGraph(const CBioseq_Handle& handle, bool b_neg_strand):   m_DataProxy(handle, b_neg_strand),    m_pData(NULL){}CTraceGraph::~CTraceGraph(){    Destroy();}bool    CTraceGraph::HasData() const{    return m_DataProxy.HasData();}bool    CTraceGraph::IsCreated() const{    return (m_pData != NULL);}bool    CTraceGraph::Create(){    m_pData = m_DataProxy.LoadData();    if(m_pData) {        SetConfGraphState(CTraceGraphProperties::eCollapsed);            bool b_ch = m_pData->GetSamplesCount() > 0;        SetSignalGraphState(b_ch    ? CTraceGraphProperties::eExpanded                                     : CTraceGraphProperties::eHidden);                m_vSignalColors.resize(4 * kGradColors);        double k = 1.0 / kGradColors;            for( int j = 0; j < kGradColors; j++ )  {            float v = 1.0f - k * j;            m_vSignalColors[j] = CGlColor(1.0f, v, v); //red            m_vSignalColors[kGradColors + j] = CGlColor(v, 1.0f, v); //green            m_vSignalColors[2 * kGradColors + j] = CGlColor(v, v, 1.0f); //blue            m_vSignalColors[3 * kGradColors + j] = CGlColor(0.5f * (1 + v), v, 0.5f * (1 + v)); //purple                }        m_pData->CalculateMax();        return true;    } else return false;}void    CTraceGraph::Destroy(){    if(m_pData) {        delete m_pData;        m_pData = NULL;        m_vSignalColors.clear();    }}const IAlnRowGraphProperties*     CTraceGraph::GetProperties() const{    return &m_Props;}void    CTraceGraph::SetProperties(IAlnRowGraphProperties* props){    CTraceGraphProperties* trace_props =         dynamic_cast<CTraceGraphProperties*>(props);    if(trace_props) {        m_Props = *trace_props;    }}void    CTraceGraph::SetConfGraphState(EGraphState state){    m_Props.m_ConfGraphState = state;}void    CTraceGraph::SetSignalGraphState(EGraphState state){    m_Props.m_SignalGraphState = state;}// vertical spacing between graph area border and graphstatic const int kGraphOffsetY = 1;static const int kConfGraphPrefH = 24;static const int kSignalGraphPrefH = 40;static const int kCollapsedGraphH = 11;int     CTraceGraph::GetPreferredHeight()    const{    int h = x_GetConfGraphH();    h += x_GetSignalGraphH();    h += 2;        return h;}int     CTraceGraph::x_GetConfGraphH() const{    switch(m_Props.m_ConfGraphState)    {    case CTraceGraphProperties::eCollapsed: return kCollapsedGraphH;     case CTraceGraphProperties::eExpanded: return kConfGraphPrefH;    case CTraceGraphProperties::eHidden: return 0;    }    return 0;}int     CTraceGraph::x_GetSignalGraphH() const{    switch(m_Props.m_SignalGraphState)    {    case CTraceGraphProperties::eCollapsed: return kCollapsedGraphH;     case CTraceGraphProperties::eExpanded: return kSignalGraphPrefH;    case CTraceGraphProperties::eHidden: return 0;    }        return 0;}// renders both Confidence graph and Chromatogramsvoid    CTraceGraph::Render(CGlPane& pane, int y, int h, const TChunkVec& chunks){    CGlAttrGuard AttrGuard(GL_ENABLE_BIT  | GL_COLOR_BUFFER_BIT | GL_HINT_BIT                             | GL_LINE_SMOOTH | GL_POLYGON_MODE | GL_LINE_BIT);             int conf_h = x_GetConfGraphH();    int sig_h = x_GetSignalGraphH();    int top_y = y;        pane.OpenOrtho();    x_RenderContour(pane, top_y, sig_h, conf_h + sig_h, chunks);  // render background            if(m_Props.m_SignalGraphState == CTraceGraphProperties::eExpanded)    {        if(pane.GetScaleX() < 1.0)   { // render signal graph            if(m_Props.m_SignalStyle == CTraceGraphProperties::eCurve)   { // render curves                glEnable(GL_BLEND);                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);                    glEnable(GL_LINE_SMOOTH);                glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);                glLineWidth(0.5);                x_RenderSignalGraph(pane, top_y, sig_h, chunks);            } else {            // render intensity bands                pane.Close();                pane.OpenPixels();                glDisable(GL_BLEND);                glDisable(GL_LINE_SMOOTH);                glLineWidth(1.0);                x_RenderIntensityGraphs(pane, top_y, sig_h, chunks);                                                        pane.Close();                pane.OpenOrtho();            }                }        top_y += sig_h;    }            if(m_Props.m_ConfGraphState == CTraceGraphProperties::eExpanded)   {        // render confidence graph        x_RenderConfGraph(pane, top_y, conf_h, chunks);            }        pane.Close();    }// Functor for coordinate translation align <->seqstruct SChunkTranslator{public:    SChunkTranslator()    : m_pSeqRange(NULL), m_pAlnRange(NULL), m_bNegative(false)    {    }        void Init(const TSignedSeqRange& seq_range,               const TSignedSeqRange& aln_range, bool negative)    {                m_pSeqRange = &seq_range;        m_pAlnRange = &aln_range;        m_bNegative = negative;        _ASSERT(m_pSeqRange->GetLength() == m_pAlnRange->GetLength());        }    inline TSignedSeqPos GetAlnPosFromSeqPos(TSignedSeqPos seq_pos)    {        _ASSERT(m_pSeqRange  && m_pAlnRange);        TSignedSeqPos seq_off = seq_pos - m_pSeqRange->GetFrom();        if(m_bNegative)    {          return m_pAlnRange->GetTo() - seq_off;        } else return seq_off + m_pAlnRange->GetFrom();    }    inline double GetAlnPosFromSeqPos(double seq_pos)    {        _ASSERT(m_pSeqRange  && m_pAlnRange);        double seq_off = seq_pos - m_pSeqRange->GetFrom();        if(m_bNegative)    {          return m_pAlnRange->GetTo() - seq_off;        } else return seq_off + m_pAlnRange->GetFrom();    }    inline TSignedSeqPos GetSeqPosFromAlnPos(TSignedSeqPos aln_pos)    {        _ASSERT(m_pSeqRange  && m_pAlnRange);        TSignedSeqPos aln_off = aln_pos - m_pAlnRange->GetFrom();        if(m_bNegative)    {          return m_pSeqRange->GetTo() - aln_off;        } else return aln_off + m_pSeqRange->GetFrom();    }    inline double GetSeqPosFromAlnPos(double aln_pos)    {        _ASSERT(m_pSeqRange  && m_pAlnRange);        double aln_off = aln_pos - m_pAlnRange->GetFrom();        if(m_bNegative)    {          return m_pSeqRange->GetTo() - aln_off;        } else return aln_off + m_pSeqRange->GetFrom();    }protected:    const TSignedSeqRange* m_pSeqRange;    const TSignedSeqRange* m_pAlnRange;    bool    m_bNegative;};void    CTraceGraph::x_RenderContour(CGlPane& pane, int y, int top_h, int total_h,                                      const TChunkVec& chunks){    glDisable(GL_BLEND);    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);    glColor3d(0.9, 0.9, 0.9);        TModelUnit offset_x = pane.GetOffsetX();    TModelUnit y1 = y;    TModelUnit y2 = y + top_h - 1;

⌨️ 快捷键说明

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