bbox.hpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:5k
- /*
- * ===========================================================================
- * PRODUCTION $Log: bbox.hpp,v $
- * PRODUCTION Revision 1000.1 2004/06/01 19:48:34 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6
- * PRODUCTION
- * ===========================================================================
- */
- #ifndef GUI_UTILS__BBOX_HPP
- #define GUI_UTILS__BBOX_HPP
- /* $Id: bbox.hpp,v 1000.1 2004/06/01 19:48:34 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: Peter Meric
- *
- * File Description:
- * CBBox - represents (and calculates) a bounding box
- *
- */
- #include <corelib/ncbistd.hpp>
- /** @addtogroup GUI_MATH
- *
- * @{
- */
- BEGIN_NCBI_SCOPE
- //
- // BBox represents a simple, rectangular bounding box
- //
- template <int N>
- class CBBox
- {
- public:
- enum { X, Y, Z };
- CBBox()
- : m_IsSet(false)
- {
- for (unsigned int i = 0; i < N; ++i) {
- lower[i] = upper[i] = 0.0f;
- }
- }
- virtual ~CBBox()
- {
- }
- void Add(const CBBox<N>& bbox)
- {
- Add(bbox.lower);
- Add(bbox.upper);
- }
- //
- // NumSets is the number of sets of points
- // Stride is the distance between the start of one set and the next
- //
- void Add(const float vals[N], int num_sets = 1, int stride = 0)
- {
- unsigned int offset = 0;
- while (num_sets-- > 0) {
- if (!m_IsSet) {
- for (unsigned int i = 0; i < N; ++i) {
- unsigned int idx = i + offset;
- lower[i] = upper[i] = vals[idx];
- }
- m_IsSet = true;
- }
- else {
- for (unsigned int i = 0; i < N; ++i) {
- unsigned int idx = i + offset;
- if (vals[idx] < lower[i]) {
- lower[i] = vals[idx];
- }
- else if (vals[idx] > upper[i]) {
- upper[i] = vals[idx];
- }
- }
- }
- offset += stride;
- }
- }
- pair<float, float> GetNthRange(unsigned int n) const
- {
- return make_pair(lower[n], upper[n]);
- }
- virtual void PrintTo(CNcbiOstream& strm) const
- {
- strm << '[';
- for (unsigned int i = 0; i < N; ++i) {
- if (i > 0) {
- strm << ", ";
- }
- strm << '(' << lower[i] << ", " << upper[i] << ')';
- }
- strm << ']';
- }
- private:
- bool m_IsSet;
- float lower[N], upper[N];
- };
- inline CNcbiOstream& operator<<(CNcbiOstream& strm, const CBBox<3>& bb)
- {
- bb.PrintTo(strm);
- return strm;
- }
- END_NCBI_SCOPE
- /* @} */
- /*
- * ===========================================================================
- * $Log: bbox.hpp,v $
- * Revision 1000.1 2004/06/01 19:48:34 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6
- *
- * Revision 1.6 2004/05/11 18:53:50 dicuccio
- * Added doxygen modules info
- *
- * Revision 1.5 2003/06/18 17:33:44 meric
- * Remove unnecessary includes
- *
- * Revision 1.4 2003/06/18 16:41:00 meric
- * First phase of print reorg: remove dependence on gui/opengl and OpenGL
- * except for class COpenGLPrintBuffer
- *
- * Revision 1.3 2003/06/16 15:55:58 dicuccio
- * Work-in-progress: everything compiles, still much reorganization to be done.
- * Moved generic functionality out of opengl/print/ and into gui/utils (print
- * options, print dialogs, etc.). Removed interactive state from CGlCanvas.
- * Added hook in CView for opening standard print dialog, and for generic print
- * handling.
- *
- * Revision 1.2 2003/06/16 12:46:21 dicuccio
- * Clean-up after initial commit
- *
- * Revision 1.1 2003/06/13 19:00:29 meric
- * Initial version
- *
- *
- * ===========================================================================
- */
- #endif // GUI_UTILS__BBOX_HPP