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

生物技术

开发平台:

C/C++

  1. /*
  2.  * ===========================================================================
  3.  * PRODUCTION $Log: vector_object.cpp,v $
  4.  * PRODUCTION Revision 1000.2  2004/06/01 21:04:32  gouriano
  5.  * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.9
  6.  * PRODUCTION
  7.  * ===========================================================================
  8.  */
  9. /*  $Id: vector_object.cpp,v 1000.2 2004/06/01 21:04:32 gouriano Exp $
  10.  * ===========================================================================
  11.  *
  12.  *                            PUBLIC DOMAIN NOTICE
  13.  *               National Center for Biotechnology Information
  14.  *
  15.  *  This software / database is a "United States Government Work" under the
  16.  *  terms of the United States Copyright Act.  It was written as part of
  17.  *  the author's official duties as a United States Government employee and
  18.  *  thus cannot be copyrighted.  This software / database is freely available
  19.  *  to the public for use. The National Library of Medicine and the U.S.
  20.  *  Government have not placed any restriction on its use or reproduction.
  21.  *
  22.  *  Although all reasonable efforts have been taken to ensure the accuracy
  23.  *  and reliability of the software and data, the NLM and the U.S.
  24.  *  Government do not and cannot warrant the performance or results that
  25.  *  may be obtained by using this software or data. The NLM and the U.S.
  26.  *  Government disclaim all warranties, express or implied, including
  27.  *  warranties of performance, merchantability or fitness for any particular
  28.  *  purpose.
  29.  *
  30.  *  Please cite the author in any work or product based on this material.
  31.  *
  32.  * ===========================================================================
  33.  *
  34.  * Authors:  Peter Meric
  35.  *
  36.  * File Description:
  37.  *   CPVecObj - vector objects - point, polygon, text
  38.  *   CPVecPoint
  39.  *   CPVecLine
  40.  *   CPVecPolygon
  41.  *   CPVecText
  42.  *
  43.  */
  44. #include <ncbi_pch.hpp>
  45. #include <gui/print/vector_object.hpp>
  46. BEGIN_NCBI_SCOPE
  47. CPVecObj::CPVecObj()
  48. {
  49. }
  50. CPVecObj::~CPVecObj()
  51. {
  52. }
  53. CPVecPoint::CPVecPoint(const float* buffer)
  54.     : m_X(buffer[0]),
  55.     m_Y(buffer[1]),
  56.     m_Z(buffer[2]),
  57. m_Color(CRgbaColor(buffer + 3, 4))
  58. {
  59. }
  60. CPVecPoint::~CPVecPoint()
  61. {
  62. }
  63. const CRgbaColor& CPVecPoint::GetColor(void) const
  64. {
  65.     return m_Color;
  66. }
  67. unsigned int CPVecPoint::GetNumPoints(void) const
  68. {
  69.     return 1;
  70. }
  71. bool CPVecPoint::IsFlatColored(void) const
  72. {
  73.     return true;
  74. }
  75. void CPVecPoint::PrintTo(CNcbiOstream& strm, short flags) const
  76. {
  77.     bool need_space = false;
  78.     if (flags & eCoordX) {
  79.         strm << m_X;
  80.         need_space = true;
  81.     }
  82.     if (flags & eCoordY) {
  83.         if (need_space) {
  84.             strm << " ";
  85.         }
  86.         strm << m_Y;
  87.         need_space = true;
  88.     }
  89.     if (flags & eCoordZ) {
  90.         if (need_space) {
  91.             strm << " ";
  92.         }
  93.         strm << m_Z;
  94.     }
  95. }
  96. inline CNcbiOstream& operator<<(CNcbiOstream& strm, const CPVecPoint& p)
  97. {
  98.     p.PrintTo(strm);
  99.     return strm;
  100. }
  101. CPVecLine::CPVecLine(const float* buffer)
  102. : m_P1(buffer), m_P2(buffer + CPVecPoint::kVertexSize)
  103. {
  104. }
  105. CPVecLine::~CPVecLine()
  106. {
  107. }
  108. pair<CPVecPoint, CPVecPoint> CPVecLine::GetPoints(void) const
  109. {
  110.     return make_pair(m_P1, m_P2);
  111. }
  112. unsigned int CPVecLine::GetNumPoints(void) const
  113. {
  114.     return 2;
  115. }
  116. bool CPVecLine::IsFlatColored(void) const
  117. {
  118.     return true;
  119. }
  120. void CPVecLine::PrintTo(CNcbiOstream& strm, short flags) const
  121. {
  122.     strm << '[';
  123.     m_P1.PrintTo(strm, flags);
  124.     strm << ", ";
  125.     m_P2.PrintTo(strm, flags);
  126.     strm << ']';
  127. }
  128. CPVecPolygon::CPVecPolygon(int num_vertices, const float* buffer)
  129. : m_FlatColored(true)
  130. {
  131.     m_Points.reserve(num_vertices);
  132.     CRgbaColor c;
  133.     for (int i = 0;  i < num_vertices;  ++i) {
  134.         CRef<CPVecPoint> p(new CPVecPoint(buffer));
  135.         if (i == 0) {
  136.             c = p->GetColor();
  137.         } else {
  138.             if ( !(c == p->GetColor()) ) {
  139.                 m_FlatColored = false;
  140.             }
  141.         }
  142.         m_Points.push_back(p);
  143.         buffer += CPVecPoint::kVertexSize;
  144.     }
  145. }
  146. CPVecPolygon::~CPVecPolygon()
  147. {
  148. }
  149. unsigned int CPVecPolygon::GetNumPoints(void) const
  150. {
  151.     return (unsigned int) m_Points.size();
  152. }
  153. bool CPVecPolygon::IsFlatColored(void) const
  154. {
  155.     return m_FlatColored;
  156. }
  157. CPVecPolygon::iterator CPVecPolygon::begin(void)
  158. {
  159.     return m_Points.begin();
  160. }
  161. CPVecPolygon::const_iterator CPVecPolygon::begin(void) const
  162. {
  163.     return m_Points.begin();
  164. }
  165. CPVecPolygon::iterator CPVecPolygon::end(void)
  166. {
  167.     return m_Points.end();
  168. }
  169. CPVecPolygon::const_iterator CPVecPolygon::end(void) const
  170. {
  171.     return m_Points.end();
  172. }
  173. CPVecPolygon::reverse_iterator CPVecPolygon::rbegin(void)
  174. {
  175.     return m_Points.rbegin();
  176. }
  177. CPVecPolygon::const_reverse_iterator CPVecPolygon::rbegin(void) const
  178. {
  179.     return m_Points.rbegin();
  180. }
  181. CPVecPolygon::reverse_iterator CPVecPolygon::rend(void)
  182. {
  183.     return m_Points.rend();
  184. }
  185. CPVecPolygon::const_reverse_iterator CPVecPolygon::rend(void) const
  186. {
  187.     return m_Points.rend();
  188. }
  189. inline CNcbiOstream& operator<<(CNcbiOstream& strm, const CPVecLine& l)
  190. {
  191.     l.PrintTo(strm);
  192.     return strm;
  193. }
  194. CPVecText::CPVecText(const string& text,
  195.                      float position[4],
  196.                      const CRgbaColor& color,
  197.                      const string& font)
  198. : m_Text(text), m_Color(color), m_Font(font)
  199. {
  200.     for (int i = 0;  i < 4;  ++i) {
  201.         m_Position[i] = position[i];
  202.     }
  203. }
  204. CPVecText::~CPVecText()
  205. {
  206. }
  207. string CPVecText::GetText(void) const
  208. {
  209.     return m_Text;
  210. }
  211. const float* CPVecText::GetPosition(void) const
  212. {
  213.     return m_Position;
  214. }
  215. const CRgbaColor& CPVecText::GetColor(void) const
  216. {
  217.     return m_Color;
  218. }
  219. string CPVecText::GetFont(void) const
  220. {
  221.     return m_Font;
  222. }
  223. END_NCBI_SCOPE
  224. /*
  225.  * ===========================================================================
  226.  * $Log: vector_object.cpp,v $
  227.  * Revision 1000.2  2004/06/01 21:04:32  gouriano
  228.  * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.9
  229.  *
  230.  * Revision 1.9  2004/05/21 22:27:50  gorelenk
  231.  * Added PCH ncbi_pch.hpp
  232.  *
  233.  * Revision 1.8  2004/01/27 18:45:51  dicuccio
  234.  * Pass CRgbaColor by const reference
  235.  *
  236.  * Revision 1.7  2003/08/15 17:02:16  meric
  237.  * Updates include paths for print-related files from gui/utils to gui/print
  238.  *
  239.  * Revision 1.6  2003/06/19 01:00:27  dicuccio
  240.  * Minor reformatting change
  241.  *
  242.  * Revision 1.5  2003/06/18 17:25:39  meric
  243.  * Final phase of print reorg: remove dependence on gui/opengl and OpenGL
  244.  *
  245.  * Revision 1.4  2003/06/18 16:40:33  meric
  246.  * First phase of print reorg: remove dependence on gui/opengl and OpenGL
  247.  * except for class COpenGLPrintBuffer
  248.  *
  249.  * Revision 1.3  2003/06/16 19:21:20  meric
  250.  * Fixed member initialization order in c'tor to match declaration order
  251.  *
  252.  * Revision 1.2  2003/06/16 12:44:52  dicuccio
  253.  * Clean-up after initial commit
  254.  *
  255.  * Revision 1.1  2003 / 06 / 13 18:13:56  meric
  256.  * Initial version
  257.  *
  258.  *
  259.  * ===========================================================================
  260.  */