glcolortable.hpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:4k
源码类别:

生物技术

开发平台:

C/C++

  1. /*
  2.  * ===========================================================================
  3.  * PRODUCTION $Log: glcolortable.hpp,v $
  4.  * PRODUCTION Revision 1000.1  2004/06/01 19:49:40  gouriano
  5.  * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6
  6.  * PRODUCTION
  7.  * ===========================================================================
  8.  */
  9. #ifndef GUI_OPENGL___GL_COLOR_TABLE__HPP
  10. #define GUI_OPENGL___GL_COLOR_TABLE__HPP
  11. /*  $Id: glcolortable.hpp,v 1000.1 2004/06/01 19:49:40 gouriano Exp $
  12.  * ===========================================================================
  13.  *
  14.  *                            PUBLIC DOMAIN NOTICE
  15.  *               National Center for Biotechnology Information
  16.  *
  17.  *  This software/database is a "United States Government Work" under the
  18.  *  terms of the United States Copyright Act.  It was written as part of
  19.  *  the author's official duties as a United States Government employee and
  20.  *  thus cannot be copyrighted.  This software/database is freely available
  21.  *  to the public for use. The National Library of Medicine and the U.S.
  22.  *  Government have not placed any restriction on its use or reproduction.
  23.  *
  24.  *  Although all reasonable efforts have been taken to ensure the accuracy
  25.  *  and reliability of the software and data, the NLM and the U.S.
  26.  *  Government do not and cannot warrant the performance or results that
  27.  *  may be obtained by using this software or data. The NLM and the U.S.
  28.  *  Government disclaim all warranties, express or implied, including
  29.  *  warranties of performance, merchantability or fitness for any particular
  30.  *  purpose.
  31.  *
  32.  *  Please cite the author in any work or product based on this material.
  33.  *
  34.  * ===========================================================================
  35.  *
  36.  * Authors:  Mike DiCuccio
  37.  *
  38.  * File Description:
  39.  *    Incremental and mutually contrastive color table generator.
  40.  */
  41. #include <corelib/ncbistd.hpp>
  42. #include <gui/opengl/glcolor.hpp>
  43. /** @addtogroup GUI_OPENGL
  44.  *
  45.  * @{
  46.  */
  47. BEGIN_NCBI_SCOPE
  48. class NCBI_GUIOPENGL_EXPORT CGlColorTable
  49. {
  50. public:
  51.     CGlColorTable();
  52.     CGlColorTable(int items, float min_color = 0.0f, float max_color = 1.0f);
  53.     void    SetMaxItems(int items);
  54.     void    SetMinColor(float f);
  55.     void    SetMinColor(unsigned char f);
  56.     void    SetMaxColor(float f);
  57.     void    SetMaxColor(unsigned char f);
  58.     CGlColor    GetColor(int i) const;
  59. private:
  60.     int m_MaxItems;
  61.     float m_ColorStep;
  62.     float m_MinColor;
  63.     float m_MaxColor;
  64.     float m_ColorDiff;
  65.     void x_CalcColorStep();
  66. };
  67. inline
  68. void CGlColorTable::SetMaxItems(int items)
  69. {
  70.     m_MaxItems = max(8, items);
  71.     x_CalcColorStep();
  72. }
  73. inline
  74. void CGlColorTable::SetMinColor(float f)
  75. {
  76.     m_MinColor = max(0.0f, f);
  77.     m_MinColor = min(1.0f, m_MinColor);
  78.     if (m_MaxColor < m_MinColor) {
  79.         std::swap(m_MaxColor, m_MinColor);
  80.     }
  81.     m_ColorDiff = m_MaxColor - m_MinColor;
  82.     x_CalcColorStep();
  83. }
  84. inline
  85. void CGlColorTable::SetMinColor(unsigned char c)
  86. {
  87.     SetMinColor(float (c) / 255.0f);
  88. }
  89. inline
  90. void CGlColorTable::SetMaxColor(float f)
  91. {
  92.     m_MaxColor = max(0.0f, f);
  93.     m_MaxColor = min(1.0f, m_MaxColor);
  94.     if (m_MaxColor < m_MinColor) {
  95.         std::swap(m_MaxColor, m_MinColor);
  96.     }
  97.     m_ColorDiff = m_MaxColor - m_MinColor;
  98.     x_CalcColorStep();
  99. }
  100. inline
  101. void CGlColorTable::SetMaxColor(unsigned char c)
  102. {
  103.     SetMinColor(float (c) / 255.0f);
  104. }
  105. inline
  106. void CGlColorTable::x_CalcColorStep()
  107. {
  108.     m_ColorStep = m_ColorDiff / m_MaxItems * 8;
  109. }
  110. END_NCBI_SCOPE
  111. /* @} */
  112. /*
  113.  * ===========================================================================
  114.  * $Log: glcolortable.hpp,v $
  115.  * Revision 1000.1  2004/06/01 19:49:40  gouriano
  116.  * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6
  117.  *
  118.  * Revision 1.6  2004/05/11 18:54:22  dicuccio
  119.  * Added doxygne modules info
  120.  *
  121.  * Revision 1.5  2003/09/29 15:20:07  dicuccio
  122.  * Deprecated gui/scope.hpp.  Merged gui/core/types.hpp into gui/types.hpp
  123.  *
  124.  * Revision 1.4  2003/01/15 20:57:01  dicuccio
  125.  * Must remember to recalculate color step if the bounds change
  126.  *
  127.  * Revision 1.3  2003/01/13 13:11:42  dicuccio
  128.  * Namespace clean-up.  Retired namespace gui -> converted to namespace ncbi.
  129.  * Moved all FLUID-generated code into namespace ncbi.
  130.  *
  131.  * Revision 1.2  2002/12/19 18:13:03  dicuccio
  132.  * Added export specifiers for Win32.
  133.  *
  134.  * Revision 1.1  2002/11/22 18:06:42  dicuccio
  135.  * Initial revision.
  136.  *
  137.  * ===========================================================================
  138.  */
  139. #endif  // GUI_OPENGL___GL_COLOR_TABLE__HPP