NCBI C++ ToolKit
compact_layout_policy.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: compact_layout_policy.cpp 34827 2016-02-17 00:59:08Z rudnev $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Liangshou Wu
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 #include <corelib/ncbiutil.hpp>
37 #include <corelib/ncbi_limits.hpp>
38 #include <math.h>
39 
41 
42 ///////////////////////////////////////////////////////////////////////////////
43 /// CCompactLayout
44 ///////////////////////////////////////////////////////////////////////////////
46 
48 {
49  return i1.second < i2.second;
50 }
51 
53 {
54  TModelUnit left = DBL_MAX;
55  TModelUnit right = 0.0;
56 
57  THeight height;
58  height[0.0] = 0.0;
60 
61  TObjectList objs_temp = objs;
62  objs_temp.sort(SGlyphBySeqSize::s_CompareCRefs);
63 
64  while ( !objs_temp.empty() ) {
65  TObjectList::iterator iter = objs_temp.begin();
66  while (iter != objs_temp.end()) {
67  CSeqGlyph* glyph = *iter;
69  glyph->GetRight() + m_MinDist);
70  if (range.GetFrom() < 0.0) {
71  range.SetFrom(0.0);
72  }
73  THeight::iterator f_iter = height.upper_bound(range.GetFrom());
74  TModelUnit h = -1.0;
75  TModelUnit upper = DBL_MAX;
76  if (f_iter == height.end()) {
77  h = height.rbegin()->second;
78  } else if ((upper = f_iter->first) >= range.GetTo()) {
79  h = (--f_iter)->second;
80  }
81  if (h >= 0.0) {
82  left = min(left, range.GetFrom());
83  right = max(right, range.GetTo());
84  glyph->SetTop(h + m_VertSpace);
85  height[range.GetFrom()] = h + m_VertSpace + glyph->GetHeight();
86  if (upper > range.GetTo()) {
87  height[range.GetTo()] = h;
88  }
89  iter = objs_temp.erase(iter);
90  } else {
91  ++iter;
92  }
93  }
94 
95  THeight::iterator i_pre = height.begin();
96  THeight::iterator i_curr = i_pre;
97  THeight::iterator i_next = i_pre;
98  ++i_next;
99  while (i_next != height.end()) {
100  while (i_next != height.end() &&
101  (i_curr->second > i_pre->second ||
102  i_curr->second > i_next->second)) {
103  i_pre = i_curr;
104  i_curr = i_next;
105  ++i_next;
106  }
107  if (i_next == height.end()) {
108  if (i_curr->second < i_pre->second) {
109  i_curr->second = i_pre->second;
110  }
111  break;
112  }
113  TModelUnit max = std::max<TModelUnit>(i_pre->second, i_next->second);
114  TModelUnit min = std::min<TModelUnit>(i_pre->second, i_next->second);
115  i_curr->second = i_curr->second == min ? max : min;
116  while (i_next != height.end() &&
117  i_curr->second <= i_next->second) {
118  i_pre = i_curr;
119  i_curr = i_next;
120  ++i_next;
121  }
122  }
123  i_next = i_curr = height.begin();
124  ++i_next;
125  while (i_next != height.end()) {
126  while (i_next != height.end() && i_curr->second != i_next->second) {
127  i_curr = i_next;
128  ++i_next;
129  }
130  if (i_next != height.end()) {
131  height.erase(i_next);
132  i_next = i_curr;
133  ++i_next;
134  }
135  }
136  }
137 
138  bound.m_Height =
139  std::max_element(height.begin(), height.end(), Height_Comparer)->second;
140  bound.m_X = left;
141  bound.m_Width = right - left;
142 }
143 
TSeqPos m_MinDist
The minimum distance we permit two items to be within, horizontally.
virtual void BuildLayout(CLayoutGroup &group, SBoundingBox &bound) const
Build layout for a list of layout objects.
CLayoutGroup is a container of CSeqGlyphs (layout objects).
const TObjectList & GetChildren() const
CLayoutGroup inline methods.
ILayoutPolicy::TObjectList TObjectList
class CSeqGlyph defines an interface that wraps a rectilinear abstract object.
Definition: seq_glyph.hpp:82
virtual TModelUnit GetRight() const
Definition: seq_glyph.hpp:603
virtual TModelUnit GetHeight() const
Definition: seq_glyph.hpp:587
virtual void SetTop(TModelUnit b)
Definition: seq_glyph.hpp:658
virtual TModelUnit GetLeft() const
Definition: seq_glyph.hpp:595
list< CRef< CSeqGlyph > > TObjectList
void erase(iterator pos)
Definition: map.hpp:167
container_type::iterator iterator
Definition: map.hpp:54
const_iterator begin() const
Definition: map.hpp:151
const_iterator end() const
Definition: map.hpp:152
const_iterator upper_bound(const key_type &key) const
Definition: map.hpp:155
container_type::value_type value_type
Definition: map.hpp:52
Definition: map.hpp:338
static bool Height_Comparer(THeight::value_type &i1, THeight::value_type &i2)
map< TModelUnit, TModelUnit > THeight
CCompactLayout.
GLdouble TModelUnit
Definition: gltypes.hpp:48
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
range(_Ty, _Ty) -> range< _Ty >
Useful/utility classes and methods.
T max(T x_, T y_)
T bound(T x_, T xlo_, T xhi_)
T min(T x_, T y_)
static bool s_CompareCRefs(const CRef< CSeqGlyph > &ref_obj1, const CRef< CSeqGlyph > &ref_obj2)
Definition: seq_glyph.hpp:467
Modified on Fri Dec 01 04:43:33 2023 by modify_doxy.py rev. 669887