hit_matrix_graph.cpp
来自「ncbi源码」· C++ 代码 · 共 719 行 · 第 1/2 页
CPP
719 行
/* * =========================================================================== * PRODUCTION $Log: hit_matrix_graph.cpp,v $ * PRODUCTION Revision 1000.3 2004/06/01 21:10:56 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.11 * PRODUCTION * =========================================================================== *//* $Id: hit_matrix_graph.cpp,v 1000.3 2004/06/01 21:10:56 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/ncbistl.hpp>#include <gui/opengl/glhelpers.hpp>#include <gui/graph/igraph_utils.hpp>#include <gui/widgets/hit_matrix/hit_matrix_graph.hpp>#include <FL/Fl.H>#include <math.h>BEGIN_NCBI_SCOPECHitElemGlyph::CHitElemGlyph(): m_ColorIndex(-1), m_bSelected(false){}CHitElemGlyph::CHitElemGlyph(const CHitElemDataAdapter& hit_elem): m_HitElem(hit_elem), m_ColorIndex(-1), m_bSelected(false){}void CHitElemGlyph::GetModelRect(TModelRect& rc) const{ rc.Init(m_HitElem.GetSubjectStart(), m_HitElem.GetQueryStart()); TSeqPos size = 1 + m_HitElem.GetLength(); rc.SetSize(size, size);}void CHitElemGlyph::Render(CGlPane& pane, ERenderingPass what){ TModelUnit x1 = 0.5 + m_HitElem.GetSubjectStart(); TModelUnit y1 = 0.5 + m_HitElem.GetQueryStart(); TModelUnit l = m_HitElem.GetLength(); TModelUnit x2 = x1 + l; TModelUnit y2 = y1 + l; switch(what) { case eEndPoints: case eHitElemLines: { glVertex2d(x1, y1); glVertex2d(x2, y2); }; break; case eProjLines: { TModelUnit left = min(x1, pane.GetVisibleRect().Left()); TModelUnit bottom = min(y1, pane.GetVisibleRect().Bottom()); glVertex2d(x1, y1); glVertex2d(left, y1); glVertex2d(left, y2); glVertex2d(x2, y2); glVertex2d(x1, y1); glVertex2d(x1, bottom); glVertex2d(x2, bottom); glVertex2d(x2, y2); }; break; default: break; }}void CHitElemGlyph::StartVertex(){ TModelUnit x1 = 0.5 + m_HitElem.GetSubjectStart(); TModelUnit y1 = 0.5 + m_HitElem.GetQueryStart(); glVertex2d(x1, y1);}void CHitElemGlyph::EndVertex(){ TModelUnit l = m_HitElem.GetLength(); TModelUnit x1 = 0.5 + m_HitElem.GetSubjectStart() + l; TModelUnit y1 = 0.5 + m_HitElem.GetQueryStart() + l; glVertex2d(x1, y1);}inline double square(double x) { return pow(x, 2); }double CHitElemGlyph::GetDistPixels(CGlPane& pane, const TVPPoint& pt) const{ TModelUnit x1 = 0.5 + m_HitElem.GetSubjectStart(); TModelUnit y1 = 0.5 + m_HitElem.GetQueryStart(); TVPPoint p1 = pane.Project(x1, y1); TModelUnit l = m_HitElem.GetLength(); TModelUnit x2 = x1 + l; TModelUnit y2 = y1 + l; TVPPoint p2 = pane.Project(x2, y2); double alpha = atan2((double)(p2.Y() - p1.Y()), (double)(p2.X() - p1.X())); double max_proj = sqrt( square(p2.Y() - p1.Y()) + square(p2.X() - p1.X())); double beta = atan2((double)(pt.Y() - p1.Y()), (double)(pt.X() - p1.X())); double hyp = sqrt( square(pt.Y() - p1.Y()) + square(pt.X() - p1.X())); double angle = beta - alpha; double proj = hyp * cos(angle); if(proj >= 0 && proj <= max_proj) { // projection point is on hit double ortho_d = fabs( hyp * sin(angle)); return ortho_d; } else { // calculate min of distances to hit's ends double d2 = sqrt( square(pt.Y() - p2.Y()) + square(pt.X() - p2.X())); return min(hyp, d2); }}bool CHitElemGlyph::InRect(CGlPane& pane, const TVPRect& rc) const{ TModelUnit x1 = 0.5 + m_HitElem.GetSubjectStart(); TModelUnit y1 = 0.5 + m_HitElem.GetQueryStart(); TVPPoint p1 = pane.Project(x1, y1); if(rc.PtInRect(p1)) { TModelUnit l = m_HitElem.GetLength(); TModelUnit x2 = x1 + l; TModelUnit y2 = y1 + l; TVPPoint p2 = pane.Project(x2, y2); return rc.PtInRect(p2); } return false;}////////////////////////////////////////////////////////////////////////////////// CHitGlyphCHitGlyph::CHitGlyph(const CHitDataAdapter* p_hit): m_pHit(p_hit){ _ASSERT(m_pHit); // create Elem glyphs size_t size = p_hit->GetElemsCount(); m_Elems.reserve(size); for( size_t i = 0; i < size; i++ ) { CHitElemDataAdapter elem = p_hit->GetElem(i); if(elem.GetQueryStart() >=0 && elem.GetSubjectStart() >= 0 ) { // not gap - create glyph m_Elems.push_back(CHitElemGlyph(elem)); } }}CHitGlyph::TElemGlyphCont& CHitGlyph::GetElems(){ return m_Elems;}void CHitGlyph::SetColorIndex(int index){ NON_CONST_ITERATE(TElemGlyphCont, it, m_Elems) { it->SetColorIndex(index); }}void CHitGlyph::Render(CGlPane& pane, CHitElemGlyph::ERenderingPass what){ int size = m_Elems.size(); switch(what) { case CHitElemGlyph::eConnectionLines: { for( int i = 0; i < size - 1; ) { m_Elems[i].EndVertex(); m_Elems[++i].StartVertex(); } }; break; default: { for( int i = 0; i < size; i++ ) { m_Elems[i].Render(pane, what); } }; //default }// switch}////////////////////////////////////////////////////////////////////////////////// CHitMatrixGraphstatic float kHitAlpha = 1.0;CHitMatrixGraph::CHitMatrixGraph(): m_DefaultColor(0.25f, 0.25f, 0.25f, kHitAlpha), m_SelColor(0.5f, 0.5f, 1.0f, 1.0f), m_HighLightColor(0.8f, 0.8f, 1.0f, 0.5), m_PathColor(0.2f, 0.2f, 0.2f, 1.0f), m_ProjLinesColor(0.8f, 0.8f, 1.0f, 0.25f), m_ProjBackColor(0.8f, 0.8f, 1.0f, 0.25f), m_pHost(NULL), m_pPane(NULL), m_State(eIdle){ CreateColorTable(32);}CHitMatrixGraph::~CHitMatrixGraph(){ DeleteGlyphs();}void CHitMatrixGraph::DeleteGlyphs(){ destroy_and_erase_elems(m_vGlyphs);}void CHitMatrixGraph::CreateGlyph(const CHitDataAdapter* p_hit_elem){ m_vGlyphs.push_back(new CHitGlyph(p_hit_elem));}void CHitMatrixGraph::Render(CGlPane& pane){ pane.OpenOrtho(); x_RenderPath(pane); x_RenderSelection(pane); x_RenderHits(pane); pane.Close(); x_RenderEventHandler(pane);}void CHitMatrixGraph::x_RenderHits(CGlPane& pane){ glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_LINE_SMOOTH); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); // draw Hit Element Lines glColorC(x_GetColorByIndex(m_CurrColorIndex)); glLineWidth(1.5f); glBegin(GL_LINES); NON_CONST_ITERATE(THitGlyphVector, it, m_vGlyphs) { // for each Hit CHitGlyph::TElemGlyphCont& elems = (*it)->GetElems(); // for each Hit Element NON_CONST_ITERATE(CHitGlyph::TElemGlyphCont, itE, elems) { if(itE->IsSelected()) { glColorC(m_SelColor); m_CurrColorIndex = -2; } else { int ind = itE->GetColorIndex(); if(ind != m_CurrColorIndex) { m_CurrColorIndex = ind; glColorC(x_GetColorByIndex(m_CurrColorIndex)); } } itE->Render(pane, CHitElemGlyph::eHitElemLines); } } glEnd(); glDisable(GL_LINE_SMOOTH); // draw connecting lines between Hit Elements glColorC(m_DefaultColor); glLineWidth(1.0f); glEnable(GL_LINE_STIPPLE); glLineStipple(1, 0x5555); glBegin(GL_LINES); NON_CONST_ITERATE(THitGlyphVector, it, m_vGlyphs) { (*it)->Render(pane, CHitElemGlyph::eConnectionLines); } glEnd(); glDisable(GL_LINE_STIPPLE);}void CHitMatrixGraph::x_RenderPath(CGlPane& pane){ glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_LINE_SMOOTH); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); glLineWidth(6.0f); glColor4d(0.8, 0.8, 0.8, 0.5); //### glBegin(GL_LINES); NON_CONST_ITERATE(TPathCont, it, m_Paths) { // for each Hit TPath& path = *it; // for each Hit Elem in the path NON_CONST_ITERATE(TPath, itE, path) { if(! (*itE)->IsSelected()) { int ind = (*itE)->GetColorIndex(); const CGlColor* pC = & x_GetColorByIndex(ind); glColor4d(pC->GetRed(), pC->GetGreen(), pC->GetBlue(), 0.25); (*itE)->Render(pane, CHitElemGlyph::eHitElemLines); } } } // draw connecting lines NON_CONST_ITERATE(TPathCont, it, m_Paths) { // for each Hit TPath& path = *it; // for each Hit Elem in the path TPath::const_iterator it1 = path.begin(); TPath::const_iterator it2 = ++it1; while( it2 != path.end() ) { (*it1)->EndVertex(); (*it2)->StartVertex(); it1 = it2; it2++; } } glEnd();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?