scatter_graph.cpp
来自「ncbi源码」· C++ 代码 · 共 188 行
CPP
188 行
/* * =========================================================================== * PRODUCTION $Log: scatter_graph.cpp,v $ * PRODUCTION Revision 1000.1 2004/06/01 20:49:37 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.5 * PRODUCTION * =========================================================================== *//* $Id: scatter_graph.cpp,v 1000.1 2004/06/01 20:49:37 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 <gui/graph/scatter_graph.hpp>BEGIN_NCBI_SCOPE////////////////////////////////////////////////////////////////////////////////// class CScatterGraph CScatterGraph::CScatterGraph(): m_MarkerType(CGraphDotMarker::eRect), m_bDrawLines(true){}CGraphDotMarker::EMarkerType CScatterGraph::GetMarkerType() const{ return m_MarkerType;}void CScatterGraph::SetMarkerType(CGraphDotMarker::EMarkerType Type){ m_MarkerType = Type;}bool CScatterGraph::IsDrawLines() const{ return m_bDrawLines;}void CScatterGraph::SetDrawLines(bool bDraw){ m_bDrawLines = bDraw;}bool CScatterGraph::SetDataSource(IGraphDataSource* pDS){ IScatterDataSource* pScatterDS = dynamic_cast<IScatterDataSource*>(pDS); bool bOk = pScatterDS!= NULL; CGraphBase::SetDataSource(bOk ? pDS : NULL); CalculateLimits(); return bOk;}const TModelRect& CScatterGraph::GetLimits() const{ return m_Limits;}void CScatterGraph::Render(CGlPane* pPane){ _ASSERT(pPane); IScatterDataSource* pSource = GetScatterDataSource(); if(pPane && pSource) { pPane->OpenOrtho(); try { glColorC(m_Color); double MarkerW = pPane->UnProjectWidth(7); double MarkerH = pPane->UnProjectHeight(7); IScatterDataSource* pSource = GetScatterDataSource(); INumericArray* pArX = pSource->GetXArray(); INumericArray* pArY = pSource->GetYArray(); int ElemN = pArX->GetSize(); // draw lines if (m_bDrawLines) { glBegin(GL_LINE_STRIP); for( int i=0; i<ElemN; i++ ) { glVertex2d(pArX->GetElem(i), pArY->GetElem(i)); } glEnd(); } //draw Markers if (m_MarkerType != CGraphDotMarker::eNone) { TModelRect rcHit(pPane->GetVisibleRect()); rcHit.Inflate(MarkerW, MarkerH); for( int i=0; i<ElemN; i++ ) { TModelUnit mX = pArX->GetElem(i); TModelUnit mY = pArY->GetElem(i); if (rcHit.PtInRect(mX, mY)) CGraphDotMarker::RenderMarker(mX, mY, MarkerW, MarkerH, m_MarkerType); } } } catch(...) { //need to trace it } pPane->Close(); }}void CScatterGraph ::CalculateLimits(){ IScatterDataSource* pSource = GetScatterDataSource(); bool bEmpty = true; if(pSource) { INumericArray* pArX = pSource->GetXArray(); INumericArray* pArY = pSource->GetYArray(); int ElemN = pArX->GetSize(); if(ElemN>0) { bEmpty = false; TModelUnit MinX, MaxX, MinY, MaxY; MinX = MaxX = pArX->GetElem(0); MinY = MaxY = pArY->GetElem(0); for( int i=1; i<ElemN; i++ ) { TModelUnit X = pArX->GetElem(i); TModelUnit Y = pArY->GetElem(i); MinX = min(MinX, X); MaxX = max(MaxX, X); MinY = min(MinY, Y); MaxY = max(MaxY, Y); } m_Limits.Init(MinX, MinY, MaxX, MaxY); } } if(bEmpty) m_Limits.Init(0, 0, 1, 1);}END_NCBI_SCOPE/* * =========================================================================== * $Log: scatter_graph.cpp,v $ * Revision 1000.1 2004/06/01 20:49:37 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.5 * * Revision 1.5 2004/05/21 22:27:42 gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.4 2003/08/11 16:10:57 yazhuk * Compilation fixes for GCC * * Revision 1.3 2003/08/10 14:11:47 dicuccio * Added makefiles for Unix projects; compilation fixes for gcc * * Revision 1.2 2003/08/08 15:59:36 yazhuk * Comments added * * =========================================================================== */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?